summaryrefslogtreecommitdiffstats
path: root/include/iprt/formats/pe.mac
blob: 8ec3cb339e6a36ffa34995731cc3bfc44ff765e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
;; @file
; IPRT - Windows PE definitions for YASM/NASM.
;

;
; Copyright (C) 2006-2019 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
; you can redistribute it and/or modify it under the terms of the GNU
; General Public License (GPL) as published by the Free Software
; Foundation, in version 2 as it comes in the "COPYING" file of the
; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
; VirtualBox OSE distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;

%ifndef ___iprt_format_pe_mac
%define ___iprt_format_pe_mac


;*******************************************************************************
;*  Header Files                                                               *
;*******************************************************************************
%include "iprt/asmdefs.mac"


;*******************************************************************************
;*  Defined Constants And Macros                                               *
;*******************************************************************************
%define  IMAGE_NT_SIGNATURE  0x00004550

; file header
%define  IMAGE_FILE_MACHINE_I386  0x014c
%define  IMAGE_FILE_MACHINE_AMD64  0x8664

%define  IMAGE_FILE_RELOCS_STRIPPED  0x0001
%define  IMAGE_FILE_EXECUTABLE_IMAGE  0x0002
%define  IMAGE_FILE_LINE_NUMS_STRIPPED  0x0004
%define  IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
%define  IMAGE_FILE_AGGRESIVE_WS_TRIM  0x0010
%define  IMAGE_FILE_LARGE_ADDRESS_AWARE  0x0020
%define  IMAGE_FILE_16BIT_MACHINE  0x0040
%define  IMAGE_FILE_BYTES_REVERSED_LO  0x0080
%define  IMAGE_FILE_32BIT_MACHINE  0x0100
%define  IMAGE_FILE_DEBUG_STRIPPED  0x0200
%define  IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP  0x0400
%define  IMAGE_FILE_NET_RUN_FROM_SWAP  0x0800
%define  IMAGE_FILE_SYSTEM  0x1000
%define  IMAGE_FILE_DLL  0x2000
%define  IMAGE_FILE_UP_SYSTEM_ONLY  0x4000
%define  IMAGE_FILE_BYTES_REVERSED_HI  0x8000


; optional header
%define  IMAGE_NT_OPTIONAL_HDR32_MAGIC  0x10B
%define  IMAGE_NT_OPTIONAL_HDR64_MAGIC  0x20B

%define  IMAGE_SUBSYSTEM_UNKNOWN  0x0
%define  IMAGE_SUBSYSTEM_NATIVE  0x1
%define  IMAGE_SUBSYSTEM_WINDOWS_GUI  0x2
%define  IMAGE_SUBSYSTEM_WINDOWS_CUI  0x3
%define  IMAGE_SUBSYSTEM_OS2_GUI  0x4
%define  IMAGE_SUBSYSTEM_OS2_CUI  0x5
%define  IMAGE_SUBSYSTEM_POSIX_CUI  0x7

%define  IMAGE_LIBRARY_PROCESS_INIT  0x0001
%define  IMAGE_LIBRARY_PROCESS_TERM  0x0002
%define  IMAGE_LIBRARY_THREAD_INIT  0x0004
%define  IMAGE_LIBRARY_THREAD_TERM  0x0008
%define  IMAGE_DLLCHARACTERISTICS_NO_ISOLATION  0x0200
%define  IMAGE_DLLCHARACTERISTICS_NO_SEH  0x0400
%define  IMAGE_DLLCHARACTERISTICS_NO_BIND  0x0800
%define  IMAGE_DLLCHARACTERISTICS_WDM_DRIVER  0x2000
%define  IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE  0x8000

%define  IMAGE_NUMBEROF_DIRECTORY_ENTRIES  0x10

%define  IMAGE_DIRECTORY_ENTRY_EXPORT  0x0
%define  IMAGE_DIRECTORY_ENTRY_IMPORT  0x1
%define  IMAGE_DIRECTORY_ENTRY_RESOURCE  0x2
%define  IMAGE_DIRECTORY_ENTRY_EXCEPTION  0x3
%define  IMAGE_DIRECTORY_ENTRY_SECURITY  0x4
%define  IMAGE_DIRECTORY_ENTRY_BASERELOC  0x5
%define  IMAGE_DIRECTORY_ENTRY_DEBUG  0x6
%define  IMAGE_DIRECTORY_ENTRY_ARCHITECTURE  0x7
%define  IMAGE_DIRECTORY_ENTRY_COPYRIGHT IMAGE_DIRECTORY_ENTRY_ARCHITECTURE
%define  IMAGE_DIRECTORY_ENTRY_GLOBALPTR  0x8
%define  IMAGE_DIRECTORY_ENTRY_TLS  0x9
%define  IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG  0xa
%define  IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT  0xb
%define  IMAGE_DIRECTORY_ENTRY_IAT  0xc
%define  IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT  0xd
%define  IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR  0xe


