flat assembler
Message board for the users of flat assembler.

Index > Windows > proc, disable frame setup?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
How do you keep proc from setting up EBP in the beginning? FASM uses ESP relative addressing anyway.

Code:
proc Something par1,par2,par3
   ...
endp    


begins with:

Code:
PUSH EBP
MOV EBP,ESP
...
    
[/code]

_________________
This is a block of text that can be added to posts you make.
Post 13 Feb 2010, 04:47
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:
FASM uses ESP relative addressing anyway.

Not sure what you mean, but proc macro defines the arguments and locals as EBP-based, so that sequence you mention has to be there. The only way to avoid it is by not defining any argument nor locals.

The macro could probably be extended to check if any of the EBP-based things are actually referenced and if none of them are then don't generate the prolog (but still generate the appropriate N in "retn N").
Post 13 Feb 2010, 05:28
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mindcooler,

There is prologue@proc symbolic constant, it holds the name of macro prologue@proc procname,flag,parmbytes,localbytes,reglist to be expanded at the very beginning of proc.

If all else fails, read the source.
Post 13 Feb 2010, 06:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
Post 13 Feb 2010, 06:29
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution,

Regarding the links, esp is quite uninforming. frameless or FPO, perhaps?
Post 13 Feb 2010, 08:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
FPO?

And 'frameless' seems like too much to type. I am lazy to type too much. Razz
Post 13 Feb 2010, 10:19
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
LocoDelAssembly wrote:
Quote:
FASM uses ESP relative addressing anyway.

Not sure what you mean, but proc macro defines the arguments and locals as EBP-based, so that sequence you mention has to be there. The only way to avoid it is by not defining any argument nor locals.


Well, my FASM generates ESP relative code for my arguments:

Code:
FF75 14       PUSH DWORD PTR SS:[ARG.4]
FF75 10       PUSH DWORD PTR SS:[ARG.3]
FF75 0C       PUSH DWORD PTR SS:[ARG.2]
FF75 08       PUSH DWORD PTR SS:[ARG.1]
FF15 A2204000 CALL DWORD PTR DS:[<&USER32.DefWindowProcW>]    

_________________
This is a block of text that can be added to posts you make.
Post 13 Feb 2010, 14:32
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
baldr wrote:
mindcooler,

There is prologue@proc symbolic constant, it holds the name of macro prologue@proc procname,flag,parmbytes,localbytes,reglist to be expanded at the very beginning of proc.

If all else fails, read the source.


Yes, I checked the macro include files, but I don't quite understand all the proc macros. The
Code:
macro prologuedef procname,flag,parmbytes,localbytes,reglist    

seems to deal with ebp, but I don't see why.

Code:
 { local loc
   loc = (localbytes+3) and (not 3)
   parmbase@proc equ ebp+8
   localbase@proc equ ebp-loc
   if parmbytes | localbytes
    push ebp
    mov ebp,esp
    if localbytes
     sub esp,loc
    end if
   end if
   irps reg, reglist \{ push reg \} }    

_________________
This is a block of text that can be added to posts you make.
Post 13 Feb 2010, 14:40
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
mindcooler wrote:
Well, my FASM generates ESP relative code for my arguments:
Are you using a custom set of macros? The standard macros don't do that.
Post 13 Feb 2010, 14:47
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
I'm using
Code:
include 'win32wxp.inc'    

_________________
This is a block of text that can be added to posts you make.
Post 13 Feb 2010, 16:58
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Where do you see ESP there???

This is what OllyDbg decodes for one of those pushes opcodes:
Code:
FF75 08          PUSH DWORD PTR SS:[EBP+8]    


All start with FF75, so in not even a single case there was an ESP-based reference.
Post 13 Feb 2010, 17:03
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Sorry, I seem to have assumed that ARG.1 was relative to ESP. In light of this it seems the question is; how do you do ESP addressed arguments? I don't think I'll ever need EBP-based parameters, and I want EBP unused so I can use EBP for short data addressing. If I can't use the existing proc macro, is there any others I can use for subroutines, or am I supposed to do them manually?

