| ... | @@ -365,8 +365,12 @@ const Header = struct { | ... | @@ -365,8 +365,12 @@ const Header = struct { |
| 365 | pub fn readHeader(file: File) !Header { | 365 | pub fn readHeader(file: File) !Header { |
| 366 | var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined; | 366 | var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined; |
| 367 | try preadNoEof(file, &hdr_buf, 0); | 367 | try preadNoEof(file, &hdr_buf, 0); |
| 368 | const hdr32 = @ptrCast(*Elf32_Ehdr, &hdr_buf); | 368 | return parseHeader(hdr_buf); |
| 369 | const hdr64 = @ptrCast(*Elf64_Ehdr, &hdr_buf); | 369 | } |
| | 370 | |
| | 371 | pub fn parseHeader(hdr_buf: *align(@alignOf(Elf64_Ehdr)) const [@sizeOf(Elf64_Ehdr)]u8) !Header { |
| | 372 | const hdr32 = @ptrCast(*const Elf32_Ehdr, hdr_buf); |
| | 373 | const hdr64 = @ptrCast(*const Elf64_Ehdr, hdr_buf); |
| 370 | if (!mem.eql(u8, hdr32.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic; | 374 | if (!mem.eql(u8, hdr32.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic; |
| 371 | if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; | 375 | if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; |
| 372 | | 376 | |