-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexereader.pas
759 lines (641 loc) · 18.6 KB
/
exereader.pas
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
unit exereader;
{$mode objfpc}{$H+}
interface
uses
SysUtils,
Math,
dosheader;
type
TExeFileKind = (
fkUnknown,
fkDOS,
fkExe16,
fkExe32,
fkExe64,
fkExeArm,
fkDll16,
fkDll32,
fkDll64,
fkDllArm,
fkVXD
);
PLongword = ^Longword;
TExeFile = class;
TImportFuncEntry = record
case IsOrdinal: Boolean of
true: (
Ordinal: Word;
);
false: (
Hint: Word;
Name: PAnsiChar;
);
end;
{ TExeImportDLL }
TExeImportDLL = class
private
FHandle: THandle;
FParent: TExeFile;
FDLLName: PChar;
FDescriptor: PIMAGE_IMPORT_DESCRIPTOR;
FEntries: array of TImportFuncEntry;
function GetCount: Integer;
function GetDLLName: string;
function GetEntry(Index: Integer): TImportFuncEntry;
public
constructor Create(AParent: TExeFile; DLL: PIMAGE_IMPORT_DESCRIPTOR);
function Read: Boolean;
function Read64: Boolean;
property Descriptor: PIMAGE_IMPORT_DESCRIPTOR read FDescriptor;
property DLLName: string read GetDLLName;
property Count: Integer read GetCount;
property Entries[Index: Integer]: TImportFuncEntry read GetEntry;
property Handle: THandle read FHandle write FHandle;
end;
TExeExportFunc = record
Name: PChar;
Ordinal: Word;
EntryPoint: longword;
end;
TDWordArray = array[0..0] of DWord;
PDWordArray = ^TDWordArray;
TExeRelocTable = record
VirtualAddress: UInt64;
Count: Integer;
Items: PWordarray;
end;
{ TExeFile }
TExeFile = class
private
FDataSize: longword;
FData: PByteArray;
FDOSHeader: PIMAGE_DOS_HEADER;
FNTHeaders64: PIMAGE_NT_HEADERS64;
FNTHeaders: PIMAGE_NT_HEADERS;
FSections: array of PIMAGE_SECTION_HEADER;
FImports: array of TExeImportDLL;
FExports: array of TExeExportFunc;
FRelocations: array of TExeRelocTable;
FDOSFileSize: longword;
FStatus: string;
FExportName: PChar;
FFileType: TExeFileKind;
function GetExport(Index: Integer): TExeExportFunc;
function GetExportCount: Integer;
function GetImport(Index: Integer): TExeImportDLL;
function GetImportCount: Integer;
function GetRelocation(Index: Integer): TExeRelocTable;
function GetRelocationCount: Integer;
function GetSection(Index: Integer): PIMAGE_SECTION_HEADER;
function GetSectionCount: Integer;
protected
function ResolveVirtualAddress32(VirtualAddress: UInt64): UInt64;
procedure ReadImports(VirtualAddress: UInt64; is64Bit: Boolean);
procedure ReadExports(VirtualAddress: UInt64);
procedure ReadRelocations(VirtualAddress: UInt64);
function ReadDOSHeader: Boolean;
function ReadWin32Header: Boolean;
function ReadWin64Header: Boolean;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function LoadFile(aFilename: string; ReadFull: Boolean = True): Boolean;
function GetRawAddress(Address: UInt64): Pointer;
function GetVirtualAddress(VirtualAddress: UInt64): Pointer;
function IsValidVirtualAddress(VirtualAddress: UInt64): Boolean;
property Status: string read FStatus;
property FileType: TExeFileKind read FFileType;
property DOSHeader: PIMAGE_DOS_HEADER read FDOSHeader;
property NTHeader: PIMAGE_NT_HEADERS read FNTHeaders;
property NTHeader64: PIMAGE_NT_HEADERS64 read FNTHeaders64;
property SectionCount: Integer read GetSectionCount;
property Sections[Index: Integer]: PIMAGE_SECTION_HEADER read GetSection;
property ImportCount: Integer read GetImportCount;
property Imports[Index: Integer]: TExeImportDLL read GetImport;
property ExportName: PChar read FExportName;
property ExportCount: Integer read GetExportCount;
property ExportFuncs[Index: Integer]: TExeExportFunc read GetExport;
property RelocationCount: Integer read GetRelocationCount;
property Relocations[Index: Integer]: TExeRelocTable read GetRelocation;
end;
implementation
{ TExeImportDLL }
function TExeImportDLL.GetDLLName: string;
begin
result:=FDLLName;
end;
function TExeImportDLL.GetCount: Integer;
begin
result:=Length(FEntries);
end;
function TExeImportDLL.GetEntry(Index: Integer): TImportFuncEntry;
begin
if(Index>=0)and(Index<Length(FEntries)) then
result:=FEntries[Index]
else
begin
result.IsOrdinal:=False;
result.Hint:=0;
result.Name:=nil;
end;
end;
constructor TExeImportDLL.Create(AParent: TExeFile;
DLL: PIMAGE_IMPORT_DESCRIPTOR);
begin
FParent:=AParent;
FDescriptor:=DLL;
end;
function TExeImportDLL.Read: Boolean;
var
p: Pointer;
ThunkData: PIMAGE_IMPORT_BY_NAME;
ThunkRef: PDWord;
ACount: Integer;
begin
result:=False;
if FDescriptor^.Name = 0 then
raise Exception.Create('Invalid Image Import Descriptor!');
try
FDLLName:=PChar(FParent.GetVirtualAddress(FDescriptor^.Name));
except
result:=False;
Exit;
end;
if FDescriptor^.OriginalFirstThunk <> 0 then
p := FParent.GetVirtualAddress(FDescriptor^.OriginalFirstThunk)
else
p := FParent.GetVirtualAddress(FDescriptor^.FirstThunk);
ACount:=0;
ThunkRef:=p;
while ThunkRef^ <> 0 do
begin
Inc(ACount);
Inc(ThunkRef);
end;
Setlength(FEntries, ACount);
ThunkRef:=p;
ACount:=0;
while ThunkRef^ <> 0 do
begin
if (ThunkRef^ and IMAGE_ORDINAL_FLAG32 = IMAGE_ORDINAL_FLAG32) then
begin
FEntries[ACount].IsOrdinal:=True;
FEntries[ACount].Ordinal:=ThunkRef^ and $FFFF;
end else
begin
FEntries[ACount].IsOrdinal:=False;
ThunkData:=FParent.GetVirtualAddress(ThunkRef^);
FEntries[ACount].Name:=PChar(@ThunkData^.Name[0]);
FEntries[ACount].Hint:=ThunkData^.Hint;
end;
Inc(ACount);
Inc(ThunkRef);
end;
result:=True;
end;
function TExeImportDLL.Read64: Boolean;
var
p: Pointer;
ThunkData: PIMAGE_IMPORT_BY_NAME;
ThunkRef: PQWord;
ACount: Integer;
begin
result:=False;
if FDescriptor^.Name = 0 then
//raise Exception.Create('Invalid Image Import Descriptor!');
Exit;
FDLLName:=PChar(FParent.GetVirtualAddress(FDescriptor^.Name));
if FDescriptor^.OriginalFirstThunk <> 0 then
p := FParent.GetVirtualAddress(FDescriptor^.OriginalFirstThunk)
else
p := FParent.GetVirtualAddress(FDescriptor^.FirstThunk);
ACount:=0;
ThunkRef:=p;
while ThunkRef^ <> 0 do
begin
Inc(ACount);
Inc(ThunkRef);
end;
Setlength(FEntries, ACount);
ThunkRef:=p;
ACount:=0;
while ThunkRef^ <> 0 do
begin
if (ThunkRef^ and IMAGE_ORDINAL_FLAG64 = IMAGE_ORDINAL_FLAG64) then
begin
FEntries[ACount].IsOrdinal:=True;
FEntries[ACount].Ordinal:=ThunkRef^ and $FFFFFFFF;
end else
begin
FEntries[ACount].IsOrdinal:=False;
ThunkData:=FParent.GetVirtualAddress(ThunkRef^);
FEntries[ACount].Name:=PChar(@ThunkData^.Name[0]);
FEntries[ACount].Hint:=ThunkData^.Hint;
end;
Inc(ACount);
Inc(ThunkRef);
end;
result:=True;
end;
{ TExeFile }
function TExeFile.GetSection(Index: Integer): PIMAGE_SECTION_HEADER;
begin
if (Index>=0)and(Index<Length(FSections)) then
result:=FSections[Index]
else
result:=nil;
end;
function TExeFile.GetImport(Index: Integer): TExeImportDLL;
begin
if (Index>=0)and(Index<Length(FImports)) then
result:=FImports[Index]
else
result:=nil;
end;
function TExeFile.GetExport(Index: Integer): TExeExportFunc;
begin
if(Index>=0)and(Index<Length(FExports)) then
result:=FExports[Index]
else begin
result.EntryPoint:=0;
result.Name:=nil;
result.Ordinal:=0;
end;
end;
function TExeFile.GetExportCount: Integer;
begin
result:=Length(FExports);
end;
function TExeFile.GetImportCount: Integer;
begin
result:=Length(FImports);
end;
function TExeFile.GetRelocation(Index: Integer): TExeRelocTable;
begin
if (Index>=0)and(Index<Length(FRelocations)) then
result:=FRelocations[Index]
else
begin
result.Count:=0;
result.Items:=nil;
result.VirtualAddress:=0;
end;
end;
function TExeFile.GetRelocationCount: Integer;
begin
result:=Length(FRelocations);
end;
function TExeFile.GetSectionCount: Integer;
begin
result:=Length(FSections);
end;
function TExeFile.IsValidVirtualAddress(VirtualAddress: UInt64): Boolean;
var
i: Integer;
begin
result:=False;
if VirtualAddress = 0 then
Exit;
for i:=0 to Length(FSections)-1 do
if (VirtualAddress >= FSections[i]^.VirtualAddress) and
(VirtualAddress < FSections[i]^.VirtualAddress + UInt64(FSections[i]^.PhysicalAddress)) // PhysicalAddress == VirtualSize!
then
begin
result:= ((VirtualAddress - FSections[i]^.VirtualAddress) + FSections[i]^.PointerToRawData) < FDataSize;
Exit;
end;
if VirtualAddress<FDataSize then
result:=True;
end;
function TExeFile.ResolveVirtualAddress32(VirtualAddress: UInt64): UInt64;
var
i: Integer;
begin
result:=0;
if VirtualAddress = 0 then
Exit;
for i:=0 to Length(FSections)-1 do
if (VirtualAddress >= FSections[i]^.VirtualAddress) and
(VirtualAddress < UInt64(FSections[i]^.VirtualAddress) + UInt64(FSections[i]^.PhysicalAddress)) // PhysicalAddress == VirtualSize!
then
begin
result:= ((VirtualAddress - FSections[i]^.VirtualAddress) + FSections[i]^.PointerToRawData);
if result>=FDataSize then
raise Exception.Create('Virtual address out of bounds');
Exit;
end;
// not sure if this is right behaviour, but it'srequired for some versions
// of kkrunchy
result:=VirtualAddress;
if result>=FDataSize then
raise Exception.Create('Virtual address out of bounds');
end;
procedure TExeFile.ReadImports(VirtualAddress: UInt64; is64Bit: Boolean);
var
ImportDesc: PIMAGE_IMPORT_DESCRIPTOR_ARRAY;
i: Integer;
begin
if not IsValidVirtualAddress(VirtualAddress) then
Exit;
ImportDesc:=GetVirtualAddress(VirtualAddress);
i:=0;
while (ImportDesc^[i].Name<>0) do
begin
Setlength(FImports, i + 1);
FImports[i]:=TExeImportDLL.Create(Self, @ImportDesc^[i]);
if is64Bit then
FImports[i].Read64
else
FImports[i].Read;
Inc(i);
end;
end;
procedure TExeFile.ReadExports(VirtualAddress: UInt64);
var
ExportDesc: PIMAGE_EXPORT_DIRECTORY;
expInfo: PDWord;
ordInfo: PWord;
addrInfo: PDWord;
j: Integer;
begin
if not IsValidVirtualAddress(VirtualAddress) then
Exit;
ExportDesc:=GetVirtualAddress(VirtualAddress);
if ExportDesc^.Name <> 0 then
begin
FExportName:=GetVirtualAddress(ExportDesc^.Name);
expInfo:=GEtVirtualAddress(ExportDesc^.AddressOfNames);
ordInfo:=GEtVirtualAddress(ExportDesc^.AddressOfNameOrdinals);
addrInfo:=GetVirtualAddress(ExportDesc^.AddressOfFunctions);
Setlength(FExports, ExportDesc^.NumberOfNames);
for j:=0 to ExportDesc^.NumberOfNames -1 do
begin
FExports[j].Name:=GetVirtualAddress(expInfo^);
FExports[j].Ordinal:=OrdInfo^;
FExports[j].EntryPoint:=AddrInfo^;
inc(expInfo);
inc(ordInfo);
inc(addrInfo);
end;
end;
end;
procedure TExeFile.ReadRelocations(VirtualAddress: UInt64);
var
Reloc:PIMAGE_BASE_RELOCATION;
i: Integer;
begin
if not IsValidVirtualAddress(VirtualAddress) then
Exit;
reloc:=GetVirtualAddress(VirtualAddress);
while reloc^.VirtualAddress>0 do
begin
if reloc^.SizeOfBlock>0 then
begin
i:=Length(FRelocations);
Setlength(FRelocations, i+1);
FRelocations[i].VirtualAddress:=reloc^.VirtualAddress;
FRelocations[i].Count:=(reloc^.SizeOfBlock - IMAGE_SIZEOF_BASE_RELOCATION) div 2;
FRelocations[i].Items:=Pointer((Reloc)+ IMAGE_SIZEOF_BASE_RELOCATION);
end;
reloc:=Pointer(UInt64(reloc)+reloc^.SizeOfBlock);
end;
end;
function TExeFile.ReadDOSHeader: Boolean;
var
HeaderOFfset: longword;
NEFlags: Byte;
begin
FStatus:='Invalid file';
FFileType:=fkUnknown;
result:=False;
if not Assigned(FData) then
Exit;
if FDataSize<SizeOf(IMAGE_DOS_HEADER) then
Exit;
FDOSHeader:=@FData[0];
if FDOSHeader^.e_magic <> cDOSMagic then
begin
FStatus:='Not an executable file';
Exit;
end;
// DOS files have length >= size indicated at offset $02 and $04
// (offset $02 indicates length of file mod 512 and offset $04
// indicates no. of 512 pages in file)
if FDOSHeader^.e_cblp = 0 then
FDOSFileSize:=512 * FDOSHeader^.e_cp
else
FDOSFileSize:=512 * (FDOSHeader^.e_cp - 1) + FDOSHeader^.e_cblp;
// DOS file relocation offset must be within DOS file size.
if FDOSHeader^.e_lfarlc > FDOSFileSize then
Exit;
FFileType:=fkDOS;
FSTatus:='';
result:=True;
if FDataSize <= cWinHeaderOffset + SizeOf(LongInt) then
Exit;
HeaderOffset:=FDOSHeader^.e_lfanew;
if FDataSize< HeaderOffset + SizeOf(IMAGE_NT_HEADERS) then
Exit;
FNTHeaders:=@FData^[HeaderOffset];
case FNTHeaders^.Signature of
cPEMagic:
begin
// 32 bit/64 bit
if FDataSize>=HeaderOffset + SizeOf(FNTHeaders^) then
begin
case FNTHeaders^.FileHeader.Machine of
$01c4: begin
// arm 32 bit
if (FNTHeaders^.FileHeader.Characteristics and IMAGE_FILE_DLL) = IMAGE_FILE_DLL then
FFileType:=fkDllArm
else
FFileType:=fkExeArm;
end;
$014c: begin
// 32 bit
if (FNTHeaders^.FileHeader.Characteristics and IMAGE_FILE_DLL) = IMAGE_FILE_DLL then
FFileType:=fkDll32
else
FFileType:=fkExe32;
end;
$8664: begin
// 64 bit
FNTHeaders64:=PIMAGE_NT_HEADERS64(FNTHeaders);
FNTHeaders:=nil;
if (FNTHeaders64^.FileHeader.Characteristics and IMAGE_FILE_DLL) = IMAGE_FILE_DLL then
FFileType:=fkDll64
else
FFileType:=fkExe64;
end;
else begin
result:=False;
FFileType:=fkUnknown;
FStatus:='Unknown Machine Type '+IntToHex(FNTHeaders^.FileHeader.Machine, 4);
FNTHeaders:=nil;
end;
end;
end;
end;
cNEMagic:
begin
// 16 bit
FNTHeaders:=nil;
if FDataSize>=HeaderOffset + cNEAppTypeOffset + SizeOf(NEFlags) then
begin
NEFlags:=FData^[HeaderOffset + cNEAppTypeOffset];
if (NEFlags and cNEDLLFlag) = cNEDLLFlag then
FFileType:=fkDll16
else
FFileType:=fkExe16;
end;
Exit;
end;
cLEMagic:
begin
FNTHeaders:=nil;
FFileType:=fkVXD;
end;
else
begin
FStatus:='Unknown NT Header Signature';
Exit;
end;
end;
end;
function TExeFile.ReadWin32Header: Boolean;
var
i: Integer;
p: longword;
begin
result:=False;
if FNTHeaders^.OptionalHeader.Magic <> $10b then
begin
FStatus:='OptionalHeader Magic is not Win32';
Exit;
end;
// read sections
if FNTHeaders^.FileHeader.NumberOfSections<=96 then
begin
Setlength(FSections, FNTHeaders^.FileHeader.NumberOfSections);
p:=FDOSHeader^.e_lfanew + SizeOf(FNTHeaders^);
for i:=0 to FNTHeaders^.FileHeader.NumberOfSections-1 do
begin
FSections[i]:=@FData^[p];
p:=p+SizeOf(FSections[i]^);
end;
end else
begin
FStatus:='Number of sections exceeds maximum';
Exit;
end;
if FNTHeaders^.OptionalHeader.DataDirectory[0].VirtualAddress <> 0 then
ReadExports(FNTHeaders^.OptionalHeader.DataDirectory[0].VirtualAddress);
if FNTHeaders^.OptionalHeader.DataDirectory[1].VirtualAddress <> 0 then
ReadImports(FNTHeaders^.OptionalHeader.DataDirectory[1].VirtualAddress, false);
if FNTHeaders^.OptionalHeader.DataDirectory[5].Size >= SizeOf(IMAGE_BASE_RELOCATION) then
ReadRelocations(FNTHeaders^.OptionalHeader.DataDirectory[5].VirtualAddress);
result:=True;
end;
function TExeFile.ReadWin64Header: Boolean;
var
i: Integer;
p: longword;
begin
result:=False;
if FNTHeaders64^.OptionalHeader.Magic <> $20b then
begin
FStatus:='Not Win32/x86';
Exit;
end;
// read sections
if FNTHeaders64^.FileHeader.NumberOfSections<=96 then
begin
Setlength(FSections, FNTHeaders64^.FileHeader.NumberOfSections);
p:=FDOSHeader^.e_lfanew + SizeOf(FNTHeaders64^);
for i:=0 to FNTHeaders64^.FileHeader.NumberOfSections-1 do
begin
FSections[i]:=@FData^[p];
p:=p+SizeOf(FSections[i]^);
end;
end else
begin
FStatus:='Number of sections exceeds maximum';
Exit;
end;
if FNTHeaders64^.OptionalHeader.DataDirectory[0].Size <> 0 then
ReadExports(FNTHeaders64^.OptionalHeader.DataDirectory[0].VirtualAddress);
if FNTHeaders64^.OptionalHeader.DataDirectory[1].Size <> 0 then
ReadImports(FNTHeaders64^.OptionalHeader.DataDirectory[1].VirtualAddress, true);
if FNTHeaders64^.OptionalHeader.DataDirectory[5].Size >= SizeOf(IMAGE_BASE_RELOCATION) then
ReadRelocations(FNTHeaders64^.OptionalHeader.DataDirectory[5].VirtualAddress);
result:=True;
end;
constructor TExeFile.Create;
begin
FData:=nil;
end;
destructor TExeFile.Destroy;
begin
Clear;
inherited Destroy;
end;
function TExeFile.GetVirtualAddress(VirtualAddress: UInt64): Pointer;
begin
result:=@FData^[ResolveVirtualAddress32(VirtualAddress)];
end;
function TExeFile.LoadFile(aFilename: string; ReadFull: Boolean): Boolean;
var
f: File;
begin
result:=False;
Clear;
Assignfile(f, aFilename);
Filemode:=0;
{$i-}reset(f,1);{$i+}
if ioresult=0 then
begin
FDataSize := Filesize(f);
if not ReadFull then
FDataSize := Min(4 * 1024, FdataSize);
Getmem(FData, FDataSize);
Blockread(f, FData^, FDataSize);
CloseFile(f);
end else
begin
FStatus:='Could not open file';
Exit;
end;
result:=ReadDOSHeader;
case FFileType of
fkExe32,
fkExeArm,
fkDll32,
fkDllArm: ReadWin32Header;
fkExe64,
fkDLL64: ReadWin64Header;
end;
end;
function TExeFile.GetRawAddress(Address: UInt64): Pointer;
begin
result:=@FData^[Address];
end;
procedure TExeFile.Clear;
var
i: Integer;
begin
for i:=0 to Length(FImports)-1 do
FImports[i].Free;
Setlength(FImports, 0);
Setlength(FExports, 0);
Setlength(FSections, 0);
FDOSHeader:=nil;
FNTHeaders:=nil;
FNTHeaders64:=nil;
FExportName:=nil;
if Assigned(FData) then
Freemem(FData);
FDataSize:=0;
FData:=nil;
end;
end.