Edit: I managed to solve the writing. It seems like the error was the casting of the value with (LPCVOID), instead I changed the value to a const int and pointed to it.
[php]
const int EngineUpgrade_Value = 0x6;
WriteProcessMemory(ProcessHandle,(void*)EngineUpgr ade_Addr,&EngineUpgrade_Value,EngineUpgrade_Size,& EngineUpgrade_Sent);[/php]
The read still doesn't work, and not only that, it also stops the writing from working. I'll try to figure that one as well.
I tried to hack an old game called Jets'n'Guns for practice (I'm really really new to hacking, just started looking at forums and stuff two days ago), and I got two errors.
For the Read, I got error 5: Access is denied.
And for writing error 299: Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
When I did it with Cheat Engine it worked just fine, but then again, I have no idea how Cheat Engine works.
Here is my code
[php]
#include <Windows.h>
#include <iostream>
using namespace std;
#define EngineUpgrade_Addr 0x03894F44
#define EngineUpgrade_Value 6
const SIZE_T EngineUpgrade_Size = sizeof(EngineUpgrade_Value);
SIZE_T EngineUpgrade_Sent = 0;
bool JetsnGuns()
{
HWND WindowHandle;
DWORD ProcessId;
HANDLE ProcessHandle;
if(!(WindowHandle = FindWindow(NULL,"Jets'n'Guns ver. 1.212 gold")))
cout<<"Jets'n'Guns couldn't be accessed (Did you start the game?)."<<endl;
while(!WindowHandle)
{
Sleep(200);
WindowHandle = FindWindow(NULL,"Jets'n'Guns ver. 1.212 gold");
}
GetWindowThreadProcessId(WindowHandle,&ProcessId);
ProcessHandle = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION,FALSE,ProcessId);
cout<<"Jets'n'Guns located. Starting to hack now."<<endl;
// this part tries to read from the address
LPVOID upgradelevel;
SIZE_T bytesgot;
if(!ReadProcessMemory(ProcessHandle ,(void*)EngineUpgrade_Addr ,&upgradelevel ,4 ,&bytesgot))
printf("Getting upgrade info... n");
printf("Level: %i",upgradelevel);
printf("nBytes got: %i",bytesgot);
printf("nError: %i",GetLastError());
// this part tries to write to the address
while(1)
{
WriteProcessMemory(ProcessHandle ,(void*)EngineUpgrade_Addr ,(LPCVOID)EngineUpgrade_Value ,EngineUpgrade_Size ,&EngineUpgrade_Sent);
Sleep(100);
printf("nError: %i",GetLastError());
}
return true;
}
[/php]
I will also be very glad if someone will point me to some DMA hacking tutorials, because the only one I found was this and I really didn't get what I'm supposed to do in C++.
Thanks in advance.
Last edited by Dragonion; 09-23-2008 at 01:01 PM.