Saturday, February 03, 2007

Code execution in stack

It's been a while since the last time I submit a post. Life getting ugly day by day...Things are changing ,so I am some how busy more than ever before, but wait,I always do have time to code even if the apocolypse is right now :)

Remember my previous post on using stack instead of data section, well here I use stack to put my code there and call it as a function ,see next:

;-----------------------code
.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib



.data
text_1 db "hello there!",0

.code
start:
mov edi,esp
add edi,4
push edi
lea esi,[espcode]
mov ecx,(endesp-espcode)
rep movsb
pop edi
mov ecx,MessageBoxA ;here we need the actual address of that api.
call edi

exit:
invoke ExitProcess,0

espcode:
push eax
mov eax,edx
pop eax
xor eax,eax ;
dec eax ;was some rabbish code!!
push 0
push 0
push offset text_1
push 0
call ecx
ret
endesp:

end start
;-----------------------end of code

As you may see the only thing was we needed either to change esp or make our code beyond esp value so as our executed code will not get corrupted while execution, I used "add edi,4" so as my code will not get overlapped with stack.

I think the code is self explanatory...

bye for now
------------------------

Labels:

Smilar pages

1 Comments:

Anonymous Anonymous said...

Data in stack - yawn. Code in stack - Mwahahaha now that's "handy" for some people.

2:02 PM  

Post a Comment

<< Home