diff options
| author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-11-23 14:59:58 +0530 |
|---|---|---|
| committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-11-23 14:59:58 +0530 |
| commit | 33e207cf0c4818256e20d1149a5b514232f7a5d4 (patch) | |
| tree | 4c9bf0ebb463ffb2b2bd064d66a98e15fda34890 | |
| parent | 36144a2ef5669710e30339351de5389616d85681 (diff) | |
| -rw-r--r-- | elf/init.lua | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/elf/init.lua b/elf/init.lua index 258e831..cbcdb85 100644 --- a/elf/init.lua +++ b/elf/init.lua @@ -25,20 +25,22 @@ local function name_offset(content, name) return at or 0 end +local function find_shstrtab(sections) + for i, sc in ipairs(sections) do + if sc.name == ".shstrtab" then + return i - 1, sc.content or "" + end + end +end + ---@param hdr Header ---@param segments Segment[] ---@param sections Section[] ---@return Ehdr, Phdr[], Shdr[] function M.layout(hdr, segments, sections) local ehdr = header.to_ehdr(hdr) - local shstrtab_index, shstrtab_contents = 0, "" - for i, sc in ipairs(sections) do - if sc.name == ".shstrtab" then - shstrtab_index = i - 1 - shstrtab_contents = sc.content or "" - end - end local cursor = ehdr.ehsize + #segments * ehdr.phentsize + local shstrtab_index, shstrtab_contents = find_shstrtab(sections) local shdrs = {} -- TODO accomodate user config's offset and alignment requirements for _, sc in ipairs(sections) do |
