| ... | ... | @@ -256,20 +256,89 @@ pub const OptionalHeaderPE64 = extern struct { |
| 256 | 256 | number_of_rva_and_sizes: u32, |
| 257 | 257 | }; |
| 258 | 258 | |
| 259 | pub const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; |
| 260 | |
| 261 | pub 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 | |
| 308 | pub const ImageDataDirectory = extern struct { |
| 309 | virtual_address: u32, |
| 310 | size: u32, |
| 311 | }; |
| 312 | |
| 259 | 313 | pub const DebugDirectoryEntry = extern struct { |
| 260 | | characteristiccs: u32, |
| 314 | characteristics: u32, |
| 261 | 315 | time_date_stamp: u32, |
| 262 | 316 | major_version: u16, |
| 263 | 317 | minor_version: u16, |
| 264 | | @"type": u32, |
| 318 | @"type": DebugType, |
| 265 | 319 | size_of_data: u32, |
| 266 | 320 | address_of_raw_data: u32, |
| 267 | 321 | pointer_to_raw_data: u32, |
| 268 | 322 | }; |
| 269 | 323 | |
| 270 | | pub const ImageDataDirectory = extern struct { |
| 271 | | virtual_address: u32, |
| 272 | | size: u32, |
| 324 | pub 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, |
| 273 | 342 | }; |
| 274 | 343 | |
| 275 | 344 | pub const SectionHeader = extern struct { |
| ... | ... | @@ -794,10 +863,6 @@ pub const MachineType = enum(u16) { |
| 794 | 863 | } |
| 795 | 864 | }; |
| 796 | 865 | |
| 797 | | const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; |
| 798 | | const IMAGE_DEBUG_TYPE_CODEVIEW = 2; |
| 799 | | const DEBUG_DIRECTORY = 6; |
| 800 | | |
| 801 | 866 | pub const CoffError = error{ |
| 802 | 867 | InvalidPEMagic, |
| 803 | 868 | InvalidPEHeader, |
| ... | ... | @@ -862,7 +927,7 @@ pub const Coff = struct { |
| 862 | 927 | }; |
| 863 | 928 | |
| 864 | 929 | const data_dirs = self.getDataDirectories(); |
| 865 | | const debug_dir = data_dirs[DEBUG_DIRECTORY]; |
| 930 | const debug_dir = data_dirs[@enumToInt(DirectoryEntry.DEBUG)]; |
| 866 | 931 | const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; |
| 867 | 932 | |
| 868 | 933 | var stream = std.io.fixedBufferStream(self.data); |
| ... | ... | @@ -875,7 +940,7 @@ pub const Coff = struct { |
| 875 | 940 | var i: u32 = 0; |
| 876 | 941 | blk: while (i < debug_dir_entry_count) : (i += 1) { |
| 877 | 942 | 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) { |
| 879 | 944 | for (self.getSectionHeaders()) |*section| { |
| 880 | 945 | const section_start = section.virtual_address; |
| 881 | 946 | const section_size = section.virtual_size; |