C++ WritingProcessMemory

Posts 14 of 4 · Page 1 of 1
C++ WritingProcessMemory
when writing process memory how would you go about adding lets say 5 offsets? would you just add the offsets and make 1 offset?
Quote Originally Posted by AkWolf907 View Post
when writing process memory how would you go about adding lets say 5 offsets? would you just add the offsets and make 1 offset?
Are you talking about if you have a pointer you want to write to? If that's the case you need to resolve the pointer to get the final address.

Here is an example:
Code:
DWORD getPointer(HANDLE pHandle, DWORD pID, char name[], std::vector<DWORD> offsets) {
	DWORD gameBase = GetModuleBaseAddress(pID, name);
	DWORD address = gameBase;

	if (offsets.empty()) {
		return NULL;
	}
	address += offsets[0];

	for (std::vector<DWORD>::iterator it = offsets.begin() + 1; it != offsets.end(); ++it) {
		ReadProcessMemory(pHandle, (LPVOID)address, &address, 4, 0);
		address = address + *it;
	}

	if (address <= gameBase) {
		return NULL;
	}

	return address;
}
usage:
Code:
std::vector<DWORD> pointer = { 0x0163B0A4, 0x384, 0x590, 0x0, 0x260, 0x73c, 0x224 }
address = getPointer(pHandle, pID, gameFile, vectorOfOffsets);
There's a better way to do that getPointer function, I just pulled that from an old project.
Quote Originally Posted by Nimboso View Post
Are you talking about if you have a pointer you want to write to? If that's the case you need to resolve the pointer to get the final address.

Here is an example:
Code:
DWORD getPointer(HANDLE pHandle, DWORD pID, char name[], std::vector<DWORD> offsets) {
	DWORD gameBase = GetModuleBaseAddress(pID, name);
	DWORD address = gameBase;

	if (offsets.empty()) {
		return NULL;
	}
	address += offsets[0];

	for (std::vector<DWORD>::iterator it = offsets.begin() + 1; it != offsets.end(); ++it) {
		ReadProcessMemory(pHandle, (LPVOID)address, &address, 4, 0);
		address = address + *it;
	}

	if (address <= gameBase) {
		return NULL;
	}

	return address;
}
usage:
Code:
std::vector<DWORD> pointer = { 0x0163B0A4, 0x384, 0x590, 0x0, 0x260, 0x73c, 0x224 }
address = getPointer(pHandle, pID, gameFile, vectorOfOffsets);
There's a better way to do that getPointer function, I just pulled that from an old project.
whats the better way ? :P
Quote Originally Posted by Sazor98 View Post
whats the better way ? :P
Mostly just better checks to see if the final address is within the module.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?