; section header
%define  IMAGE_SIZEOF_SHORT_NAME  0x8

%define  IMAGE_SCN_TYPE_REG  0x00000000
%define  IMAGE_SCN_TYPE_DSECT  0x00000001
%define  IMAGE_SCN_TYPE_NOLOAD  0x00000002
%define  IMAGE_SCN_TYPE_GROUP  0x00000004
%define  IMAGE_SCN_TYPE_NO_PAD  0x00000008
%define  IMAGE_SCN_TYPE_COPY  0x00000010

%define  IMAGE_SCN_CNT_CODE  0x00000020
%define  IMAGE_SCN_CNT_INITIALIZED_DATA  0x00000040
%define  IMAGE_SCN_CNT_UNINITIALIZED_DATA  0x00000080

%define  IMAGE_SCN_LNK_OTHER  0x00000100
%define  IMAGE_SCN_LNK_INFO  0x00000200
%define  IMAGE_SCN_TYPE_OVER  0x00000400
%define  IMAGE_SCN_LNK_REMOVE  0x00000800
%define  IMAGE_SCN_LNK_COMDAT  0x00001000
%define  IMAGE_SCN_MEM_PROTECTED  0x00004000
%define  IMAGE_SCN_NO_DEFER_SPEC_EXC  0x00004000
%define  IMAGE_SCN_GPREL  0x00008000
%define  IMAGE_SCN_MEM_FARDATA  0x00008000
%define  IMAGE_SCN_MEM_SYSHEAP  0x00010000
%define  IMAGE_SCN_MEM_PURGEABLE  0x00020000
%define  IMAGE_SCN_MEM_16BIT  0x00020000
%define  IMAGE_SCN_MEM_LOCKED  0x00040000
%define  IMAGE_SCN_MEM_PRELOAD  0x00080000

%define  IMAGE_SCN_ALIGN_1BYTES  0x00100000
%define  IMAGE_SCN_ALIGN_2BYTES  0x00200000
%define  IMAGE_SCN_ALIGN_4BYTES  0x00300000
%define  IMAGE_SCN_ALIGN_8BYTES  0x00400000
%define  IMAGE_SCN_ALIGN_16BYTES  0x00500000
%define  IMAGE_SCN_ALIGN_32BYTES  0x00600000
%define  IMAGE_SCN_ALIGN_64BYTES  0x00700000
%define  IMAGE_SCN_ALIGN_128BYTES  0x00800000
%define  IMAGE_SCN_ALIGN_256BYTES  0x00900000
%define  IMAGE_SCN_ALIGN_512BYTES  0x00A00000
%define  IMAGE_SCN_ALIGN_1024BYTES  0x00B00000
%define  IMAGE_SCN_ALIGN_2048BYTES  0x00C00000
%define  IMAGE_SCN_ALIGN_4096BYTES  0x00D00000
%define  IMAGE_SCN_ALIGN_8192BYTES  0x00E00000
%define  IMAGE_SCN_ALIGN_MASK   0x00F00000
%define  IMAGE_SCN_ALIGN_SHIFT  20

%define  IMAGE_SCN_LNK_NRELOC_OVFL  0x01000000
%define  IMAGE_SCN_MEM_DISCARDABLE  0x02000000
%define  IMAGE_SCN_MEM_NOT_CACHED  0x04000000
%define  IMAGE_SCN_MEM_NOT_PAGED  0x08000000
%define  IMAGE_SCN_MEM_SHARED  0x10000000
%define  IMAGE_SCN_MEM_EXECUTE  0x20000000
%define  IMAGE_SCN_MEM_READ  0x40000000
%define  IMAGE_SCN_MEM_WRITE  0x80000000


