Jump to content

Weird Stuff Happens With My Program...

- - - - -

  • Please log in to reply
13 replies to this topic

#1
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I am trying to make a program that would read data from a file that would tell it more about what to do.

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?

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
MemoryCopy() actually needs to be this:
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 

	xor eax, eax 

	lp1: 

		dec ecx 

		

		mov al, byte ptr [edx+ecx] 

		mov byte ptr [ebx+ecx], al 

		

		jecxz lp1s 

		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 

I fixed MemoryCopy(), but the problem is still there.


Well, it's okay. I'm sure I'll get that stuff to work some day. But for now I can use another method.

#3
Gunner

Gunner

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
What kind of weird stuff is happening?

#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
Attached File  Snap.png   95.51K   202 downloads

I attached the file with the snapshot of the command prompt window.

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
What output are you expecting? And why is your MemoryCopy so complicated? I know it does two different copy loops depending on the relation between the two pointers, but is that necessary?

This is the simplest way I know:
MemoryCopy  proc

push    ebp
mov     ebp, esp
push    edi
push    esi


mov     edi, [ebp + 8]
mov     esi, [ebp + 12]
mov     ecx, [ebp + 16]


cld
rep     movsb


pop     esi
pop     edi
pop     ebp
ret     ; or ret 12 depending on the calling convention you use


MemoryCopy  endp

(There are faster ways, though.)
sudo rm -rf /

#6
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I tested it and it worked.
		push dword ptr 0 

		push dword ptr SIZEOF mem2 

		push dword ptr offset mem2 

		call FillMemory 

		

		push dword ptr SIZEOF mem1 

		push dword ptr offset mem2 

		push dword ptr offset mem1 

		call MemoryCopy 

		

		mov ebx, offset mem1 

		mov edx, offset mem2 

		xor ecx, ecx 

		lp01: 

			cmp ecx, SIZEOF mem1 

			jnl lp01s 

			

			mov al, byte ptr [ebx+ecx] 

			cmp al, byte ptr [edx+ecx] 

			jnz lp01ne 

			

			inc ecx 

			jmp lp01 

		lp01ne: 

			push dword ptr string("MemoryCopy() failed. ", 13, 10) 

			call StdOut 

			jmp lp01f 

		lp01s: 

			push dword ptr string("MemoryCopy() succeded! ", 13, 10) 

			call StdOut 

			jmp lp01f 

		lp01f: 

mem1
mem1     db 1, 8, 7, 12, 84, 223, 81, 74, 78, 91, 32, 93, 124, 249, 124, 192, 184, 83, 85, 35, 95, 38, 94, 38, 45, 32, 43, 125, 149, 243, 91, 100, 0 


mem2
mem2     DB SIZEOF mem1 dup (?) 


The reason it matters about which loop to use is that if the two memory buffers overlap then it would be better to check which end of the memory buffer to start copying with.

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Okay, so we see what output you're getting, but what output are you expecting?
sudo rm -rf /

