-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpe_version.dpr
53 lines (47 loc) · 1.26 KB
/
pe_version.dpr
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
program pe_version;
{$APPTYPE CONSOLE}
uses
SysUtils,Classes,PE,FileIO,Res;
var
F:TFileStream;
DOS_header:TImageDosHeader;
ImageHeader: TImageFileHeader;
OptHeader: TImageOptionalHeader;
SectHeader: TImageSectionHeader;
Signature: Array[1..4] of Char;
t:Integer;
// Needs "yum install ld-linux.so.2" on 64-bit FEDORA
begin
if ParamCount=0 then
begin
WriteLn('Usage: '+ExtractFileName(ParamStr(0))+' <input file>');
Halt(1);
end;
F:=TFileStream.Create(ParamStr(1),fmOpenRead);
Try
read_dos_header(F,dos_header);
F.Seek(DOS_header.e_lfanew,soFromBeginning);
ReadBin(F,@signature,4);
if signature<>'PE'#0#0 then
begin
WriteLn('This file is not a Microsoft PE format');
Halt(3);
end;
read_image_file_header(F,ImageHeader);
if ImageHeader.SizeOfOptionalHeader<>0 then
read_image_optional_header(F,OptHeader,ImageHeader.SizeOfOptionalHeader);
for t:=0 to ImageHeader.NumberOfSections-1 do
begin
read_section_header(F,SectHeader);
if StrComp(@SectHeader.Name[0],'.rsrc')=0 then
begin
parse_resource_dir(F,SectHeader,0,0,0);
Halt(0);
end;
end;
WriteLn('This file has no resources');
Halt(4);
Finally
F.Free;
end;
end.