; relocations
%define  IMAGE_REL_BASED_ABSOLUTE  0x0
%define  IMAGE_REL_BASED_HIGH  0x1
%define  IMAGE_REL_BASED_LOW  0x2
%define  IMAGE_REL_BASED_HIGHLOW  0x3
%define  IMAGE_REL_BASED_HIGHADJ  0x4
%define  IMAGE_REL_BASED_MIPS_JMPADDR  0x5
%define  IMAGE_REL_BASED_MIPS_JMPADDR16 0x9
%define  IMAGE_REL_BASED_IA64_IMM64  0x9
%define  IMAGE_REL_BASED_DIR64  0xa
%define  IMAGE_REL_BASED_HIGH3ADJ 0xb


; imports
%define  IMAGE_ORDINAL_FLAG32  0x80000000
%define  IMAGE_ORDINAL_FLAG64  UINT64_MAX(0x8000000000000000)


; debug dir
%define  IMAGE_DEBUG_TYPE_UNKNOWN           UINT32_C(0x0)
%define  IMAGE_DEBUG_TYPE_COFF              UINT32_C(0x1)
%define  IMAGE_DEBUG_TYPE_CODEVIEW          UINT32_C(0x2)
%define  IMAGE_DEBUG_TYPE_FPO               UINT32_C(0x3)
%define  IMAGE_DEBUG_TYPE_MISC              UINT32_C(0x4)
%define  IMAGE_DEBUG_TYPE_EXCEPTION         UINT32_C(0x5)
%define  IMAGE_DEBUG_TYPE_FIXUP             UINT32_C(0x6)
%define  IMAGE_DEBUG_TYPE_OMAP_TO_SRC       UINT32_C(0x7)
%define  IMAGE_DEBUG_TYPE_OMAP_FROM_SRC     UINT32_C(0x8)
%define  IMAGE_DEBUG_TYPE_BORLAND           UINT32_C(0x9)
%define  IMAGE_DEBUG_TYPE_RESERVED10        UINT32_C(0x10)

%define  IMAGE_DEBUG_MISC_EXENAME           UINT32_C(1)

; security directory
%define  WIN_CERT_REVISION_1_0              UINT16_C(0x0100)
%define  WIN_CERT_REVISION_2_0              UINT16_C(0x0200)

%define  WIN_CERT_TYPE_X509                 UINT16_C(1)
%define  WIN_CERT_TYPE_PKCS_SIGNED_DATA     UINT16_C(2)
%define  WIN_CERT_TYPE_RESERVED_1           UINT16_C(3)
%define  WIN_CERT_TYPE_TS_STACK_SIGNED      UINT16_C(4)
%define  WIN_CERT_TYPE_EFI_PKCS115          UINT16_C(0x0ef0)
%define  WIN_CERT_TYPE_EFI_GUID             UINT16_C(0x0ef1)


; For .DBG files.
%define  IMAGE_SEPARATE_DEBUG_SIGNATURE     UINT16_C(0x4944)

%define  IMAGE_SIZE_OF_SYMBOL               18
%define  IMAGE_SIZE_OF_SYMBOL_EX            20

%define  IMAGE_SYM_UNDEFINED                INT16_C(0)
%define  IMAGE_SYM_ABSOLUTE                 INT16_C(-1)
%define  IMAGE_SYM_DEBUG                    INT16_C(-2)