_________________
This is a block of text that can be added to posts you make.
Post 13 Feb 2010, 23:00
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
mindcooler wrote:
In light of this it seems the question is; how do you do ESP addressed arguments?
Did you see my links above?

http://board.flatassembler.net/topic.php?t=5938 is one way to do it. There are other ways also that may be more convenient for you. But do take the time to read the entire fist post to realise both the advantages and disadvantages. It is not all easy going with ESP as a base pointer, so consider carefully whether you want to completely eliminate EBP based variables.
I previously said: wrote:
For those of you that may not be aware of why ESP basing is not normally used, here are some reasons why you might not use it:

1) Calls to other proc's with pushing of parameters requires special handling [...]
2) General purpose push/pop creates a nightmare with accessing local variables and caller parameters.
Post 14 Feb 2010, 00:31
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Hmm, my experiences thus far, correct me if I'm wrong:

- Without EBP addressing you can't invoke from the stack, as ESP changes at runtime. Unless you start calculating offsets manually that is.
- EBP addressing is one byte shorter than ESP addressing

I think I'm going to free up another register from my data addressing :S Can you do without ESI or EDI? :P

_________________
This is a block of text that can be added to posts you make.
Post 15 Feb 2010, 01:05
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Is this the way to do subroutines if you do away with proc?

Code:
WindowProc:
 virtual at esp+8
 .wmsg  rd 1
 end virtual

        cmp     [.wmsg],WM_DESTROY
        jne     .exit
        invoke  PostQuitMessage,0
 .exit:
        jmp    [DefWindowProc]    

_________________
This is a block of text that can be added to posts you make.
Post 15 Feb 2010, 02:09
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
mindcooler wrote:
Is this the way to do subroutines if you do away with proc?

Code:
WindowProc:
 virtual at esp+8
 .wmsg  rd 1
 end virtual

        cmp     [.wmsg],WM_DESTROY
        jne     .exit
        invoke  PostQuitMessage,0
 .exit:
        jmp    [DefWindowProc]    
That only works when the entry parameters for WindowProc are exactly the same as the parameters required for DefWindowProc. Extremely hacky way to do things.
Post 15 Feb 2010, 06:55
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7737
Location: Kraków, Poland
Tomasz Grysztar
Since DefWindowProc is a kind of WindowProc, it has the exactly same parameters by definition. Actually it's a nice interface forwarding you have here.
Post 15 Feb 2010, 07:32
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
revolution wrote:
Extremely hacky way to do things.


I call it "not doing unnecessary stuff". This is the main reason for my switch from high level languages. I chose fasm because I hate linkers :P

Tomasz Grysztar wrote:
Actually it's a nice interface forwarding you have here.


Coming from you, that means a lot to me :)

I now have this basis for a WindowProc:

Code:
WindowProc:

 virtual at esp+8
 .wmsg  rd 1
 end virtual

        cmp     [.wmsg],WM_DESTROY
        jne     .default
        invoke  PostQuitMessage,0
 .exit:
        xor     eax,eax
        ret     $10
 .default:
        jmp    [DefWindowProc]
.end start    


We'll see if I get into addressing trouble as I expand on it. being able to use EBP for work data not on the stack will surely save addressing bytes?

_________________
This is a block of text that can be added to posts you make.
Post 15 Feb 2010, 12:35
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution wrote:
Extremely hacky way to do things.
Ain't assembly language programming all about being hacky? Wink

That's why I do hate the way MS extends [for example] MessageBox into MessageBoxEx and later into [undocumented] MessageBoxTimeout (i.e. appending new parameter at the end instead of inserting it as first). pop eax / push default_value / push eax / jmp functionEx looks much better than copying entire call frame.

FPO is "frame pointer omission", by the way. Wink

__________
mindcooler,

You have to save ebp anyway to be compliant to stdcall / cdecl, haven't you? And each access through esp adds SIB byte to the toll… where is the profit? As far as I can see, only elimination of prologue (3 bytes)/epilogue (1 byte) matters, so (byte-wise) four esp-relative accesses is the break-point.
Post 15 Feb 2010, 16:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
baldr: The potential "profit" is the extra register for general purpose computations.
Post 15 Feb 2010, 17:15
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.