flat assembler
Message board for the users of flat assembler.
Index
> Windows > DialogBox problem |
Author |
|
Evgeny 16 Jan 2006, 15:03
What's wrong with this code?
Code: format pe gui 4.0 entry start include 'win32a.inc' start: invoke GetModuleHandle,0 invoke DialogBoxParam,eax,101,0,MainDlgProc,eax invoke ExitProcess,eax MainDlgProc: cmp dword[esp+0x08],\ ;ESP+0x08: DialogProc.uMsg. WM_INITDIALOG jz .init ;***************************************; nop ;Try to (un)comment this. ;***************************************; xor eax,eax ;Return 0. ret 0x10 ;4 parameters * 4 bytes. .init: xor eax,eax inc eax ;Return 1. ret 0x10 ;4 parameters * 4 bytes. data import library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'apia/kernel32.inc' include 'apia/user32.inc' end data data resource from 'res/main.res' end data
|
|||||||||||
16 Jan 2006, 15:03 |
|
Evgeny 17 Jan 2006, 06:08
Quote: The first thing i noticed is that your dialog has no handlers for closing the window. I've removed that code when I searched for error. Quote: also your not saving your esp to ebp. Saving ESP to EBP (creating stack frame) is usually done to simplify access to local variables. I have no local variables, so… Quote: and i believe the value for uMsg should be +0x0C not +0x08. +0x08 is your wParam. Why? I'm addressing via esp, not ebp (and even when addressing via ebp [ebp+0x08] will be hWndDlg, not wParam!): Code: [esp+0x00] ;Return address. [esp+0x04] ;1st parameter (hWndDlg). [esp+0x08] ;2nd parameter (uMsg). [esp+0x0c] ;3rd parameter (wParam). [esp+0x10] ;4th parameter (lParam). Quote: i personally like ot copy the uMsg into eax Thanks, I know how to write good-style WindowProc's and DialogProc's. But the question was: why my code doesn't work, when nop is uncommented? On WinXP DialogProc returns 0xffffffff (and GetLastError reports, that class was not found), on Win98 it causes divide error in USER.EXE. Why? [added] Hmm… I've placed dialog resource into separate section and now it works ok. But why? |
|||
17 Jan 2006, 06:08 |
|
shoorick 17 Jan 2006, 06:33
your program works occasionally
you do not restore stack before leaving window proc: should be: leave ret 0x10 (do not mess with ret macro in procedure defined with proc macro) regards! ====== i was wrong: you did not made frame - then i do not know ====== add 2: the thing is aligning - after added "align 32" before import and resources everything start to work with nop and without (32 - i do not know exact needed aligning for such data - can be less then 32) regards! |
|||
17 Jan 2006, 06:33 |
|
Evgeny 17 Jan 2006, 06:46
I've just downloaded fasm v1.65.8 and now it works. Problem was in fasm v1.64?
|
|||
17 Jan 2006, 06:46 |
|
shoorick 17 Jan 2006, 06:51
i still use 1.64 (a while). your example with aligning works in 1.64 - i tested. maybe "data" macro in 1.65 has aligning inside - just do not know yet.
regards! |
|||
17 Jan 2006, 06:51 |
|
FrozenKnight 17 Jan 2006, 09:25
Sorry about the confused post i was kind of tired. i only scanned it anc compared it to a disasembly of one of my programs the 0x0C is correct when you push ebp onto the stack like i did :/
|
|||
17 Jan 2006, 09:25 |
|
Reverend 17 Jan 2006, 13:46
AFAIK resources must be aligned to some fixed value. You were just lucky once, beacuse without nop the alignment was ok. This one byte 0x90 crashed the program.
|
|||
17 Jan 2006, 13:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.