%define  IMAGE_SYM_CLASS_END_OF_FUNCTION    UINT8_C(0xff) ; -1
%define  IMAGE_SYM_CLASS_NULL               UINT8_C(0)
%define  IMAGE_SYM_CLASS_AUTOMATIC          UINT8_C(1)
%define  IMAGE_SYM_CLASS_EXTERNAL           UINT8_C(2)
%define  IMAGE_SYM_CLASS_STATIC             UINT8_C(3)
%define  IMAGE_SYM_CLASS_REGISTER           UINT8_C(4)
%define  IMAGE_SYM_CLASS_EXTERNAL_DEF       UINT8_C(5)
%define  IMAGE_SYM_CLASS_LABEL              UINT8_C(6)
%define  IMAGE_SYM_CLASS_UNDEFINED_LABEL    UINT8_C(7)
%define  IMAGE_SYM_CLASS_MEMBER_OF_STRUCT   UINT8_C(8)
%define  IMAGE_SYM_CLASS_ARGUMENT           UINT8_C(9)
%define  IMAGE_SYM_CLASS_STRUCT_TAG         UINT8_C(10)
%define  IMAGE_SYM_CLASS_MEMBER_OF_UNION    UINT8_C(11)
%define  IMAGE_SYM_CLASS_UNION_TAG          UINT8_C(12)
%define  IMAGE_SYM_CLASS_TYPE_DEFINITION    UINT8_C(13)
%define  IMAGE_SYM_CLASS_UNDEFINED_STATIC   UINT8_C(14)
%define  IMAGE_SYM_CLASS_ENUM_TAG           UINT8_C(15)
%define  IMAGE_SYM_CLASS_MEMBER_OF_ENUM     UINT8_C(16)
%define  IMAGE_SYM_CLASS_REGISTER_PARAM     UINT8_C(17)
%define  IMAGE_SYM_CLASS_BIT_FIELD          UINT8_C(18)
%define  IMAGE_SYM_CLASS_FAR_EXTERNAL       UINT8_C(68)
%define  IMAGE_SYM_CLASS_BLOCK              UINT8_C(100)
%define  IMAGE_SYM_CLASS_FUNCTION           UINT8_C(101)
%define  IMAGE_SYM_CLASS_END_OF_STRUCT      UINT8_C(102)
%define  IMAGE_SYM_CLASS_FILE               UINT8_C(103)
%define  IMAGE_SYM_CLASS_SECTION            UINT8_C(104)
%define  IMAGE_SYM_CLASS_WEAK_EXTERNAL      UINT8_C(105)
%define  IMAGE_SYM_CLASS_CLR_TOKEN          UINT8_C(107)


%define  IMAGE_SYM_TYPE_NULL                UINT16_C(0x0000)
%define  IMAGE_SYM_TYPE_VOID                UINT16_C(0x0001)
%define  IMAGE_SYM_TYPE_CHAR                UINT16_C(0x0002)
%define  IMAGE_SYM_TYPE_SHORT               UINT16_C(0x0003)
%define  IMAGE_SYM_TYPE_INT                 UINT16_C(0x0004)
%define  IMAGE_SYM_TYPE_LONG                UINT16_C(0x0005)
%define  IMAGE_SYM_TYPE_FLOAT               UINT16_C(0x0006)
%define  IMAGE_SYM_TYPE_DOUBLE              UINT16_C(0x0007)
%define  IMAGE_SYM_TYPE_STRUCT              UINT16_C(0x0008)
%define  IMAGE_SYM_TYPE_UNION               UINT16_C(0x0009)
%define  IMAGE_SYM_TYPE_ENUM                UINT16_C(0x000a)
%define  IMAGE_SYM_TYPE_MOE                 UINT16_C(0x000b)
%define  IMAGE_SYM_TYPE_BYTE                UINT16_C(0x000c)
%define  IMAGE_SYM_TYPE_WORD                UINT16_C(0x000d)
%define  IMAGE_SYM_TYPE_UINT                UINT16_C(0x000e)
%define  IMAGE_SYM_TYPE_DWORD               UINT16_C(0x000f)
%define  IMAGE_SYM_TYPE_PCODE               UINT16_C(0x8000)

%define  IMAGE_SYM_DTYPE_NULL               UINT16_C(0x0)
%define  IMAGE_SYM_DTYPE_POINTER            UINT16_C(0x1)
%define  IMAGE_SYM_DTYPE_FUNCTION           UINT16_C(0x2)
%define  IMAGE_SYM_DTYPE_ARRAY              UINT16_C(0x3)


%define N_BTMASK                            UINT16_C(0x000f)
%define N_TMASK                             UINT16_C(0x0030)
%define N_TMASK1                            UINT16_C(0x00c0)
%define N_TMASK2                            UINT16_C(0x00f0)
%define N_BTSHFT                            4
%define N_TSHIFT                            2


;*******************************************************************************
;*  Structures and Typedefs                                                    *
;*******************************************************************************

struc IMAGE_FILE_HEADER
    .Machine resw 1                      ;;< 0x00
    .NumberOfSections resw 1             ;;< 0x02
    .TimeDateStamp resd 1                ;;< 0x04
    .PointerToSymbolTable resd 1         ;;< 0x08
    .NumberOfSymbols resd 1              ;;< 0x0c
    .SizeOfOptionalHeader resw 1         ;;< 0x10
    .Characteristics resw 1              ;;< 0x12
endstruc
AssertCompileSize(IMAGE_FILE_HEADER, 0x14)

struc IMAGE_DATA_DIRECTORY
    .VirtualAddress resd 1
    .Size resd 1
