Size of initialized data is frequently wrong. The file will load with any value you put there. Sizeofimage is a consequence.
Yep. Fortunately some other values are valid ;)
And I managed to translate them into a new macro,
@MbRet, see attachment:
include \masm32\MasmBasic\
MasmBasic.inc ;
downloadCodeBelow PROTO :DWORD, :DWORD, :DWORD
CodeAbove proc uses edi hwnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL MyLocVar:DWORD, LocBuffer[260]:BYTE
ClearLocals push
esi ; esi to stack
lea esi, LocBuffer
nop
push
eax ; ouch, we are not good at counting pushes and pops! pop
esi ; restore the stack
@MbRet
CodeAbove endp
Has2Args proc uses
esi edi ebx mode, arg2
; no locals here
push
eax mov ecx, mode
pop
eax push
eax ; one push too much
@MbRet
Has2Args endp
Has3Args proc uses
ecx mode, arg2, arg3
push
eax mov ecx, mode
pop
eax pop
eax ; one pop too much
@MbRet
Has3Args endp
Init invoke CodeAbove, 11111111h, 22222222h, 33333333h, 44444444h
invoke CodeBelow, 11111111h, 22222222h, 33333333h
invoke Has3Args, 12345678h, 22222222h, 33333333h
invoke Has2Args, 12345678h, 22222222h
Inkey "ok?"
ExitCodeBelow proc uses esi edi ebx ecx edx eax arg1, arg2, arg3
LOCAL MyLocVar:DWORD
LOCAL LocBuffer[40h]:BYTE
ClearLocals ; optional: zero-initialise local variables (not with uses in proc head) lea
esi, LocBuffer
; whatever pop
eax ; ouch, again we are not good at counting pushes and pops! @MbRet
CodeBelow endp
EndOfCodeOutput:stack error in line 11, (push-pop)=-1
stack error in line 43, (push-pop)=1
line 27: retaddr 12345678 is above code segment
@MbRet generates just an ordinary
ret for usedeb=0. So for testing, set usedeb=1 and see what happens. I have applied it to RichMasm, over 130
rets are now active observers of stack corruption, at least in my debug version :P
Warning: Do not use for Windows callback functions. It won't crash, but no warnings either. Own procedures without a stack frame will issue a warning and crash directly afterwards, as expected.