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 


Getting the right address for opcode manipulation in C++

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

Joined: 11 Jul 2017
Posts: 2

PostPosted: Tue Jul 11, 2017 1:23 pm    Post subject: Getting the right address for opcode manipulation in C++ Reply with quote

So I'm trying to get into C++ memory hacking and, although rater succesfull so far, im stuck trying to NOPe out an operation manipulationg a value, instead of continuously changing it.

Ive got working funktions to write and read memory of my game, but Im not able to figure out the right way to get the address of the opcode I want to change:

Looking at it in the CheatEngine disassembler I can see that its address is "game.exe +637E9" which (here is my mistake probably) is equivalent to Module base address + 637E9?

However changing the following two bytes to 0x9090 using my C++ code doesnt seem to work. Ive also tried not to add the base address to it but still it doesnt work.

I dont think its a mistake in my code since it works for other values but I will still post it in case anybody cares:

Code:

 void init() {  //yes its ugly!

   HWND window = FindWindow(0, _T("AssaultCube")); 
   if (window == 0) {
      printf("Window not found!\n");
      Sleep(3000);
      exit(-1);
   }

   DWORD pID = 0; 
   GetWindowThreadProcessId(window, &pID);

   DWORD baseAddr = dwGetModuleBaseAddress(pID, _T("ac_client.exe"));

   HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
   
}

void WriteMem(appinf AC, DWORD address, int value ) {

   WriteProcessMemory(AC.handle, (LPVOID)address, &value, sizeof(value) , 0);

   cout << "\n Adress written to: " << address << endl;

}





Thanks for any help in advance!

_________________
I am speechless!
Back to top
View user's profile Send private message
horsedeg
Newbie cheater
Reputation: 0

Joined: 26 Jun 2017
Posts: 24

PostPosted: Tue Jul 11, 2017 11:50 pm    Post subject: Reply with quote

Not too experienced, but I struggled with some smaller, similar stuff just recently. If your application is 64-bit then run your program x64, and vice versa. Also, try using more couts to find out which part doesn't match what you see in Cheat Engine.

Lastly, DWORD is not big enough to hold some memory addresses. It can only hold up to 0x7FFFFFFF (or 2147483647 in decimal, which is the max for 32-bit storage). So if any address is something like 0x1356A1000 (which is 9 long), storing it in a DWORD will truncate it to 0x356A1000, leaving out the 1. I struggled for hours with this problem. Instead you can use uint64_t for 64-bit addresses (and uint32_t for 32-bit addresses). You also need to modify your dwGetModuleBaseAddress and change the DWORDs to uint64_t. You can do a type cast if you have to, but I don't think it's necessary. Also make it return uint64_t.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 137

Joined: 25 Jan 2006
Posts: 7258
Location: 127.0.0.1

PostPosted: Wed Jul 12, 2017 1:39 am    Post subject: Reply with quote

Another thing to note based on what you showed, you are writing an 'int' value to memory meaning you are writing 4 bytes regardless of what the value contains. So instead of just writing 0x9090, you are instead writing 0x00009090 (4 bytes).

You need to write just a single byte or write a 'word' (2 bytes) to only overwrite the two bytes you are trying to write. For example:

Code:
/**
 * Write two bytes to memory. (short)
 */
void WriteMem(appinf AC, DWORD address, short value)
{
    WriteProcessMemory(AC.handle, (LPVOID)address, &value, 2, 0);
    cout << "\n Adress written to: " << address << endl;
}

/**
 * Write one byte to memory. (unsigned char)
 */
void WriteMem(appinf AC, DWORD address, unsigned char value)
{
    WriteProcessMemory(AC.handle, (LPVOID)address, &value, 1, 0);
    cout << "\n Adress written to: " << address << endl;
}


Then you could either do:
Code:
WriteMem(appinfVariable, 0x12345678, 0x9090);

or
Code:
WriteMem(appinfVariable, 0x12345678, 0x90);
WriteMem(appinfVariable, 0x12345679, 0x90);

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Sergeant_Salz
How do I cheat?
Reputation: 0

Joined: 11 Jul 2017
Posts: 2

PostPosted: Wed Jul 12, 2017 5:06 am    Post subject: Reply with quote

Thank you verry much for helping me! I did as you told me and it did the trick! The problem probably was the variable type but the Int thing would also have given me a headache so thank you two again Laughing

One more thing: Do I have to close this topic now or something simelar? Im not a regular forum user Razz

_________________
I am speechless!
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 137

Joined: 25 Jan 2006
Posts: 7258
Location: 127.0.0.1

PostPosted: Wed Jul 12, 2017 11:16 am    Post subject: Reply with quote

Sergeant_Salz wrote:
Thank you verry much for helping me! I did as you told me and it did the trick! The problem probably was the variable type but the Int thing would also have given me a headache so thank you two again Laughing

One more thing: Do I have to close this topic now or something simelar? Im not a regular forum user Razz


Not a problem. And no the topic will only be locked if it is off-topic or otherwise breaking some forum rule that would need it to be locked. We prefer to keep topics open in case someone else has a similar issue and wants to respond.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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