endstruc


struc IMAGE_OPTIONAL_HEADER32
    .Magic resw 1                        ;;< 0x00
    .MajorLinkerVersion resb 1           ;;< 0x02
    .MinorLinkerVersion resb 1           ;;< 0x03
    .SizeOfCode resd 1                   ;;< 0x04
    .SizeOfInitializedData resd 1        ;;< 0x08
    .SizeOfUninitializedData resd 1      ;;< 0x0c
    .AddressOfEntryPoint resd 1          ;;< 0x10
    .BaseOfCode resd 1                   ;;< 0x14
    .BaseOfData resd 1                   ;;< 0x18
    .ImageBase resd 1                    ;;< 0x1c
    .SectionAlignment resd 1             ;;< 0x20
    .FileAlignment resd 1                ;;< 0x24
    .MajorOperatingSystemVersion resw 1  ;;< 0x28
    .MinorOperatingSystemVersion resw 1  ;;< 0x2a
    .MajorImageVersion resw 1            ;;< 0x2c
    .MinorImageVersion resw 1            ;;< 0x2e
    .MajorSubsystemVersion resw 1        ;;< 0x30
    .MinorSubsystemVersion resw 1        ;;< 0x32
    .Win32VersionValue resd 1            ;;< 0x34
    .SizeOfImage resd 1                  ;;< 0x38
    .SizeOfHeaders resd 1                ;;< 0x3c
    .CheckSum resd 1                     ;;< 0x40
    .Subsystem resw 1                    ;;< 0x44
    .DllCharacteristics resw 1           ;;< 0x46
    .SizeOfStackReserve resd 1           ;;< 0x48
    .SizeOfStackCommit resd 1            ;;< 0x4c
    .SizeOfHeapReserve resd 1            ;;< 0x50
    .SizeOfHeapCommit resd 1             ;;< 0x54
    .LoaderFlags resd 1                  ;;< 0x58
    .NumberOfRvaAndSizes resd 1          ;;< 0x5c
    .DataDirectory resb IMAGE_DATA_DIRECTORY_size * IMAGE_NUMBEROF_DIRECTORY_ENTRIES ;;< 0x60; 0x10*8 = 0x80
endstruc
AssertCompileSize(IMAGE_OPTIONAL_HEADER32, 0xe0);

struc IMAGE_OPTIONAL_HEADER64
    .Magic resw 1                        ;;< 0x00
    .MajorLinkerVersion resb 1           ;;< 0x02
    .MinorLinkerVersion resb 1           ;;< 0x03
    .SizeOfCode resd 1                   ;;< 0x04
    .SizeOfInitializedData resd 1        ;;< 0x08
    .SizeOfUninitializedData resd 1      ;;< 0x0c
    .AddressOfEntryPoint resd 1          ;;< 0x10
    .BaseOfCode resd 1                   ;;< 0x14
    .ImageBase resq 1                    ;;< 0x18
    .SectionAlignment resd 1             ;;< 0x20
    .FileAlignment resd 1                ;;< 0x24
    .MajorOperatingSystemVersion resw 1  ;;< 0x28
    .MinorOperatingSystemVersion resw 1  ;;< 0x2a
    .MajorImageVersion resw 1            ;;< 0x2c
    .MinorImageVersion resw 1            ;;< 0x2e
    .MajorSubsystemVersion resw 1        ;;< 0x30
    .MinorSubsystemVersion resw 1        ;;< 0x32
    .Win32VersionValue resd 1            ;;< 0x34
    .SizeOfImage resd 1                  ;;< 0x38
    .SizeOfHeaders resd 1                ;;< 0x3c
    .CheckSum resd 1                     ;;< 0x40
    .Subsystem resw 1                    ;;< 0x44
    .DllCharacteristics resw 1           ;;< 0x46
    .SizeOfStackReserve resq 1           ;;< 0x48
    .SizeOfStackCommit resq 1            ;;< 0x50
    .SizeOfHeapReserve resq 1            ;;< 0x58
    .SizeOfHeapCommit resq 1             ;;< 0x60
    .LoaderFlags resd 1                  ;;< 0x68
    .NumberOfRvaAndSizes resd 1          ;;< 0x6c
    .DataDirectory resb IMAGE_DATA_DIRECTORY_size * IMAGE_NUMBEROF_DIRECTORY_ENTRIES ;;< 0x70; 0x10*8 = 0x80
