-
Notifications
You must be signed in to change notification settings - Fork 2
/
code.asm
3285 lines (3163 loc) · 101 KB
/
code.asm
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
.486
.model flat,stdcall
option casemap:none
;#######################################
Include code.inc
;#######################################
.data
include crt_tm.inc
APPOBJ STRUCT
szFile db 260 dup(?) ;; File name
lpMem dd ? ;; Image memory
cbMem dd ? ;; Image memory size
hInstance dd ? ;; Handler of Instance
hWinMain dd ? ;; Handler of Window
hIcon dd ? ;; Handler of Icon
hFont dd ? ;; Handler of Font
dwReserve dd 4 dup(?) ;; 64 bit or 32 bit or reserved
hHeap dd ?
hImageList dd ?
dwReserve1 dd 4 dup(?)
hMenu dd ? ;; handler of menu
hTooltip dd ? ;; tooltip
APPOBJ ENDS
PLUGIN STRUCT
dwID DWORD ?
dwIndirect DWORD ?
lpfnProc DWORD ?
lpNext DWORD ?
dwReserve DWORD ?
PLUGIN ENDS
HE_DATA_INFO STRUCT
lpBuffer DWORD ?
dwSize DWORD ?
dwIsReadOnly DWORD ?
HE_DATA_INFO ENDS
HE_POS STRUCT
dwOffset DWORD ?
bHiword DWORD ?
bTxtSection DWORD ?
HE_POS ENDS
HE_WIN_POS STRUCT
iState DWORD ?
dwPos RECT <>
HE_WIN_POS ENDS
HE_SETTINGS STRUCT
dwMask DWORD ?
pHandler DWORD ?
posCaret HE_POS <>
dwSelStart DWORD ?
dwSelEnd DWORD ?
hParent DWORD ?
UNION
lpFile DWORD ?
diMem HE_DATA_INFO <>
ENDS
wpUser HE_WIN_POS <>
HE_SETTINGS ENDS
;#######################################
hAccelerator dd ?
hTree dd ?
hStatus dd ?
hEditRpt dd ?
hChild1 dd ?
hChild2 dd ?
hChild3 dd ?
hChild4 dd ?
hList dd ?
hListBox dd ?
hButton1 dd ?
hButton2 dd ?
hButton3 dd ?
hButton4 dd ?
hButton5 dd ?
hEdit dd ?
hEdit1 dd ?
hEdit2 dd ?
hMenuPlg dd ?
hMenuTrack dd ?
hImgList dd ?
hEvent dd ?
lpCommand dd ?
lpPEDetectEntry dd ?
lpOldListView dd ?
stFile APPOBJ <>
szFaceName db 'MS Shell Dlg',0
szClsButton db 'BUTTON',0
szClsEdit db 'EDIT',0
szRichDll db 'RichEd20.DLL',0
szClsRichEdit db 'RichEdit20A',0
szClsStatic db 'STATIC',0
szClsListBox db 'LISTBOX',0
szClsTree db 'SysTreeView32',0
szClsListV db 'SysListView32',0
szClsTooltip db 'tooltips_class32',0
szApp db 'About ..#'
szClsName db 'Microsoft Portable Executable File Scanner',0
szOtherStuff db 'Copyright(C)2014 Hsiang Chen',0
szOpen db '&Open',0
szOpenTooltip db 'Click this button to open a file.',0
szHideWindow db '&PE Scanner',0
szPlugins db '>',0
sz16Edit db '16Edit.DLL',0
szExport db '&Export(fn)',0
szImport db '&Import(fn)',0
szSecName db 'Name',0
szSecVirSize db 'Vir. Size',0
szSecVirAddr db 'Vir. Address',0
szSecRawSize db 'Raw Size',0
szSecRawOffset db 'Raw Offset',0
szSecRelocations db 'p.Relocations',0
szSecLinenumbers db 'p.Linenumbers',0
szSecNReloc db 'n.Relocations',0
szSecNLinenum db 'n.Linenumbers',0
szCharacteristics db 'Characteristics',0
szImgDosHeader db 'MS-DOS 2.0 Compatible Header',0
szImgFileHeader db 'COFF File Header',0
szImgOptionalHeader db 'Optional Header',0
szImgDataDirectory db 'Data Directory',0
szImgData db 'Misc.',0
szScanDone db 'Scan Done !',0
szFilter db 'ExE/DLL File(*.exe;*.dll)',0,'*.exe;*dll',0,'Object/Exports Library Files(*.obj;*.exp)',0,'*.obj;*exp',0,'All Files(*.*)',0,'*.*',0,0
szObjName db 'PE Scanner File Object [modify enabled].',0
szEventName db 'PE Scanner Event.',0
szFailOpen db 'Fail open file !',0
szFailMap db 'Fail map file !',0
szFailVAlloc db 'Fail allocate virtual memory.',0
szNoDos db 'Not a valid DOS Header !',0
szNoPE db 'Not a valid PE Header !',0
szFmt2 db '%02X ',0
szFmt4 db '%04X ',0
szFmt8 db '%08X',0
szFmt16 db '%08X %08X ',0
szFmt db '%s',0
szFmtL db '%lu',0
szFmtMisc db 'Virtual Address :%08X ; Offset :%08X ; isize :%08X',0
szFmtTime1 db 'CR:%lu/%lu/%lu %02lu:%02lu:%02lu',0
szFmtTime2 db 'LA:%lu/%lu/%lu %02lu:%02lu:%02lu',0
szFmtTime3 db 'LW:%lu/%lu/%lu %02lu:%02lu:%02lu',0
szFmtTime db '%lu/%lu/%lu %02lu:%02lu:%02lu',0
szBytes db 'bytes',0
szObjDect db 'Objective file detected.',0
szEditTooltip1 db 'This edit show you PEiD-like information.',0
szEditTooltip2 db 'This edit show you Log information.',0
szListBoxTooltip db 'Double click an item to open a Data Directory (Need 16Edit.DLL and file is NOT readonly).',0
szPluginBtTooltip db 'Click this button to view plugins.',0
;;DOS Header
sze_magic db 'e_magic :',0
sze_cblp db 'e_cblp :',0
sze_cp db 'e_cp :',0
sze_crlc db 'e_crlc :',0
sze_cparhdr db 'e_cparhdr :',0
sze_minalloc db 'e_minalloc :',0
sze_maxalloc db 'e_maxalloc :',0
sze_ss db 'e_ss :',0
sze_sp db 'e_sp :',0
sze_csum db 'e_csum :',0
sze_ip db 'e_ip :',0
sze_cs db 'e_cs :',0
sze_lfarlc db 'e_lfarlc :',0
sze_ovno db 'e_ovno :',0
sze_res db 'e_res :',0
sze_oemid db 'e_oemid :',0
sze_oeminfo db 'e_oeminfo :',0
sze_res2 db 'e_res2 :',0
sze_lfanew db 'e_lfanew :',0
;;NT Headers
szSignature db 'Signature :',0
szFHMachine db 'Machine : ',0
szFHNumberOfSections db 'Nnmber Of Sections : ',0
szFHTimeDateStamp db 'Time Date Stamp : ',0
szFHPointerToSymbolTable db 'Pointer To Symbol Table : ',0
szFHNumberOfSymbols db 'Number Of Symbols : ',0
szFHSizeOfOptionalHeader db 'Size Of Optional Header : ',0
szFHCharacteristics db 'Characteristics : ',0
szImgNtHeaders db 'Microsoft NT Headers',0
szImgSecHeader db 'Section Headers',0
szOHMagic db 'Magic :',0
szOHMajorLinkerVersion db 'Major Linker Version :',0
szOHMinorLinkerVersion db 'Minor Linker Version :',0
szOHSizeOfCode db 'Size Of Code :',0
szOHSizeOfInitializedData db 'Size Of Initialized Data :',0
szOHSizeOfUninitializedData db 'Size Of Uninitialized Data :',0
szOHAddressOfEntryPoint db 'Address Of Entry Point :',0
szOHBaseOfCode db 'Base Of Code :',0
szOHBaseOfData db 'Base Of Data :',0
szOHImageBase db 'Image Base :',0
szOHSectionAlignment db 'Section Alignment :',0
szOHFileAlignment db 'File Alignment :',0
szOHMajorOperatingSystemVersion db 'Major Operating System Version :',0
szOHMinorOperatingSystemVersion db 'Minor Operating System Version :',0
szOHMajorImageVersion db 'Major Image Version :',0
szOHMinorImageVersion db 'Minor Image Version :',0
szOHMajorSubsystemVersion db 'Major Subsystem Version :',0
szOHMinorSubsystemVersion db 'Minor Subsystem Version :',0
szOHWin32VersionValue db 'Win32 Version Value :',0
szOHSizeOfImage db 'Size Of Image :',0
szOHSizeOfHeaders db 'Size Of Headers :',0
szOHCheckSum db 'CheckSum :',0
szOHSubsystem db 'Subsystem :',0
szOHDllCharacteristics db 'Dll Characteristics :',0
szOHSizeOfStackReserve db 'Size Of Stack Reserve :',0
szOHSizeOfStackCommit db 'Size Of Stack Commit :',0
szOHSizeOfHeapReserve db 'Size Of Heap Reserve :',0
szOHSizeOfHeapCommit db 'Size Of Heap Commit :',0
szOHLoaderFlags db 'Loader Flags :',0
szOHNumberOfRvaAndSizes db 'Number Of Rva And Sizes :',0
;;Directory
szOHD db 'Virtual Address :%08X ; Image Size :%08X',0
szOHD1 db 'Entry Export :',0
szOHD2 db 'Entry Import :',0
szOHD3 db 'Entry Resource :',0
szOHD4 db 'Entry Exception :',0
szOHD5 db 'Entry Security :',0
szOHD6 db 'Entry Base Relocation :',0
szOHD7 db 'Entry Debug :',0
szOHD8 db 'Entry Architecture :',0
szOHD9 db 'Entry Global Ptr :',0
szOHD10 db 'Entry TLS :',0
szOHD11 db 'Entry Load Configure :',0
szOHD12 db 'Entry Bound Import :',0
szOHD13 db 'Entry IAT :',0
szOHD14 db 'Entry Delay Import :',0
szOHD15 db 'Entry COM Descriptor :',0
;;Misc
szSecName1 db 'Section''s Name :',0
szErrorLeak db 'PE Scanner detect application not running correctly!',0DH,0AH,'Need CLOSE NOW!!',0
szEditEP db 'EP[RVA]:',20H,0
szEditEP1 db 'EP[Offset]:',20H,0
szCheckBox db '&Stay On Top',0
sz16EditMissed db '"16Edit.DLL" not found !',0
szFindFilter db '*.*',0
szLoadDll db 'LoadDll',0
szDoMyJob db 'DoMyJob',0
szDoMyJobIndirect db 'DoMyJobIndirect',0
szSubsystemNative db 'Device drivers and native Windows processes',0
szSubsystemWinGUI db 'The Windows graphical user interface (GUI) subsystem',0
szSubsystemWinCUI db 'The Windows character subsystem',0
szSubsystemOS2CUI db 'OS/2 CUI',0
szSubsystemPOSIXCUI db 'The Posix character subsystem',0
szSubsystemNativeWin db 'Windows Native',0
szSubsystemWinCE db 'Windows CE GUI',0
szSubsystemUnknown db 'An unknown subsystem',0
szSubsystemEFIApp db 'An Extensible Firmware Interface (EFI) application',0
szSubsystemEFIBoot db 'An EFI driver with boot services',0
szSubsystemEFIRunt db 'An EFI driver with run-time services',0
szSubsystemEFIRom db 'An EFI ROM image',0
szSubsystemXbox db 'XBOX',0
szSubsystemIs db 'Subsystem is "%s"',0
szEExport db '[0]Export_Entry',0
szEImport db '[1]Import_Entry',0
szEResource db '[2]Resource_Entry',0
szEException db '[3]Exception_Entry',0
szESecurity db '[4]Security_Entry',0
szEBaseReloc db '[5]BaseReloc_Entry',0
szEDebug db '[6]Debug_Entry',0
szEArchitecture db '[7]Architecture_Entry',0
szEGlobalptr db '[8]GlobalPtr_Entry',0
szETLS db '[9]TLS_Entry',0
szELoadConfig db '[A]LoadConfig_Entry',0
szEBoundImport db '[B]BoundImport_Entry',0
szEIAT db '[C]IAT_Entry',0
szEDelayImport db '[D]DelayImport_Entry',0
szEComDescriptor db '[E]COMDescriptor_Entry',0
szHEEnterWindowLoop db 'HEEnterWindowLoop',0
szHESpecifySettings db 'HESpecifySettings',0
szTitleDisassmbler db '[ PE Disassembler(32Bit & 64Bit,LDE engine) ]',0
szTitleR2O db '[ File Location Calculator ]',0
szCalculate db '&Calculate',0
szTimeCvtStatic1 db 'FileTime',0
szTimeCvtStatic2 db 'LocalTime',0
szProfile db '\cfg.ini',0
szProfileDir db '\PES',0
szApp_ db 'Pos',0
szProfileX db 'left',0
szProfileY db 'top',0
szProfileW db 'width',0
szProfileB db 'height',0
szApp1 db 'Misc',0
szProfileTopmost db 'topmost',0
szProfilePlgEnabled db 'plugins_enable',0
szProfileRecents db 'recent_files_enable',0
szProfileLEI db 'log_exports_imports_enable',0
szMsgDelCfgFiles db 'Are you sure about deleting configure files in this computer?',0
szProgressTitle db 'Deleting files ...',0
szMsgCloseWindow db 'Quit now?',0
dwCMDID dd 4000
szDisasmAddr db 'Address',0
szDisasmData db 'Hex Bytes',0
szDisasmAsm db 'Assembler',0
sz16EditCls db '16EditControl',0
szPEDetectDll db 'check.dll',0
szPEDetect db 'GetInfo',0
szMachineIs db 'Machine type is "%s"',0
szMachine00 db 'Unknown Machine',0
szMachine1d3 db 'Matsushita AM33',0
szMachine8664 db 'x64',0
szMachine1c0 db 'ARM little endian',0
szMachine1c4 db 'ARMv7 (or higher) Thumb mode only',0
szMachineaa64 db 'ARMv8 in 64-bit mode',0
szMachineebc db 'EFI byte code',0
szMachine14c db 'Intel 386 or later processors and compatible processors',0
szMachine200 db 'Intel Itanium processor family',0
szMachine9041 db 'Mitsubishi M32R little endian',0
szMachine266 db 'MIPS16',0
szMachine366 db 'MIPS with FPU',0
szMachine466 db 'MIPS16 with FPU',0
szMachine1f0 db 'Power PC little endian',0
szMachine1f1 db 'Power PC with floating point support',0
szMachine166 db 'MIPS little endian',0
szMachine1a2 db 'Hitachi SH3',0
szMachine1a3 db 'Hitachi SH3 DSP',0
szMachine1a6 db 'Hitachi SH4',0
szMachine1a8 db 'Hitachi SH5',0
szMachine1c2 db 'ARM or Thumb ("interworking")',0
szMachine169 db 'MIPS little-endian WCE v2',0
szEPName db 'Entry Point located on section,"%s"',0
szCheckSum db 'The CheckSum of File is "%08X"',0
szMD5 db 'The MD5 of File is "%08X:%08X:%08X:%08X"',0
szLinkerVersionIs db 'The Version of Linker is "%lu .%lu"',0
szFirstBytes db 'The Pattern of Entry Point is "%s"',0
szDiv db 260 dup('-')
szRet db 0DH,0AH,0
szFileTimeStamp db 'FileTimeStamp:',0
szSystemTime db 'Output:',0
szTimeCal db '[ TimeDateStamp Calculator ]',0
szCrc32Fmt db 'The CRC32 of File is "%08X"',0
@hImgList equ hImgList
;#######################################
.code
;#######################################
Include Rva2Offset.asm
Include Offset2Rva.asm
Include SEH.ASM
Include OpenFile.asm
Include LDE64.ASM
;#######################################
_GetRVAName proc uses esi edi edx ecx ebx,_lpMem:DWORD,_dwRva:DWORD
LOCAL @nSec:DWORD
xor eax,eax
mov esi,_lpMem
mov edi,_dwRva
.if WORD PTR [esi] != 'ZM'
jmp _OutProc
.endif
add esi,[esi+3CH]
.if WORD PTR [esi] != 'EP'
jmp _OutProc
.endif
mov ecx,esi
add ecx,06H
mov ax,WORD PTR [ecx]
mov @nSec,eax
movzx eax,[esi+IMAGE_NT_HEADERS.OptionalHeader.Magic]
.if eax == 010BH
add esi,24+216+8
.elseif eax == 020BH
add esi,24+232+8
.endif
.while @nSec
mov ecx,esi
add ecx,08H
add ecx,04H
mov edx,DWORD PTR [ecx] ;; VirtualAddress
add ecx,04H
mov eax,DWORD PTR [ecx] ;; SizeOfRawData
add eax,edx
.if ( edi >= edx && edi <= eax ) || edi < DWORD PTR [ecx+4]
jmp _GetNameHereAndDo
.endif
add esi,sizeof IMAGE_SECTION_HEADER
dec @nSec
.endw
_GetNameHereAndDo:
mov @nSec,esi
invoke GlobalAlloc,GPTR,9
.if eax
mov edi,eax
mov esi,@nSec
mov ecx,8
cld
rep movsb
.endif
_OutProc:
ret
_GetRVAName endp
_GetProfilePath proc _lpBuffer:DWORD ;; get profile pathname here
jmp @F
db 'APPDATA',0
@@:
invoke GetEnvironmentVariable,offset @B - 8,_lpBuffer,260
invoke lstrcat,_lpBuffer,offset szProfileDir
invoke CreateDirectory,_lpBuffer,0
invoke lstrcat,_lpBuffer,offset szProfile
ret
_GetProfilePath endp
;#######################################
_HexViewProc proc uses esi edi ecx edx ebx,lParam:DWORD
LOCAL @hFile:DWORD
LOCAL @hFileMap:DWORD
LOCAL @hLib:DWORD
LOCAL @lpHEEnterWindowLoop:DWORD
LOCAL @lpHESpecifySettings:DWORD
LOCAL @lpMem:DWORD
LOCAL @dwSize:DWORD
LOCAL @stHE:HE_SETTINGS
MOV @hLib,0
mov @hFile,0
mov @hFileMap,0
mov @lpMem,0
invoke CreateFile,offset stFile.szFile,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
cmp eax,-1
je _OutHex
mov @hFile,eax
invoke GetFileSize,@hFile,0
cmp eax,-1
je _OutHex
mov @dwSize,eax
invoke CreateFileMapping,@hFile,0,PAGE_READWRITE,0,0,offset szObjName
or eax,eax
jz _OutHex
mov @hFileMap,eax
invoke MapViewOfFile,@hFileMap,FILE_MAP_READ or FILE_MAP_WRITE,0,0,0
or eax,eax
jz _OutHex
mov @lpMem,eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov esi,eax
add esi,[esi+3CH]
movzx eax,[esi+IMAGE_NT_HEADERS.OptionalHeader.Magic]
.if eax == 010BH
add esi,24+92+4
.elseif eax == 020BH
add esi,24+108+4
.endif
mov eax,lParam
.if eax == '0'
.elseif eax == '1'
add esi,8
.elseif eax == '2'
add esi,16
.elseif eax == '3'
add esi,24
.elseif eax == '4'
add esi,32
.elseif eax == '5'
add esi,40
.elseif eax == '6'
add esi,48
.elseif eax == '7'
add esi,56
.elseif eax == '8'
add esi,64
.elseif eax == '9'
add esi,72
.elseif eax == 'A'
add esi,80
.elseif eax == 'B'
add esi,88
.elseif eax == 'C'
add esi,96
.elseif eax == 'D'
add esi,104
.else
add esi,112
.endif
mov eax,DWORD PTR [esi]
mov ecx,DWORD PTR [esi+4]
invoke _RVAToRAW,@lpMem,eax
add ecx,eax
;; EAX - ECX
pushad
invoke LoadLibrary,offset sz16Edit
.if !eax
invoke SendMessage,hEdit1,WM_SETTEXT,0,offset sz16EditMissed
popad
jmp _OutHex
.endif
mov @hLib,eax
invoke GetProcAddress,@hLib,offset szHESpecifySettings
.if !eax
popad
jmp _OutHex
.endif
mov @lpHESpecifySettings,eax
invoke GetProcAddress,@hLib,offset szHEEnterWindowLoop
.if !eax
popad
jmp _OutHex
.endif
mov @lpHEEnterWindowLoop,eax
xor eax,eax
mov ecx,sizeof @stHE
lea edi,@stHE
cld
rep stosb
popad
mov @stHE.dwMask,08H or 100H or 40H or 80H
mov @stHE.dwSelStart,eax
dec ecx
mov @stHE.dwSelEnd,ecx
push stFile.hWinMain
pop @stHE.hParent
mov eax,@lpMem
mov @stHE.diMem.lpBuffer,eax
mov ecx,@dwSize
mov @stHE.diMem.dwSize,ecx
mov @stHE.diMem.dwIsReadOnly,0
lea eax,@stHE
push eax
call @lpHESpecifySettings
call @lpHEEnterWindowLoop
_OutHex:
.if @hLib
invoke FreeLibrary,@hLib
.endif
.if @lpMem
invoke UnmapViewOfFile,@lpMem
.endif
.if @hFileMap
invoke CloseHandle,@hFileMap
.endif
.if @hFile
invoke CloseHandle,@hFile
.endif
ret
_HexViewProc endp
_TrackPopupMenu proc lParam:DWORD
LOCAL @stRc:RECT
invoke GetWindowRect,lParam,addr @stRc
invoke TrackPopupMenu,hMenuPlg,TPM_LEFTALIGN,@stRc.right,@stRc.top,0,stFile.hWinMain,0
ret
_TrackPopupMenu endp
_InitSecDlg proc lParam:DWORD
LOCAL @stLVC:LV_COLUMN
invoke SetEvent,hEvent
invoke WaitForSingleObject,hEvent,INFINITE
invoke SendMessage,lParam,LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT
mov @stLVC.imask,LVCF_FMT or LVCF_SUBITEM or LVCF_TEXT or LVCF_WIDTH
mov @stLVC.fmt,LVCFMT_CENTER
mov @stLVC.lx,76
mov @stLVC.iSubItem,0
mov @stLVC.pszText,offset szCharacteristics
mov @stLVC.cchTextMax,sizeof szCharacteristics
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecNLinenum
mov @stLVC.cchTextMax,sizeof szSecNLinenum
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecNReloc
mov @stLVC.cchTextMax,sizeof szSecNReloc
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecLinenumbers
mov @stLVC.cchTextMax,sizeof szSecLinenumbers
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecRelocations
mov @stLVC.cchTextMax,sizeof szSecRelocations
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecRawOffset
mov @stLVC.cchTextMax,sizeof szSecRawOffset
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecRawSize
mov @stLVC.cchTextMax,sizeof szSecRawSize
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecVirAddr
mov @stLVC.cchTextMax,sizeof szSecVirAddr
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecVirSize
mov @stLVC.cchTextMax,sizeof szSecVirSize
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
inc @stLVC.iSubItem
mov @stLVC.pszText,offset szSecName
mov @stLVC.cchTextMax,sizeof szSecName
invoke SendMessage,lParam,LVM_INSERTCOLUMN,0,addr @stLVC
invoke ResetEvent,hEvent
ret
_InitSecDlg endp
_ScanSecDlg proc uses esi edi,lParam:DWORD
LOCAL @stlvi:LV_ITEM
LOCAL @nSec:DWORD
LOCAL @szBuf[260]:BYTE
mov @stlvi.imask,LVIF_TEXT
mov @stlvi.iItem,0
mov @stlvi.cchTextMax,260
;invoke SendMessage,lParam,LVM_INSERTITEM,0,addr @stlvi
assume fs:nothing
push ebp
push offset @@Exit
push offset _HandlerProc
push fs:[0]
mov fs:[0],esp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmp stFile.lpMem,0
jne @F
invoke _OpenFile,offset stFile.szFile
or eax,eax
jz @@Exit
mov stFile.lpMem,eax
@@:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov esi,stFile.lpMem
add esi,[esi+3CH]
mov ax,WORD PTR [esi]
cmp ax,'EP'
je @F
jmp @@Exit
@@:
mov edi,esi
add edi,06H
xor ecx,ecx
mov cx,WORD PTR [edi]
mov @nSec,ecx
add esi,sizeof IMAGE_NT_HEADERS
@@:
mov edi,esi
mov @stlvi.pszText,edi
mov @stlvi.iSubItem,0
pushad
invoke SendMessage,lParam,LVM_INSERTITEM,0,addr @stlvi
popad
add edi,8
mov ecx,6
_MiniLoop:
pushad
invoke wsprintf,addr @szBuf,offset szFmt8,DWORD PTR [edi]
inc @stlvi.iSubItem
lea eax,@szBuf
mov @stlvi.pszText,eax
invoke SendMessage,lParam,LVM_SETITEM,0,addr @stlvi
popad
add edi,4
loop _MiniLoop
invoke wsprintf,addr @szBuf,offset szFmt4,WORD PTR [edi]
inc @stlvi.iSubItem
lea eax,@szBuf
mov @stlvi.pszText,eax
invoke SendMessage,lParam,LVM_SETITEM,0,addr @stlvi
add edi,2
invoke wsprintf,addr @szBuf,offset szFmt4,WORD PTR [edi]
inc @stlvi.iSubItem
lea eax,@szBuf
mov @stlvi.pszText,eax
invoke SendMessage,lParam,LVM_SETITEM,0,addr @stlvi
add edi,2
invoke wsprintf,addr @szBuf,offset szFmt8,DWORD PTR [edi]
inc @stlvi.iSubItem
lea eax,@szBuf
mov @stlvi.pszText,eax
invoke SendMessage,lParam,LVM_SETITEM,0,addr @stlvi
dec @nSec
cmp @nSec,0
jle @@Exit
add esi,sizeof IMAGE_SECTION_HEADER
inc @stlvi.iItem
mov @stlvi.iSubItem,0
jmp @B
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@Exit:
pop fs:[0]
add esp,12
ret
_ScanSecDlg endp
_CleanOutEd proc _hWnd:DWORD
pushad
xor eax,eax
push eax
mov esi,esp
invoke SendDlgItemMessage,_hWnd,1060,WM_SETTEXT,0,esi
invoke SendDlgItemMessage,_hWnd,1056,WM_SETTEXT,0,esi
invoke SendDlgItemMessage,_hWnd,1014,WM_SETTEXT,0,esi
invoke SendDlgItemMessage,_hWnd,1015,WM_SETTEXT,0,esi
invoke SendDlgItemMessage,_hWnd,1088,WM_SETTEXT,0,esi
invoke SendDlgItemMessage,_hWnd,1057,WM_SETTEXT,0,esi
add esp,4
invoke GetDlgItem,_hWnd,1058
.if eax
invoke EnableWindow,eax,0
.endif
popad
ret
_CleanOutEd endp
_R2OProc proc uses esi edi,hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL @szBuf[260]:BYTE
LOCAL @imgbase[2]:DWORD
LOCAL @stHE:HE_SETTINGS
.if uMsg == WM_INITDIALOG
invoke SendMessage,hWnd,WM_SETTEXT,0,offset szTitleR2O
cmp stFile.lpMem,0
jz @F
invoke CheckDlgButton,hWnd,1054,BST_CHECKED
invoke GetDlgItem,hWnd,1014
.if eax
invoke EnableWindow,eax,1
.endif
invoke GetDlgItem,hWnd,1056
.if eax
invoke EnableWindow,eax,0
.endif
invoke GetDlgItem,hWnd,1015
.if eax
invoke EnableWindow,eax,0
.endif
invoke GetDlgItem,hWnd,1060
.if eax
invoke EnableWindow,eax,0
.endif
.elseif uMsg == WM_COMMAND
mov eax,wParam
and eax,0FFFFH
.if eax == 1052
xor eax,eax
lea edi,@szBuf
mov ecx,sizeof @szBuf
cld
rep stosb
push ebp
push offset @@check
push offset _HandlerProc
assume fs:nothing
push fs:[0]
mov fs:[0],esp
mov esi,stFile.lpMem
assume esi:PTR IMAGE_DOS_HEADER
.if [esi].e_magic == IMAGE_DOS_SIGNATURE
add esi,[esi].e_lfanew
assume esi:PTR IMAGE_NT_HEADERS
.if [esi].Signature == IMAGE_NT_SIGNATURE
.if [esi].OptionalHeader.Magic == 020BH ;; 64 bit
push [esi].OptionalHeader.BaseOfData
pop @imgbase[0]
push [esi].OptionalHeader.ImageBase
pop @imgbase[4]
.else ;; 32 bit
push [esi].OptionalHeader.ImageBase
pop @imgbase[0]
mov @imgbase[4],0
.endif
.endif
.endif
@@check:
assume esi:nothing
pop fs:[0]
add esp,12
invoke IsDlgButtonChecked,hWnd,1053
.if eax == BST_CHECKED
invoke SendDlgItemMessage,hWnd,1056,WM_GETTEXT,sizeof @szBuf,addr @szBuf
.if eax
invoke _Ascii2Dword16,addr @szBuf
sub eax,@imgbase
mov edi,eax
invoke wsprintf,addr @szBuf,offset szFmt8,eax
invoke SendDlgItemMessage,hWnd,1014,WM_SETTEXT,0,addr @szBuf
invoke _GetRVAName,stFile.lpMem,edi
.if eax
push eax
invoke SendDlgItemMessage,hWnd,1088,WM_SETTEXT,0,eax
pop eax
invoke GlobalFree,eax
.endif
invoke _RVAToRAW,stFile.lpMem,edi
.if eax
push eax
mov esi,eax
add esi,stFile.lpMem
lea edi,@szBuf
mov ecx,16
___loop_1:
push ecx
xor eax,eax
cld
lodsb
invoke wsprintf,edi,offset szFmt2,eax
add edi,eax
pop ecx
loop ___loop_1
xor eax,eax
cld
stosb
invoke SendDlgItemMessage,hWnd,1057,WM_SETTEXT,0,addr @szBuf
invoke GetDlgItem,hWnd,1058
.if eax
invoke EnableWindow,eax,1
.endif
pop eax
invoke wsprintf,addr @szBuf,offset szFmt8,eax
invoke SendDlgItemMessage,hWnd,1015,WM_SETTEXT,0,addr @szBuf
mov @imgbase,0
.endif
.endif
.else
invoke IsDlgButtonChecked,hWnd,1054
.if eax == BST_CHECKED
.if stFile.dwReserve == 64
invoke wsprintf,addr @szBuf,offset szFmt8,@imgbase[4]
invoke SendDlgItemMessage,hWnd,1060,WM_SETTEXT,0,addr @szBuf
.endif
invoke SendDlgItemMessage,hWnd,1014,WM_GETTEXT,sizeof @szBuf,addr @szBuf
.if eax
invoke _Ascii2Dword16,addr @szBuf
push eax
add eax,@imgbase
invoke wsprintf,addr @szBuf,offset szFmt8,eax
invoke SendDlgItemMessage,hWnd,1056,WM_SETTEXT,0,addr @szBuf
pop eax
push eax
invoke _GetRVAName,stFile.lpMem,eax
.if eax
push eax
invoke SendDlgItemMessage,hWnd,1088,WM_SETTEXT,0,eax
pop eax
invoke GlobalFree,eax
.endif
pop eax
invoke _RVAToRAW,stFile.lpMem,eax
.if eax
push eax
mov esi,eax
add esi,stFile.lpMem
lea edi,@szBuf
mov ecx,16
___loop_2:
push ecx
xor eax,eax
cld
lodsb
invoke wsprintf,edi,offset szFmt2,eax
add edi,eax
pop ecx
loop ___loop_2
xor eax,eax
cld
stosb
invoke SendDlgItemMessage,hWnd,1057,WM_SETTEXT,0,addr @szBuf
invoke GetDlgItem,hWnd,1058
.if eax
invoke EnableWindow,eax,1
.endif
pop eax
invoke wsprintf,addr @szBuf,offset szFmt8,eax
invoke SendDlgItemMessage,hWnd,1015,WM_SETTEXT,0,addr @szBuf
mov @imgbase,0
.endif
.endif
.else
invoke SendDlgItemMessage,hWnd,1015,WM_GETTEXT,sizeof @szBuf,addr @szBuf
.if eax
invoke _Ascii2Dword16,addr @szBuf
push eax
mov esi,eax
add esi,stFile.lpMem
lea edi,@szBuf
mov ecx,16
___loop_3:
push ecx
xor eax,eax
cld
lodsb
invoke wsprintf,edi,offset szFmt2,eax
add edi,eax
pop ecx
loop ___loop_3
xor eax,eax
cld
stosb
invoke SendDlgItemMessage,hWnd,1057,WM_SETTEXT,0,addr @szBuf
invoke GetDlgItem,hWnd,1058
.if eax
invoke EnableWindow,eax,1
.endif
pop eax
invoke _Offset2Rva,stFile.lpMem,eax
.if eax
push eax
invoke _GetRVAName,stFile.lpMem,eax
.if eax
push eax
invoke SendDlgItemMessage,hWnd,1088,WM_SETTEXT,0,eax
pop eax
invoke GlobalFree,eax
.endif
pop eax
push eax
invoke wsprintf,addr @szBuf,offset szFmt8,eax
invoke SendDlgItemMessage,hWnd,1014,WM_SETTEXT,0,addr @szBuf
pop eax
add @imgbase,eax
invoke wsprintf,addr @szBuf,offset szFmt8,@imgbase
invoke SendDlgItemMessage,hWnd,1056,WM_SETTEXT,0,addr @szBuf
.if stFile.dwReserve == 64
invoke wsprintf,addr @szBuf,offset szFmt8,@imgbase[4]
invoke SendDlgItemMessage,hWnd,1060,WM_SETTEXT,0,addr @szBuf
.endif
mov @imgbase,0
.endif
.endif
.endif
.endif
.if @imgbase
invoke _CleanOutEd,hWnd
.endif
.elseif eax == 1058
invoke LoadLibrary,offset sz16Edit
.if eax
mov @imgbase,eax
invoke GetProcAddress,@imgbase,offset szHESpecifySettings
.if eax
mov esi,eax
xor eax,eax
mov ecx,sizeof @stHE
lea edi,@stHE
cld
rep stosb
invoke SendDlgItemMessage,hWnd,1015,WM_GETTEXT,sizeof @szBuf,addr @szBuf
invoke _Ascii2Dword16,addr @szBuf
mov @stHE.dwMask,04H or 100H or 80H or 40H
mov @stHE.posCaret.dwOffset,eax
push hWnd
pop @stHE.hParent
push stFile.lpMem
pop @stHE.diMem.lpBuffer
push stFile.cbMem
pop @stHE.diMem.dwSize
mov @stHE.diMem.dwIsReadOnly,1
lea eax,@stHE
push eax
call esi
invoke GetProcAddress,@imgbase,offset szHEEnterWindowLoop
.if eax
call eax
.endif
.endif
invoke FreeLibrary,eax
.else
invoke EnableWindow,lParam,0
.endif
.elseif eax == 1059
jmp @F
.elseif eax == 1053
invoke _CleanOutEd,hWnd
invoke GetDlgItem,hWnd,1056
.if eax
invoke EnableWindow,eax,1