flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > FASM custom IMAGE_DOS_HEADER bug? |
| Author |
|
|
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. |
|||
|
|
vityacv 17 Oct 2026, 17:05
The PE offset at 0x3C is already set (40 00 00 00), so it runs fine on Windows.
An attached stub can be bigger than 64 bytes, so manually editing fields afterwards isn't practical. Having FASM attach it as-is would be much better. |
|||
|
|
Tomasz Grysztar 17 Oct 2026, 18:10
As noted here, I am aware that current PE loaders do not care about MZ header fields other than the "MZ" signature and the PE offset. But this is not an universal rule and fasm aims to produce files that should be valid for various legacy systems, too.
Therefore I second revolution's suggestion to manually overwrite the header in post-processing. With fasm2 it is very easy: Code: format PE64 on 'nul' postpone ? store 0: 3Ch-2 at :2 end postpone int3 |
|||
|
|
vityacv 22 Oct 2026, 18:23
Tomasz Grysztar wrote: But this is not an universal rule and fasm aims to produce files that should be valid for various legacy systems, too. Yes, but if a user supplies a non-standard custom DOS stub, FASM silently "fixes" it - altering the output without any warning. For comparison, Microsoft Linker (v14.51) leaves the stub untouched except for e_lfanew (and adding the Rich Header). Even with an almost-blank stub (only e_magic and e_lfanew), it issues a warning and attaches it as-is. |
|||
|
|
Tomasz Grysztar 23 Oct 2026, 15:49
I'm not going to produce a malformed MZ header just because makers of other software decided that it's not important anymore. Even if not to others, it is important to me (in part due to fasm's DOS roots).
And with fasm2 you can do anything you want anyway, either by post-processing as demonstrated above, or even by making a customized PE.INC. With fasm 1 post-processing is an option too, but requires separate stages (like the ones made by Grom PE). |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.