program Project1;
{$APPTYPE CONSOLE}
uses
Windows;
function IntToStr(i: Integer):
string;
begin
Str(i, Result);
end;
var
{ Datei Öffnen }
hFile: THandle;
lpNumberOfBytesRead: DWORD;
{ Zwischenspeicherung }
lpBuffer: Pointer;
x: Word;
dwTmp, dwSize, dwWinSize: Cardinal;
{ PE-Stuff }
NtHeaders: PImageNtHeaders;
Section: PImageSectionHeader;
begin
dwSize := 0;
dwWinSize := 0;
hFile := CreateFile(PChar(ParamStr(0)), GENERIC_READ, FILE_SHARE_READ,
nil, OPEN_EXISTING, 0, 0);
if (hFile <> INVALID_HANDLE_VALUE)
then
begin
dwWinSize := GetFileSize(hFile,
nil);
GetMem(lpBuffer, $800);
// nur 2048 Bytes einlesen, mehr sollte nicht benötigt werden.
ReadFile(hFile, lpBuffer^, $800, lpNumberOfBytesRead,
nil);
if (lpBuffer <>
nil)
then
begin
NtHeaders := PImageNtHeaders(Cardinal(lpBuffer) + Cardinal(PImageDosHeader(lpBuffer)._lfanew));
if (NtHeaders^.Signature = IMAGE_NT_SIGNATURE)
then
begin
for x := 0
to NtHeaders^.FileHeader.NumberOfSections -1
do
begin
Section := PImageSectionHeader(Cardinal(NtHeaders) + SizeOf(TImageNtHeaders) + (SizeOf(TImageSectionHeader) * x));
dwTmp := Section.PointerToRawData + Section.SizeOfRawData;
if (dwTmp > dwSize)
then
dwSize := dwTmp;
end;
FreeMem(lpBuffer);
end;
end;
end;
CloseHandle(hFile);
WriteLn('
WinFileSize: ' + IntToStr(dwWinSize));
WriteLn('
MyFileSize: ' + IntToStr(dwSize));
ReadLn;
{ TODO -oUser -cConsole Main : Hier Code einfügen }
end.