diff options
| author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-11-09 12:13:12 +0530 |
|---|---|---|
| committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-11-09 12:13:12 +0530 |
| commit | b56fa87e13a9a97c77f035e4ae1934b52560acfb (patch) | |
| tree | cec7b7afb7bb9ed74bd876a30b8c8bd5d3ce5f92 /elf/test.lua | |
| parent | b12a3a53ec1258e4d815e491b0169977bbfa4444 (diff) | |
Add some big endian testcases.
Diffstat (limited to 'elf/test.lua')
| -rw-r--r-- | elf/test.lua | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/elf/test.lua b/elf/test.lua index 6c555a5..edd5f7d 100644 --- a/elf/test.lua +++ b/elf/test.lua @@ -195,6 +195,86 @@ test("header.pack 32_le_i386", function () assert(actual == expected, "mismatch") end) +test("header.pack 32_be_i386", function () + local header = { + class = ec.Class.bit32, + data = ec.Endian.big, + 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" + "7f454c46010201000000000000000000", + -- "I2I2I4" + "0002000300000001", + -- string.rep(fmt.word(hdr.class), 3), where I4 is selected + "01020304", -- entry + "11121314", -- phoff + "21222324", -- shoff + -- "I4I2I2I2I2I2I2" + "31323334", -- flags + "3435", -- ehsize + "3637", -- phentsize + "3839", -- phnum + "3a3b", -- shentsize + "3c3d", -- shnum + "3e3f", -- shstrndx + })) + local actual = elf_header.pack(elf_header.normalize(header)) + assert(#actual == 52, "invalid ELF32 header size") + assert(actual == expected, "mismatch") +end) + +test("header.pack 64_be_x86-64", function () + local header = { + class = ec.Class.bit64, + data = ec.Endian.big, + type = ec.Type.exec, + machine = ec.Machine.x86_64, + entry = 0x0102030405060708, + phoff = 0x1112131415161718, + shoff = 0x2122232425262728, + flags = 0x31323334, + ehsize = 0x3435, + phentsize = 0x3637, + phnum = 0x3839, + shentsize = 0x3a3b, + shnum = 0x3c3d, + shstrndx = 0x3e3f, + } + local expected = hex_to_bytes(table.concat({ + -- "BBBBBBBBBxxxxxxx" + "7f454c46020201000000000000000000", + -- "I2I2I4" + "0002003e00000001", + -- string.rep(fmt.word(hdr.class), 3), where I8 is selected + "0102030405060708", + "1112131415161718", + "2122232425262728", + -- "I4I2I2I2I2I2I2" + "31323334", -- flags + "3435", -- ehsize + "3637", -- phentsize + "3839", -- phnum + "3a3b", -- shentsize + "3c3d", -- shnum + "3e3f", -- shstrndx + })) + local actual = elf_header.pack(elf_header.normalize(header)) + assert(#actual == 64, "invalid ELF64 header size") + assert(actual == expected, "mismatch") +end) + -- Test segment.lua -- Test section.lua -- Test layout.lua |
