flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > FASM custom IMAGE_DOS_HEADER bug?

Author
Thread Post new topic Reply to topic
vityacv



Joined: 27 Oct 2012
Posts: 21
vityacv 16 Oct 2026, 13:50
Attempt to use a blank (nulls just test sample) 64-byte stub:

4D5A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000

Attach it via format pe64 on 'stub.bin':

4D5A4000010000000400000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000040000000

FASM treats it as a legacy MZ executable (e_lfarlc < 0x40) and overwrites e_cblp, e_cp, e_cparhdr, and e_lfarlc.
How to attach a raw stub as-is without FASM modifying these fields?

Also tested with 0xFF fill:

4D5AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40000000

• FASM 1: error: value out of range. (or out of memory)
• FASM 2: (heavy lag) Error: error reading file 'stub.bin'.

In FASM 2 (pe.inc), e_cp = 0xFFFF calculates .TEMPLATE_LENGTH ≈ 32MB, and it tries to read 32MB from a 64-byte file. Can this file size check
be added or bypassed?


Last edited by vityacv on 16 Oct 2026, 13:58; edited 2 times in total
Post 16 Oct 2026, 13:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21181
Location: In your JS exploiting you and your system
revolution 16 Oct 2026, 13:57
Some fields in the MZ header need to be correct for the loader to find the PE header. So modifying the header is needed for the file to load correctly. Without the changes the file is not valid.

To get a raw header with all zero bytes, manually overwrite the header after fasm creates the binary. The file probably won't run after that because the PE header offset is lost. Try it and see what Windows makes of it.
Post 16 Oct 2026, 13:57
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.