The basic idea is to read another file and to replace things within that file and to save the new stuff into another file.
I tried making a function that would get the command line arguments and put them into an array, but it does weird stuff instead.
The function name is get_cmd_array(). The other function, free_array(), is supposed to free everything in the array.
So I'm trying to fix get_cmd_array(); the rest of the code seems to be fine.
.386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\masm32.inc include \masm32\include\kernel32.inc includelib \masm32\lib\masm32.lib includelib \masm32\lib\kernel32.lib ;extern replace : near string macro p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, \ p31, p32 LOCAL a ifnb <p1> ;; Saves a string (up to 32 entries (ex. string "Hello World!", 13, 10, 13, 10, "..... " makes 6 entries)) and returns its memory address. .data a db p1 for entry, <p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, \ p31, p32> ifnb <entry> db entry endif endm db 0 else .data? a DB 512 dup (?) endif .code exitm <offset a> endm some_functions macro to_nspace: @@: mov al, byte ptr [ebx] cmp al, 0 jz finish inc ebx cmp al, 32 jz @B cmp al, 9 jz @B @@: dec ebx ret 0 to_space: @@: mov al, byte ptr [ebx] cmp al, 0 jz finish cmp al, 32 jz @F cmp al, 9 jz @F inc ebx jmp @B @@: ret 0 skip: cmp byte ptr [ebx], 34 jz skip_lp2 skip_lp1: mov al, byte ptr [ebx] cmp al, 34 jz skip_lp1s cmp al, 32 jz skip_finish cmp al, 9 jz skip_finish cmp al, 13 jz skip_finish cmp al, 10 jz skip_finish cmp al, 0 jz finish inc ebx jmp skip_lp1 skip_lp1s: mov eax, ebx inc eax push ebx push eax call StringCopy mov byte ptr [ebx], 32 jmp skip_finish skip_lp2: inc ebx mov al, byte ptr [ebx] cmp al, 34 jz skip_lp2s cmp al, 0 jz skip_finish jmp skip_lp2 skip_lp2s: inc ebx mov eax, ebx inc eax push ebx push eax call StringCopy mov byte ptr [ebx], 32 jmp skip_finish skip_finish: ret 0 endm .data .data? CommandLine DWORD ? CmdLine DB 512 dup (?) conffile DB 512 dup (?) file_arr DD 128 dup (?) .code start: call main ret main proc enter 0, 0 call GetCommandLine mov dword ptr [CommandLine], eax mov ebx, eax mov eax, offset CmdLine push ebx push eax call StringCopy mov ebx, eax call to_nspace call skip call to_nspace mov eax, offset conffile push ebx push eax call StringCopy call skip call to_nspace push dword ptr offset file_arr push ebx call get_cmd_array mov ebx, offset file_arr lp1: mov eax, dword ptr [ebx] cmp eax, 0 jz lp1s push ebx push eax call StdOut push dword ptr string(13, 10) call StdOut pop ebx add ebx, 4 jmp lp1 lp1s: push dword ptr offset file_arr call free_array jmp finish some_functions finish: leave ret 0 main endp get_cmd_array proc ;; the_string:DWORD, the_array:DWORD enter 4, 0 mov eax, dword ptr [ebp+12] mov dword ptr [ebp-4], eax mov eax, dword ptr [ebp+8] mov ebx, eax lp1: mov edx, ebx call skip sub ebx, edx jz finish inc ebx push ebx push edx push ebx push dword ptr 0 call GlobalAlloc mov ebx, eax mov eax, dword ptr [ebp-4] xchg eax, ebx pop edx mov dword ptr [ebx], eax push eax push edx call MemoryCopy mov ebx, eax mov eax, dword ptr [ebp-4] xchg eax, ebx add ebx, eax dec ebx mov byte ptr [ebx], 0 add dword ptr [ebp-4], 4 mov ebx, edx call skip jmp lp1 some_functions finish: mov eax, dword ptr [ebp-4] mov ebx, eax mov dword ptr [ebx], 0 mov eax, dword ptr [ebp+12] leave ret 8 get_cmd_array endp free_array proc ;; the_array:DWORD enter 0, 0 mov eax, dword ptr [ebp+8] mov ebx, eax lp1: mov eax, dword ptr [ebx] cmp eax, 0 jz lp1s push ebx push eax call GlobalFree pop ebx add ebx, 4 jmp lp1 lp1s: leave ret 4 free_array endp MemoryCopy proc ;; from:DWORD, to:DWORD, size:DWORD enter 0, 0 pusha mov eax, dword ptr [ebp+08] mov edx, eax mov eax, dword ptr [ebp+12] mov ebx, eax cmp ebx, edx jg lbl1 xor ecx, ecx jmp lp2 lbl1: mov eax, dword ptr [ebp+16] mov ecx, eax lp1: jecxz lp1s mov al, byte ptr [edx+ecx] mov byte ptr [ebx+ecx], al dec ecx jmp lp1 lp1s: jmp finish lp2: mov eax, dword ptr [ebp+16] cmp eax, ecx jng lp2s mov al, byte ptr [edx+ecx] mov byte ptr [ebx+ecx], al inc ecx jmp lp2 lp2s: jmp finish finish: mov eax, dword ptr [ebp+16] mov dword ptr [ebp-4], eax popa leave ret 12 MemoryCopy endp StringLength proc ;; s:DWORD enter 0, 0 pusha mov eax, dword ptr [ebp+8] mov ebx, eax xor ecx, ecx lp1: mov al, byte ptr [ebx+ecx] cmp al, 0 jz lp1s inc ecx jmp lp1 lp1s: mov eax, ecx mov dword ptr [ebp-4], eax popa leave ret 4 StringLength endp StringCopy proc ;; to:DWORD, from:DWORD enter 0, 0 pusha push dword ptr [ebp+12] call StringLength inc eax push eax push dword ptr [ebp+08] push dword ptr [ebp+12] call MemoryCopy popa leave ret 8 StringCopy endp end start
Does anyone know what's wrong?


Sign In
Create Account


Back to top










