summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mkelf.lua17
1 files changed, 10 insertions, 7 deletions
diff --git a/mkelf.lua b/mkelf.lua
index eb76d16..b6535d6 100644
--- a/mkelf.lua
+++ b/mkelf.lua
@@ -99,20 +99,24 @@ local function efmt(endian)
return (endian == Endian.big) and ">" or "<"
end
+local function szfmt(class)
+ return (class == Class.bit64) and "I8" or "I4"
+end
+
---@param hdr ElfHeader
---@nodiscard
local function ElfHeader_pack(hdr)
- local ident = string.pack("BBBBBBBBBxxxxxxx",
+ return string.pack("BBBBBBBBBxxxxxxx" ..
+ efmt(hdr.data) ..
+ "I2I2I4" ..
+ string.rep(szfmt(hdr.class), 3) ..
+ "I4I2I2I2I2I2I2",
hdr.magic[1], hdr.magic[2], hdr.magic[3], hdr.magic[4],
hdr.class,
hdr.data,
hdr.ident_version,
hdr.osabi,
- hdr.abiversion)
- local sz = (hdr.class == Class.bit64) and "I8" or "I4"
- local h = string.pack(efmt(hdr.data) .. "I2I2I4" ..
- sz .. sz .. sz ..
- "I4I2I2I2I2I2I2",
+ hdr.abiversion,
hdr.type,
hdr.machine,
hdr.version,
@@ -126,7 +130,6 @@ local function ElfHeader_pack(hdr)
hdr.shentsize,
hdr.shnum,
hdr.shstrndx)
- return ident .. h
end
---@type ElfHeader