authorgravatar for PecoraInPannaCotta@gmail.comGiuseppe Cesarano <PecoraInPannaCotta@gmail.com> 2025-11-26 00:09:40+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-11-26 11:30:03+01:00
log0b5b35c6964ea91133c82adbbd8ab3cf81388b26
tree087c8531f6ff1a7f5e286b855f452c95d191be85
parent5f73c01368f418bb9b5186ff14bcdacb044fcb86

std.elf implemented DynamicSectionBufferIterator


1 files changed, 32 insertions(+), 0 deletions(-)

lib/std/elf.zig+32
...@@ -768,6 +768,21 @@ pub const Header = struct {...@@ -768,6 +768,21 @@ pub const Header = struct {
768 };768 };
769 }769 }
770770
771 pub fn iterateDynamicSectionBuffer(
772 h: *const Header,
773 buf: []const u8,
774 offset: u64,
775 size: u64,
776 ) DynamicSectionBufferIterator {
777 return .{
778 .is_64 = h.is_64,
779 .endian = h.endian,
780 .offset = offset,
781 .end_offset = offset + size,
782 .buf = buf,
783 };
784 }
785
771 pub const ReadError = Io.Reader.Error || error{786 pub const ReadError = Io.Reader.Error || error{
772 InvalidElfMagic,787 InvalidElfMagic,
773 InvalidElfVersion,788 InvalidElfVersion,
...@@ -963,6 +978,23 @@ pub const DynamicSectionIterator = struct {...@@ -963,6 +978,23 @@ pub const DynamicSectionIterator = struct {
963 }978 }
964};979};
965980
981pub const DynamicSectionBufferIterator = struct {
982 is_64: bool,
983 endian: Endian,
984 offset: u64,
985 end_offset: u64,
986
987 buf: []const u8,
988
989 pub fn next(it: *DynamicSectionBufferIterator) !?Elf64_Dyn {
990 if (it.offset >= it.end_offset) return null;
991 const size: u64 = if (it.is_64) @sizeOf(Elf64_Dyn) else @sizeOf(Elf32_Dyn);
992 defer it.offset += size;
993 var reader: std.Io.Reader = .fixed(it.buf[it.offset..]);
994 return try takeDynamicSection(&reader, it.is_64, it.endian);
995 }
996};
997
966pub fn takeDynamicSection(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Dyn {998pub fn takeDynamicSection(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Dyn {
967 if (is_64) {999 if (is_64) {
968 const dyn = try reader.takeStruct(Elf64_Dyn, endian);1000 const dyn = try reader.takeStruct(Elf64_Dyn, endian);