flat assembler
Message board for the users of flat assembler.
Index
> Windows > File position |
Author |
|
score_under 27 Aug 2009, 20:33
Simple question, probably not a simple answer
How do I get the position of a label in the resultant PE file of the generated piece of code? In this case: Code: Characteristics dd 0x0 TimeDateStamp dd %t MajorVersion dw 0x0 MinorVersion dw 0x0 DebugType dd 0x1 DataSize dd EndDbg-CoffHeader DataRVA dd rva CoffHeader DataSeek dd (File position ??) I am experimenting with trying to implement debug information (the kind that Olly allows ) in the EXE file. Of course the next step is to edit the part of the PE header that points to the debug information table, but there's really nothing you can do on FASM to edit the PE header directly. (Or if there is, it needs to be much better documented) (If there is not, one of the first things I would like to see is a custom section alignment in the file and in virtual memory) Also edit- http://www.jorgon.freeserve.co.uk/TestbugHelp/Optimisation.htm#hint How about implementing that too? |
|||
27 Aug 2009, 20:33 |
|
Borsuc 27 Aug 2009, 23:38
See my thread on building the PE format & header completely manually with FASM macros here.
However before you go there let me emphasize what you're looking for (because the manual PE macro code is kinda hard to grasp at first). You're looking for a way to obtain the "current file position", am I right? It's not that hard so let me explain. First, you have to OVERRIDE the "org" directive, because you'll need to update an internal (read: probably local, for convenience) variable. Code: ; Override 'org' directive to find out the file offset fileoffset=0 ; this does not store the current offset, rather it stores the offset where the '$$' is in the FILE macro org value* { fileoffset=fileoffset+$-$$ org value ; use the normal 'org' functionality here } Important! Keep in mind that if you want to use FASM's multi-pass method of obtaining file offsets, then you will have to declare label offsets IN THE FILE, not use "fileoffset-$$+label" directly, because it would use the CURRENT (wrong) fileoffset -- in the meantime, this variable could get updated! So for example if you have this: Code: dd fileoffset-$$+label label: Code: dd label_fileoffset label: label_fileoffset = fileoffset-$$+label ; this uses the proper 'fileoffset' found HERE, not at the beginning of the file! Personally I recommend you make fileoffset "local" to not conflict with possible variables with that name. To do that, enclose the macro in another macro or "rept 1" instruction (in case of macro, you purge it afterwards) just to declare it local like this: Code: rept 1 { local fileoffset macro somemacro \{ ; blah \} } Code: macro init { local fileoffset macro somemacro \{ ; blah \} } init purge init |
|||
27 Aug 2009, 23:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.