From be6b03a9cfa83535bb258f554aaf237fdb623bf1 Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Wed, 4 Nov 2026 21:16:40 +0530 Subject: Honor these user specified header fields. --- elf/header.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/elf/header.lua b/elf/header.lua index ca50391..de939d9 100644 --- a/elf/header.lua +++ b/elf/header.lua @@ -64,6 +64,19 @@ function M.normalize(hdropts) error("data must be Endian.little or Endian.big in header", 3) end + local phoff, ehsize, phentsize, shentsize + if hdropts.class == ec.Class.bit32 then + phoff = hdropts.phoff or 0x34 + ehsize = hdropts.ehsize or 0x34 + phentsize = hdropts.phentsize or 0x20 + shentsize = hdropts.shentsize or 0x28 + else + phoff = hdropts.phoff or 0x40 + ehsize = hdropts.ehsize or 0x40 + phentsize = hdropts.phentsize or 0x38 + shentsize = hdropts.shentsize or 0x40 + end + return { magic = hdropts.magic or { 0x7f, 0x45, 0x4c, 0x46 }, class = hdropts.class, @@ -80,10 +93,10 @@ function M.normalize(hdropts) phnum = hdropts.phnum or 0, shnum = hdropts.shnum or 0, shstrndx = hdropts.shstrndx or 0, - phoff = (hdropts.class == ec.Class.bit32) and 0x34 or 0x40, - ehsize = (hdropts.class == ec.Class.bit32) and 0x34 or 0x40, - phentsize = (hdropts.class == ec.Class.bit32) and 0x20 or 0x38, - shentsize = (hdropts.class == ec.Class.bit32) and 0x28 or 0x40, + phoff = phoff, + ehsize = ehsize, + phentsize = phentsize, + shentsize = shentsize, } end -- cgit v1.3