mirror of
https://github.com/ziglang/zig.git
synced 2025-12-05 22:03:06 +00:00
std.elf implemented DynamicSectionBufferIterator
This commit is contained in:
parent
5f73c01368
commit
0b5b35c696
@ -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,
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user