endstruc                                 ; size: 0xf0
AssertCompileSize(IMAGE_OPTIONAL_HEADER64, 0xf0);


struc IMAGE_NT_HEADERS32
    .Signature resd 1                    ;;< 0x00
    .FileHeader resb IMAGE_FILE_HEADER_size ;           ;;< 0x04
    .OptionalHeader resb IMAGE_OPTIONAL_HEADER32_size   ;;< 0x18
endstruc                                 ; size:  0xf8
AssertCompileSize(IMAGE_NT_HEADERS32, 0xf8);
AssertCompileMemberOffset(IMAGE_NT_HEADERS32, FileHeader, 4);
AssertCompileMemberOffset(IMAGE_NT_HEADERS32, OptionalHeader, 24);

struc IMAGE_NT_HEADERS64
    .Signature resd 1                                  ;;< 0x00
    .FileHeader resb IMAGE_FILE_HEADER_size            ;;< 0x04
    .OptionalHeader resb IMAGE_OPTIONAL_HEADER64_size  ;;< 0x18
endstruc                                 ; size: 0x108
AssertCompileSize(IMAGE_NT_HEADERS64, 0x108);
AssertCompileMemberOffset(IMAGE_NT_HEADERS64, FileHeader, 4);
AssertCompileMemberOffset(IMAGE_NT_HEADERS64, OptionalHeader, 24);


struc IMAGE_SECTION_HEADER
    .Name resb IMAGE_SIZEOF_SHORT_NAME
    .Misc.VirtualSize resd 1
    .VirtualAddress resd 1
    .SizeOfRawData resd 1
    .PointerToRawData resd 1
    .PointerToRelocations resd 1
    .PointerToLinenumbers resd 1
    .NumberOfRelocations resw 1
    .NumberOfLinenumbers resw 1
    .Characteristics resd 1
endstruc
%define IMAGE_SECTION_HEADER.Misc.PhysicalAddress IMAGE_SECTION_HEADER.Misc.VirtualSize


struc IMAGE_BASE_RELOCATION
    .VirtualAddress resd 1
    .SizeOfBlock resd 1
endstruc


struc IMAGE_EXPORT_DIRECTORY
    .Characteristics resd 1
    .TimeDateStamp resd 1
    .MajorVersion resw 1
    .MinorVersion resw 1
    .Name resd 1
    .Base resd 1
    .NumberOfFunctions resd 1
    .NumberOfNames resd 1
    .AddressOfFunctions resd 1
    .AddressOfNames resd 1
    .AddressOfNameOrdinals resd 1
endstruc


struc IMAGE_IMPORT_DESCRIPTOR
    .u.Characteristics resd 1
    .TimeDateStamp resd 1
    .ForwarderChain resd 1
    .Name resd 1
    .FirstThunk resd 1
endstruc
%define IMAGE_IMPORT_DESCRIPTOR.u.OriginalFirstThunk IMAGE_IMPORT_DESCRIPTOR.u.Characteristics

struc IMAGE_IMPORT_BY_NAME
    .Hint resw 1
    .Name resb 1
endstruc


struc IMAGE_THUNK_DATA64
    .u1.ForwarderString resq 1
endstruc
%define IMAGE_THUNK_DATA64.u1.Function      IMAGE_THUNK_DATA64.u1.ForwarderString
%define IMAGE_THUNK_DATA64.u1.Ordinal       IMAGE_THUNK_DATA64.u1.ForwarderString
%define IMAGE_THUNK_DATA64.u1.AddressOfData IMAGE_THUNK_DATA64.u1.ForwarderString

struc IMAGE_THUNK_DATA32
    .u1.ForwarderString resd 1
endstruc
%define IMAGE_THUNK_DATA32.u1.Function      IMAGE_THUNK_DATA32.u1.ForwarderString
%define IMAGE_THUNK_DATA32.u1.Ordinal       IMAGE_THUNK_DATA32.u1.ForwarderString
%define IMAGE_THUNK_DATA32.u1.AddressOfData IMAGE_THUNK_DATA32.u1.ForwarderString


