DillerInc
Хех, как все просто......
А сначала вообще в ступор я впал
Даже весь код написать пришлось.
Код:
program rf;
{$APPTYPE CONSOLE}
uses
Windows;
var
hExe: Cardinal = 0;
MemPtr: Pointer = nil;
FileSize, BytesRead, MemSize: Cardinal;
begin
hExe := CreateFile('c:\temp\test.txt', GENERIC_READ, 0, NIL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if hExe = INVALID_HANDLE_VALUE then WriteLn('CreateFile failed with code: ', GetLastError()) else WriteLn('CreateFile succeeded');
FileSize := GetFileSize(hExe, nil);
if FileSize = INVALID_FILE_SIZE then WriteLn('GetSize failed with code: ', GetLastError()) else WriteLn('GetSize succeeded, FileSize = ', FileSize);
asm
mov eax, [FileSize] // FileSize -> eax
add eax, $00010000 // +65536
and eax, $3FFF0000 // выравнивание + ограничение по размеру
mov [MemSize], eax // eax -> MemSize
end;
MemPtr := VirtualAlloc(nil, MemSize, MEM_COMMIT, PAGE_READWRITE);
if MemPtr = nil then WriteLn('VA failed with code: ', GetLastError()) else WriteLn('VA succeeded');
if not ReadFile(hExe, MemPtr^, FileSize, BytesRead, NIL) then
WriteLn('RF failed with code: ', GetLastError(), '. FileSize = ', FileSize, ', BytesRead = ', BytesRead, '.')
else
WriteLn('RF succeeded. FileSize = ', FileSize, ', BytesRead = ', BytesRead, '.');
ReadLn;
VirtualFree(MemPtr, 0, MEM_RELEASE);
CloseHandle(hExe);
end.
Видно, что изменилось?