-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPEOptionHeader.cpp
More file actions
638 lines (564 loc) · 30.1 KB
/
PEOptionHeader.cpp
File metadata and controls
638 lines (564 loc) · 30.1 KB
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
#include "PEOptionHeader.h"
#include "stringTemplate.h"
#include "global.h"
const char PEOptionHeader::DllCharacterStr[16][35]=
{
"",
"",
"",
"",
"",
"", //0-5位强制为0
"DLL可以在加载时被重定位",
"强制代码实施完整性检查",
"该映像兼容DEP",
"可以隔离,但不隔离此映像",
"映像不使用SEH",
"不绑定映像",
"",
"该映像为WDM driver",
"",
"可用于终端服务器"
};
void PEOptionHeader32::writeDataToFile( HANDLE tempFile )
{
StringTemplate st;
HANDLE hFile = tempFile;
char separator[2] = ",";
char temp[1024];
char retu[1024];
writeStringToFile(hFile,"{ name:'IMAGE_OPTIONAL_HEADER::Base',title:'NT扩展头',value:[");
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","Magic" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.Magic),temp ) );
st.exchange( "desc","魔术字,说明文件的类型(107H == ROM 镜像;10BH == PE32;20BH == PE64)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.Magic) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorLinkerVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorLinkerVersion),temp ) );
st.exchange( "desc","链接器主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorLinkerVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorLinkerVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorLinkerVersion),temp ) );
st.exchange( "desc","链接器副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorLinkerVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfCode" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfCode),temp ) );
st.exchange( "desc","所有含代码的节的总大小(基于文件对齐)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfCode) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfInitializedData" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfInitializedData),temp ) );
st.exchange( "desc","所有含已初始化数据的节的总大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfInitializedData) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfUninitializedData" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfUninitializedData),temp ) );
st.exchange( "desc","所有含未初始化数据的节的总大小(在文件中不占用空间,但是在被加载到内存之后,PE加载程序将会为这些数据分配适当的空间)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfUninitializedData) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","AddressOfEntryPoint" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.AddressOfEntryPoint),temp ) );
st.exchange( "desc","程序执行入口RVA(记录了启动代码距离该PE加载后的起始位置到底多少个字节。对于程序映像,它是启动地址;对于设备驱动程序,它是初始化函数的地址;对于DLL来说,它是可选的,如果不存在需要设置为0)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.AddressOfEntryPoint) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","BaseOfCode" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.BaseOfCode),temp ) );
st.exchange( "desc","代码的节的起始RVA(表示映像被加载到内存中后,代码节的开头相对于映像基址的偏移地址)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.BaseOfCode) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","BaseOfData" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.BaseOfData),temp ) );
st.exchange( "desc","数据的节的起始RVA(表示映像被加载到内存中后,数据节的开头相对于映像基址的偏移地址)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.BaseOfData) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","ImageBase" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.ImageBase),temp ) );
st.exchange( "desc","PE映像的优先装入地址(EXE文件总是可以以这个位置装入;但是如果一个程序引入了多个DLL文件,则DLL实际装入地址与该值可能就会不同;该值必须是64K的整数倍)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.ImageBase) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SectionAlignment" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SectionAlignment),temp ) );
st.exchange( "desc","内存中的节的对齐粒度" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SectionAlignment) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","FileAlignment" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.FileAlignment),temp ) );
st.exchange( "desc","文件中的节的对齐粒度" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.FileAlignment) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorOperatingSystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorOperatingSystemVersion),temp ) );
st.exchange( "desc","操作系统主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorOperatingSystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorOperatingSystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorOperatingSystemVersion),temp ) );
st.exchange( "desc","操作系统副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorOperatingSystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorImageVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorImageVersion),temp ) );
st.exchange( "desc","该PE主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorImageVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorImageVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorImageVersion),temp ) );
st.exchange( "desc","该PE副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorImageVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorSubsystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorSubsystemVersion),temp ) );
st.exchange( "desc","所需子系统的主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorSubsystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorSubsystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorSubsystemVersion),temp ) );
st.exchange( "desc","所需子系统的副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorSubsystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","Win32VersionValue" );
st.exchange( "value", "\'\'" );
st.exchange( "desc","子系统版本的值(未用,必须设置为0)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.Win32VersionValue) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfImage" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfImage),temp ) );
st.exchange( "desc","内存中整个PE的映像尺寸(可以比实际的值大,但不能比它小,且必须保证它是SectionAlignment的整数倍)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfImage) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfHeaders" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfHeaders),temp ) );
st.exchange( "desc","所有头+节表按照文件对齐粒度对齐后的大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfHeaders) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","CheckSum" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.CheckSum),temp ) );
st.exchange( "desc","校验和(大多数PE文件中,该值是0;但在一些内核模式的驱动程序和系统DLL中,它必须存在且有效)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.CheckSum) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
wsprintfA( temp,"指定使用界面的子系统:" );
switch( optionHeader.Subsystem ){
case IMAGE_SUBSYSTEM_UNKNOWN : wsprintfA( &temp[strlen(temp)],"未知的子系统" ); break;
case IMAGE_SUBSYSTEM_NATIVE : wsprintfA( &temp[strlen(temp)],"设备驱动程序和 Native Windows 进程" ); break;
case IMAGE_SUBSYSTEM_WINDOWS_GUI : wsprintfA( &temp[strlen(temp)],"Windows 图形用户界面" ); break;
case IMAGE_SUBSYSTEM_WINDOWS_CUI : wsprintfA( &temp[strlen(temp)],"Windows 字符模式" ); break;
case IMAGE_SUBSYSTEM_POSIX_CUI : wsprintfA( &temp[strlen(temp)],"POSIX字符模式" ); break;
case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI : wsprintfA( &temp[strlen(temp)],"Windows CE 图形界面" ); break;
case IMAGE_SUBSYSTEM_EFI_APPLICATION : wsprintfA( &temp[strlen(temp)],"可扩展固件接口(EFI)应用程序" ); break;
case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER : wsprintfA( &temp[strlen(temp)],"带引导服务的EFI驱动程序" ); break;
case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER : wsprintfA( &temp[strlen(temp)],"带运行时服务的EFI驱动程序" ); break;
case IMAGE_SUBSYSTEM_EFI_ROM : wsprintfA( &temp[strlen(temp)],"EFI ROM 镜像" ); break;
case IMAGE_SUBSYSTEM_XBOX : wsprintfA( &temp[strlen(temp)],"XBOX" ); break;
}
st.exchange( "desc",temp );
st.exchange( "name","Subsystem" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.Subsystem),temp ) );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.Subsystem) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
wsprintfA( temp,"DLL文件特性(不是针对DLL文件的,而是针对所有PE文件的)" );
bool sign = false;
for ( int i = 0 ; i < 16 ; i ++ ){
if ( ( ( 1 << i) & optionHeader.DllCharacteristics) == 0 )
continue;
if ( sign ){
wsprintfA( &temp[strlen(temp)],"、%s",DllCharacterStr[i] );
}else{
wsprintfA( &temp[strlen(temp)],":%s",DllCharacterStr[i] );
sign = true;
}
}
st.exchange( "desc",temp );
st.exchange( "name","DllCharacteristics" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.DllCharacteristics),temp ) );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.DllCharacteristics) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfStackReserve" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfStackReserve),temp ) );
st.exchange( "desc","初始化的栈大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfStackReserve) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfStackCommit" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfStackCommit),temp ) );
st.exchange( "desc","初始化时实际提交的栈大小的栈大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfStackCommit) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfHeapReserve" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfHeapReserve),temp ) );
st.exchange( "desc","初始化时保留的堆大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfHeapReserve) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfHeapCommit" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfHeapCommit),temp ) );
st.exchange( "desc","初始化时实际提交的堆大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfHeapCommit) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","LoaderFlags" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.LoaderFlags),temp ) );
st.exchange( "desc","加载标志" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.LoaderFlags) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","NumberOfRvaAndSizes" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.NumberOfRvaAndSizes),temp ) );
st.exchange( "desc","数据目录结构的项目数量" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.NumberOfRvaAndSizes) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeStringToFile(hFile,"]}");
}
void PEOptionHeader64::writeDataToFile( HANDLE tempFile )
{
StringTemplate st;
HANDLE hFile = tempFile;
char separator[2] = ",";
char temp[1024];
char retu[1024];
writeStringToFile(hFile,"{ name:'IMAGE_OPTIONAL_HEADER::Base',title:'NT扩展头',value:[");
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","Magic" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.Magic),temp ) );
st.exchange( "desc","魔术字,说明文件的类型(107H == ROM 镜像;10BH == PE32;20BH == PE64)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.Magic) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorLinkerVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorLinkerVersion),temp ) );
st.exchange( "desc","链接器主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorLinkerVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorLinkerVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorLinkerVersion),temp ) );
st.exchange( "desc","链接器副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorLinkerVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfCode" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfCode),temp ) );
st.exchange( "desc","所有含代码的节的总大小(基于文件对齐)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfCode) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfInitializedData" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfInitializedData),temp ) );
st.exchange( "desc","所有含已初始化数据的节的总大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfInitializedData) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfUninitializedData" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfUninitializedData),temp ) );
st.exchange( "desc","所有含未初始化数据的节的总大小(在文件中不占用空间,但是在被加载到内存之后,PE加载程序将会为这些数据分配适当的空间)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfUninitializedData) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","AddressOfEntryPoint" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.AddressOfEntryPoint),temp ) );
st.exchange( "desc","程序执行入口RVA(记录了启动代码距离该PE加载后的起始位置到底多少个字节。对于程序映像,它是启动地址;对于设备驱动程序,它是初始化函数的地址;对于DLL来说,它是可选的,如果不存在需要设置为0)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.AddressOfEntryPoint) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","BaseOfCode" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.BaseOfCode),temp ) );
st.exchange( "desc","代码的节的起始RVA(表示映像被加载到内存中后,代码节的开头相对于映像基址的偏移地址)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.BaseOfCode) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","ImageBase" );
st.exchange( "value", ( wsprintfA( temp,"%I64u",optionHeader.ImageBase),temp ) );
st.exchange( "desc","PE映像的优先装入地址(EXE文件总是可以以这个位置装入;但是如果一个程序引入了多个DLL文件,则DLL实际装入地址与该值可能就会不同;该值必须是64K的整数倍)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.ImageBase) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SectionAlignment" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SectionAlignment),temp ) );
st.exchange( "desc","内存中的节的对齐粒度" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SectionAlignment) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","FileAlignment" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.FileAlignment),temp ) );
st.exchange( "desc","文件中的节的对齐粒度" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.FileAlignment) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorOperatingSystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorOperatingSystemVersion),temp ) );
st.exchange( "desc","操作系统主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorOperatingSystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorOperatingSystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorOperatingSystemVersion),temp ) );
st.exchange( "desc","操作系统副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorOperatingSystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorImageVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorImageVersion),temp ) );
st.exchange( "desc","该PE主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorImageVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorImageVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorImageVersion),temp ) );
st.exchange( "desc","该PE副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorImageVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MajorSubsystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MajorSubsystemVersion),temp ) );
st.exchange( "desc","所需子系统的主版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MajorSubsystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","MinorSubsystemVersion" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.MinorSubsystemVersion),temp ) );
st.exchange( "desc","所需子系统的副版本号" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.MinorSubsystemVersion) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","Win32VersionValue" );
st.exchange( "value", "\'\'" );
st.exchange( "desc","子系统版本的值(未用,必须设置为0)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.Win32VersionValue) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfImage" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfImage),temp ) );
st.exchange( "desc","内存中整个PE的映像尺寸(可以比实际的值大,但不能比它小,且必须保证它是SectionAlignment的整数倍)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfImage) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfHeaders" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.SizeOfHeaders),temp ) );
st.exchange( "desc","所有头+节表按照文件对齐粒度对齐后的大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfHeaders) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","CheckSum" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.CheckSum),temp ) );
st.exchange( "desc","校验和(大多数PE文件中,该值是0;但在一些内核模式的驱动程序和系统DLL中,它必须存在且有效)" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.CheckSum) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
wsprintfA( temp,"指定使用界面的子系统:" );
switch( optionHeader.Subsystem ){
case IMAGE_SUBSYSTEM_UNKNOWN : wsprintfA( &temp[strlen(temp)],"未知的子系统" ); break;
case IMAGE_SUBSYSTEM_NATIVE : wsprintfA( &temp[strlen(temp)],"设备驱动程序和 Native Windows 进程" ); break;
case IMAGE_SUBSYSTEM_WINDOWS_GUI : wsprintfA( &temp[strlen(temp)],"Windows 图形用户界面" ); break;
case IMAGE_SUBSYSTEM_WINDOWS_CUI : wsprintfA( &temp[strlen(temp)],"Windows 字符模式" ); break;
case IMAGE_SUBSYSTEM_POSIX_CUI : wsprintfA( &temp[strlen(temp)],"POSIX字符模式" ); break;
case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI : wsprintfA( &temp[strlen(temp)],"Windows CE 图形界面" ); break;
case IMAGE_SUBSYSTEM_EFI_APPLICATION : wsprintfA( &temp[strlen(temp)],"可扩展固件接口(EFI)应用程序" ); break;
case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER : wsprintfA( &temp[strlen(temp)],"带引导服务的EFI驱动程序" ); break;
case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER : wsprintfA( &temp[strlen(temp)],"带运行时服务的EFI驱动程序" ); break;
case IMAGE_SUBSYSTEM_EFI_ROM : wsprintfA( &temp[strlen(temp)],"EFI ROM 镜像" ); break;
case IMAGE_SUBSYSTEM_XBOX : wsprintfA( &temp[strlen(temp)],"XBOX" ); break;
}
st.exchange( "desc",temp );
st.exchange( "name","Subsystem" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.Subsystem),temp ) );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.Subsystem) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
wsprintfA( temp,"DLL文件特性(不是针对DLL文件的,而是针对所有PE文件的)" );
bool sign = false;
for ( int i = 0 ; i < 16 ; i ++ ){
if ( ( ( 1 << i) & optionHeader.DllCharacteristics) == 0 )
continue;
if ( sign ){
wsprintfA( &temp[strlen(temp)],"、%s",DllCharacterStr[i] );
}else{
wsprintfA( &temp[strlen(temp)],":%s",DllCharacterStr[i] );
sign = true;
}
}
st.exchange( "desc",temp );
st.exchange( "name","DllCharacteristics" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.DllCharacteristics),temp ) );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.DllCharacteristics) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfStackReserve" );
st.exchange( "value", ( wsprintfA( temp,"%I64u",optionHeader.SizeOfStackReserve),temp ) );
st.exchange( "desc","初始化的栈大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfStackReserve) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfStackCommit" );
st.exchange( "value", ( wsprintfA( temp,"%I64u",optionHeader.SizeOfStackCommit),temp ) );
st.exchange( "desc","初始化时实际提交的栈大小的栈大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfStackCommit) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfHeapReserve" );
st.exchange( "value", ( wsprintfA( temp,"%I64u",optionHeader.SizeOfHeapReserve),temp ) );
st.exchange( "desc","初始化时保留的堆大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfHeapReserve) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","SizeOfHeapCommit" );
st.exchange( "value", ( wsprintfA( temp,"%I64u",optionHeader.SizeOfHeapCommit),temp ) );
st.exchange( "desc","初始化时实际提交的堆大小" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.SizeOfHeapCommit) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","LoaderFlags" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.LoaderFlags),temp ) );
st.exchange( "desc","加载标志" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.LoaderFlags) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeSeparatorToFile(hFile);
st.setBaseStr( StringTemplate::baseTemplate );
st.exchange( "name","NumberOfRvaAndSizes" );
st.exchange( "value", ( wsprintfA( temp,"%u",optionHeader.NumberOfRvaAndSizes),temp ) );
st.exchange( "desc","数据目录结构的项目数量" );
st.exchange( "length",( wsprintfA( temp,"%u",sizeof(optionHeader.NumberOfRvaAndSizes) ),temp ) );
st.getString(retu);
writeStringToFile(hFile,retu);
writeStringToFile(hFile,"]}");
}