struc IMAGE_LOAD_CONFIG_DIRECTORY32
    .Size resd 1
    .TimeDateStamp resd 1
    .MajorVersion resw 1
    .MinorVersion resw 1
    .GlobalFlagsClear resd 1
    .GlobalFlagsSet resd 1
    .CriticalSectionDefaultTimeout resd 1
    .DeCommitFreeBlockThreshold resd 1
    .DeCommitTotalFreeThreshold resd 1
    .LockPrefixTable resd 1
    .MaximumAllocationSize resd 1
    .VirtualMemoryThreshold resd 1
    .ProcessHeapFlags resd 1
    .ProcessAffinityMask resd 1
    .CSDVersion resw 1
    .Reserved1 resw 1
    .EditList resd 1
    .SecurityCookie resd 1
    .SEHandlerTable resd 1
    .SEHandlerCount resd 1
endstruc

struc IMAGE_LOAD_CONFIG_DIRECTORY64
    .Size resd 1
    .TimeDateStamp resd 1
    .MajorVersion resw 1
    .MinorVersion resw 1
    .GlobalFlagsClear resd 1
    .GlobalFlagsSet resd 1
    .CriticalSectionDefaultTimeout resd 1
    .DeCommitFreeBlockThreshold resq 1
    .DeCommitTotalFreeThreshold resq 1
    .LockPrefixTable resq 1
    .MaximumAllocationSize resq 1
    .VirtualMemoryThreshold resq 1
    .ProcessAffinityMask resq 1
    .ProcessHeapFlags resd 1
    .CSDVersion resw 1
    .Reserved1 resw 1
    .EditList resq 1
    .SecurityCookie resq 1
    .SEHandlerTable resq 1
    .SEHandlerCount resq 1
endstruc


struc IMAGE_DEBUG_DIRECTORY
    .Characteristics resd 1
    .TimeDateStamp resd 1
    .MajorVersion resw 1
    .MinorVersion resw 1
    .Type resd 1
    .SizeOfData resd 1
    .AddressOfRawData resd 1
    .PointerToRawData resd 1
endstruc

struc IMAGE_DEBUG_MISC
    .DataType resd 1
    .Length resd 1
    .Unicode resb 1
    .Reserved resb 3
    .Data resb 1
endstruc


struc WIN_CERTIFICATE
    .dwLength  resd 1
    .wRevision resw 1
    .wCertificateType resw 1
    .bCertificate resb 8
endstruc

;; The header of a .DBG file (NT4).
struc IMAGE_SEPARATE_DEBUG_HEADER
    .Signature resw 1              ;;< 0x00
    .Flags resw 1                  ;;< 0x02
    .Machine resw 1                ;;< 0x04
    .Characteristics resw 1        ;;< 0x06
    .TimeDateStamp resd 1          ;;< 0x08
    .CheckSum resd 1               ;;< 0x0c
    .ImageBase resd 1              ;;< 0x10
    .SizeOfImage resd 1            ;;< 0x14
    .NumberOfSections resd 1       ;;< 0x18
    .ExportedNamesSize resd 1      ;;< 0x1c
    .DebugDirectorySize resd 1     ;;< 0x20
    .SectionAlignment resd 1       ;;< 0x24
    .Reserved resd 2               ;;< 0x28
endstruc                           ; size: 0x30
AssertCompileSize(IMAGE_SEPARATE_DEBUG_HEADER, 0x30);


struc IMAGE_COFF_SYMBOLS_HEADER
    .NumberOfSymbols resd 1
    .LvaToFirstSymbol resd 1
    .NumberOfLinenumbers resd 1
    .LvaToFirstLinenumber resd 1
    .RvaToFirstByteOfCode resd 1
    .RvaToLastByteOfCode resd 1
    .RvaToFirstByteOfData resd 1
    .RvaToLastByteOfData resd 1
endstruc
AssertCompileSize(IMAGE_COFF_SYMBOLS_HEADER, 0x20);


struc IMAGE_LINENUMBER
    .Type.VirtualAddress resd 1
    .Linenumber resw 1
endstruc
AssertCompileSize(IMAGE_LINENUMBER, 6);
%define IMAGE_LINENUMBER.Type.SymbolTableIndex IMAGE_LINENUMBER.Type.VirtualAddress


