Archived
1
0

Init project

This commit is contained in:
Sweet Bread
2022-11-06 13:51:51 +03:00
commit c163efd83d
32 changed files with 1110 additions and 0 deletions
+191
View File
@@ -0,0 +1,191 @@
format ELF
public send as 'dns.send'
public get_field as 'dns.get_field'
include '../include/_macros.inc'
include '../include/_dns.inc'
extrn string.len
section '.strtab'
random_filename db "/dev/random", 0
section '.bss' writeable
sock_fd rd 1
request_len rw 1
DNS_request dnsreq
DNS_server sockaddr 00,53, 8,8,8,8
section '.dns.text' executable
send:
prelude
; open
mov eax, 5
mov ebx, random_filename
mov ecx, 0
mov edx, 0
int 80h
push eax
; read
mov ebx, eax
mov eax, 3
mov ecx, ID
mov edx, 2
int 80h
; close
mov eax, 6
pop ebx
int 80h
mov eax, [ebp+2*4]
mov ecx, DNS_question
.bigloop:
xor ebx, ebx
.small0loop:
cmp [eax+ebx], byte '.'
je .small0break
cmp [eax+ebx], byte 0
je .small0break
inc ebx
jmp .small0loop
.small0break:
mov [ecx], ebx
inc ecx
xor ebx, ebx
.small1loop:
cmp [eax], byte '.'
je .small1break
cmp [eax], byte 0
je .bigbreak
mov bl, [eax]
mov [ecx], bl
inc ecx
inc eax
jmp .small1loop
.small1break:
inc eax
jmp .bigloop
.bigbreak:
mov [ecx], byte 0
mov [ecx+1], dword 01000100h
add ecx, 5
sub ecx, DNS_request
mov [request_len], cx
; socket
mov eax, 167h
mov ebx, AF_INET
mov ecx, SOCK_DGRAM
mov edx, IPPROTO_IP
int 80h
mov [sock_fd], eax
; sendto
mov eax, 369
mov ebx, [sock_fd]
mov ecx, DNS_request
xor edx, edx
mov dx, [request_len]
mov esi, flags
mov edi, [ebp+3*4]
push ebp
mov ebp, 16
int 80h
pop ebp
; read
mov eax, 3
mov ebx, [sock_fd]
mov ecx, [ebp+4*4]
mov edx, [ebp+5*4]
int 80h
; close
mov eax, 6
mov ebx, [sock_fd]
int 80h
mov eax, [ebp+4]
mov [ebp+5*4], eax
postlude
add esp, 4*4
ret
get_field:
prelude
mov eax, [ebp+3*4]
mov bx , [ebp+2*4]
mov ch , [eax+2*2]
mov cl , [eax+2*2+1]
cmp bx, cx
jl @f
mov [ebp+3*4], dword 0
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
@@:
add eax, 3*4
mov bh , [eax-8]
mov bl , [eax-7]
@@:
dec bx
push eax
call string.len
pop ecx
add eax, ecx
cmp ecx, 2
je .a
inc eax
.a:
add eax, 2*2
cmp bx , 0
je @f
jmp @b
@@:
cmp word [ebp+2*4], 0
je @f
push eax
call string.len
pop ecx
add eax, ecx
cmp ecx, 2
je .b
inc eax
.b:
add eax, 2*2+4
xor ebx, ebx
mov bx , [eax]
add eax, ebx
inc word [ebp+2*4]
jmp @b
@@:
mov [ebp+3*4], eax
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
+57
View File
@@ -0,0 +1,57 @@
format ELF
public myip as 'dnstoys.myip'
include '../include/_macros.inc'
include '../include/_dns.inc'
extrn network.get_ip
extrn dns.send
extrn dns.get_field
extrn string.len
section '.strtab'
dnstoys db "dns.toys", 0
endpoints:
.ip db "ip", 0
section '.bss' writeable
response rb 200
DNS_server sockaddr 00,53, ?,?,?,?
DNS_request dnsreq
section '.dnstoys.text'
myip:
push 0
prelude
push dnstoys
call network.get_ip
pop eax
mov eax, [eax]
mov [DNS_server+4], eax
push dword 200
push response
push DNS_server
push endpoints.ip
call dns.send
push response
push dword 0
call dns.get_field
pop eax
push eax
call string.len
pop ebx
add eax, ebx
cmp ebx, 2
je @f
inc eax
@@:
add eax, 2*3+4+1
mov ebx, [ebp+2*4]
mov [ebp+4], ebx
mov [ebp+2*4], eax
postlude
ret
+194
View File
@@ -0,0 +1,194 @@
format ELF
public open as 'file.open'
public close as 'file.close'
public content as 'file.content'
include '../include/_file.inc'
include '../include/_macros.inc'
extrn string.len
extrn string.copy
extrn path.filename
section '.strtab'
str1 db "File object ", 0
; str2 db " at "
section '.bss' writeable
pointer rd 1
fd rd 1
memory rd 1
sizes_ sizes
file_stat stat
section '.file.text' executable
open:
prelude
; open
mov eax, 5
mov ebx, [ebp+2*4]
mov ecx, O_RDONLY
mov edx, O_DIRECTORY
int 80h
mov [fd], eax
; 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 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
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
mov [pointer], eax
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_.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_.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
; 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
postlude
ret
close:
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
push eax
; 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
postlude
add esp, 4
ret
content:
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
+90
View File
@@ -0,0 +1,90 @@
format ELF
public get_ip as 'network.get_ip'
public IP_to_str as 'network.IP_to_str'
include '../include/_macros.inc'
include '../include/_dns.inc'
extrn dns.send
extrn dns.get_field
extrn string.len
section '.bss' writeable
IP_str rb 19
DNS_server sockaddr 00,53, 8,8,8,8
response rb 200
section '.network.text' executable
get_ip:
prelude
push dword 200
push response
push DNS_server
push dword [ebp+2*4]
call dns.send
push response
push dword 0
call dns.get_field
pop eax
push eax
call string.len
pop ebx
add eax, ebx
cmp ebx, 2
je @f
inc eax
@@:
add eax, 2*3+4
mov [ebp+2*4], eax
postlude
ret
IP_to_str:
prelude
mov ecx, [ebp+2*4]
xor ebx, ebx
mov esi, IP_str
.loop:
mov al, [ecx+ebx]
push 10
.smloop:
cmp ax, 10
jnl @f
push eax
jmp .smbr
@@:
mov edx, 10
div dl
mov dl, ah
push edx
xor ah, ah
jmp .smloop
.smbr:
pop eax
cmp al, byte 10
je .smbrbr
add al, '0'
mov [esi], al
inc esi
jmp .smbr
.smbrbr:
inc ebx
cmp ebx, 4
je .break
mov [esi], byte '.'
inc esi
jmp .loop
.break:
mov [esi], byte 0
mov [ebp+2*4], dword IP_str
postlude
ret
+29
View File
@@ -0,0 +1,29 @@
format ELF
public filename as 'path.filename'
include '../include/_macros.inc'
extrn string.len
section '.text' executable
filename:
prelude
mov eax, [ebp+2*4]
push eax
call string.len
pop ebx
.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
+173
View File
@@ -0,0 +1,173 @@
format ELF
public char as 'print.char'
public _str as 'print.str'
public nl as 'print.nl'
public _bin as 'print.bin'
public _int as 'print.int'
public exit
include '../include/_macros.inc'
_new_line equ 10
section '.bss' writeable
buffer rb 32
section '.std.text' executable
char:
prelude
mov cl, [ebp+2*4]
mov [buffer], cl
mov eax, 4
mov ebx, 1
mov ecx, buffer
mov edx, 1
int 80h
mov [buffer], byte 0
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
_str:
prelude
mov ecx, [ebp+2*4]
xor edx, edx
@@:
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
postlude
add esp, 4
ret
nl:
push _new_line
call char
ret
_bin:
prelude
mov eax, [ebp+2*4]
push 2
mov ebx, 2
@@:
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
add al, '0'
mov [ebx], al
inc ebx
jmp @b
@@:
push buffer
call _str
mov eax, buffer
@@:
cmp eax, ebx
je @f
mov [ebx-1], byte 0
dec ebx
jmp @b
@@:
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
_int:
prelude
mov eax, [ebp+2*4]
push 10
mov ebx, 10
@@:
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
add al, '0'
mov [ebx], al
inc ebx
jmp @b
@@:
mov [ebx], byte 0
push buffer
call _str
mov eax, buffer
@@:
cmp eax, ebx
je @f
mov [ebx-1], byte 0
dec ebx
jmp @b
@@:
mov eax, [ebp+4]
mov [ebp+2*4], eax
postlude
add esp, 4
ret
exit:
mov eax, 1
xor ebx, ebx
int 80h
+46
View File
@@ -0,0 +1,46 @@
format ELF
public copy as 'string.copy'
public len as 'string.len'
include "../include/_macros.inc"
section '.string.text' executable
copy:
prelude
mov eax, [ebp+3*4]
mov ebx, [ebp+2*4]
xor ecx, ecx
.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
len:
prelude
mov eax, [ebp+2*4]
xor ebx, ebx
.loop:
cmp [eax+ebx], byte 0
je .break
inc ebx
jmp .loop
.break:
mov [ebp+2*4], ebx
postlude
ret