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 local M = {} function M.normalize(section) if not section.name then error("name is required in section", 3) end if not section.type then error("type is required in section", 3) end if not section.flags then error("flags required in section", 3) end section.addr = section.addr or 0 section.offset = section.offset or 0 section.size = section.size or 0 section.link = section.link or 0 section.info = section.info or 0 section.addralign = section.addralign or 0 section.entsize = section.entsize or 0 end function M.validate(section) --TODO end local function section_index(name) -- TODO return 42 end ---@param section Section ---@param endian Endian ---@return string ---@nodiscard function M.pack(section, endian, class) return string.pack(fmt.endian(endian) .. "I4I4" .. string.rep(fmt.word(class), 4) .. "I4I4" .. string.rep(fmt.word(class), 2), section_index(section.name), section.type, section.flags, section.addr, section.offset, section.size, section.link, section.info, section.addralign, section.entsize) end return M