From b408893577d64b02caecd77778c6c5517d552b3a Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Thu, 29 Oct 2026 18:47:36 +0530 Subject: Start packing sections. --- elf/section.lua | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'elf') diff --git a/elf/section.lua b/elf/section.lua index 5e185fd..ca9953e 100644 --- a/elf/section.lua +++ b/elf/section.lua @@ -1,6 +1,16 @@ local fmt = require("elf.fmt") ---@class Section +---@field name string +---@field type SectionType +---@field flags integer +---@field addr? integer +---@field offset? integer +---@field size? integer +---@field link? integer +---@field info? integer +---@field addralign? integer +---@field entsize? integer ---@class Sections local M = {} @@ -9,9 +19,26 @@ local M = {} ---@param endian Endian ---@return string ---@nodiscard -function M.pack(sections, endian) - -- TODO - return string.pack("B", 0x1) +function M.pack(sections, endian, class) + local s = {} + for i, section in ipairs(sections) do + s[i] = string.pack(fmt.endian(endian) .. + "I4I4" .. + string.rep(fmt.word(class), 4) .. + "I4I4" .. + string.rep(fmt.word(class), 2), + section.name, + section.type, + section.flags, + section.addr, + section.offset, + section.size, + section.link, + section.info, + section.addralign, + section.entsize) + end + return table.concat(s) end return M -- cgit v1.3