Skip to content

Commit

Permalink
give error when mapping fails
Browse files Browse the repository at this point in the history
  • Loading branch information
cheat-engine committed Oct 14, 2022
1 parent 26923f1 commit 87c9249
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Cheat Engine/FileMapping.pas
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,24 @@ constructor TFileMapping.create(filename: string);
try
//open file
FileHandle := CreateFile(PChar(filename), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if FileHandle = INVALID_HANDLE_VALUE then
if (FileHandle = 0) or (FileHandle=INVALID_HANDLE_VALUE) then
FileHandle := CreateFile(PChar(filename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

if FileHandle = INVALID_HANDLE_VALUE then
if (FileHandle = 0) or (FileHandle=INVALID_HANDLE_VALUE) then
raise EFileMapError.create(Format(rsDoesNotExist, [filename]));


FFileSize:=0;
FFileSize:=GetFileSize(FileHandle,pointer(ptruint(@fileSize)+4));

if FFileSize=0 then
raise EFileMapError.create('Can not map an empty file');


//still here, so create filemapping
FileMapping := CreateFileMapping(FileHandle, nil, PAGE_WRITECOPY , 0, 0, nil);
if FileMapping = 0 then raise EFileMapError.create(rsMappingFailed);
if (FileMapping = 0) or (FileMapping=INVALID_HANDLE_VALUE) then
raise EFileMapError.create(rsMappingFailed);

//map it completely
FFileContent:= MapViewOfFile(FileMapping, FILE_MAP_COPY , 0, 0, 0);
Expand Down

0 comments on commit 87c9249

Please sign in to comment.