;;#pragma pack(2)
;;struc IMAGE_SYMBOL
;;{
;;    union
;;    {
;;        uint8_t         ShortName[8];
;;        struct
;;        {
;;            .Short resd 1
;;            .Long resd 1
;;        } Name;
;;        uint32_t        LongName[2];
;;    } N;
;;
;;    .Value resd 1
;;    int16_t     SectionNumber;
;;    .Type resw 1
;;    .StorageClass resb 1
;;    .NumberOfAuxSymbols resb 1
;;} IMAGE_SYMBOL;
;;#pragma pack()
;;AssertCompileSize(IMAGE_SYMBOL, IMAGE_SIZE_OF_SYMBOL);
;;
;;
;;#pragma pack(2)
;;typedef struct IMAGE_AUX_SYMBOL_TOKEN_DEF
;;{
;;    .bAuxType resb 1
;;    .bReserved resb 1
;;    .SymbolTableIndex resd 1
;;    uint8_t     rgbReserved[12];
;;} IMAGE_AUX_SYMBOL_TOKEN_DEF;
;;#pragma pack()
;;AssertCompileSize(IMAGE_AUX_SYMBOL_TOKEN_DEF, IMAGE_SIZE_OF_SYMBOL);
;;
;;
;;#pragma pack(1)
;;typedef union _IMAGE_AUX_SYMBOL
;;{
;;    struct
;;    {
;;        .TagIndex resd 1
;;        union
;;        {
;;            struct
;;            {
;;                .Linenumber resw 1
;;                .Size resw 1
;;            } LnSz;
;;        } Misc;
;;        union
;;        {
;;            struct
;;            {
;;                .PointerToLinenumber resd 1
;;                .PointerToNextFunction resd 1
;;            } Function;
;;            struct
;;            {
;;                uint16_t    Dimension[4];
;;            } Array;
;;        } FcnAry;
;;        .TvIndex resw 1
;;    } Sym;
;;
;;    struct
;;    {
;;        uint8_t     Name[IMAGE_SIZE_OF_SYMBOL];
;;    } File;
;;
;;    struct
;;    {
;;        .Length resd 1
;;        .NumberOfRelocations resw 1
;;        .NumberOfLinenumbers resw 1
;;        .CheckSum resd 1
;;        .Number resw 1
;;        .Selection resb 1
;;        .bReserved resb 1
;;        .HighNumber resw 1
;;    } Section;
;;
;;    IMAGE_AUX_SYMBOL_TOKEN_DEF TokenDef;
;;    struct
;;    {
;;        .crc resd 1
;;        uint8_t     rgbReserved[14];
;;    } CRC;
;;} IMAGE_AUX_SYMBOL;
;;#pragma pack()
;;AssertCompileSize(IMAGE_AUX_SYMBOL, IMAGE_SIZE_OF_SYMBOL);
;;
;;
;;
;;struc IMAGE_SYMBOL_EX
;;{
;;    union
;;    {
;;        uint8_t         ShortName[8];
;;        struct
;;        {
;;            .Short resd 1
;;            .Long resd 1
;;        } Name;
;;        uint32_t        LongName[2];
;;    } N;
;;
;;    .Value resd 1
;;    int32_t     SectionNumber;          /* The difference from IMAGE_SYMBOL
;;    .Type resw 1
;;    .StorageClass resb 1
;;    .NumberOfAuxSymbols resb 1
;;} IMAGE_SYMBOL_EX;
;;AssertCompileSize(IMAGE_SYMBOL_EX, IMAGE_SIZE_OF_SYMBOL_EX);
;;
;;
;;typedef union _IMAGE_AUX_SYMBOL_EX
;;{
;;    struct
;;    {
;;        .WeakDefaultSymIndex resd 1
;;        .WeakSearchType resd 1
;;        uint8_t     rgbReserved[12];
;;    } Sym;
;;
;;    struct
;;    {
;;        uint8_t     Name[IMAGE_SIZE_OF_SYMBOL_EX];
;;    } File;
;;
;;    struct
;;    {
;;        .Length resd 1
;;        .NumberOfRelocations resw 1
;;        .NumberOfLinenumbers resw 1
;;        .CheckSum resd 1
;;        .Number resw 1
;;        .Selection resb 1
;;        .bReserved resb 1
;;        .HighNumber resw 1
;;        uint8_t     rgbReserved[2];
;;    } Section;
;;
;;    IMAGE_AUX_SYMBOL_TOKEN_DEF TokenDef;
;;
;;    struct
;;    {
;;        .crc resd 1
;;        uint8_t     rgbReserved[16];
;;    } CRC;
;;} IMAGE_AUX_SYMBOL_EX;
;;AssertCompileSize(IMAGE_AUX_SYMBOL_EX, IMAGE_SIZE_OF_SYMBOL_EX);

%endif