#8
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I was expecting it to get everything from the command line, starting from the 3rd argument (I could start from the first, if I wanted to, but I want to start from 3rd just for this application), and put all that into an array (as in C/C++'s 'char *argv[]').
Then the main() procedure is supposed to iterate through the array and print every entry in that array onto the screen, with each entry having its own line.

It printed the first two entries ("two" and "three") but it skipped the third entry. But when I insert an extra space after the last command-line argument, it puts the third entry too. The reason for that is because when it sees the NULL, when it gets to the end of the command line string, it thinks that it's already over, so it doesn't do the last entry. When there's a space, it does the last entry, and finishes the next time it gets to the NULL. I fixed that, now.

The other thing is that the words ("two" and "three" and ...) had weird stuff after them, that changed almost every time the program was run. I fixed that using the GMEM_ZEROINIT flag, in the call to GlobalAlloc().

The other thing I changed, to make sure the command line arguments got copied right, is I made the program output the length of the string for that array entry.

But yeah, it's good now.

.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 


include \fractions.inc 

includelib \fractions.lib 


public StringLength 

public strcat 

public strlen 

public strcpy 


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 

extern replace                        : near 

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 

		cmp byte ptr [ebx], 0 

		jz finish 

	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 almost_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 

	almost_finish: 

		mov al, byte ptr [ebx-1] 

		cmp al, 32 

		jz finish 

		cmp al, 9 

		jz finish 

		cmp al, 13 

		jz finish 

		cmp al, 10 

		jz finish 

		jmp skip_finish 

	skip_finish: 

	ret 0 

endm 


.data 

mem1     db 1, 8, 7, 12, 84, 223, 81, 74, 78, 91, 32, 93, 124, 249, 124, 192, 184, 83, 85, 35, 95, 38, 94, 38, 45, 32, 43, 125, 149, 243, 91, 100, 0 

.data? 

mem2     DB SIZEOF mem1 dup (?) 

CommandLine                           DWORD ? 

CmdLine                               DB  512 dup (?) 

conffile                              DB  512 dup (?) 

file_arr                              DD  128 dup (?) 

s1                                    DWORD ? 

.code 

start: 


call main 


ret 


main proc 

	enter 0, 0 

	

	;; Test the MemoryCopy() function. 

	pusha 

		push dword ptr 0 

		push dword ptr SIZEOF mem2 

		push dword ptr offset mem2 

		call FillMemory 

		

		push dword ptr SIZEOF mem1 

		push dword ptr offset mem2 

		push dword ptr offset mem1 

		call MemoryCopy 

		

		mov ebx, offset mem1 

		mov edx, offset mem2 

		xor ecx, ecx 

		lp01: 

			cmp ecx, SIZEOF mem1 

			jnl lp01s 

			

			mov al, byte ptr [ebx+ecx] 

			cmp al, byte ptr [edx+ecx] 

			jnz lp01ne 

			

			inc ecx 

			jmp lp01 

		lp01ne: 

			push dword ptr string("MemoryCopy() failed. ", 13, 10) 

			call StdOut 

			jmp lp01f 

		lp01s: 

			push dword ptr string("MemoryCopy() succeded! ", 13, 10) 

			call StdOut 

			jmp lp01f 

		lp01f: 

	popa 

	

	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 

	

	push ebx 

		mov ebx, offset conffile 

		call skip 

		mov byte ptr [ebx], 0 

		

		push dword ptr offset conffile 

		call StdOut 

		push dword ptr string(13, 10, 13, 10) 

		call StdOut 

	pop ebx 

	

	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 

		enter 0, 0 

			enter 0, 0 

			push eax 

			call StringLength 

			push dword ptr string() 

			push eax 

			call i2str 

			push eax 

			call StdOut 

			leave 

			push dword ptr string(32) 

			call StdOut 

		leave 

		pop ebx 

		

		mov eax, dword ptr [ebx] 

		

		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 

	

	;; Allocate memory. 

		push ebx 

		push edx 

	inc ebx 

	push ebx 

	; push dword ptr 0 

	push dword ptr GMEM_ZEROINIT 

	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 

	call to_nspace 

	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 

	xor eax, eax 

	lp1: 

		dec ecx 

		

		mov al, byte ptr [edx+ecx] 

		mov byte ptr [ebx+ecx], al 

		

		jecxz lp1s 

		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 


putchar proc 

	mov eax, dword ptr [esp+4] 

	mov byte ptr [s1+0], al 

	mov byte ptr [s1+1], 0 

	push dword ptr offset s1 

	call StdOut 

	ret 4 

putchar endp 


StringLength@4 proc     ;; the_string: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@4 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 


; i2str proc 

	; enter 0, 0 

	; push esi 

	; push edi 

	; push ecx 

	; push edx 

	; push ebx 

	

	; mov byte ptr [ebp-1], 0 

	

	; mov esi, dword ptr [ebp+8] 

	; mov edi, dword ptr [ebp+12] 

	; push esi 

	; call iLength 

	; xchg eax, ecx 

	; mov eax, esi 

	; lp1: 

		; jecxz lp1s 

		; dec ecx 

		; push ecx 

		; inc ecx 

		; mov ebx, eax 

		; call exp10 

		; xchg eax, ebx 

		; xor edx, edx 

		; div ebx 

		; dec ecx 

		; add al, 48 

		; mov byte ptr [edi], al 

		; inc edi 

		; sub al, 48 

		; push ecx 

		; mov ebx, eax 

		; call exp10 

		; mul ebx 

		; sub esi, eax 

		; mov eax, esi 

		; jmp lp1 

	; lp1s: 

	; mov byte ptr [edi], 0 

	

	; mov eax, dword ptr [ebp+12] 

	

	; pop ebx 

	; pop edx 

	; pop ecx 

	; pop edi 

	; pop esi 

	; leave 

	; ret 8 

; i2str endp 


; iLength proc 

	; enter 0, 0 

	; push ebx 

	; push ecx 

	; push edx 

	

	; mov eax, dword ptr [ebp+8] 

	; xor ecx, ecx 

	; lp1: 

		; mov ebx, 10 

		; xor edx, edx 

		; div ebx 

		; inc ecx 

		; cmp eax, 0 

		; jnz lp1 

	; lp1s: 

	

	; mov eax, ecx 

	

	; pop edx 

	; pop ecx 

	; pop ebx 

	; leave 

	; ret 4 

; iLength endp 


; exp10 proc 

	; enter 0, 0 

	; push ebx 

	; push ecx 

	; push edx 

	

	; mov ecx, dword ptr [ebp+8] 

	; mov eax, 1 

	; mov ebx, 10 

	; lp1: 

		; jecxz lp1s 

		; mul ebx 

		; dec ecx 

		; jmp lp1 

	; lp1s: 

	

	; pop edx 

	; pop ecx 

	; pop ebx 

	; leave 

	; ret 4 

; exp10 endp 


FillMemory proc 

enter 0, 0 

	push ebx 

	push ecx 

	

	mov eax, dword ptr [ebp+8] 

	mov ebx, eax 

	

	mov eax, dword ptr [ebp+12] 

	mov ecx, eax 

	

	mov eax, dword ptr [ebp+16] 

	lp1: 

		sub ecx, 4 

		jl lp2b 

		

		mov dword ptr [ebx], eax 

		

		add ebx, 4 

		jmp lp1 

	lp2b: add ecx, 4 

	lp2: 

		sub ecx, 2 

		jl lp3b 

		

		mov word ptr [ebx], ax 

		

		add ebx, 2 

		jmp lp2 

	lp3b: sub ecx, 1 

	lp3c: jl lp3f 

	lp3d: mov byte ptr [ebx], al 

	lp3f: 

	

	pop ecx 

	pop ebx 

	mov eax, dword ptr [ebp+8] 

	leave 

ret 12 

FillMemory endp 


StringCat proc 

	enter 0, 0 

	pusha 

	

	push dword ptr [ebp+08] 

	call StringLength 

	add eax, dword ptr [ebp+08] 

	push dword ptr [ebp+12] 

	push eax 

	call StringCopy 

	

	popa 

	leave 

	ret 8 

StringCat endp 


; public _StringLength 

; public _strcat 

; public _strlen 

; public _strcpy 


StringLength: jmp StringLength@4 

strcat: jmp StringCat 

strlen: jmp StringLength 

strcpy: jmp StringCopy 


end start 


And the screen:
Attached File  Snap2.png   172.12K   170 downloads

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Okay, great! Glad I could be of no help. :D
sudo rm -rf /

#10
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
What?

#11
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
I didn't do anything except ask you questions.
sudo rm -rf /

#12
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
Post #7 somewhat helped me get on track.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users