flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [BUG]cinvoke restores ESP incorrectly with "double" |
Author |
|
kohlrak 11 Oct 2009, 03:27
Erm, isn't that call @f going to cause a problem?
|
|||
11 Oct 2009, 03:27 |
|
bitshifter 11 Oct 2009, 03:46
Im counting 12 bytes to cleanup the stack.
Remember, printf's ret compliments its call. Maybe Loco can explain this a bit more... Last edited by bitshifter on 11 Oct 2009, 04:43; edited 1 time in total |
|||
11 Oct 2009, 03:46 |
|
revolution 11 Oct 2009, 04:36
The code above is the same as:
Code: text_string: db "%f", 10, 0 push dword [eax+4] push dword [eax] push text_string call [printf] add esp, 8 ; <<< Should be 12 |
|||
11 Oct 2009, 04:36 |
|
sinsi 11 Oct 2009, 04:47
I get the call @f bit (it pushes the address of the string, which is printf's first param) but I don't get how the macro interprets <"%f", 10>
Is that in the internals of fasm? And yes, it should be 12. |
|||
11 Oct 2009, 04:47 |
|
revolution 11 Oct 2009, 04:55
sinsi: See the WIN32{A|W}X.INC files:
Code: ... macro pushd value { match first=,more, value \{ \local ..continue call ..continue db value,0 ..continue: pushd equ \} ... |
|||
11 Oct 2009, 04:55 |
|
sinsi 11 Oct 2009, 05:13
oops for some reason I thought pushd was an actual mnemonic
|
|||
11 Oct 2009, 05:13 |
|
LocoDelAssembly 11 Oct 2009, 05:16
Just to be super clarify with sugar on top:
Code: format pe console include 'win32ax.inc' int3 cinvoke printf, .fmt, dword [.double], dword [.double+4] cinvoke printf, .fmt, double [.double] cinvoke printf, .fmt, double 1.0 ret .fmt db "%f", 0 .double dq 1.0 align 4 ; Just to be safe data import library msvcrt,'msvcrt.dll' import msvcrt,\ printf, 'printf' end data Code: CPU Disasm Address Hex dump Command Comments 00401000 /. CC INT3 00401001 |. FF35 52104000 PUSH DWORD PTR DS:[401052] 00401007 |. FF35 4E104000 PUSH DWORD PTR DS:[40104E] 0040100D |. 68 4B104000 PUSH test.0040104B ; ASCII "%f" 00401012 |. FF15 94104000 CALL DWORD PTR DS:[<&msvcrt.printf>] 00401018 |. 83C4 0C ADD ESP,0C ; OK 0040101B |. FF35 52104000 PUSH DWORD PTR DS:[401052] 00401021 |. FF35 4E104000 PUSH DWORD PTR DS:[40104E] 00401027 |. 68 4B104000 PUSH test.0040104B ; ASCII "%f" 0040102C |. FF15 94104000 CALL DWORD PTR DS:[<&msvcrt.printf>] 00401032 |. 83C4 08 ADD ESP,8 ; WRONG 00401035 |. 68 0000F03F PUSH 3FF00000 0040103A |. 6A 00 PUSH 0 0040103C |. 68 4B104000 PUSH test.0040104B ; ASCII "%f" 00401041 |. FF15 94104000 CALL DWORD PTR DS:[<&msvcrt.printf>] 00401047 |. 83C4 08 ADD ESP,8 ; WRONG 0040104A \. C3 RETN 0040104B 25 DB 25 ; CHAR '%' 0040104C 66 DB 66 ; CHAR 'f' 0040104D 00 DB 00 |
|||
11 Oct 2009, 05:16 |
|
bitshifter 11 Oct 2009, 08:18
Now that i think of it...
About two weeks ago i was using sprintf to format a string of doubles. I tried to use double sized args and it just kept blowing up in my face. Being so lazy i didnt check in debugger and just pushed dwords instead. Im sure now that this is exactly what was happening to me in my code. |
|||
11 Oct 2009, 08:18 |
|
Tomasz Grysztar 11 Oct 2009, 08:50
sinsi wrote: Is that in the internals of fasm? Well, it is not. I'm moving it to "Macroinstructions". |
|||
11 Oct 2009, 08:50 |
|
Tomasz Grysztar 11 Oct 2009, 09:13
Loco, thanks for the detailed report, as in this case it really was important. The problem was a typo in win32ax.inc, all the other includes (even win32axp.inc) had it correct.
|
|||
11 Oct 2009, 09:13 |
|
LocoDelAssembly 11 Oct 2009, 17:13
Seems to work great now. Thanks for the fix.
|
|||
11 Oct 2009, 17:13 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.