mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.elf implemented DynamicSectionBufferIterator
This commit is contained in:
parent
5f73c01368
commit
0b5b35c696
1 changed files with 32 additions and 0 deletions
|
|
@ -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{
|
pub const ReadError = Io.Reader.Error || error{
|
||||||
InvalidElfMagic,
|
InvalidElfMagic,
|
||||||
InvalidElfVersion,
|
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 {
|
pub fn takeDynamicSection(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Dyn {
|
||||||
if (is_64) {
|
if (is_64) {
|
||||||
const dyn = try reader.takeStruct(Elf64_Dyn, endian);
|
const dyn = try reader.takeStruct(Elf64_Dyn, endian);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue