diff options
Diffstat (limited to 'elf')
| -rw-r--r-- | elf/test.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/elf/test.lua b/elf/test.lua index dda8f78..c906fed 100644 --- a/elf/test.lua +++ b/elf/test.lua @@ -151,6 +151,50 @@ test("header.pack 64_le_x86-64", function () assert(actual == expected, "mismatch") end) +test("header.pack 32_le_i386", function () + local header = { + class = ec.Class.bit32, + data = ec.Endian.little, + type = ec.Type.exec, + machine = ec.Machine.i386, + entry = 0x01020304, + phoff = 0x11121314, + shoff = 0x21222324, + flags = 0x31323334, + ehsize = 0x3435, + phentsize = 0x3637, + phnum = 0x3839, + shentsize = 0x3a3b, + shnum = 0x3c3d, + shstrndx = 0x3e3f, + } + local expected = hex_to_bytes(table.concat({ + -- "BBBBBBBBBxxxxxxx" + "7f454c46010101000000000000000000", + -- "I2I2I4" + "0200030001000000", + -- string.rep(fmt.word(hdr.class), 3), where I4 is selected + table.concat({ + "04030201", -- entry + "14131211", -- phoff + "24232221", -- shoff + }), + -- "I4I2I2I2I2I2I2" + table.concat({ + "34333231", -- flags + "3534", -- ehsize + "3736", -- phentsize + "3938", -- phnum + "3b3a", -- shentsize + "3d3c", -- shnum + "3f3e", -- shstrndx + }), + })) + local actual = elf_header.pack(elf_header.normalize(header)) + assert(#actual == 52, "invalid ELF32 header size") + assert(actual == expected, "mismatch") +end) + -- Test segment.lua -- Test section.lua -- Test layout.lua |
