| ... | ... | @@ -419,6 +419,91 @@ pub const DebugType = enum(u32) { |
| 419 | 419 | EX_DLLCHARACTERISTICS = 20, |
| 420 | 420 | }; |
| 421 | 421 | |
| 422 | pub const ImportDirectoryEntry = extern struct { |
| 423 | /// The RVA of the import lookup table. |
| 424 | /// This table contains a name or ordinal for each import. |
| 425 | /// (The name "Characteristics" is used in Winnt.h, but no longer describes this field.) |
| 426 | import_lookup_table_rva: u32, |
| 427 | |
| 428 | /// The stamp that is set to zero until the image is bound. |
| 429 | /// After the image is bound, this field is set to the time/data stamp of the DLL. |
| 430 | time_date_stamp: u32, |
| 431 | |
| 432 | /// The index of the first forwarder reference. |
| 433 | forwarder_chain: u32, |
| 434 | |
| 435 | /// The address of an ASCII string that contains the name of the DLL. |
| 436 | /// This address is relative to the image base. |
| 437 | name_rva: u32, |
| 438 | |
| 439 | /// The RVA of the import address table. |
| 440 | /// The contents of this table are identical to the contents of the import lookup table until the image is bound. |
| 441 | import_address_table_rva: u32, |
| 442 | }; |
| 443 | |
| 444 | pub const ImportLookupEntry32 = struct { |
| 445 | pub const ByName = packed struct { |
| 446 | name_table_rva: u31, |
| 447 | flag: u1 = 0, |
| 448 | }; |
| 449 | |
| 450 | pub const ByOrdinal = packed struct { |
| 451 | ordinal_number: u16, |
| 452 | unused: u15 = 0, |
| 453 | flag: u1 = 1, |
| 454 | }; |
| 455 | |
| 456 | const mask = 0x80000000; |
| 457 | |
| 458 | pub fn getImportByName(raw: u32) ?ByName { |
| 459 | if (mask & raw != 0) return null; |
| 460 | return @bitCast(ByName, raw); |
| 461 | } |
| 462 | |
| 463 | pub fn getImportByOrdinal(raw: u32) ?ByOrdinal { |
| 464 | if (mask & raw == 0) return null; |
| 465 | return @bitCast(ByOrdinal, raw); |
| 466 | } |
| 467 | }; |
| 468 | |
| 469 | pub const ImportLookupEntry64 = struct { |
| 470 | pub const ByName = packed struct { |
| 471 | name_table_rva: u31, |
| 472 | unused: u32 = 0, |
| 473 | flag: u1 = 0, |
| 474 | }; |
| 475 | |
| 476 | pub const ByOrdinal = packed struct { |
| 477 | ordinal_number: u16, |
| 478 | unused: u47 = 0, |
| 479 | flag: u1 = 1, |
| 480 | }; |
| 481 | |
| 482 | const mask = 0x8000000000000000; |
| 483 | |
| 484 | pub fn getImportByName(raw: u64) ?ByName { |
| 485 | if (mask & raw != 0) return null; |
| 486 | return @bitCast(ByName, raw); |
| 487 | } |
| 488 | |
| 489 | pub fn getImportByOrdinal(raw: u64) ?ByOrdinal { |
| 490 | if (mask & raw == 0) return null; |
| 491 | return @bitCast(ByOrdinal, raw); |
| 492 | } |
| 493 | }; |
| 494 | |
| 495 | /// Every name ends with a NULL byte. IF the NULL byte does not fall on |
| 496 | /// 2byte boundary, the entry structure is padded to ensure 2byte alignment. |
| 497 | pub const ImportHintNameEntry = extern struct { |
| 498 | /// An index into the export name pointer table. |
| 499 | /// A match is attempted first with this value. If it fails, a binary search is performed on the DLL's export name pointer table. |
| 500 | hint: u16, |
| 501 | |
| 502 | /// Pointer to NULL terminated ASCII name. |
| 503 | /// Variable length... |
| 504 | name: [1]u8, |
| 505 | }; |
| 506 | |
| 422 | 507 | pub const SectionHeader = extern struct { |
| 423 | 508 | name: [8]u8, |
| 424 | 509 | virtual_size: u32, |