 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
`unknown Grandmaster Cheater
Reputation: 0
Joined: 20 Nov 2006 Posts: 658 Location: You lost the game.
|
Posted: Sun May 03, 2009 6:51 pm Post subject: [C++] Copying a file into memory |
|
|
I'm trying to read a file, and copy it into memory that I allocated with VirtualAlloc, but every time I call the ReadFile API my program just crashes. After adding a SEH, the call to GetLastError() told me that I had a "Invalid Window Handle," although I don't think that is related to ReadFile. Code is as follows:
| Code: | BOOL bRead;
HANDLE hCEMFile;
LPVOID lpvCRCBase;
LPDWORD lpBytesRead = 0;
hCEMFile = CreateFile(
"kMS.CEM",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if( hCEMFile == INVALID_HANDLE_VALUE )
{
MessageBox( NULL, "Error opening CEM File! CRC Bypass not enabled!", "Warning!", MB_ICONWARNING | MB_OK );
return;
}
lpvCRCBase = VirtualAlloc( NULL, 6291456, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
if( lpvCRCBase == NULL )
{
MessageBox( NULL, "Error allocating memory! CRC Bypass not enabled!", "Warning!", MB_ICONWARNING | MB_OK );
return;
}
bRead = ReadFile( hCEMFile, lpvCRCBase, 6291456, lpBytesRead, NULL ); // crash here
if( !bRead || lpBytesRead != (LPDWORD)6291456 )
{
MessageBox( NULL, "Error reading CEM File! CRC Bypass not enabled!", "Warning!", MB_ICONWARNING | MB_OK );
return;
}
|
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun May 03, 2009 7:03 pm Post subject: |
|
|
The pointer is not initialized.
Change:
| Code: | | LPDWORD lpBytesRead = 0; |
To either:
| Code: | | LPDWORD lpBytesRead = new DWORD; |
or
| Code: | DWORD lpBytesRead;
...
ReadFile(hCEMFile, lpvCRCBase, 6291456, &lpBytesRead, NULL); |
_________________
|
|
| Back to top |
|
 |
`unknown Grandmaster Cheater
Reputation: 0
Joined: 20 Nov 2006 Posts: 658 Location: You lost the game.
|
Posted: Sun May 03, 2009 7:08 pm Post subject: |
|
|
Oh wow, that's what I get for using a data type I never messed around with before .
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|