Thread: IDA & MASM Confusions
-
03-01-2012, 04:36 PM #1Security Researcher
- Join Date
- Oct 2010
- Location
- Bangalore
- Posts
- 14
- Thanks
- 2
- Thanked 5 Times in 4 Posts
IDA & MASM Confusions
Greetings to all,
I have been trying to brush my ASM skills offlate and started to understand the internals of MASM and IDA. I coded a very simple program with MASM. The code is as follows:
Now when I assemble this code and do a static analysis in IDA, I see the following dis-assembly:Code:.386 .model flat,stdcall option casemap:none include windows.inc include kernel32.inc includelib kernel32.lib include user32.inc includelib user32.lib .data szMsg db "Beep",0 szCaption db "Windows Beep",0 szOK db "You pressed OK",0 szCancel db "You pressed Cancel",0 .code main: invoke Beep,750,500 invoke MessageBox,NULL,addr szMsg,addr szCaption,MB_OKCANCEL .IF eax==IDOK invoke MessageBeep,MB_ICONEXCLAMATION invoke MessageBox,NULL,addr szOK,addr szCaption,MB_OK .ELSE invoke MessageBeep,MB_ICONEXCLAMATION invoke MessageBox,NULL,addr szCancel,addr szCaption,MB_OK .ENDIF xor eax,eax invoke ExitProcess,eax end main

Now my question is where do the INT 3 in the last but one line of IDA analysis came from? Because the IDA analysis of the following code:
gives the following output in IDA:Code:.386 .model flat,stdcall option casemap:none include windows.inc include kernel32.inc includelib kernel32.lib include user32.inc includelib user32.lib .data szCaption db "CommandLine",0 .data? hInstance HINSTANCE ? CmdLine LPSTR ? szStr dd ? .code main: invoke GetCommandLine mov CmdLine,eax invoke MessageBox,NULL,CmdLine,addr szCaption, MB_OK xor eax,eax invoke ExitProcess,eax end main

Anyone can help me understand, what is the concept behind this? Any help would be greatly appreciated.
Thanks
Nishant
03-01-2012, 04:45 PM #2Security Researcher
- Join Date
- Oct 2010
- Location
- Bangalore
- Posts
- 14
- Thanks
- 2
- Thanked 5 Times in 4 Posts
Sorry for the poor resolution of images. Better resolution version are below:
Image#1 > https://docs.google.com/open?id=0B0H...WGlpMEx4Z1pjdw
Image#2 > https://docs.google.com/open?id=0B0H...SGxlVHAwalU0dw
03-01-2012, 05:04 PM #3Security Researcher


- Join Date
- Jul 2010
- Location
- India
- Posts
- 596
- Blog Entries
- 23
- Thanks
- 279
- Thanked 150 Times in 76 Posts
Hi,
Since we already had this discussion, and I got more doubts am putting my explanation + my doubts .
#3495222 - Pastie
And the IDA generated alternate of this code is the following,
#3495228 - Pastie
[Question ]
Her if we check the IDA code on line 68 we could see
int 3 ; Trap to Debugger
Which is not there in the actual MASM code, and a sensible explanation for this is ,
[Answer]
Since a call is made to exit Process and not a JMP,
call ExitProcess
A CALL on completion of a module would return back to caller, in order to stop that form happening since its an ExitProcess call , an Intrupt [int 3] is raised and the program halts and won't let it return back to the MAIN, coz it's pointless.
So this is what I believe is happening here , and in the following case,
MASM Code: #3495340 - Pastie
IDA Code: #3495336 - Pastie
Here in the following code since the code conversation is in the main module a direct JMP is made which dsn't have to return back to caller, so the INT 3 call is omitted.
47 jmp ds:ExitProcess
Now this explains what Nishant has asked, but my confusion now is how does , MASM compiler treat IF loops, does anyone got a documentation| reference on code conversation on MASM IF : ELSE clauses . Is If statement treated as separate function if so, then what data does each IF , ELSE, module return etc etc.
You always have cool brain teasers Man \m/Hacking Is a Matter of Time Knowledge and Patience
The Following User Says Thank You to fb1h2s For This Useful Post:
nishant (03-02-2012)
03-02-2012, 10:46 AM #4Security Researcher
- Join Date
- Oct 2010
- Location
- Bangalore
- Posts
- 14
- Thanks
- 2
- Thanked 5 Times in 4 Posts
Hi Rahul,
Thanks for your reply. But question still remains: That in both the cases I have donein the main block (not inside any IF..ELSE or any secondary function.) Then why did MASM convert one to Call ExitProcess and other to as JMP ds:ExitProcess. Hope you get my questions.Code:xor eax,eax invoke ExitProcess,eax end main



LinkBack URL
About LinkBacks



Reply With Quote

i am a secret hacker with all...
05-22-2013, 09:35 PM in Noobs Corner