The site moved to root domain where all post are imported. Please go to http://pusheax.com/
I am not an asm coder, in past i have searched a lots for ASM(nasm) code of MessagBox() function Example just to get started. Because everything was fairly new to me(i had no clue!). So i just decided to post a simple example code which was my first assembly program for windows, in case someone is searching for basic example for getting started. I hope it will be useful to someone who is in same situation as i was!
msgb db "pusheax.com!",0
title db "Security Research!",0
push dword 0x00
push dword title
push dword msgb
push dword 0
“extern” is importing symbol from other module. In our case the symbols are _ExitProcess@4 and _MessageBoxA@16. There are three things we see are:
1. underscore before MessageBoxA .
“global _main” , declaring it as startup of our asm instructions(C style).
“Section .data” , you know what is it! Declaring uninitialized data such as variable.
in ASM it is opposite:
First pushing the 0x00000000L(MB_OK) to stack. Currently top of the stack!
Then pushing “title” . “title” is now top of the stack.
Then pushing “msgb”. Same as above. “msgb(string)” top of the stack .
And last push is 0 . Same as above.
At last call the function.
Stack is LIFO(Last in first out). So it is now:
Compile the code :
nasm -fwin32 msg.asm
gcc msg.obj -o msg.exe
import MessageBoxA user32.dll ;Include the dll user32.dll
extern MessageBoxA ; Now calling external symbol without underscore....
msgme db "Hi",0 ;Say "Hi" to pusheax.com
section .text use32 CLASS=CODE ;"use32 CLASS=CODE for telling the other linker(Such as alink.exe) that program for 32bit
..start: ; ..start (not _start) for other linker for start of the code
push dword 0x00 ; MB_OK
mov esi,msgme ;esi="Hi"
push esi ;"Hi" is now top of the stack, second paramaters title
push dword msgme ; Say "Hi"
push dword 0 ;Reserve
call [MessageBoxA] ;Call the Function
;nasm -fobj msg2.asm
;alink -oPE msg2.obj
If we use ld(with gcc) then our command should be ld -o what.exe what.obj -luser32.dll whereas alink.exe -oPE what.exe but nasm. For alink we don’t need to declare how many parameters , underscore etc and for ld we need to declare all the required things and extra option “-l” to link dll.
Which Linker you will use?