aboutsummaryrefslogtreecommitdiff
path: root/elf/section.lua
blob: ca9953e1b5d085d0e0f8e95c981481f7c84279dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 = {}

---@param sections Sections
---@param endian Endian
---@return string
---@nodiscard
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