diff options
| -rw-r--r-- | mkelf.lua | 60 |
1 files changed, 32 insertions, 28 deletions
@@ -80,6 +80,37 @@ local Machine <const> = { ---@field shnum integer ---@field shstrndx integer +---@param hdr ElfHeader +---@nodiscard +local function ElfHeader_pack(hdr) + local ident = string.pack("BBBBBBBBBxxxxxxx", + hdr.magic[1], hdr.magic[2], hdr.magic[3], hdr.magic[4], + hdr.class, + hdr.data, + hdr.ident_version, + hdr.osabi, + hdr.abiversion) + local e = (hdr.data == Endian.big) and ">" or "<" + local sz = (hdr.class == Class.bit64) and "I8" or "I4" + local h = string.pack(e .. "I2I2I4" .. + sz .. sz .. sz .. + "I4I2I2I2I2I2I2", + hdr.type, + hdr.machine, + hdr.version, + hdr.entry, + hdr.phoff, + hdr.shoff, + hdr.flags, + hdr.ehsize, + hdr.phentsize, + hdr.phnum, + hdr.shentsize, + hdr.shnum, + hdr.shstrndx) + return ident .. h +end + ---@type ElfHeader local header <const> = { magic = { 0x7f, 0x45, 0x4c, 0x46 }, @@ -102,34 +133,7 @@ local header <const> = { shnum = 0, shstrndx = 0, - pack = function(self) - local ident = string.pack("BBBBBBBBBxxxxxxx", - self.magic[1], self.magic[2], self.magic[3], self.magic[4], - self.class, - self.data, - self.ident_version, - self.osabi, - self.abiversion) - local e = (self.data == Endian.big) and ">" or "<" - local sz = (self.class == Class.bit64) and "I8" or "I4" - local hdr = string.pack(e .. "I2I2I4" .. - sz .. sz .. sz .. - "I4I2I2I2I2I2I2", - self.type, - self.machine, - self.version, - self.entry, - self.phoff, - self.shoff, - self.flags, - self.ehsize, - self.phentsize, - self.phnum, - self.shentsize, - self.shnum, - self.shstrndx) - return ident .. hdr - end + pack = ElfHeader_pack } local function main() |
