NO

Author Topic: Missing ret statement in the procedure  (Read 2292 times)

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Missing ret statement in the procedure
« on: April 09, 2014, 08:56:42 PM »
Testing Poasm Version 8.00.0, the procedure testproc below will end without the ret statement :

Code: [Select]
.386
.model flat,stdcall
option casemap:none

MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox  EQU <MessageBoxA>
ExitProcess PROTO :DWORD

testproc    PROTO :DWORD,:DWORD

MB_OK       EQU 0

.data

capt        db 'Hello',0
message     db 'This is a test',0

.code

start:

    invoke  testproc,ADDR message,ADDR capt

    invoke  ExitProcess,0

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

testproc PROC _msg:DWORD,_title:DWORD

    invoke  MessageBox,0,DWORD PTR [esp+12],\
            DWORD PTR [esp+12],MB_OK

    ret     2*4

testproc ENDP

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

END start

Analyzing the COFF object module with objconv :

Code: [Select]
_testproc@8 LABEL NEAR
        push    0
        push    dword ptr [esp+0CH]
        push    dword ptr [esp+0CH]
        push    0
; Note: Function does not end with ret or jmp
        call    _MessageBoxA@16
_start  ENDP
Code it... That's all...

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Missing ret statement in the procedure
« Reply #1 on: April 12, 2014, 02:54:09 PM »
It's a "known feature" - use retn or retf instead of ret in this case (no epilogue). I use ret as a kind of pseudo instruction: it triggers the emission of epilogue code plus a ret instruction when needed, so when "no epilogue" is set you get no ret instruction either. I looked at improving this, but it was just too much work (at least for this version).
/Pelle

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Re: Missing ret statement in the procedure
« Reply #2 on: April 12, 2014, 07:29:15 PM »
Hi Pelle,

Many thanks for the information. Replacing ret with retn worked fine.
Code it... That's all...