unit EntryPoint;
interface
function GetEntryPoint(Filename:
string):integer;
implementation
uses
Math,SysUtils;
function GetEntryPoint(Filename:
string):integer;
var
F:
File;
Buffer,e:
string;
m:integer;
PEHeaderPoint:longint;
function HexToInt(H:
String): integer;
var i: Integer;
begin
Result:= 0;
for i:= Length(H)
downto 1
do
Case H[i]
of
'
0'..'
9': Result:= Result+ (Ord(H[i])- 48) * Round(Power(16, Length(H)- i));
'
A'..'
F': Result:= Result+ (Ord(H[i])- 55) * Round(Power(16, Length(H)- i));
end;
end;
begin
AssignFile(f, Filename);
reset(f,1);
Seek(F, $3C);
//$3C Bytes nach anfang der Datei steht die Position des PE Headers
SetLength(buffer,4);
Blockread(F,Buffer[1],Length(Buffer));
//Ausgelesen wo der PE Header anfängt
E:='
';
for m:=1
to Length(Buffer)
do
if ord(Buffer[m])>$F
then
E:=E+inttoHex(ord(Buffer[m]),2)
else
E:=E+inttoHex(ord(Buffer[m]),1);
PEHeaderPoint:=hextoint(E);
Seek(F, $28+PEHeaderPoint);
//$28 Bytes nach anfang des Headers steht die Position des EntryPoints
Blockread(F,Buffer[1],Length(Buffer));
//Entry Point wird ausgelesen
Result:=hextoint(inttoHex(ord(Buffer[4]),2)+inttoHex(ord(Buffer[3]),2)+inttoHex(ord(Buffer[2]),2)+inttoHex(ord(Buffer[1]),2));
CloseFile(f);
end;
end.