diff --git a/dnstoys.o b/dnstoys.o index 8af284a..7833286 100644 Binary files a/dnstoys.o and b/dnstoys.o differ diff --git a/examples/HWA/main b/examples/HWA/main index 8fb7e1b..fb0303f 100644 Binary files a/examples/HWA/main and b/examples/HWA/main differ diff --git a/examples/HWA/makefile b/examples/HWA/makefile index 0adebfc..d6206ad 100644 --- a/examples/HWA/makefile +++ b/examples/HWA/makefile @@ -1,16 +1,13 @@ all: main -main: ../../std.o ../../string.o main.o - ld -m elf_i386 main.o ../../std.o ../../string.o --output main +main: /lib/sbalib.so main.o + ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 main.o /lib/sbalib.so -o main main.o: - fasm main.asm + fasm main.asm > /dev/null -../../std.o: - make -C ../../ std.o - -../../string.o: - make -C ../../ string.o +/lib/sbalib.so: + make -C ../../ clear: rm main.o main diff --git a/examples/file/main b/examples/file/main index 30355a7..281125d 100644 Binary files a/examples/file/main and b/examples/file/main differ diff --git a/examples/file/makefile b/examples/file/makefile index 270ac57..d6206ad 100644 --- a/examples/file/makefile +++ b/examples/file/makefile @@ -1,22 +1,13 @@ all: main -main: ../../file.o ../../std.o ../../path.o ../../string.o main.o - ld -m elf_i386 main.o ../../file.o ../../std.o ../../path.o ../../string.o --output main +main: /lib/sbalib.so main.o + ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 main.o /lib/sbalib.so -o main main.o: - fasm main.asm + fasm main.asm > /dev/null -../../std.o: - make -C ../.. std.o - -../../file.o: - make -C ../.. file.o - -../../path.o: - make -C ../.. path.o - -../../string.o: - make -C ../.. string.o +/lib/sbalib.so: + make -C ../../ clear: rm main.o main diff --git a/examples/network/main b/examples/network/main index 2ae5a2c..756bac4 100644 Binary files a/examples/network/main and b/examples/network/main differ diff --git a/examples/network/makefile b/examples/network/makefile index b73a1df..d6206ad 100644 --- a/examples/network/makefile +++ b/examples/network/makefile @@ -1,25 +1,13 @@ all: main -main: ../../std.o ../../string.o ../../network.o ../../dns.o ../../dnstoys.o main.o - ld -m elf_i386 main.o ../../std.o ../../string.o ../../network.o ../../dns.o ../../dnstoys.o --output main - +main: /lib/sbalib.so main.o + ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 main.o /lib/sbalib.so -o main + main.o: - fasm main.asm + fasm main.asm > /dev/null -../../std.o: - make -C ../.. std.o +/lib/sbalib.so: + make -C ../../ -../../string.o: - make -C ../.. string.o - -../../network.o: - make -C ../.. network.o - -../../dns.o: - make -C ../.. dns.o - -../../dnstoys.o: - make -C ../.. dnstoys.o - clear: rm main.o main diff --git a/heap.o b/heap.o new file mode 100644 index 0000000..55ec61f Binary files /dev/null and b/heap.o differ diff --git a/makefile b/makefile index 3c124cb..34c6353 100644 --- a/makefile +++ b/makefile @@ -1,25 +1,9 @@ -all: std.o string.o file.o path.o network.o dns.o dnstoys.o +all: $(patsubst src/%.asm,%.o, $(wildcard src/*)) + ld -m elf_i386 -shared *.o -o sbalib.so + cp sbalib.so /lib/ -std.o: - fasm src/std.asm std.o - -string.o: - fasm src/string.asm string.o - -file.o: - fasm src/file.asm file.o - -path.o: - fasm src/path.asm path.o - -network.o: - fasm src/network.asm network.o - -dns.o: - fasm src/dns.asm dns.o - -dnstoys.o: - fasm src/dnstoys.asm dnstoys.o +%.o: + fasm $(patsubst %.o,src/%.asm,$@) $@ > /dev/null clear: - rm *.o + rm *.o sbalib.so \ No newline at end of file diff --git a/network.o b/network.o index 435a59d..b6e6019 100644 Binary files a/network.o and b/network.o differ diff --git a/sbalib.so b/sbalib.so new file mode 100644 index 0000000..79d1df9 Binary files /dev/null and b/sbalib.so differ diff --git a/src/dnstoys.asm b/src/dnstoys.asm index 74e1220..1f330fb 100644 --- a/src/dnstoys.asm +++ b/src/dnstoys.asm @@ -27,7 +27,6 @@ myip: push dnstoys call network.get_ip pop eax - mov eax, [eax] mov [DNS_server+4], eax push dword 200 diff --git a/src/heap.asm b/src/heap.asm new file mode 100644 index 0000000..e4298ee --- /dev/null +++ b/src/heap.asm @@ -0,0 +1,98 @@ +format ELF +public _add as 'heap.add' +public del as 'heap.del' + +include '../include/macros.inc' +extrn exit + +section '.bss' writeable +_heap: + db 0xB ; flag + dd 4 ; size + dd 4096 ; available memory + + rd 4096 + +section '.text' executable +_add: + prelude + + mov ecx, [ebp+2*4] ; size + mov eax, _heap + xor edx, edx + + .loop: + cmp [eax], byte 0 + je .empty + + mov bl, [eax] + bt bx, 0 + jc .busy + + inc eax + cmp edx, 0 + jne @f + mov edx, eax + @@: + cmp ecx, [eax] + jl .more + je .equal + ; less + sub ecx, [eax] + add eax, [eax] + add eax, 4 + jmp .loop + .equal: + mov [edx], byte 9 + mov ebx, [ebp+2*4] + mov [edx+1], ebx + add edx, 5 + mov [ebp+2*4], edx + postlude + ret + .more: + mov ebx, edx + add ebx, [ebp+2*4] + mov [ebx], byte 9 + inc ebx + mov eax, [eax] + sub eax, ecx + mov [ebx], eax + + add ebx, [ebp+2*4] + mov [edx-1], byte 9 + mov edx, ebx + + add edx, 5 + mov [ebp+2*4], edx + postlude + ret + + .empty: + cmp edx, 0 + jne @f + mov edx, eax + @@: + je @f + dec edx + @@: + jmp .equal + + .busy: + xor edx, edx + inc eax + add eax, [eax] + add eax, 4 + + jmp .loop + +del: + push eax + mov eax, [esp+4*2] + sub eax, 5 + and byte [eax], 254 + mov eax, [esp+4] + mov [esp+4*2], eax + pop eax + add esp, 4 + ret diff --git a/src/network.asm b/src/network.asm index fe78f61..25f063e 100644 --- a/src/network.asm +++ b/src/network.asm @@ -26,15 +26,7 @@ get_ip: 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 eax, [eax] mov [ebp+2*4], eax postlude diff --git a/src/std.asm b/src/std.asm index 08ccb0c..17fa64d 100644 --- a/src/std.asm +++ b/src/std.asm @@ -69,6 +69,7 @@ _bin: push 2 mov ebx, 2 + xor edx, edx @@: cmp eax, 2 diff --git a/src/string.asm b/src/string.asm index 4650bc5..01accff 100644 --- a/src/string.asm +++ b/src/string.asm @@ -2,8 +2,10 @@ format ELF public copy as 'string.copy' public len as 'string.len' public parse_int as 'string.parse_int' +public concat as 'string.concat' include "../include/macros.inc" +extrn heap.add section '.string.text' executable copy: @@ -82,3 +84,34 @@ parse_int: mov [ebp+4*2], eax postlude ret + +concat: + prelude + + push dword [ebp+3*4] + call len + push dword [ebp+2*4] + call len + mov eax, [esp+4] + add [esp], eax + dec dword [esp] + call heap.add + pop eax + mov edx, eax + + push dword [ebp+3*4] + push eax + call copy + + add eax, [esp] + mov ebx, [ebp+2*4] + mov [esp], ebx + push eax + call copy + + mov eax, [ebp+4] + mov [ebp+2*4], eax + mov [ebp+3*4], edx + postlude + add esp, 4 + ret \ No newline at end of file diff --git a/std.o b/std.o index 069204b..e4d6f58 100644 Binary files a/std.o and b/std.o differ diff --git a/string.o b/string.o index d611758..fa8cd2d 100644 Binary files a/string.o and b/string.o differ