git clone http://ratfactor.com/repos/mez/mez.git
This is a utility written in Zig to help me debug the 32-bit ELF executables I’m exporting from Meow5, my toy language experiment.
It’s highly visual and shows me exactly what I want to know about:
It also includes a zem.zig
program that writes a multi-segment
ELF exectuable that prints “Hello world.” to make sure I’m doing
it right.
Example output (of Meow5 executable itself):
$ mez meow5
+-[ELF Header]------------------------------------------+
| 7F E L F 01 01 01 00 00 00 00 00 00 00 00 00 02 00 |
| 03 00 01 00 00 00 FA A5 04 08 34 00 00 00 88 6A 00 00 |
| 00 00 00 00 34 00 20 00 03 00 28 00 0B 00 0A 00 /-----+
+--+---------------------------------------------/
+-- Entry point address: 0x0804A5FA
+-- Program header file offset: 0x34
+-- Program header size: 32 (0x20)
\-- Program header count: 3
|
+-- Program Header 0 at 0x34, type: PT_LOAD
+-- Program Header 1 at 0x54, type: PT_LOAD
+-- Program Header 2 at 0x74, type: PT_LOAD
+-[Program Header 0]------------------------------+
| 01 00 00 00 00 00 00 00 00 80 04 08 00 80 04 08 |
| 94 00 00 00 94 00 00 00 04 00 00 00 00 10 00 00 |
+--+----------------------------------------------+
+-- File data start offset: 0x0
+-- File data bytes to load: 148 (0x94)
+-- Memory segment start addr: 0x08048000
+-- Memory segment byte size: 148 (0x94)
+-- Memory segment flags: R (0x4)
from 8048000 to 8048094...
0x08048000 7f 45 4c 46 01 01 01 00 00 00 00 00 .ELF........
0x0804800c 00 00 00 00 02 00 03 00 01 00 00 00 ............
0x08048018 fa a5 04 08 34 00 00 00 88 6a 00 00 ....4....j..
0x08048024 00 00 00 00 34 00 20 00 03 00 28 00 ....4.....(.
...100 more bytes to load...
+-[Program Header 1]------------------------------+
| 01 00 00 00 00 10 00 00 00 90 04 08 00 90 04 08 |
| 19 18 00 00 19 18 00 00 05 00 00 00 00 10 00 00 |
+--+----------------------------------------------+
+-- File data start offset: 0x1000
+-- File data bytes to load: 6169 (0x1819)
+-- Memory segment start addr: 0x08049000
+-- Memory segment byte size: 6169 (0x1819)
+-- Memory segment flags: R+X (0x5)
+-- Contains entry point 0x0804A5FA
from 8049000 to 804a819...
0x08049000 5b b8 01 00 00 00 cd 80 a1 a4 c9 04 [...........
0x0804900c 08 ff e0 00 00 00 00 08 00 00 00 0f ............
0x08049018 00 00 00 03 00 00 00 65 78 69 74 00 .......exit.
0x08049024 58 b9 00 00 00 00 80 3c 08 00 74 03 X......<..t.
...Skipping to entry point...
0x0804a5f0 00 6d 61 6b 65 5f 65 6c 66 00 fc c7 .make_elf...
0x0804a5fc 05 3c b1 04 08 02 00 00 00 c7 05 44 .<.........D
0x0804a608 b1 04 08 00 00 00 00 c7 05 4c b1 04 .........L..