Register
Bitwise»Forums»Making valid .bin files in x64 compiler
1 posts
Making valid .bin files in x64 compiler
10 months, 1 week ago Edited by huzaifa on Jan. 26, 2019, 2:45 p.m.
In the three part series of the "Programming a x64 compiler from scratch", the first part confused me a bit. Per wrote bytes to a .bin file, and when he disassembled it, it was working. Seemingly, he wrote machine code without an assembler or a compiler. When I tried the same thing, the objdump program threw an error, stating that the .bin file is corrupt or invalid. How could I resolve this?
Mārtiņš Možeiko
1989 posts / 1 project
Making valid .bin files in x64 compiler
10 months, 1 week ago
Did you try writing exact same bytes as he did, or this is your custom thing you wrote?
To diagnose why something is not working here you should open file in hexeditor and go byte by byte over it, starting from top. Look up structure descriptions that specifies how executable format is defined, and verify that your bytes are exactly what should be.
Ameen Sayegh
52 posts
Making valid .bin files in x64 compiler
9 months, 1 week ago
Make sure you tell objdump that the file is binary format using the switch --target=binary.
From the error message, it seems that objdump doesn't know that the file is raw machine code without headers.