flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Post-Processor file size operator?

Author
Thread Post new topic Reply to topic
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy 11 Jun 2015, 01:48
Hello, is there a way to determine the completed file's size inside of the code? I looked at the '$$' but I'm not too sure that's what I'm looking for. What I am looking for is something like this:

invoke printf,"%d",%thisfile'scompiledsize%

I wish to do this inside of the code, without having to invoke GetFileSize. Is this possible?
Post 11 Jun 2015, 01:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 02:40
Do you mean fasm's source code? Or within the your own source code? It is not clear what you are doing. Can you post your code example please?
Post 11 Jun 2015, 02:40
View user's profile Send private message Visit poster's website Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy 11 Jun 2015, 04:05
I think expressing myself through an image would best help me explain what I'm looking for:
Image
Post 11 Jun 2015, 04:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 04:41
Getting the on-disk size of a PE file without the normal disk functions is not a trivial thing. The in-memory address ranges and the on-disk sizes are different. You would have to scan the section headers to determine the on-disk size of each individual section.

Since you don't want to use GetFileSize then you make your task a lot more involved.

Do you want to modify fasm source code to pass into the program the on-disk size? Is that why you posted this in the "Compiler Internals" forum?


Last edited by revolution on 11 Jun 2015, 13:59; edited 1 time in total
Post 11 Jun 2015, 04:41
View user's profile Send private message Visit poster's website Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy 11 Jun 2015, 13:49
Yes! That's exactly what I am looking for. I thought there was already a way to do this, I must have been mistaken.

I have done a very poor job of explaining myself. What I was looking for was if there was already a way for FASM to insert to the finished product's file size into the finished product wherever specified. I should not have mentioned GetFileSize since that only made things more confusing. I had no original intention to modify FASM, I was looking for a built in functionality.
Post 11 Jun 2015, 13:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 13:58
If you look at PARSER.INC and find the label 'get_predefined_id' you could add another value similar to the existing %t.
Post 11 Jun 2015, 13:58
View user's profile Send private message Visit poster's website Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy 11 Jun 2015, 17:11
Is parser.inc used in the final stages of compilation, at the time where the final size would be or could be known?
Post 11 Jun 2015, 17:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 Jun 2015, 01:38
You need to start with parser.inc to add the symbol (something like %s, or whatever). Then you add processing for that similar to %t to generate the value you want. The size value would come from the PE formatter code. And being a forward referenced value you would need a minimum of two passes to get the correct value.
Post 12 Jun 2015, 01:38
View user's profile Send private message Visit poster's website Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy 12 Jun 2015, 05:34
Okay, time to delve into FASM's source, thanks!
Post 12 Jun 2015, 05:34
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 12 Jun 2015, 19:40
For stuff like this I use multi stage assembly with an initial "null" pass that fills in the binary with placeholders then a second assembly that fills this in with proper values:
Code:
format PE console 4.0
entry start
include '%fasminc%/win32ax.inc'
section '.data' data readable writable
if 0 ; First assemble with 0; then assemble with 1 (this will have the size)
virtual at 0
file 'test.exe' ; assuming source is test.asm
_mysize = $ ; actual
end virtual
else
_mysize = 0 ; null
end if
mysize dd _mysize
section '.code' code readable executable
start:
cinvoke printf,"Size: %d",[mysize]
ret
section '.idata' import data readable writable
library msvcrt,'MSVCRT.DLL'
import msvcrt,printf,'printf'     
Post 12 Jun 2015, 19:40
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.