Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[SOLVED] [C++] Get DWORD from address like "game.exe&qu

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
maxmakki
How do I cheat?
Reputation: 0

Joined: 29 Jun 2012
Posts: 7

PostPosted: Sat Jun 30, 2012 1:21 am    Post subject: [SOLVED] [C++] Get DWORD from address like "game.exe&qu Reply with quote

Hello everyone,

I have a static address I'd like to code into a trainer, but the address is not something like 12345678, it's more like "game.exe"+0002347C.

My code looks something like this:

Code:

// console trainer, read / write in C++

DWORD pointer = baseAddress;
DWORD pTemp;
DWORD pointerAddr;

for( int c = 0; c < pointerLevel; c++ )
{
   if( c == 0 )
   {
      if( !ReadProcessMemory( hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL ) )
         cout << "FAILED READ 1" << endl;
   }
   pointerAddr = pTemp + offsets[c];
   if( !ReadProcessMemory( hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL ) )
      cout << "FAILED READ 2" << endl;
}

if ( !WriteProcessMemory(hProcHandle, (BYTE*)pointerAddr, &value, sizeof(value), NULL) )
   cout << "FAILED WRITE" << endl;
else
   cout << "WORKS" << endl;


How do I get "game.exe"+0002347C to go into the ReadProcessMemory and WriteProcessMemory functions?

Thank you.

Max


Last edited by maxmakki on Sat Jun 30, 2012 6:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Sat Jun 30, 2012 4:22 am    Post subject: Reply with quote

http://forum.cheatengine.org/viewtopic.php?p=5240405#5240405
Back to top
View user's profile Send private message
maxmakki
How do I cheat?
Reputation: 0

Joined: 29 Jun 2012
Posts: 7

PostPosted: Sat Jun 30, 2012 12:50 pm    Post subject: Reply with quote

Hi Innovation,

Thanks for the link.

I'm having some difficulty with initializing TCHAR using the memory module. When I do:

Code:

baseAddress  = dwGetModuleBaseAddress( processId, "\"game.exe\"+00012345" );


dwGetModuleBaseAddress always returns 0. I set processId like this:

Code:

// Set processId

DWORD processId = NULL;
PROCESSENTRY32 pe32 = {sizeof(PROCESSENTRY32)};
HANDLE hProcSnap;
HANDLE hProcHandle;

while(!processId)
{
   system("CLS");
   cout << "Searching for " << processName <<"..." <<endl;
   hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
   
   if(Process32First(hProcSnap, &pe32))
   {
      do
      {
         if(!strcmp(pe32.szExeFile, processName))
         {
            processId = pe32.th32ProcessID;
            break;
         }
      }
      while(Process32Next(hProcSnap, &pe32));
   }
   Sleep(1000);
}


Which appears to be a valid processId. I'm assuming it's the way I am entering the TCHAR value. What could be wrong?

Thank you.

Max

---------- EDIT -----------

I found a previous post by Innovation that utilizes this function. I tried setting the TCHAR like this:

Code:

DWORD speedMovBaseAddress  = dwGetModuleBaseAddress( processId, _T("game.exe+00012345") );


It still returned 0. Then I tried:

Code:

DWORD speedMovBaseAddress  = dwGetModuleBaseAddress( processId, _T("game.exe") );


And it returned "FAILED READ 2" from the bit of code I included in my first post to this thread. I believe it is because I was not able to account for the +00012345 part of the memory module. Any ideas?

Thanks

Max

---------- EDIT -----------

My updated code looks something like this:

Code:

// console trainer, read / write in C++

DWORD baseAddress = dwGetModuleBaseAddress( processId, _T("game.exe") );
DWORD staticOffset = { 0x12345 };
DWORD offsets = { 0x12, 0x34, 0x56 };

DWORD pointer = baseAddress;
DWORD pTemp;
DWORD pointerAddr;

for( int c = 0; c < 3; c++ )
{
   if( c == 0 )
   {
      if( !ReadProcessMemory( hProcHandle, (LPCVOID)(pointer+staticOffset), &pTemp, sizeof(DWORD), NULL ) )
         cout << "FAILED READ 1" << endl;
   }
   pointerAddr = pTemp + offsets[c];
   if( !ReadProcessMemory( hProcHandle, (LPCVOID)pointerAddr, &pTemp, sizeof(DWORD), NULL ) )
      cout << "FAILED READ 2" << endl;
}

if ( !WriteProcessMemory(hProcHandle, (BYTE*)pointerAddr, &value, sizeof(value), NULL) )
   cout << "FAILED WRITE" << endl;
else
   cout << "WORKS" << endl;


I keep getting "FAILED READ 2". It's difficult to debug this given that I don't know if I'm doing the "game.exe"+00012345 part right. Maybe someone else sees something I don't?

Thanks

Max

---------- EDIT (Still can't reply twice in a row) -----------

It was an offset issue, my offsets were listed backwards. All good now.

Max
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites