From f7bc8900bfef87f67230ac5af7edb2d7766b3ba3 Mon Sep 17 00:00:00 2001 From: Erik Hugne Date: Mon, 25 Apr 2022 22:45:12 +0200 Subject: [PATCH] std.coff: parse out codebase and entrypoint from optionalheader --- lib/std/coff.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/std/coff.zig b/lib/std/coff.zig index 8fabd8e214..7c077a9ec8 100644 --- a/lib/std/coff.zig +++ b/lib/std/coff.zig @@ -197,7 +197,11 @@ pub const Coff = struct { const opt_header_pos = try self.in_file.getPos(); self.pe_header.magic = try in.readIntLittle(u16); - // All we care about is the image base value and PDB info + try self.in_file.seekTo(opt_header_pos + 16); + self.pe_header.entry_addr = try in.readIntLittle(u32); + try self.in_file.seekTo(opt_header_pos + 20); + self.pe_header.code_base = try in.readIntLittle(u32); + // The header structure is different for 32 or 64 bit var num_rva_pos: u64 = undefined; if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { @@ -374,6 +378,8 @@ const OptionalHeader = struct { magic: u16, data_directory: [IMAGE_NUMBEROF_DIRECTORY_ENTRIES]DataDirectory, + entry_addr: u32, + code_base: u32, image_base: u64, };