function GetApplicationSize(
var AppWinSize, AppDwSize: Int64): Boolean;
var
{ Datei Öffnen }
hFile: THandle;
lpNumberOfBytesRead: DWORD;
{ Zwischenspeicherung }
lpBuffer: Pointer;
x: Word;
dwTmp, dwSize, dwWinSize: Cardinal;
{ PE-Stuff }
NtHeaders: PImageNtHeaders;
Section: PImageSectionHeader;
TmpResult: Boolean;
begin
dwSize := 0;
dwWinSize := 0;
TmpResult := false;
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;
TmpResult := true;
FreeMem(lpBuffer);
end;
end;
end;
CloseHandle(hFile);
AppWinSize := dwWinSize;
AppDwSize := dwSize;
result := TmpResult;
end;