|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Sergeant_Salz How do I cheat? Reputation: 0
Joined: 11 Jul 2017 Posts: 2
|
Posted: Tue Jul 11, 2017 1:23 pm Post subject: Getting the right address for opcode manipulation in C++ |
|
|
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 |
|
|
horsedeg Cheater Reputation: 0
Joined: 26 Jun 2017 Posts: 27
|
Posted: Tue Jul 11, 2017 11:50 pm Post subject: |
|
|
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 |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Wed Jul 12, 2017 1:39 am Post subject: |
|
|
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 |
|
|
Sergeant_Salz How do I cheat? Reputation: 0
Joined: 11 Jul 2017 Posts: 2
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
|
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
|
|