authorgravatar for william@sengir.comWilliam Sengir <william@sengir.com> 2022-08-28 03:14:15-07:00
committergravatar for william@sengir.comWilliam Sengir <william@sengir.com> 2022-08-28 06:20:18-07:00
log91b9f295d3ad74ac0ba9d1329bf5c581a45f6e89
tree07fd8ff6039a87d9beab52712bed46fff07f02d4
parent3860e664c596bb4c0425de58768d63ee95fe36ef
signaturelock-open Commit is signed but in an unrecognized format.

coff: publicize and flesh out more image constants


1 files changed, 76 insertions(+), 11 deletions(-)

lib/std/coff.zig+76-11
......@@ -256,20 +256,89 @@ pub const OptionalHeaderPE64 = extern struct {
256256 number_of_rva_and_sizes: u32,
257257};
258258
259pub const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
260
261pub const DirectoryEntry = enum(u16) {
262 /// Export Directory
263 EXPORT = 0,
264
265 /// Import Directory
266 IMPORT = 1,
267
268 /// Resource Directory
269 RESOURCE = 2,
270
271 /// Exception Directory
272 EXCEPTION = 3,
273
274 /// Security Directory
275 SECURITY = 4,
276
277 /// Base Relocation Table
278 BASERELOC = 5,
279
280 /// Debug Directory
281 DEBUG = 6,
282
283 /// Architecture Specific Data
284 ARCHITECTURE = 7,
285
286 /// RVA of GP
287 GLOBALPTR = 8,
288
289 /// TLS Directory
290 TLS = 9,
291
292 /// Load Configuration Directory
293 LOAD_CONFIG = 10,
294
295 /// Bound Import Directory in headers
296 BOUND_IMPORT = 11,
297
298 /// Import Address Table
299 IAT = 12,
300
301 /// Delay Load Import Descriptors
302 DELAY_IMPORT = 13,
303
304 /// COM Runtime descriptor
305 COM_DESCRIPTOR = 14,
306};
307
308pub const ImageDataDirectory = extern struct {
309 virtual_address: u32,
310 size: u32,
311};
312
259313pub const DebugDirectoryEntry = extern struct {
260 characteristiccs: u32,
314 characteristics: u32,
261315 time_date_stamp: u32,
262316 major_version: u16,
263317 minor_version: u16,
264 @"type": u32,
318 @"type": DebugType,
265319 size_of_data: u32,
266320 address_of_raw_data: u32,
267321 pointer_to_raw_data: u32,
268322};
269323
270pub const ImageDataDirectory = extern struct {
271 virtual_address: u32,
272 size: u32,
324pub const DebugType = enum(u32) {
325 UNKNOWN = 0,
326 COFF = 1,
327 CODEVIEW = 2,
328 FPO = 3,
329 MISC = 4,
330 EXCEPTION = 5,
331 FIXUP = 6,
332 OMAP_TO_SRC = 7,
333 OMAP_FROM_SRC = 8,
334 BORLAND = 9,
335 RESERVED10 = 10,
336 VC_FEATURE = 12,
337 POGO = 13,
338 ILTCG = 14,
339 MPX = 15,
340 REPRO = 16,
341 EX_DLLCHARACTERISTICS = 20,
273342};
274343
275344pub const SectionHeader = extern struct {
......@@ -794,10 +863,6 @@ pub const MachineType = enum(u16) {
794863 }
795864};
796865
797const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
798const IMAGE_DEBUG_TYPE_CODEVIEW = 2;
799const DEBUG_DIRECTORY = 6;
800
801866pub const CoffError = error{
802867 InvalidPEMagic,
803868 InvalidPEHeader,
......@@ -862,7 +927,7 @@ pub const Coff = struct {
862927 };
863928
864929 const data_dirs = self.getDataDirectories();
865 const debug_dir = data_dirs[DEBUG_DIRECTORY];
930 const debug_dir = data_dirs[@enumToInt(DirectoryEntry.DEBUG)];
866931 const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data;
867932
868933 var stream = std.io.fixedBufferStream(self.data);
......@@ -875,7 +940,7 @@ pub const Coff = struct {
875940 var i: u32 = 0;
876941 blk: while (i < debug_dir_entry_count) : (i += 1) {
877942 const debug_dir_entry = try reader.readStruct(DebugDirectoryEntry);
878 if (debug_dir_entry.type == IMAGE_DEBUG_TYPE_CODEVIEW) {
943 if (debug_dir_entry.type == .CODEVIEW) {
879944 for (self.getSectionHeaders()) |*section| {
880945 const section_start = section.virtual_address;
881946 const section_size = section.virtual_size;