Archived
1
0

Spaces to tabs

This commit is contained in:
Sweet Bread 2022-11-06 18:21:21 +03:00
parent c163efd83d
commit 20a9a96dc7
16 changed files with 399 additions and 400 deletions

View File

@ -2,43 +2,43 @@ This project for me just for fun to not spending time for routine operations
1. std
- print
- str
- int
- [ ] float
- [ ] hex
- char
- bin
- nl
- exit
- str
- int
- ~~float~~
- ~~hex~~
- char
- bin
- nl
- exit
2. file
- open
- close
- content
- [ ] size
- [ ] next_line
- close
- content
- ~~size~~
- ~~next_line~~
3. path
- filename
- [ ] join
- [ ] is_dir
- [ ] is_file
- ~~join~~
- ~~is_dir~~
- ~~is_file~~
4. string
- copy
- len
- [ ] split
- [ ] replace
- [ ] find
- [ ] parse_int
- [ ] parse_float
- len
- ~~split~~
- ~~replace~~
- ~~find~~
- ~~parse_int~~
- ~~parse_float~~
5. network
- get_ip
- IP_to_str
- IP_to_str
6. dns
- send
- get_field
- get_field
7. [dnstoys](https://www.dns.toys/)
- myip
- [ ] weather and other
8. [ ] http
9. [ ] json
- ~~weather and other~~
8. ~~http~~
9. ~~json~~
<sup>A lot of shit code included</sup>

View File

@ -8,7 +8,7 @@ extrn print.nl
extrn exit
macro nl {
call print.nl
call print.nl
}
@ -18,16 +18,16 @@ str1 db "Hello world!", 0
section '.text' executable
_start:
push dword 123
call print.int
nl
push dword 123
call print.int
nl
push dword 123
call print.bin
nl
push dword 123
call print.bin
nl
push str1
call print.str
nl
push str1
call print.str
nl
call exit
call exit

View File

@ -8,4 +8,4 @@ main: ../../std.o
make -C ../../ std.o
clear:
rm main.o main
rm main.o main

Binary file not shown.

View File

@ -10,7 +10,7 @@ extrn exit
section '.strtab'
filename db "/home/sweetbread/headers", 0
filename db "makefile", 0
section '.bss' writeable
@ -19,21 +19,22 @@ file_ rd 1
section '.text' executable
_start:
push filename
call file.open
pop eax
mov [file_], eax
push dword [file_]
call print.str
call print.nl
call print.nl
push filename
call file.open
pop eax
mov [file_], eax
push dword [file_]
call print.str
call print.nl
call print.nl
push dword [file_]
call file.content
call print.str
push dword [file_]
call file.content
call print.str
call print.nl
push dword [file_]
call file.close
push dword [file_]
call file.close
call exit
call exit

Binary file not shown.

View File

@ -21,4 +21,3 @@ main: ../../file.o ../../std.o ../../path.o ../../string.o
clear:
rm main.o main

View File

@ -15,14 +15,14 @@ hostname db "google.com", 0
section '.text' executable
_start:
call dnstoys.myip
call print.str
call print.nl
call dnstoys.myip
call print.str
call print.nl
push hostname
call network.get_ip
call network.IP_to_str
call print.str
call print.nl
push hostname
call network.get_ip
call network.IP_to_str
call print.str
call print.nl
call exit
call exit

View File

@ -22,4 +22,4 @@ dnstoys.o:
fasm src/dnstoys.asm dnstoys.o
clear:
rm *.o
rm *.o

View File

@ -12,32 +12,32 @@ section '.strtab'
dnstoys db "dns.toys", 0
endpoints:
.ip db "ip", 0
.ip db "ip", 0
section '.bss' writeable
response rb 200
response rb 200
DNS_server sockaddr 00,53, ?,?,?,?
DNS_request dnsreq
section '.dnstoys.text'
myip:
push 0
prelude
push 0
prelude
push dnstoys
call network.get_ip
pop eax
mov eax, [eax]
mov [DNS_server+4], eax
push dnstoys
call network.get_ip
pop eax
mov eax, [eax]
mov [DNS_server+4], eax
push dword 200
push dword 200
push response
push DNS_server
push DNS_server
push endpoints.ip
call dns.send
call dns.send
push response
push dword 0
push response
push dword 0
call dns.get_field
pop eax
push eax
@ -50,8 +50,8 @@ myip:
@@:
add eax, 2*3+4+1
mov ebx, [ebp+2*4]
mov [ebp+4], ebx
mov [ebp+2*4], eax
mov ebx, [ebp+2*4]
mov [ebp+4], ebx
mov [ebp+2*4], eax
postlude
ret
ret

View File

@ -1,6 +1,6 @@
format ELF
public open as 'file.open'
public close as 'file.close'
public open as 'file.open'
public close as 'file.close'
public content as 'file.content'
include '../include/_file.inc'
@ -11,13 +11,13 @@ extrn path.filename
section '.strtab'
str1 db "File object ", 0
; str2 db " at "
str1 db "File object ", 0
; str2 db " at "
section '.bss' writeable
pointer rd 1
fd rd 1
fd rd 1
memory rd 1
sizes_ sizes
file_stat stat
@ -25,170 +25,169 @@ file_stat stat
section '.file.text' executable
open:
prelude
prelude
; open
mov eax, 5
mov ebx, [ebp+2*4]
mov ecx, O_RDONLY
mov edx, O_DIRECTORY
int 80h
; open
mov eax, 5
mov ebx, [ebp+2*4]
mov ecx, O_RDONLY
mov edx, O_DIRECTORY
int 80h
mov [fd], eax
mov [fd], eax
; fstat
mov eax, 108
mov ebx, [fd]
mov ecx, file_stat
int 80h
; fstat
mov eax, 108
mov ebx, [fd]
mov ecx, file_stat
int 80h
push str1
call string.len
pop eax
mov [sizes_.str1], al
push str1
call string.len
pop eax
mov [sizes_.str1], al
push dword [ebp+2*4]
call string.len
pop eax
mov [sizes_.full_filename], al
push dword [ebp+2*4]
call string.len
pop eax
mov [sizes_.full_filename], al
push dword [ebp+2*4]
call path.filename
call string.len
pop ebx
mov [sizes_.filename], bl
push dword [ebp+2*4]
call path.filename
call string.len
pop ebx
mov [sizes_.filename], bl
mov eax, [file_stat.off_t]
add al , [sizes_.str1]
add al , [sizes_.full_filename]
add al , [sizes_.filename]
add al , [sizes_.fd]
add al , [sizes_.all_size]
mov [memory], eax
push eax
mov eax, [file_stat.off_t]
add al , [sizes_.str1]
add al , [sizes_.full_filename]
add al , [sizes_.filename]
add al , [sizes_.fd]
add al , [sizes_.all_size]
mov [memory], eax
push eax
; mmap2
mov eax, 192
xor ebx, ebx
pop ecx
mov edx, PROT_READ
or edx, PROT_WRITE
mov esi, MAP_PRIVATE
or esi, MAP_ANONYMOUS
mov edi, -1
push ebp
xor ebp, ebp
int 80h
pop ebp
; mmap2
mov eax, 192
xor ebx, ebx
pop ecx
mov edx, PROT_READ
or edx, PROT_WRITE
mov esi, MAP_PRIVATE
or esi, MAP_ANONYMOUS
mov edi, -1
push ebp
xor ebp, ebp
int 80h
pop ebp
mov [pointer], eax
mov [pointer], eax
push str1
push eax
call string.copy
push str1
push eax
call string.copy
xor ebx, ebx
mov bl , [sizes_.str1]
add eax, ebx
mov ebx, [ebp+2*4]
push ebx
call path.filename
push eax
call string.copy
xor ebx, ebx
mov bl , [sizes_.str1]
add eax, ebx
mov ebx, [ebp+2*4]
push ebx
call path.filename
push eax
call string.copy
xor ebx, ebx
mov bl , [sizes_.filename]
add eax, ebx
inc eax
push dword [ebp+2*4]
push eax
call string.copy
xor ebx, ebx
mov bl , [sizes_.filename]
add eax, ebx
inc eax
push dword [ebp+2*4]
push eax
call string.copy
xor ebx, ebx
mov bl , [sizes_.full_filename]
add eax, ebx
inc eax
mov ebx, [fd]
mov [eax], ebx
xor ebx, ebx
mov bl , [sizes_.full_filename]
add eax, ebx
inc eax
mov ebx, [fd]
mov [eax], ebx
xor ebx, ebx
mov bl , [sizes_.fd]
add eax, ebx
mov ebx, [memory]
mov [eax], ebx
xor ebx, ebx
mov bl , [sizes_.fd]
add eax, ebx
mov ebx, [memory]
mov [eax], ebx
xor ebx, ebx
mov bl , [sizes_.all_size]
add eax, ebx
inc eax
push eax
xor ebx, ebx
mov bl , [sizes_.all_size]
add eax, ebx
inc eax
push eax
; read
mov eax, 3
mov ebx, [fd]
pop ecx
mov edx, [file_stat.off_t]
int 80h
; read
mov eax, 3
mov ebx, [fd]
pop ecx
mov edx, [file_stat.off_t]
int 80h
mov eax, [pointer]
mov [ebp+2*4], eax
mov eax, [pointer]
mov [ebp+2*4], eax
postlude
ret
postlude
ret
close:
prelude
prelude
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
add eax, ebx
inc eax
push eax
call string.len
pop ebx
add eax, ebx
inc eax
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
add eax, ebx
inc eax
push eax
call string.len
pop ebx
add eax, ebx
inc eax
push eax
push eax
; close
mov ebx, [eax]
mov eax, 6
int 80h
; close
mov ebx, [eax]
mov eax, 6
int 80h
; munmap
mov eax, 91
mov ebx, [ebp+2*4]
pop ecx
add ecx, 4
mov ecx, [ecx]
int 80h
mov eax, [ebp+4]
mov [ebp+2*4], eax
; munmap
mov eax, 91
mov ebx, [ebp+2*4]
pop ecx
add ecx, 4
mov ecx, [ecx]
int 80h
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
postlude
add esp, 4
ret
content:
prelude
prelude
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
add eax, ebx
inc eax
push eax
call string.len
pop ebx
add eax, ebx
add eax, 1+4+4+1
mov [ebp+2*4], eax
postlude
ret
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
add eax, ebx
inc eax
push eax
call string.len
pop ebx
add eax, ebx
add eax, 1+4+4+1
mov [ebp+2*4], eax
postlude
ret

View File

@ -1,6 +1,6 @@
format ELF
public get_ip as 'network.get_ip'
public IP_to_str as 'network.IP_to_str'
public get_ip as 'network.get_ip'
public IP_to_str as 'network.IP_to_str'
include '../include/_macros.inc'
include '../include/_dns.inc'
@ -15,11 +15,11 @@ response rb 200
section '.network.text' executable
get_ip:
prelude
prelude
push dword 200
push response
push DNS_server
push DNS_server
push dword [ebp+2*4]
call dns.send
push response
@ -36,14 +36,14 @@ get_ip:
@@:
add eax, 2*3+4
mov [ebp+2*4], eax
mov [ebp+2*4], eax
postlude
ret
ret
IP_to_str:
prelude
prelude
mov ecx, [ebp+2*4]
mov ecx, [ebp+2*4]
xor ebx, ebx
mov esi, IP_str
@ -85,6 +85,6 @@ IP_to_str:
.break:
mov [esi], byte 0
mov [ebp+2*4], dword IP_str
mov [ebp+2*4], dword IP_str
postlude
ret
ret

View File

@ -6,24 +6,24 @@ extrn string.len
section '.text' executable
filename:
prelude
prelude
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
.loop:
cmp [ebx+eax], byte '/'
je .break
cmp ebx, 0
je .break
.loop:
cmp [ebx+eax], byte '/'
je .break
cmp ebx, 0
je .break
dec ebx
jmp .loop
.break:
add eax, ebx
inc eax
mov [ebp+2*4], eax
postlude
ret
dec ebx
jmp .loop
.break:
add eax, ebx
inc eax
mov [ebp+2*4], eax
postlude
ret

View File

@ -15,159 +15,159 @@ buffer rb 32
section '.std.text' executable
char:
prelude
prelude
mov cl, [ebp+2*4]
mov [buffer], cl
mov cl, [ebp+2*4]
mov [buffer], cl
mov eax, 4
mov ebx, 1
mov ecx, buffer
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, buffer
mov edx, 1
int 80h
mov [buffer], byte 0
mov [buffer], byte 0
mov eax, [ebp+4]
mov [ebp+2*4], eax
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
postlude
add esp, 4
ret
_str:
prelude
prelude
mov ecx, [ebp+2*4]
mov ecx, [ebp+2*4]
xor edx, edx
xor edx, edx
@@:
cmp [ecx+edx], byte 0
je @f
inc edx
jmp @b
@@:
mov eax, 4
mov ebx, 1
int 80h
@@:
cmp [ecx+edx], byte 0
je @f
inc edx
jmp @b
@@:
mov eax, 4
mov ebx, 1
int 80h
mov eax, [ebp+4]
mov [ebp+2*4], eax
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
postlude
add esp, 4
ret
nl:
push _new_line
call char
ret
push _new_line
call char
ret
_bin:
prelude
prelude
mov eax, [ebp+2*4]
mov eax, [ebp+2*4]
push 2
mov ebx, 2
push 2
mov ebx, 2
@@:
cmp eax, 2
jl @f
@@:
cmp eax, 2
jl @f
div ebx
push edx
xor edx, edx
jmp @b
@@:
push eax
mov ebx, buffer
@@:
pop eax
cmp al, 2
je @f
div ebx
push edx
xor edx, edx
jmp @b
@@:
push eax
mov ebx, buffer
@@:
pop eax
cmp al, 2
je @f
add al, '0'
mov [ebx], al
inc ebx
add al, '0'
mov [ebx], al
inc ebx
jmp @b
@@:
push buffer
call _str
jmp @b
@@:
push buffer
call _str
mov eax, buffer
mov eax, buffer
@@:
cmp eax, ebx
je @f
@@:
cmp eax, ebx
je @f
mov [ebx-1], byte 0
dec ebx
mov [ebx-1], byte 0
dec ebx
jmp @b
@@:
mov eax, [ebp+4]
mov [ebp+2*4], eax
jmp @b
@@:
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
postlude
add esp, 4
ret
_int:
prelude
mov eax, [ebp+2*4]
prelude
mov eax, [ebp+2*4]
push 10
mov ebx, 10
push 10
mov ebx, 10
@@:
cmp eax, 10
jl @f
@@:
cmp eax, 10
jl @f
div ebx
push edx
xor edx, edx
jmp @b
@@:
push eax
mov ebx, buffer
@@:
pop eax
cmp al, 10
je @f
div ebx
push edx
xor edx, edx
jmp @b
@@:
push eax
mov ebx, buffer
@@:
pop eax
cmp al, 10
je @f
add al, '0'
mov [ebx], al
inc ebx
add al, '0'
mov [ebx], al
inc ebx
jmp @b
@@:
mov [ebx], byte 0
push buffer
call _str
jmp @b
@@:
mov [ebx], byte 0
push buffer
call _str
mov eax, buffer
mov eax, buffer
@@:
cmp eax, ebx
je @f
@@:
cmp eax, ebx
je @f
mov [ebx-1], byte 0
dec ebx
mov [ebx-1], byte 0
dec ebx
jmp @b
@@:
mov eax, [ebp+4]
mov [ebp+2*4], eax
jmp @b
@@:
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
postlude
add esp, 4
ret
exit:
mov eax, 1
xor ebx, ebx
int 80h
mov eax, 1
xor ebx, ebx
int 80h

View File

@ -6,41 +6,41 @@ include "../include/_macros.inc"
section '.string.text' executable
copy:
prelude
prelude
mov eax, [ebp+3*4]
mov ebx, [ebp+2*4]
xor ecx, ecx
mov eax, [ebp+3*4]
mov ebx, [ebp+2*4]
xor ecx, ecx
.loop:
cmp [eax+ecx], byte 0
je .break
.loop:
cmp [eax+ecx], byte 0
je .break
mov dl, [eax+ecx]
mov [ebx+ecx], dl
inc ecx
jmp .loop
.break:
mov eax, [ebp+4]
mov [ebp+3*4], eax
postlude
add esp, 4*2
ret
mov dl, [eax+ecx]
mov [ebx+ecx], dl
inc ecx
jmp .loop
.break:
mov eax, [ebp+4]
mov [ebp+3*4], eax
postlude
add esp, 4*2
ret
len:
prelude
prelude
mov eax, [ebp+2*4]
xor ebx, ebx
mov eax, [ebp+2*4]
xor ebx, ebx
.loop:
cmp [eax+ebx], byte 0
je .break
.loop:
cmp [eax+ebx], byte 0
je .break
inc ebx
jmp .loop
.break:
mov [ebp+2*4], ebx
postlude
ret
inc ebx
jmp .loop
.break:
mov [ebp+2*4], ebx
postlude
ret