flat assembler
Message board for the users of flat assembler.

Index > Windows > Displaying amount of bytes before EXEcutable size increases

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 18 Oct 2017, 15:16
I was playing with size coding for a while. The size of PE EXE you get with FASM is usually a multiple of 512 bytes. One of the things I felt would be useful is to know how many bytes can be added before the EXE size increases.

I have a macro that is able to show numeric values of FASM variables. The problem is that it’s not obvious for me how to calculate the value when using flat section only. Can anyone shed some light on this?
Post 18 Oct 2017, 15:16
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8263
Location: Kraków, Poland
Tomasz Grysztar 18 Oct 2017, 15:26
You'd need to calculate the RVA of the top of initialized part of the section, and then how many bytes are left to the nearest 512 byte boundary.

What would help here is if I backported fasmg's "$@" feature into fasm 1. Currently fasm 1 has nothing similar, so you have to manually place the calculation at the boundary between initialized and uninitialized data.
Post 18 Oct 2017, 15:26
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 18 Oct 2017, 15:43
Tomasz Grysztar wrote:
You'd need to calculate the RVA of the top of initialized part of the section, and then how many bytes are left to the nearest 512 byte boundary.

What would help here is if I backported fasmg's "$@" feature into fasm 1. Currently fasm 1 has nothing similar, so you have to manually place the calculation at the boundary between initialized and uninitialized data.

Thanks, it almost works, there’s just a small difficulty.

Since I’m doing size coding, I decided to store a pointer to all the data my program needs in a non-volatile register. To make access to the data more readable I put all the fields into a struct and then put a single instance of it, like this:
Code:
data import
        library kernel32, 'kernel32.dll',\
        ...

        struct TProgramData
                szEdit  db      "EDIT", 0
                ; More initialized data here

                pBuffer dd      ?
                ; More uninitialized data here
        ends
        ProgramData     TProgramData
end data    


The following formula works almost well:
Code:
512 - ((rva ProgramData.pBuffer) mod 512)    


… until the value becomes 3. When it does, it nevers gets to zero, but becomes 511, 510, etc. after file size increases. Seems to be caused by some kind of alignment. It’s not critical, but would be quite nice to solve the problem. Is it possible?
Post 18 Oct 2017, 15:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8263
Location: Kraków, Poland
Tomasz Grysztar 18 Oct 2017, 16:18
This certainly does sound like some kind of alignment causing the jump in size. The "import" macro does contain one that looks like this:
Code:
rb (- rva $) and 3    
You could try commenting out this line to see if this is the reason.
Post 18 Oct 2017, 16:18
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 18 Oct 2017, 17:41
Tomasz Grysztar wrote:
This certainly does sound like some kind of alignment causing the jump in size. The "import" macro does contain one that looks like this:
Code:
rb (- rva $) and 3    
You could try commenting out this line to see if this is the reason.

Nope, commenting it and/or a few other lines that reserve some bytes depenging on current offset $ just makes the actual values shift this or that way, but doesn’t make them change smoothly near the 512 byte boundary.

I guess, it’s not a big deal anyway: at least it shows the right values in most cases and the values are not expected to be used for anything except being a reference value. So, thanks for your help.
Post 18 Oct 2017, 17:41
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:  


< 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.