flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > New "align" formatter directive

Author
Thread Post new topic Reply to topic
GR-K



Joined: 11 Aug 2006
Posts: 13
Location: Novosibirsk, Russia
GR-K
If I am not mistake, officially, NT systems EXEs loader supports PE-files aligning up to 32 bytes. It is very useful when a program is designed for such systems (as most of currently available defragmentators which are uses CreateFile to open disks). But there is a little "hacks" may have place.

For example, find out MSCOFF example from FASM. Then command something like this:
Quote:
LINK.EXE /OUT:EXAMPLE.EXE /SUBSYSTEM:WINDOWS MSCOFF.OBJ /ENTRY:demo USER32.LIB /DRIVER /ALIGN:4
The /DRIVER parameter is necessary. Output is only 812 bytes long. Sure, you can use any other linker, but I suppose that everybody have link.exe. I am still cannot find how to change PEs aligning in FASM (except writing of RAW PE or source changing). Think, that it is not a bad idea to include new directive in FASM's PE formatter.
Post 11 Aug 2006, 08:49
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
hmm, "format pe align 32" might be added, but how to distinguish file align and memory align?
Post 11 Aug 2006, 10:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1607
Location: Ukraine
shoorick
"pealign" "alignsect(ion)"
Post 11 Aug 2006, 10:30
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
ugh... new keywords Wink

or "format PE align 200h, 1000h" :DDD
no new keywords
Post 11 Aug 2006, 10:36
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
GR-K



Joined: 11 Aug 2006
Posts: 13
Location: Novosibirsk, Russia
GR-K
Anyway PE formatter does not support align directive.

Assembler don't need to distinguish them. Simply, file align means how many nulls will be added to the end of executable Smile, when memory align - how many nulls to add before the next command.

P.S.: I know only two ways to get executable with a file alignment smaller than 200h. 1st, is to write RAW PE, and 2nd is to use "format PE native" directive and then change subsystem manually.
Post 11 Aug 2006, 11:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
On disk the file will still occupy 4k minimum unless you are storing the file on a floppy. So a file size of 812 bytes is really going to be 4096 bytes anyway.
Post 11 Aug 2006, 14:04
View user's profile Send private message Visit poster's website Reply with quote
GR-K



Joined: 11 Aug 2006
Posts: 13
Location: Novosibirsk, Russia
GR-K
Sure that is. Do you think that it is better to download an 4KB file? As assembler coder I like to write programs as small as possible. Don't you?

It is bad that when I am coding in my favorite assember, I need to cut all this nulls and set 4B alignment up manually. Because of it I am asking Tomasz for adding directive that will change default PE file alignment.
Post 12 Aug 2006, 06:06
View user's profile Send private message Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
Maybe fasm's default value (0x200=512) for a non-native PE image is somehow optimized for disk access, since most disks have sector size of 512 bytes.
Post 12 Aug 2006, 15:05
View user's profile Send private message Reply with quote
GR-K



Joined: 11 Aug 2006
Posts: 13
Location: Novosibirsk, Russia
GR-K
Disk access? No. Simply, 200h bytes it is minimal aling value for w9x systems. And EXE with smaller alignment will not work on them. It means that your program will incompatible with older OS versions. The reason for adding directive that will change standart alignment value is that most of modern programs written directly for NT/W2K/XP systems and it will help to get smallest executables.
Post 12 Aug 2006, 16:03
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
It may make sense to allow custom file alignment, though for memory alignment alignments smallers that 4 kilobytes are not a good idea - the system wouldn't be able to apply the page attributes correctly for each section.
The reason why it's not implemented yet is that it would require rewriting some bits of PE formatter and thus it's not really a quick and easy addition.
The PE formatter is one of the few parts of fasm that never got completely rewritten and remains really only a bit altered in general design since it's introduction in fasm 1.04 - and the time the PE documentations I had allowed no file alignment smaller than 200h. Later I inclined it a bit to make the "native" be handled differently, but it's still a bit of a special case - at the same time I tried preparing it allow custom alignment, but few details prevented me from finishing.
But, since it's actually the first time that this feature is openly requested, I'm motivated to get back to it.
Post 12 Aug 2006, 18:00
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
tomasz: and what about syntax for it?
Post 12 Aug 2006, 20:37
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
Your suggestion was good IMO, as I noted it would be only the file alignment to be adjusted.
Post 12 Aug 2006, 20:43
View user's profile Send private message Visit poster's website Reply with quote
GR-K



Joined: 11 Aug 2006
Posts: 13
Location: Novosibirsk, Russia
GR-K
Thanks for reply, and thanks for your work.

It's easy to change align manually (and then cut off all not needed nulls), and everybody (or not?) can change hardcoded values in sources, but it will better to have customizable PE formatter.

Tnx again, I'll wait :)
Post 13 Aug 2006, 07:33
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.