Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/std/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,21 @@ pub const Header = struct {
};
}

pub fn iterateDynamicSectionBuffer(
h: *const Header,
buf: []const u8,
offset: u64,
size: u64,
) DynamicSectionBufferIterator {
return .{
.is_64 = h.is_64,
.endian = h.endian,
.offset = offset,
.end_offset = offset + size,
.buf = buf,
};
}

pub const ReadError = Io.Reader.Error || error{
InvalidElfMagic,
InvalidElfVersion,
Expand Down Expand Up @@ -963,6 +978,23 @@ pub const DynamicSectionIterator = struct {
}
};

pub const DynamicSectionBufferIterator = struct {
is_64: bool,
endian: Endian,
offset: u64,
end_offset: u64,

buf: []const u8,

pub fn next(it: *DynamicSectionBufferIterator) !?Elf64_Dyn {
if (it.offset >= it.end_offset) return null;
const size: u64 = if (it.is_64) @sizeOf(Elf64_Dyn) else @sizeOf(Elf32_Dyn);
defer it.offset += size;
var reader: std.Io.Reader = .fixed(it.buf[it.offset..]);
return try takeDynamicSection(&reader, it.is_64, it.endian);
}
};

pub fn takeDynamicSection(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Dyn {
if (is_64) {
const dyn = try reader.takeStruct(Elf64_Dyn, endian);
Expand Down