| 
			
				|  | Cheat Engine The Official Site of Cheat Engine
 
 
 |  
 
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| GoatSmegma How do I cheat?
 
 ![]() Reputation: 0 
 Joined: 06 Jan 2023
 Posts: 8
 
 
 | 
			
				|  Posted: Fri May 19, 2023 1:49 pm    Post subject: [C++] [Solved] How to properly calculate pointers |   |  
				| 
 |  
				| Currently I don't understand to calculate my address, the game I program my dll for which I inject via CE uses an module "some.dll", I grab its base address via: 
  	  | Code: |  	  | DWORD baseAddress = (DWORD)GetModuleHandle("some.dll"); | 
 now I get the supposedly correct base address of that module in decimal (693895168) which I double checked with Cheat Engine's "Enumerate DLL's and Symbols"
 however if I double click my Pointer in CE to see its offsets I see this: "some.dll"+000840D0 -> 29A21858 but 295C0000 + 000840D0 = 298004D0 what did I miss here? And would this be an correct way to do this:
 
 or is it unnecessary to turn it into decimal? 	  | Code: |  	  | DWORD finalAddress = BaseAddress + 540880 + 4 + 8 + 40 + 60 + 1436 + 20 + 52; | 
 thanks in advance.
 
 Last edited by GoatSmegma on Sat May 20, 2023 5:24 am; edited 1 time in total
 |  |  
		| Back to top |  |  
		|  |  
		| LeFiXER Grandmaster Cheater Supreme
 
 ![]() Reputation: 20 
 Joined: 02 Sep 2011
 Posts: 1069
 Location: 0x90
 
 | 
			
				|  Posted: Fri May 19, 2023 2:47 pm    Post subject: |   |  
				| 
 |  
				| Addresses are hexadecimal. I would say it's unnecessary to use decimal. You should specify these values as hex: 
  	  | Code: |  	  | BaseAddress + 0x840D0 + 0x4 + 0x8 + 0x28 + 0x3C + 0x59C+ 0x14 + 0x34;
 
 | 
 
 Although, pointers don't work like that. You should loop through reading the resolved value and adding the offset to that value e.g.:
 
  	  | Code: |  	  | int offsets[8] = { 0x840D0, 0x4, 0x8, 0x28, 0x3C, 0x59C, 0x14, 0x34 };
 
 int getPointer(HANDLE processHandle, int baseAddress, int offsetArray[]){
 int tmpArray[] = offsetArray;
 int curOffset = 0;
 int arrLen = sizeof(tmpArray) / sizeof(int);
 int resolvedAddress = baseAddress;
 
 for(int i = 0; i < arrLen; i++) {
 curOffset = tmpArray[i];
 ReadProcessMemory(processHandle, (LPCVOID)resolvedAddress, &resolvedAddress, 4, NULL) // This is for 4-byte addresses, can be adapted for 8-byte addresses
 resolvedAddress += curOffset;
 }
 return resolvedAddress;
 }
 
 | 
 
 I'm not a C++ programmer so perhaps it will point you in the right direction, assuming it doesn't work for you.
 |  |  
		| Back to top |  |  
		|  |  
		| GoatSmegma How do I cheat?
 
 ![]() Reputation: 0 
 Joined: 06 Jan 2023
 Posts: 8
 
 
 | 
			
				|  Posted: Fri May 19, 2023 3:55 pm    Post subject: |   |  
				| 
 |  
				| thanks, I've done some digging and found a post which explained pointers thoroughly, then I managed to get it running, partly, 
 
  	  | Code: |  	  | ReadProcessMemory(pHandle, (void*)(thebase + 0x840D0), &thefirst, sizeof(thefirst), 0); ReadProcessMemory(pHandle, (void*)(thefirst + 0x4), &thesecond, sizeof(thesecond), 0);
 ReadProcessMemory(pHandle, (void*)(thesecond + 0x8), &thethird, sizeof(thethird), 0);
 ReadProcessMemory(pHandle, (void*)(thethird + 0x28), &thefourth, sizeof(thefourth), 0);
 ReadProcessMemory(pHandle, (void*)(thefourth + 0x3C), &thefifth, sizeof(thefifth), 0);
 ReadProcessMemory(pHandle, (void*)(thefifth + 0x59C), &thesixth, sizeof(thesixth), 0);
 ReadProcessMemory(pHandle, (void*)(thesixth + 0x14), &theseventh, sizeof(theseventh), 0);
 ReadProcessMemory(pHandle, (void*)(theseventh + 0x34), &theeight, sizeof(theeight), 0);
 | 
 But for some reason it fails once I reach the point at "the fifth + 0x59C"
 
  	  | Code: |  	  | base     697605372   = 29949CFC ✓ first    623250096   = 25260AB0 ✓
 second   623248832   = 252605C0 ✓
 third    618133528   = 24D7F818 ✓
 fourth   618134728   = 24D7FCC8 ✓
 fifth    96304864    = 05BD7EE0 X
 sixth    5414284     = 00529D8C X
 seventh  1159335936  = 451A1000 X
 eight    0           = ???????? X
 
 | 
 edit: I tried doing it manually with an calculator and CE, and it worked, I took 24D7FCC8 added 5C9 to it and got the correct memory location, I also tried to replace "sizeof(thefifth)" (and all other similar sizeof occurences) with just 4, however it still gets an wrong address from it.
 |  |  
		| Back to top |  |  
		|  |  
		| GoatSmegma How do I cheat?
 
 ![]() Reputation: 0 
 Joined: 06 Jan 2023
 Posts: 8
 
 
 | 
			
				|  Posted: Sat May 20, 2023 5:23 am    Post subject: |   |  
				| 
 |  
				| Got it working   
  	  | Code: |  	  | DWORD address = *(DWORD*)(BaseAddress + 0x840D0); DWORD thefirst = *(DWORD*)(address + 0x4);
 DWORD thesecond = *(DWORD*)(thefirst + 0x8);
 DWORD thethird = *(DWORD*)(thesecond + 0x28);
 DWORD thefourth = *(DWORD*)(thethird + 0x3C);
 DWORD thefifth = *(DWORD*)(thefourth + 0x59C);
 DWORD thesixth = *(DWORD*)(thefifth + 0x14);
 DWORD posY = thesixth + 0x34;
 | 
 
 thanks to ParkourPenguin, I stol- borrowed your code and to inuyasha0011 for that helpful pointer info, weirdly enough I still dont know why my code failed at the
 but 	  | Code: |  	  | ReadProcessMemory(pHandle, (void*)(thefifth + 0x59C), &thesixth, 4, 0); | 
 worked, now I guess I write an similar function that LeFiXER provided, thanks again for that. 	  | Code: |  	  | DWORD thefifth = *(DWORD*)(thefourth + 0x59C); | 
 |  |  
		| Back to top |  |  
		|  |  
		| LeFiXER Grandmaster Cheater Supreme
 
 ![]() Reputation: 20 
 Joined: 02 Sep 2011
 Posts: 1069
 Location: 0x90
 
 | 
			
				|  Posted: Sat May 20, 2023 5:38 am    Post subject: |   |  
				| 
 |  
				|  	  | GoatSmegma wrote: |  	  | I still dont know why my code failed at the but 	  | Code: |  	  | ReadProcessMemory(pHandle, (void*)(thefifth + 0x59C), &thesixth, 4, 0); | 
 worked, now I guess I write an similar function that LeFiXER provided, thanks again for that. 	  | Code: |  	  | DWORD thefifth = *(DWORD*)(thefourth + 0x59C); | 
 | 
 
 It's because void is a "generic" pointer type that doesn't allow arithmetic. It must be cast to a specific data type first. Also, you're welcome
  . |  |  
		| Back to top |  |  
		|  |  
		| GoatSmegma How do I cheat?
 
 ![]() Reputation: 0 
 Joined: 06 Jan 2023
 Posts: 8
 
 
 | 
			
				|  Posted: Sat May 20, 2023 8:30 am    Post subject: |   |  
				| 
 |  
				|  	  | LeFiXER wrote: |  	  | It's because void is a "generic" pointer type that doesn't allow arithmetic. It must be cast to a specific data type first.
 | 
 yet another thanks for you, nice explanation, have a good day
   |  |  
		| Back to top |  |  
		|  |  
		| LeFiXER Grandmaster Cheater Supreme
 
 ![]() Reputation: 20 
 Joined: 02 Sep 2011
 Posts: 1069
 Location: 0x90
 
 | 
			
				|  Posted: Sat May 20, 2023 2:49 pm    Post subject: |   |  
				| 
 |  
				|  	  | GoatSmegma wrote: |  	  | yet another thanks for you, nice explanation, have a good day  | 
 
 No problem at all!
  . I hope you are able to achieve what you set out to do! |  |  
		| 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
 
 |  |