diff --git a/README.md b/README.md index e7cca27..1af7a28 100644 --- a/README.md +++ b/README.md @@ -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~~ A lot of shit code included diff --git a/examples/HWA/.fuse_hidden0000030700000001 b/examples/HWA/.fuse_hidden0000030700000001 deleted file mode 100644 index 390bf10..0000000 Binary files a/examples/HWA/.fuse_hidden0000030700000001 and /dev/null differ diff --git a/examples/HWA/main.asm b/examples/HWA/main.asm index 87c4b38..56e42b7 100644 --- a/examples/HWA/main.asm +++ b/examples/HWA/main.asm @@ -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 diff --git a/examples/HWA/makefile b/examples/HWA/makefile index 9f448d3..0f22a74 100644 --- a/examples/HWA/makefile +++ b/examples/HWA/makefile @@ -8,4 +8,4 @@ main: ../../std.o make -C ../../ std.o clear: - rm main.o main \ No newline at end of file + rm main.o main diff --git a/examples/file/main b/examples/file/main index 815a45b..2b304cf 100644 Binary files a/examples/file/main and b/examples/file/main differ diff --git a/examples/file/main.asm b/examples/file/main.asm index 5406198..c1f3e9e 100644 --- a/examples/file/main.asm +++ b/examples/file/main.asm @@ -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 \ No newline at end of file + call exit diff --git a/examples/file/main.o b/examples/file/main.o index 8ed1881..8691127 100644 Binary files a/examples/file/main.o and b/examples/file/main.o differ diff --git a/examples/file/makefile b/examples/file/makefile index 528218f..9221dee 100644 --- a/examples/file/makefile +++ b/examples/file/makefile @@ -21,4 +21,3 @@ main: ../../file.o ../../std.o ../../path.o ../../string.o clear: rm main.o main - diff --git a/examples/network/main.asm b/examples/network/main.asm index 929c2ce..9220c43 100644 --- a/examples/network/main.asm +++ b/examples/network/main.asm @@ -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 \ No newline at end of file + call exit diff --git a/makefile b/makefile index 035d3b3..3c124cb 100644 --- a/makefile +++ b/makefile @@ -22,4 +22,4 @@ dnstoys.o: fasm src/dnstoys.asm dnstoys.o clear: - rm *.o \ No newline at end of file + rm *.o diff --git a/src/dnstoys.asm b/src/dnstoys.asm index 8d290b6..84c9786 100644 --- a/src/dnstoys.asm +++ b/src/dnstoys.asm @@ -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 diff --git a/src/file.asm b/src/file.asm index a8a102d..b80476e 100644 --- a/src/file.asm +++ b/src/file.asm @@ -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 diff --git a/src/network.asm b/src/network.asm index 59fa7e7..7043536 100644 --- a/src/network.asm +++ b/src/network.asm @@ -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 \ No newline at end of file + ret diff --git a/src/path.asm b/src/path.asm index f209ce0..c00fb2b 100644 --- a/src/path.asm +++ b/src/path.asm @@ -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 \ No newline at end of file + dec ebx + jmp .loop + .break: + add eax, ebx + inc eax + mov [ebp+2*4], eax + postlude + ret diff --git a/src/std.asm b/src/std.asm index 65127d6..77a256c 100644 --- a/src/std.asm +++ b/src/std.asm @@ -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 \ No newline at end of file + mov eax, 1 + xor ebx, ebx + int 80h diff --git a/src/string.asm b/src/string.asm index 152f8b0..4d8488c 100644 --- a/src/string.asm +++ b/src/string.asm @@ -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 \ No newline at end of file + inc ebx + jmp .loop + .break: + mov [ebp+2*4], ebx + postlude + ret