flat assembler
Message board for the users of flat assembler.
Index
> Windows > MessageBox throws Excpetion |
Author |
|
TightCoderEx 15 Jun 2013, 18:33
Early in the development of this app I remember seeing error messages appear properly, but didn't test after each subsequent phase.
I deliberately changed @ line 41 Code: mov al, sizeof.WNDCLASSEX + 7 Code: mov edx, RegErr .Err: invoke MessageBox, rbx, rdx, ErrTitle, MB_OK + MB_ICONSTOP mov eax, 48 jmp .Exit Quote:
Quote: USER32!MessageBoxTimeoutA+0x185: I'm running Win7 Service Pack 1
|
|||||||||||
15 Jun 2013, 18:33 |
|
bitRAKE 15 Jun 2013, 19:34
[double post]
Last edited by bitRAKE on 15 Jun 2013, 21:22; edited 1 time in total |
|||
15 Jun 2013, 19:34 |
|
TightCoderEx 15 Jun 2013, 20:49
I do remember reading a lot about alignment of stack and structures, but brand new to Win64, so not aware of this mod 16 requirement. To fix, I just let the WNDCLASSEX frame persist just before ExitProcess and then re-align again with a push rax.
It does bring into question though, why only MessageBox as in the original version everything else worked just being qword aligned. |
|||
15 Jun 2013, 20:49 |
|
bitRAKE 15 Jun 2013, 21:21
Not all APIs use SSE moves which require alignment. AFAIK, that is the source of the requirement, but there might be others. Note the PUSH count between invoke's -- they just happen to be even. Also, note how most of the class items are constant, and it requires more bytes of code to create the structure than to just instance a structure in the data section.
hInstance is always the base address: http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx ...the program can only be relocated if you include a relocation section. The menu ID can be put in the class structure, too. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
15 Jun 2013, 21:21 |
|
TightCoderEx 15 Jun 2013, 22:54
I had noticed that about the instance handle. On entry to the windows procedure, the stack is also misaligned, but for now it's not causing a problem so I'll just deal with whatever API accordingly if one should present a problem like MessageBox.
Quote: Also, note how most of the class items are constant, and it requires more bytes of code to create the structure than to just instance a structure in the data section. Disassembly from TEMPLATE.ASM Code: - 401000 4883ec08 sub rsp,8 - 401004 4883ec20 sub rsp,20h - 401008 48c7c100000000 mov rcx,0 - 40100f ff1563200000 call GetModuleHandle - 401015 4883c420 add rsp,20h - 401019 48890529100000 mov [00402049],rax - 401020 4883ec20 sub rsp,20h - 401024 48c7c100000000 mov rcx,0 - 40102b 48c7c2007f0000 mov rdx,7F00h - 401032 ff15f8200000 call LoadIcon - 401038 4883c420 add rsp,20h - 40103c 4889050e100000 mov [00402051)],rax - 401043 4889052f100000 mov [00402079)],rax - 40104a 4883ec20 sub rsp,20h - 40104e 48c7c100000000 mov rcx,0 - 401055 48c7c2007f0000 mov rdx,7F00h - 40105c ff15c6200000 call LoadCursor - 401062 4883c420 add rsp,20h - 401066 488905ec0f0000 mov [00402059],rax - 40106d 4883ec20 sub rsp,20h - 401071 48c7c131204000 mov rcx, 00402031 - 401078 ff15ca200000 call RegisterClass - 40107e 4883c420 add rsp,20h - 401082 4885c0 test rax,rax = 133 bytes + bytes for WNDCLASS Code: - 401000 55 push rbp - 401001 4889e5 mov rbp,rsp - 401004 31db xor ebx,ebx - 401006 ba007f0000 mov edx,7F00h - 40100b 4883ec20 sub rsp,20h - 40100f 4889d9 mov rcx,rbx - 401012 ff1520310000 call LoadIcon - 401018 4883c420 add rsp,20h - 40101c 50 push rax - 40101d 4989c7 mov r15,rax - 401020 6800204000 push 402000 - 401025 53 push rbx - 401026 6a0d push 0Dh - 401028 ba007f0000 mov edx,7F00h - 40102d 4883ec20 sub rsp,20h - 401031 4889d9 mov rcx,rbx - 401034 ff15f6300000 call LoadCursor - 40103a 4883c420 add rsp,20h - 40103e 50 push rax - 40103f 4157 push r15 - 401041 4883ec20 sub rsp,20h - 401045 4889d9 mov rcx,rbx - 401048 ff152a300000 call GetModuleHandle - 40104e 4883c420 add rsp,20h - 401052 50 push rax - 401053 48890526100000 mov [402080],rax - 40105a 53 push rbx - 40105b 68c0114000 push 4011c0 - 401060 b803000000 mov eax,3 - 401065 48c1e020 shl rax,20h - 401069 b050 mov al,50h - 40106b 50 push rax - 40106c 89e1 mov ecx,esp - 40106e 4883ec20 sub rsp,20h - 401072 ff15e0300000 call RegisterClassEx - 401078 4883c420 add rsp,20h - 40107c 6685c0 test ax,ax = 127 bytes |
|||
15 Jun 2013, 22:54 |
|
bitRAKE 15 Jun 2013, 23:07
TightCoderEx wrote: On entry to the windows procedure, the stack is also misaligned, but for now it's not causing a problem so I'll just deal with whatever API accordingly if one should present a problem like MessageBox. Looks like you've shaved off quite a few bytes. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
15 Jun 2013, 23:07 |
|
TightCoderEx 16 Jun 2013, 00:43
Thanks for the input and I was mistaken about the misalignment in PROC. I failed to notice that the epilog macro creates at least and empty frame, thus aligning the stack.
|
|||
16 Jun 2013, 00:43 |
|
spandexyfronts 22 Sep 2013, 04:09
thanks to bitRAKE for posting such a useful tip...
aligning the stack to 16b just fixed a few problems i've been having with the invoke feature |
|||
22 Sep 2013, 04:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.