The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: Biterider on November 14, 2018, 12:34:06 AM

Title: Standard Prologue/Epilogue
Post by: Biterider on November 14, 2018, 12:34:06 AM
Hi
If we want to change something when a procedure is called, we have to redefine the standard prologue or epilogue. Now, if I want to add something before or after the standard prologue/epilogue, is there a way to call the standard prologue/epilogue generation from within their modified versions?

NewPrologue macro ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams
    Call StdPrologue, ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams
    DoMyStuff
    exitm <0>
endm


Biterider
Title: Re: Standard Prologue/Epilogue
Post by: johnsa on November 14, 2018, 03:08:25 AM
I don't believe so. If the prologue is set to default then the code generates the operations directly as opposed to substituting in the macro.
We could look at allowing evaluation of the default prologue if you inserted option prologue:default into your actual macro.
Title: Re: Standard Prologue/Epilogue
Post by: mabdelouahab on November 14, 2018, 06:49:27 AM
johnsa
If we can figure out the name of the default  Prologue macro, Something like @Line,@FileName,@CurSeg,... , for example @DefaultPrologueMacro
So that we can use it as follows

StdPrologue equ @DefaultPrologueMacro
NewPrologue macro ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams
    DoMyStuff
    exitm <StdPrologue(ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams)>
endm
OPTION PROLOGUE:NewPrologue


Answer with johnsa
Title: Re: Standard Prologue/Epilogue
Post by: jj2007 on November 14, 2018, 01:29:06 PM
Have you thought of doing it the other way round?

PrologueDef macro ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams
   if defined @UserPrologue
        @UserPrologue ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams
   endif
...

Title: Re: Standard Prologue/Epilogue
Post by: Biterider on November 14, 2018, 05:40:48 PM
Hi
Yes, good point.
In this case you will need 4 callbacks or user-macros. Before and after the user defined code and for the prologue and the epilogue.
Arguments for this callbacks/macros can be a bit tricky, since you don't know what you want to pass to them. This needs a bit of elaboration.

Using the first approach, you will only need 2 callbacks/macros to the default prologue and epilogue.

Biterider

Title: Re: Standard Prologue/Epilogue
Post by: johnsa on November 14, 2018, 08:46:05 PM

As I mentioned, there is no "default" macro. If the default mode is enabled, the assembler directly generates the prologue.
The option from my side would be a sort-of, "pre"-prologue macro.
I'm curious what you'd be looking to do with this, perhaps there is another solution that doesn't involve messing with the prologue at all ?
Title: Re: Standard Prologue/Epilogue
Post by: Biterider on November 14, 2018, 10:53:42 PM
Hello John
Things were much easier in the 32-bit world. Because the prologue and epilogue code is much simpler, you could handle it.
In 64-bit world, the prologue and epilogue have become much more complicated and additionally depend on many settings.

This feature request targets the following usage:
That means, if we want to follow the suggested path, that we need 4 macros: a pre- and a post- prologue and epilogue macro.

Biterider
Title: Re: Standard Prologue/Epilogue
Post by: johnsa on November 15, 2018, 03:17:05 AM
The easiest to implement solution would be:

Currently we have these options:

option prologue:none
option prologue:default
option prologue:usermacro

If we add:

option prologue:usermacro,default

That would add the usermacro code before generating the default.. and the same in reverse for epilogue.

If you're ok with that I will add it to our list.
Title: Re: Standard Prologue/Epilogue
Post by: mabdelouahab on November 15, 2018, 05:22:15 AM
For me, that's good, because I'm looking for the same thing, but for Biterider I don't know.
Title: Re: Standard Prologue/Epilogue
Post by: Biterider on November 15, 2018, 06:32:09 AM
Hi
I'm risking to be the bad guy, but the first 2 points
Quote
  • OOP / COM redirection after the default prologue
  • Detecting a buffer overflow by inserting a security cookie value after the default prologue
can not be implemented if
Quoteoption prologue:usermacro,default
That would add the usermacro code before generating the default

Imho, we have to look how to trigger the default code generation from within the usermacro.

BTW, the security cookie should be an option for the default prologue/epilogue like it is for some compilers.

Biterider

Title: Re: Standard Prologue/Epilogue
Post by: jj2007 on November 15, 2018, 12:27:40 PM
Hi biterider, bad guy ;)

What stops you from simply writing a prologue macro that has all the features you need? You don't need any additional intervention from the assembler, even bad ol' ML can do that...
Title: Re: Standard Prologue/Epilogue
Post by: mabdelouahab on November 15, 2018, 03:52:01 PM
jj2007, maybe he needs some modifications to the input, that he see as necessary.
For example

NewPrologue macro ProcName, Flags, ParamBytes, LocalBytes, RegList, UserParams
    DoMyStuff
    exitm <StdPrologue(ProcName, modifiedFlags, ParamBytes, modifiedLocalBytes, modifiedRegList, UserParams)>
endm


Sometimes we need things that way.
Title: Re: Standard Prologue/Epilogue
Post by: aw27 on November 16, 2018, 09:02:37 PM
It took some time to tune UASM to work well with 64-bit SEH. I don't think, but may be wrong, we can design a "default" macro for that. Even Masm does not use since long default prologue/epilogue macros, a few things can't be done proper and cleanly that way.
I know that people that make standalone asm applications is not concerned at all with SEH. But they are not concerned as well with security cookies/canaries.
However, the solution presented by johnsa seems reasonable but in reverse order because I don't see any reason to expect a second epilogue after the epilogue or insert extraneous code before or in the middle of a prologue. These areas are sacred. For special requirements do full prologue/epilogue macros by hand and good luck.
Just my 2 cents.
Title: Re: Standard Prologue/Epilogue
Post by: Biterider on November 16, 2018, 11:01:28 PM
Hi
When I read the last post, it occurred to me that I completely forgot about SEH!
For me it makes no sense to have a second epilogue, since nothing is executed after the return instruction from the default epilogue anyway.
Thus, everything could be reduced to a pos-prologue and pre-epilogue, as written preciously.

I think that the timing and performance stuff can also be done with this approach.
A delicate thing is the pos-prologue when you change the stack. This needs more elaboration to be done properly.

Biterider

Title: Re: Standard Prologue/Epilogue
Post by: johnsa on November 16, 2018, 11:52:57 PM

Well for post-prologue and pre-epilogue we shouldn't need to touch anything as that would be possible now.
AW is right, he has done some excellent 64bit SEH work and put me through the ringer to make it work properly under different modes and proc styles :)