@@ -267,6 +267,8 @@ pub const SHT_HIPROC = 0x7fffffff;
267
267
pub const SHT_LOUSER = 0x80000000 ;
268
268
pub const SHT_HIUSER = 0xffffffff ;
269
269
270
+ pub const NT_GNU_BUILD_ID = 3 ;
271
+
270
272
pub const STB_LOCAL = 0 ;
271
273
pub const STB_GLOBAL = 1 ;
272
274
pub const STB_WEAK = 2 ;
@@ -362,6 +364,47 @@ pub const SectionHeader = struct {
362
364
try elf .seekable_stream .seekTo (name_offset );
363
365
return try isString (elf , name );
364
366
}
367
+
368
+ pub const NoteDescription = struct {
369
+ elf : * Elf ,
370
+ start_pos : usize ,
371
+ len : usize ,
372
+ };
373
+ pub fn isNote (elf_section : SectionHeader , elf : * Elf , name : []const u8 , wanted_type : u64 ) ! ? NoteDescription {
374
+ if (elf_section .sh_type != SHT_NOTE ) return null ;
375
+
376
+ try elf .seekable_stream .seekTo (elf_section .offset );
377
+
378
+ var desc_len : usize = undefined ;
379
+
380
+ if (elf .is_64 ) {
381
+ const hdr = Elf64_Nhdr {
382
+ .n_namesz = try elf .in_stream .readInt (Elf64_Word , elf .endian ),
383
+ .n_descsz = try elf .in_stream .readInt (Elf64_Word , elf .endian ),
384
+ .n_type = try elf .in_stream .readInt (Elf64_Word , elf .endian ),
385
+ };
386
+ if (name .len + 1 != hdr .n_namesz ) return null ;
387
+ if (wanted_type != hdr .n_type ) return null ;
388
+ desc_len = hdr .n_descsz ;
389
+ } else {
390
+ const hdr = Elf32_Nhdr {
391
+ .n_namesz = try elf .in_stream .readInt (Elf32_Word , elf .endian ),
392
+ .n_descsz = try elf .in_stream .readInt (Elf32_Word , elf .endian ),
393
+ .n_type = try elf .in_stream .readInt (Elf32_Word , elf .endian ),
394
+ };
395
+ if (name .len + 1 != hdr .n_namesz ) return null ;
396
+ if (wanted_type != hdr .n_type ) return null ;
397
+ desc_len = hdr .n_descsz ;
398
+ }
399
+
400
+ if (! try isString (elf , name )) return null ;
401
+
402
+ return NoteDescription {
403
+ .elf = elf ,
404
+ .start_pos = try elf .seekable_stream .getPos (),
405
+ .len = desc_len ,
406
+ };
407
+ }
365
408
};
366
409
367
410
pub const Elf = struct {
0 commit comments