/
peview.cpp
2970 lines (2670 loc) · 123 KB
/
peview.cpp
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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <algorithm>
#include <cstring>
#include <cctype>
#include <string.h>
#include <inttypes.h>
#include <iomanip>
#include <mutex>
#include <sstream>
#include <type_traits>
#include <utility>
#include "peview.h"
#include "coffview.h"
#define STRING_READ_CHUNK_SIZE 32
using namespace BinaryNinja;
using namespace std;
static PEViewType* g_peViewType = nullptr;
static const char* imageDirName[] = { "exportTable", "importTable", "resourceTable", "exceptionTable", "certificateTable", "baseRelocationTable", "debug", "architecture", "globalPtr", "tlsTable", "loadConfigTable", "boundImport", "iat", "delayImportDescriptor", "clrRuntimeHeader", "reserved"};
void BinaryNinja::InitPEViewType()
{
static PEViewType type;
BinaryViewType::Register(&type);
g_peViewType = &type;
}
// String representation of Rich header object types
static const string kProdId_C = "[ C ]";
static const string kProdId_CPP = "[C++]";
static const string kProdId_RES = "[RES]";
static const string kProdId_IMP = "[IMP]";
static const string kProdId_EXP = "[EXP]";
static const string kProdId_ASM = "[ASM]";
static const string kProdId_LNK = "[LNK]";
static const string kProdId_UNK = "[ ? ]";
static const std::map<uint16_t, string> ProductIdMap = {
{0x0000, kProdId_UNK},
{0x0002, kProdId_IMP},
{0x0004, kProdId_LNK},
{0x0006, kProdId_RES},
{0x000A, kProdId_C},
{0x000B, kProdId_CPP},
{0x000F, kProdId_ASM},
{0x0015, kProdId_C},
{0x0016, kProdId_CPP},
{0x0019, kProdId_IMP},
{0x001C, kProdId_C},
{0x001D, kProdId_CPP},
{0x003D, kProdId_LNK},
{0x003F, kProdId_EXP},
{0x0040, kProdId_ASM},
{0x0045, kProdId_RES},
{0x005A, kProdId_LNK},
{0x005C, kProdId_EXP},
{0x005D, kProdId_IMP},
{0x005E, kProdId_RES},
{0x005F, kProdId_C},
{0x0060, kProdId_CPP},
{0x006D, kProdId_C},
{0x006E, kProdId_CPP},
{0x0078, kProdId_LNK},
{0x007A, kProdId_EXP},
{0x007B, kProdId_IMP},
{0x007C, kProdId_RES},
{0x007D, kProdId_ASM},
{0x0083, kProdId_C},
{0x0084, kProdId_CPP},
{0x0091, kProdId_LNK},
{0x0092, kProdId_EXP},
{0x0093, kProdId_IMP},
{0x0094, kProdId_RES},
{0x0095, kProdId_ASM},
{0x009A, kProdId_RES},
{0x009B, kProdId_EXP},
{0x009C, kProdId_IMP},
{0x009D, kProdId_LNK},
{0x009E, kProdId_ASM},
{0x00AA, kProdId_C},
{0x00AB, kProdId_CPP},
{0x00C9, kProdId_RES},
{0x00CA, kProdId_EXP},
{0x00CB, kProdId_IMP},
{0x00CC, kProdId_LNK},
{0x00CD, kProdId_ASM},
{0x00CE, kProdId_C},
{0x00CF, kProdId_CPP},
{0x00DB, kProdId_RES},
{0x00DC, kProdId_EXP},
{0x00DD, kProdId_IMP},
{0x00DE, kProdId_LNK},
{0x00DF, kProdId_ASM},
{0x00E0, kProdId_C},
{0x00E1, kProdId_CPP},
{0x00FF, kProdId_RES},
{0x0100, kProdId_EXP},
{0x0101, kProdId_IMP},
{0x0102, kProdId_LNK},
{0x0103, kProdId_ASM},
{0x0104, kProdId_C},
{0x0105, kProdId_CPP}
};
// Mapping of Rich header build number to version strings
static const std::map<uint16_t, const string> ProductMap = {
// Source: https://github.com/dishather/richprint/blob/master/comp_id.txt
{0x0000, "Imported Functions"},
{0x0684, "VS97 v5.0 SP3 cvtres 5.00.1668"},
{0x06B8, "VS98 v6.0 cvtres build 1720"},
{0x06C8, "VS98 v6.0 SP6 cvtres build 1736"},
{0x1C87, "VS97 v5.0 SP3 link 5.10.7303"},
{0x5E92, "VS2015 v14.0 UPD3 build 24210"},
{0x5E95, "VS2015 UPD3 build 24213"},
// http://bytepointer.com/articles/the_microsoft_rich_header.htm
{0x0BEC, "VS2003 v7.1 Free Toolkit .NET build 3052"},
{0x0C05, "VS2003 v7.1 .NET build 3077"},
{0x0FC3, "VS2003 v7.1 | Windows Server 2003 SP1 DDK build 4035"},
{0x1C83, "MASM 6.13.7299"},
{0x178E, "VS2003 v7.1 SP1 .NET build 6030"},
{0x1FE8, "VS98 v6.0 RTM/SP1/SP2 build 8168"},
{0x1FE9, "VB 6.0/SP1/SP2 build 8169"},
{0x20FC, "MASM 6.14.8444"},
{0x20FF, "VC++ 6.0 SP3 build 8447"},
{0x212F, "VB 6.0 SP3 build 8495"},
{0x225F, "VS 6.0 SP4 build 8799"},
{0x2263, "MASM 6.15.8803"},
{0x22AD, "VB 6.0 SP4 build 8877"},
{0x2304, "VB 6.0 SP5 build 8964"},
{0x2306, "VS 6.0 SP5 build 8966"},
// {0x2346, "MASM 6.15.9030 (VS.NET 7.0 BETA 1)"},
{0x2346, "VS 7.0 2000 Beta 1 build 9030"},
{0x2354, "VS 6.0 SP5 Processor Pack build 9044"},
{0x2426, "VS2001 v7.0 Beta 2 build 9254"},
{0x24FA, "VS2002 v7.0 .NET build 9466"},
{0x2636, "VB 6.0 SP6 / VC++ build 9782"},
{0x26E3, "VS2002 v7.0 SP1 build 9955"},
{0x520D, "VS2013 v12.[0,1] build 21005"},
{0x521E, "VS2008 v9.0 build 21022"},
{0x56C7, "VS2015 v14.0 build 22215"},
{0x59F2, "VS2015 v14.0 build 23026"},
{0x5BD2, "VS2015 v14.0 UPD1 build 23506"},
{0x5D10, "VS2015 v14.0 UPD2 build 23824"},
{0x5E97, "VS2015 v14.0 UPD3.1 build 24215"},
{0x7725, "VS2013 v12.0 UPD2 build 30501"},
{0x766F, "VS2010 v10.0 build 30319"},
{0x7809, "VS2008 v9.0 SP1 build 30729"},
{0x797D, "VS2013 v12.0 UPD4 build 31101"},
{0x9D1B, "VS2010 v10.0 SP1 build 40219"},
{0x9EB5, "VS2013 v12.0 UPD5 build 40629"},
{0xC497, "VS2005 v8.0 (Beta) build 50327"},
{0xC627, "VS2005 v8.0 | VS2012 v11.0 build 50727"},
{0xC751, "VS2012 v11.0 Nov CTP build 51025"},
{0xC7A2, "VS2012 v11.0 UPD1 build 51106"},
{0xEB9B, "VS2012 v11.0 UPD2 build 60315"},
{0xECC2, "VS2012 v11.0 UPD3 build 60610"},
{0xEE66, "VS2012 v11.0 UPD4 build 61030"},
{0x5E9A, "VS2015 v14.0 build 24218"},
{0x61BB, "VS2017 v14.1 build 25019"},
// https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
{0x2264, "VS 6 [SP5,SP6] build 8804"},
{0x23D8, "Windows XP SP1 DDK"},
{0x0883, "Windows Server 2003 DDK"},
{0x08F4, "VS2003 v7.1 .NET Beta build 2292"},
{0x9D76, "Windows Server 2003 SP1 DDK (for AMD64)"},
{0x9E9F, "VS2005 v8.0 Beta 1 build 40607"},
{0xC427, "VS2005 v8.0 Beta 2 build 50215"},
{0xC490, "VS2005 v8.0 build 50320"},
{0x50E2, "VS2008 v9.0 Beta 2 build 20706"},
{0x501A, "VS2010 v10.0 Beta 1 build 20506"},
{0x520B, "VS2010 v10.0 Beta 2 build 21003"},
{0x5089, "VS2013 v12.0 Preview build 20617"},
{0x515B, "VS2013 v12.0 RC build 20827"},
{0x527A, "VS2013 v12.0 Nov CTP build 21114"},
{0x7674, "VS2013 v12.0 UPD2 RC build 30324"},
{0x63A3, "VS2017 v15.3.3 build 25507"},
{0x63C6, "VS2017 v15.4.4 build 25542"},
{0x63CB, "VS2017 v15.4.5 build 25547"},
// https://walbourn.github.io/visual-studio-2015-update-2/
{0x5D6E, "VS2015 v14.0 UPD2 build 23918"},
// https://walbourn.github.io/visual-studio-2017/
{0x61B9, "VS2017 v15.[0,1] build 25017"},
{0x63A2, "VS2017 v15.2 build 25019"},
// https://walbourn.github.io/vs-2017-15-5-update/
{0x64E6, "VS2017 v15 build 25830"},
{0x64E7, "VS2017 v15.5.2 build 25831"},
{0x64EA, "VS2017 v15.5.[3,4] build 25834"},
{0x64EB, "VS2017 v15.5.[5,6,7] build 25835"},
// https://walbourn.github.io/vs-2017-15-6-update/
{0x6610, "VS2017 v15.6.[0,1,2] build 26128"},
{0x6611, "VS2017 v15.6.[3,4] build 26129"},
{0x6613, "VS2017 v15.6.6 build 26131"},
{0x6614, "VS2017 v15.6.7 build 26132"},
// https://devblogs.microsoft.com/visualstudio/visual-studio-2017-update/
{0x6723, "VS2017 v15.1 build 26403"},
// https://walbourn.github.io/vs-2017-15-7-update/
{0x673C, "VS2017 v15.7.[0,1] build 26428"},
{0x673D, "VS2017 v15.7.2 build 26429"},
{0x673E, "VS2017 v15.7.3 build 26430"},
{0x673F, "VS2017 v15.7.4 build 26431"},
{0x6741, "VS2017 v15.7.5 build 26433"},
// https://walbourn.github.io/visual-studio-2019/
{0x6B74, "VS2019 v16.0.0 build 27508"},
// https://walbourn.github.io/vs-2017-15-8-update/
{0x6866, "VS2017 v15.8.0 build 26726"},
{0x6869, "VS2017 v15.8.4 build 26729"},
{0x686A, "VS2017 v15.8.9 build 26730"},
{0x686C, "VS2017 v15.8.5 build 26732"},
// https://walbourn.github.io/vs-2017-15-9-update/
{0x698F, "VS2017 v15.9.[0,1] build 27023"},
{0x6990, "VS2017 v15.9.2 build 27024"},
{0x6991, "VS2017 v15.9.4 build 27025"},
{0x6992, "VS2017 v15.9.5 build 27026"},
{0x6993, "VS2017 v15.9.7 build 27027"},
{0x6996, "VS2017 v15.9.11 build 27030"},
{0x6997, "VS2017 v15.9.12 build 27031"},
{0x6998, "VS2017 v15.9.14 build 27032"},
{0x699A, "VS2017 v15.9.16 build 27034"},
// https://walbourn.github.io/vs-2019-update-3/
{0x6DC9, "VS2019 v16.3.2 UPD3 build 28105"},
// https://walbourn.github.io/visual-studio-2013-update-3/
{0x7803, "VS2013 v12.0 UPD3 build 30723"},
// experimentation
{0x685B, "VS2017 v15.8.? build 26715"},
{27508, "VS2019 v16.0.0 build 27508"},
// https://walbourn.github.io/vs-2019-update-1/
{27702, "VS2019 v16.1.2 build 27702"},
// https://walbourn.github.io/vs-2019-update-2/
{27905, "VS2019 v16.2.3 build 27905"},
// https://walbourn.github.io/vs-2019-update-3/
{28105, "VS2019 v16.3.2 build 28105"},
// https://walbourn.github.io/vs-2019-update-4/
{28314, "VS2019 v16.4.0 build 28314"},
{28315, "VS2019 v16.4.3 build 28315"},
{28316, "VS2019 v16.4.4 build 28316"},
{28319, "VS2019 v16.4.6 build 28319"},
// https://walbourn.github.io/vs-2019-update-5/
{28610, "VS2019 v16.5.0 build 28610"},
{28611, "VS2019 v16.5.1 build 28611"},
{28612, "VS2019 v16.5.2 build 28612"},
{28614, "VS2019 v16.5.4 build 28614"},
// https://walbourn.github.io/vs-2019-update-6/
{28805, "VS2019 v16.6.0 build 28805"},
{28806, "VS2019 v16.6.1 build 28806"},
// https://walbourn.github.io/vs-2019-update-7/
{29110, "VS2019 v16.7.0 build 29110"},
{29111, "VS2019 v16.7.1 build 29111"},
{29112, "VS2019 v16.7.5 build 29112"},
// https://walbourn.github.io/vs-2019-update-8/
{29333, "VS2019 v16.8.0 build 29333"},
{29334, "VS2019 v16.8.2 build 29334"},
{29335, "VS2019 v16.8.3 build 29335"},
{29336, "VS2019 v16.8.4 build 29336"},
{29337, "VS2019 v16.8.5 build 29337"},
// https://walbourn.github.io/vs-2019-update-9/
{29910, "VS2019 v16.9.0 build 29910"},
{29911, "VS2019 v16.9.1 build 29911"},
{29912, "VS2019 v16.9.2 build 29912"},
{29913, "VS2019 v16.9.3 build 29913"},
{29914, "VS2019 v16.9.4 build 29914"},
{29915, "VS2019 v16.9.5 build 29915"},
// https://walbourn.github.io/vs-2019-update-10/
{30037, "VS2019 v16.10.0 build 30037"},
{30038, "VS2019 v16.10.2 build 30038"},
{30040, "VS2019 v16.10.4 build 30040"},
// https://walbourn.github.io/vs-2019-update-11/
{30133, "VS2019 v16.11.0 build 30133"},
{30136, "VS2019 v16.11.4 build 30136"},
{30137, "VS2019 v16.11.6 build 30137"},
{30138, "VS2019 v16.11.8 build 30138"},
{30139, "VS2019 v16.11.9 build 30139"},
{30140, "VS2019 v16.11.10 build 30140"},
{30141, "VS2019 v16.11.11 build 30141"},
{30142, "VS2019 v16.11.12 build 30142"},
{30143, "VS2019 v16.11.13 build 30143"},
{30145, "VS2019 v16.11.14 build 30145"},
{30146, "VS2019 v16.11.16 build 30146"},
{30147, "VS2019 v16.11.19 build 30147"},
{30148, "VS2019 v16.11.24 build 30148"},
// https://walbourn.github.io/visual-studio-2022/
{30705, "VS2022 17.0.0 build 30705"},
{30706, "VS2022 17.0.2 build 30706"},
{30709, "VS2022 17.0.5 build 30709"},
// https://walbourn.github.io/vs-2022-update-1/
{31104, "VS2022 17.1.0 build 31104"},
{31105, "VS2022 17.1.2 build 31105"},
{31106, "VS2022 17.1.4 build 31106"},
{31107, "VS2022 17.1.6 build 31107"},
// https://walbourn.github.io/vs-2022-update-2/
{31328, "VS2022 v17.2.0 build 31328"},
{31329, "VS2022 v17.2.1 build 31329"},
{31332, "VS2022 v17.2.5 build 31332"},
// https://walbourn.github.io/vs-2022-update-3/
{31629, "VS2022 v17.3.0 build 31629"},
{31630, "VS2022 v17.3.4 build 31630"},
// https://walbourn.github.io/vs-2022-update-4/
{31933, "VS2022 17.4.0 build 31933"},
{31935, "VS2022 17.4.2 build 31935"},
{31937, "VS2022 17.4.3 build 31937"},
{31942, "VS2022 17.4.5 build 31942"},
// https://walbourn.github.io/vs-2022-update-5/
{32215, "VS2022 17.5.0 build 32215"},
{32216, "VS2022 17.5.3 build 32216"},
{32217, "VS2022 17.5.4 build 32217"},
};
static const string kUnknownProduct = "<unknown>";
// Returns a stringified Rich header object type given a product id
const string &GetRichObjectType(uint16_t prodId) {
auto it = ProductIdMap.find(prodId);
if (it != ProductIdMap.end()) {
return it->second;
} else {
return kProdId_UNK;
}
}
// Returns a stringified Rich header product name given a build number
const string &GetRichProductName(uint16_t buildNum) {
auto it = ProductMap.find(buildNum);
if (it != ProductMap.end()) {
return it->second;
} else {
return kUnknownProduct;
}
}
static string GetDebugTypeName(int type)
{
switch (type)
{
case IMAGE_DEBUG_TYPE_UNKNOWN: return "debug_type_unknown";
case IMAGE_DEBUG_TYPE_COFF: return "debug_type_coff";
case IMAGE_DEBUG_TYPE_CODEVIEW: return "debug_type_codeview";
case IMAGE_DEBUG_TYPE_FPO: return "debug_type_fpo";
case IMAGE_DEBUG_TYPE_MISC: return "debug_type_misc";
case IMAGE_DEBUG_TYPE_EXCEPTION: return "debug_type_exception";
case IMAGE_DEBUG_TYPE_FIXUP: return "debug_type_fixup";
case IMAGE_DEBUG_TYPE_OMAP_TO_SRC: return "debug_type_omap_to_src";
case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC: return "debug_type_omap_from_src";
case IMAGE_DEBUG_TYPE_BORLAND: return "debug_type_borland";
case IMAGE_DEBUG_TYPE_RESERVED10: return "debug_type_reserved10";
case IMAGE_DEBUG_TYPE_CLSID: return "debug_type_clsid";
case IMAGE_DEBUG_TYPE_VC_FEATURE: return "debug_type_vc_feature";
case IMAGE_DEBUG_TYPE_POGO: return "debug_type_pogo";
case IMAGE_DEBUG_TYPE_ILTCG: return "debug_type_iltcg";
case IMAGE_DEBUG_TYPE_MPX: return "debug_type_mpx";
case IMAGE_DEBUG_TYPE_REPRO: return "debug_type_repro";
case IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS: return "debug_type_ex_dll_characteristics";
default: return string("debug_type_unknown(") + string(std::to_string(type)) + string(")");
}
}
PEView::PEView(BinaryView* data, bool parseOnly) : BinaryView("PE", data->GetFile(), data), m_parseOnly(parseOnly)
{
CreateLogger("BinaryView");
m_logger = CreateLogger("BinaryView.PEView");
m_backedByDatabase = data->GetFile()->IsBackedByDatabase("PE");
}
bool PEView::Init()
{
std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();
map<string, size_t> usedSectionNames;
BinaryReader reader(GetParentView(), LittleEndian);
Ref<Platform> platform;
Ref<Settings> settings;
PEHeader header;
PEOptionalHeader opt;
memset(&opt, 0, sizeof(opt));
try
{
// Read PE offset
reader.Seek(0x3c);
uint32_t peOfs = reader.Read32();
// Read Rich header
vector<pair<uint32_t, uint32_t>> richValues;
const uint32_t richHeaderBase = 0x80;
if (peOfs > richHeaderBase)
{
reader.Seek(richHeaderBase);
for (uint32_t i = 0; i < ((peOfs - richHeaderBase) / 8); i++)
{
uint32_t var1 = reader.Read32();
uint32_t var2 = reader.Read32();
richValues.push_back({var1, var2});
}
}
// Read PE header
reader.Seek(peOfs);
header.magic = reader.Read32();
header.machine = reader.Read16();
header.sectionCount = reader.Read16();
header.timestamp = reader.Read32();
header.coffSymbolTable = reader.Read32();
header.coffSymbolCount = reader.Read32();
header.optionalHeaderSize = reader.Read16();
header.characteristics = reader.Read16();
m_logger->LogDebug(
"PEHeader:\n"
"\tmagic: 0x%08x\n"
"\tmachine: 0x%04x\n"
"\tsectionCount: 0x%04x\n"
"\ttimestamp: 0x%08x\n"
"\tcoffSymbolTable: 0x%08x\n"
"\tcoffSymbolCount: 0x%08x\n"
"\toptionalHeaderSize: 0x%04x\n"
"\tcharacteristics: 0x%04x %s, %s, %s\n",
header.magic,
header.machine,
header.sectionCount,
header.timestamp,
header.coffSymbolTable,
header.coffSymbolCount,
header.optionalHeaderSize,
header.characteristics,
header.characteristics & 1 ? "No Relocations" : "",
header.characteristics & 2 ? "Executable" : "",
header.characteristics & 0x2000 ? "Dll" : "Unknown");
uint64_t optionalHeaderOffset = reader.GetOffset();
// Read optional header
opt.magic = reader.Read16();
opt.majorLinkerVersion = reader.Read8();
opt.minorLinkerVersion = reader.Read8();
opt.sizeOfCode = reader.Read32();
opt.sizeOfInitData = reader.Read32();
opt.sizeOfUninitData = reader.Read32();
opt.addressOfEntry = reader.Read32();
opt.baseOfCode = reader.Read32();
m_logger->LogDebug(
"PEOptionalHeader:\n"
"\tmagic %04x (%s-bit)\n"
"\tmajorLinkerVersion: %02x\n"
"\tminorLinkerVersion: %02x\n"
"\tsizeOfCode: %08x\n"
"\tsizeOfInitData: %08x\n"
"\tsizeOfUninitData: %08x\n"
"\taddressOfEntry: %08x\n"
"\tbaseOfCode: %08x\n",
opt.magic, opt.magic == 0x10b ? "32" : opt.magic == 0x20b ? "64" : "??",
opt.majorLinkerVersion,
opt.minorLinkerVersion,
opt.sizeOfCode,
opt.sizeOfInitData,
opt.sizeOfUninitData,
opt.addressOfEntry,
opt.baseOfCode);
if (opt.magic == 0x10b) // 32-bit
{
m_is64 = false;
opt.baseOfData = reader.Read32();
opt.imageBase = reader.Read32();
opt.sectionAlign = reader.Read32();
opt.fileAlign = reader.Read32();
opt.majorOSVersion = reader.Read16();
opt.minorOSVersion = reader.Read16();
opt.majorImageVersion = reader.Read16();
opt.minorImageVersion = reader.Read16();
opt.majorSubsystemVersion = reader.Read16();
opt.minorSubsystemVersion = reader.Read16();
opt.win32Version = reader.Read32();
opt.sizeOfImage = reader.Read32();
opt.sizeOfHeaders = reader.Read32();
opt.checksum = reader.Read32();
opt.subsystem = reader.Read16();
opt.dllCharacteristics = reader.Read16();
opt.sizeOfStackReserve = reader.Read32();
opt.sizeOfStackCommit = reader.Read32();
opt.sizeOfHeapReserve = reader.Read32();
opt.sizeOfHeapCommit = reader.Read32();
opt.loaderFlags = reader.Read32();
opt.dataDirCount = reader.Read32();
}
else if (opt.magic == 0x20b) // 64-bit
{
m_is64 = true;
opt.baseOfData = 0;
opt.imageBase = reader.Read64();
opt.sectionAlign = reader.Read32();
opt.fileAlign = reader.Read32();
opt.majorOSVersion = reader.Read16();
opt.minorOSVersion = reader.Read16();
opt.majorImageVersion = reader.Read16();
opt.minorImageVersion = reader.Read16();
opt.majorSubsystemVersion = reader.Read16();
opt.minorSubsystemVersion = reader.Read16();
opt.win32Version = reader.Read32();
opt.sizeOfImage = reader.Read32();
opt.sizeOfHeaders = reader.Read32();
opt.checksum = reader.Read32();
opt.subsystem = reader.Read16();
opt.dllCharacteristics = reader.Read16();
opt.sizeOfStackReserve = reader.Read64();
opt.sizeOfStackCommit = reader.Read64();
opt.sizeOfHeapReserve = reader.Read64();
opt.sizeOfHeapCommit = reader.Read64();
opt.loaderFlags = reader.Read32();
opt.dataDirCount = reader.Read32();
}
else
{
m_logger->LogError("invalid PE optional header type");
return false;
}
map<string, Ref<Metadata>> metadataMap = {
{"Machine", new Metadata((uint64_t) header.machine)},
{"Characteristics", new Metadata((uint64_t) header.characteristics)},
{"Magic", new Metadata((uint64_t) opt.magic)},
{"MajorLinkerVersion", new Metadata((uint64_t) opt.majorLinkerVersion)},
{"MinorLinkerVersion", new Metadata((uint64_t) opt.minorLinkerVersion)},
{"MajorOSVersion", new Metadata((uint64_t) opt.majorOSVersion)},
{"MinorOSVersion", new Metadata((uint64_t) opt.minorOSVersion)},
{"MajorImageVersion", new Metadata((uint64_t) opt.majorImageVersion)},
{"MajorImageVersion", new Metadata((uint64_t) opt.majorImageVersion)},
{"MinorSubsystemVersion", new Metadata((uint64_t) opt.minorSubsystemVersion)},
{"MinorSubsystemVersion", new Metadata((uint64_t) opt.minorSubsystemVersion)},
{"Subsystem", new Metadata((uint64_t) opt.subsystem)},
{"DllCharacteristics", new Metadata((uint64_t) opt.dllCharacteristics)},
};
Ref<Metadata> metadata = new Metadata(metadataMap);
platform = g_peViewType->RecognizePlatform(header.machine, LittleEndian, GetParentView(), metadata);
// set m_arch early so the to make it available for the demangler
m_arch = platform ? platform->GetArchitecture() : g_peViewType->GetArchitecture(header.machine, LittleEndian);
if (!m_arch)
{
// There is no registered architecture for this header.machine likely malware doing something funky
// assume x86/x86_64
m_arch = g_peViewType->GetArchitecture(opt.magic == 0x20b ? 0x8664 : 0x14c, LittleEndian);
m_logger->LogWarn(
"This binary doesn't specify its architecture. Defaulting to x86. If this isn't correct please "
"re-open with 'with options' and specify the correct architecture.");
}
if (!platform)
platform = g_peViewType->GetPlatform(opt.subsystem, m_arch);
if (!platform)
platform = m_arch->GetStandalonePlatform();
m_imageBase = m_peImageBase = opt.imageBase;
SetOriginalBase(m_peImageBase);
m_entryPoint = opt.addressOfEntry;
Ref<Settings> viewSettings = Settings::Instance();
m_extractMangledTypes = viewSettings->Get<bool>("analysis.extractTypesFromMangledNames", this);
m_simplifyTemplates = viewSettings->Get<bool>("analysis.types.templateSimplifier", this);
settings = GetLoadSettings(GetTypeName());
if (settings && settings->Contains("loader.imageBase") && settings->Contains("loader.architecture")) // handle overrides
{
m_imageBase = settings->Get<uint64_t>("loader.imageBase", this);
Ref<Architecture> arch = Architecture::GetByName(settings->Get<string>("loader.architecture", this));
if (!m_arch || (arch && (arch->GetName() != m_arch->GetName())))
m_arch = arch;
}
// Apply architecture and platform
if (!m_arch)
{
switch (header.machine)
{
case 0x14c:
m_logger->LogError("Support for PE architecture 'x86' is not present");
break;
case 0x1c0:
m_logger->LogError("Support for PE architecture 'armv7' is not present");
break;
case 0x8664:
m_logger->LogError("Support for PE architecture 'x86_64' is not present");
break;
case 0xaa64:
#ifndef DEMO_VERSION
m_logger->LogError("Support for PE architecture 'arm64' is not present");
#else
m_logger->LogError("Binary Ninja free does not support PE architecture 'arm64'. "
"Purchase Binary Ninja to unlock all features.");
#endif
break;
default:
m_logger->LogError("PE architecture '0x%x' is not supported", header.machine);
break;
}
return false;
}
platform = platform->GetAssociatedPlatformByAddress(m_entryPoint);
if (settings && settings->Contains("loader.platform")) // handle overrides
{
Ref<Platform> platformOverride = Platform::GetByName(settings->Get<string>("loader.platform", this));
if (platformOverride)
platform = platformOverride;
}
SetDefaultPlatform(platform);
SetDefaultArchitecture(platform->GetArchitecture());
bool fileAlignmentValid = ((opt.fileAlign >= 0x200) && (opt.fileAlign <= 0x10000)) ? (opt.fileAlign & (opt.fileAlign - 1)) == 0 : false;
uint32_t resolvedSectionAlignment = fileAlignmentValid ? opt.sectionAlign : (header.machine == IMAGE_FILE_MACHINE_IA64) ? 0x2000 : 0x1000;
uint32_t resolvedFileAlignment = fileAlignmentValid ? opt.fileAlign : 0x200;
if (!fileAlignmentValid)
m_logger->LogWarn("PE has invalid FileAlignment with value: 0x%x", opt.fileAlign);
m_sizeOfHeaders = opt.sizeOfHeaders;
if (opt.sizeOfHeaders % resolvedFileAlignment)
m_sizeOfHeaders = (opt.sizeOfHeaders + resolvedFileAlignment) & ~(resolvedFileAlignment - 1);
m_relocatable = (opt.dllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) > 0;
m_logger->LogDebug(
"OptionalHeaderComponents:\n"
"\topt.baseOfData %08lx\n"
"\topt.imageBase %016lx\n"
"\topt.sectionAlign %08lx\n"
"\topt.fileAlign %08lx\n"
"\topt.majorOSVersion %04hx\n"
"\topt.minorOSVersion %04hx\n"
"\topt.majorImageVersion %04hx\n"
"\topt.minorImageVersion %04hx\n"
"\topt.majorSubsystemVersion %04hx\n"
"\topt.minorSubsystemVersion %04hx\n"
"\topt.win32Version %08lx\n"
"\topt.sizeOfImage %08lx\n"
"\topt.sizeOfHeaders %08lx\n"
"\topt.checksum %08lx\n"
"\topt.subsystem %04hx\n"
"\topt.dllCharacteristics %04hx\n"
"\topt.sizeOfStackReserve %016lx\n"
"\topt.sizeOfStackCommit %016lx\n"
"\topt.sizeOfHeapReserve %016lx\n"
"\topt.sizeOfHeapCommit %016lx\n"
"\topt.loaderFlags %08lx\n"
"\topt.dataDirCount %016llx\n"
"\topt.imageBase %016llx\n"
"\topt.sizeOfHeaders %08lx\n"
"\topt.addressOfEntry %08lx\n",
opt.baseOfData,
opt.imageBase,
opt.sectionAlign,
opt.fileAlign,
opt.majorOSVersion,
opt.minorOSVersion,
opt.majorImageVersion,
opt.minorImageVersion,
opt.majorSubsystemVersion,
opt.minorSubsystemVersion,
opt.win32Version,
opt.sizeOfImage,
opt.sizeOfHeaders,
opt.checksum,
opt.subsystem,
opt.dllCharacteristics,
opt.sizeOfStackReserve,
opt.sizeOfStackCommit,
opt.sizeOfHeapReserve,
opt.sizeOfHeapCommit,
opt.loaderFlags,
opt.dataDirCount,
opt.imageBase,
opt.sizeOfHeaders,
opt.addressOfEntry);
// PE Optional Header Validation
if (opt.dataDirCount > 16)
{
m_logger->LogWarn("PE Optional Header: NumberOfRvaAndSizes exceeds allowable size. Truncating count: %d to 16.",
opt.dataDirCount);
opt.dataDirCount = 16;
}
// Read data directories
for (uint32_t i = 0; i < opt.dataDirCount; i++)
{
PEDataDirectory dir;
dir.virtualAddress = reader.Read32();
dir.size = reader.Read32();
m_dataDirs.push_back(dir);
}
// Add extra segment to hold header so that it can be viewed. This must be first so
// that real sections take priority.
if (header.sectionCount)
AddAutoSegment(m_imageBase, m_sizeOfHeaders, 0, m_sizeOfHeaders, SegmentReadable);
else
{
uint64_t sizeOfImage = opt.sizeOfImage;
if (opt.sizeOfImage % resolvedSectionAlignment)
sizeOfImage = (opt.sizeOfImage + resolvedSectionAlignment) & ~(resolvedSectionAlignment - 1);
uint64_t dataLength = GetParentView()->GetEnd();
dataLength = std::min(std::max((uint64_t)m_sizeOfHeaders, sizeOfImage), dataLength);
AddAutoSegment(m_imageBase, sizeOfImage, 0, dataLength, SegmentReadable);
}
reader.Seek(optionalHeaderOffset + header.optionalHeaderSize);
// Read sections
BinaryReader sectionNameReader(GetParentView(), LittleEndian);
for (uint16_t i = 0; i < header.sectionCount; i++)
{
PESection section;
m_logger->LogDebug("Offset: %lx\n", reader.GetOffset());
char name[9];
memset(name, 0, sizeof(name));
reader.Read(name, 8);
string resolvedName = name;
if (name[0] == '/' && header.coffSymbolTable)
{
uint32_t stringTableBase = header.coffSymbolTable + (header.coffSymbolCount * 18);
errno = 0;
uint32_t offset = strtoul(name+1, nullptr, 10);
if (errno == 0 && offset > 0 && stringTableBase + offset < GetParentView()->GetEnd())
{
sectionNameReader.Seek(stringTableBase + offset);
resolvedName = sectionNameReader.ReadCString();
}
}
section.name = resolvedName;
if (section.name == ".reloc")
m_relocatable = true;
section.virtualSize = reader.Read32();
section.virtualAddress = reader.Read32();
section.sizeOfRawData = reader.Read32();
section.pointerToRawData = reader.Read32();
if (fileAlignmentValid && (section.pointerToRawData & (resolvedFileAlignment - 1)))
{
m_logger->LogWarn("PE section[%u] violates file alignment: pointerToRawData: 0x%x. Aligning to 0x%x.", i,
section.pointerToRawData, resolvedFileAlignment);
section.pointerToRawData &= ~(resolvedFileAlignment - 1);
}
section.pointerToRelocs = reader.Read32();
section.pointerToLineNumbers = reader.Read32();
section.relocCount = reader.Read16();
section.lineNumberCount = reader.Read16();
section.characteristics = reader.Read32();
if (section.virtualSize == 0)
{
section.virtualSize = section.sizeOfRawData;
}
m_sections.push_back(section);
uint32_t flags = 0;
if (section.characteristics & 0x80000000)
flags |= SegmentWritable;
if (section.characteristics & 0x40000000)
flags |= SegmentReadable;
if (section.characteristics & 0x20000000)
flags |= SegmentExecutable;
if (section.characteristics & 0x80)
flags |= SegmentContainsData;
if (section.characteristics & 0x40)
flags |= SegmentContainsData;
if (section.characteristics & 0x20)
flags |= SegmentContainsCode;
m_logger->LogDebug(
"Section [%d]\n"
"\tsection.name %s\n"
"\tsection.virtualSize: %lx\n"
"\tsection.virtualAddress: %lx\n"
"\tsection.sizeOfRawData: %lx\n"
"\tsection.pointerToRawData: %lx\n"
"\tsection.pointerToRelocs: %lx\n"
"\tsection.pointerToLineNumbers: %lx\n"
"\tsection.relocCount: %hx\n"
"\tsection.lineNumberCount: %hx\n"
"\tsection.characteristics: %lx\n"
"\tsection.virtualSize: %lx\n",
i, section.name.c_str(),
section.virtualAddress,
section.sizeOfRawData,
section.pointerToRawData,
section.pointerToRelocs,
section.pointerToLineNumbers,
section.relocCount,
section.lineNumberCount,
section.characteristics);
m_logger->LogDebug("Segment: Vaddr: %08" PRIx64 " Vsize: %08" PRIx64 " Offset: %08" PRIx64 " Rawsize: %08" PRIx64
" %c%c%c %s\n",
section.virtualAddress + m_imageBase,
section.virtualSize,
section.pointerToRawData,
section.sizeOfRawData,
(flags & SegmentExecutable) > 0 ? 'x':'-',
(flags & SegmentReadable) > 0 ? 'r':'-',
(flags & SegmentWritable) > 0 ? 'w':'-',
section.name.c_str());
if (!section.virtualSize)
continue;
AddAutoSegment(section.virtualAddress + m_imageBase, section.virtualSize, section.pointerToRawData, section.sizeOfRawData, flags);
BNSectionSemantics semantics = DefaultSectionSemantics;
uint32_t pFlags = flags & 0x7;
if (pFlags == (SegmentReadable | SegmentExecutable))
semantics = ReadOnlyCodeSectionSemantics;
else if (pFlags == SegmentReadable)
semantics = ReadOnlyDataSectionSemantics;
else if (pFlags == (SegmentReadable | SegmentWritable))
semantics = ReadWriteDataSectionSemantics;
// FIXME: For now everride semantics for well known section names and warn about the semantic promotion
static map<string, BNSectionSemantics> promotedSectionSemantics =
{
{"text", ReadOnlyCodeSectionSemantics},
{"code", ReadOnlyCodeSectionSemantics},
{"rdata", ReadOnlyDataSectionSemantics},
{"data", ReadWriteDataSectionSemantics},
{"bss", ReadWriteDataSectionSemantics}
};
string shortName = section.name;
if (shortName.length() && shortName[0] == '.')
shortName.erase(shortName.begin());
transform(shortName.begin(), shortName.end(), shortName.begin(), ::tolower);
if (auto itr = promotedSectionSemantics.find(shortName); (itr != promotedSectionSemantics.end()) && (itr->second != semantics))
{
m_logger->LogInfo("%s section semantics have been promoted to facilitate analysis.", section.name.c_str());
semantics = itr->second;
}
auto emplaced = usedSectionNames.emplace(section.name, 1);
if (emplaced.second)
{
AddAutoSection(section.name, section.virtualAddress + m_imageBase, section.virtualSize, semantics);
}
else
{
stringstream ss;
ss << section.name << "_" << ++emplaced.first->second;
AddAutoSection(ss.str(), section.virtualAddress + m_imageBase, section.virtualSize, semantics);
}
}
// Finished for parse only mode
if (m_parseOnly)
return true;
// Add the entry point as a function if the architecture is supported
if (m_entryPoint)
AddEntryPointForAnalysis(platform, m_imageBase + m_entryPoint);
// Create various PE header yypes
// Create MS-DOS Header Type
StructureBuilder dosHeaderBuilder;
dosHeaderBuilder.AddMember(Type::ArrayType(Type::IntegerType(1, true), 2), "e_magic");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_cblp");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_cp");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_crlc");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_cparhdr");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_minalloc");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_maxalloc");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_ss");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_sp");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_csum");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_ip");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_cs");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_lfarlc");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_ovno");
dosHeaderBuilder.AddMember(Type::ArrayType(Type::IntegerType(1, true), 8), "e_res1");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_oemid");
dosHeaderBuilder.AddMember(Type::IntegerType(2, false), "e_oeminfo");
dosHeaderBuilder.AddMember(Type::ArrayType(Type::IntegerType(1, true), 20), "e_res2");
dosHeaderBuilder.AddMember(Type::IntegerType(4, false), "e_lfanew");
Ref<Structure> dosHeaderStruct = dosHeaderBuilder.Finalize();
Ref<Type> dosHeaderType = Type::StructureType(dosHeaderStruct);
QualifiedName dosHeaderName = string("DOS_Header");
string dosHeaderTypeId = Type::GenerateAutoTypeId("pe", dosHeaderName);
QualifiedName dosHeaderTypeName = DefineType(dosHeaderTypeId, dosHeaderName, dosHeaderType);
DefineDataVariable(m_imageBase, Type::NamedType(this, dosHeaderTypeName));
DefineAutoSymbol(new Symbol(DataSymbol, "__dos_header", m_imageBase, NoBinding));
DefineDataVariable(m_imageBase + 0x40, Type::VoidType());
DefineAutoSymbol(new Symbol(DataSymbol, "__dos_stub", m_imageBase + 0x40, NoBinding));
// Create Rich Header Type
// TODO move decoded rich info to comments once comments work with linear view
if (richValues.size() >= 4)
{
bool validRichHeader = false;
uint32_t xorKey = richValues[0].second;
uint32_t entryIdx;
vector<uint64_t> richMetadataLookupIdentifiers;
vector<string> richMetadataLookupNames;
for (const auto& [id, name] : ProductMap)
{
richMetadataLookupIdentifiers.push_back(id);
richMetadataLookupNames.push_back(name);
}
StoreMetadata("RichHeaderLookupIdentifiers", new Metadata(richMetadataLookupIdentifiers), true);
StoreMetadata("RichHeaderLookupNames", new Metadata(richMetadataLookupNames), true);
vector<Ref<Metadata>> richMetadata;
for (entryIdx = 0; entryIdx < richValues.size(); entryIdx++)
{
if ((richValues[entryIdx].first == 0x68636952) && (richValues[entryIdx].second == xorKey))
{
validRichHeader = true;
break;
}
richValues[entryIdx].first ^= xorKey;
richValues[entryIdx].second ^= xorKey;
if (entryIdx > 1) // Skip the first 2 entries as they don't contain interesting information
{
map<string, Ref<Metadata>> entryMetadata = {
{string("ObjectTypeValue"), new Metadata((uint64_t)richValues[entryIdx].first >> 16)},
{string("ObjectTypeName"), new Metadata(GetRichObjectType(richValues[entryIdx].first >> 16))},
{string("ObjectVersionValue"), new Metadata((uint64_t)richValues[entryIdx].first & 0xffff)},
{string("ObjectVersionName"), new Metadata(GetRichProductName(richValues[entryIdx].first & 0xffff))},
{string("ObjectCount"), new Metadata((uint64_t)richValues[entryIdx].second)}
};
richMetadata.push_back(new Metadata(entryMetadata));
}
if (!entryIdx && richValues[entryIdx].first != 0x536e6144)
break;
}
if (validRichHeader)
{
StoreMetadata("RichHeader", new Metadata(richMetadata), true);
StructureBuilder richHeaderBuilder;
richHeaderBuilder.AddMember(Type::IntegerType(4, false), "e_magic__DanS");
richHeaderBuilder.AddMember(Type::ArrayType(Type::IntegerType(4, false), 3), "e_align");
for (uint32_t i = 2; i < entryIdx; i++)
{
stringstream ss;
ss << "e_entry_id" << std::dec << i-2 << "__" << std::hex << std::setw(8) << std::setfill('0') << richValues[i].first;
richHeaderBuilder.AddMember(Type::IntegerType(4, false), ss.str());
ss.str("");
ss.clear();
ss << "e_entry_count" << std::dec << i-2 << "__" << richValues[i].second;
richHeaderBuilder.AddMember(Type::IntegerType(4, false), ss.str());
}
richHeaderBuilder.AddMember(Type::ArrayType(Type::IntegerType(1, true), 4), "e_magic");
richHeaderBuilder.AddMember(Type::IntegerType(4, false), "e_checksum");
Ref<Structure> richHeaderStruct = richHeaderBuilder.Finalize();
Ref<Type> richHeaderType = Type::StructureType(richHeaderStruct);
QualifiedName richHeaderName = string("Rich_Header");
string richHeaderTypeId = Type::GenerateAutoTypeId("pe", richHeaderName);
QualifiedName richHeaderTypeName = DefineType(richHeaderTypeId, richHeaderName, richHeaderType);
DefineDataVariable(m_imageBase + richHeaderBase, Type::NamedType(this, richHeaderTypeName));
DefineAutoSymbol(new Symbol(DataSymbol, "__rich_header", m_imageBase + richHeaderBase, NoBinding));
}
}