DLL Hook -> Edit GameIP Problem

i have the following problem, i have a game exe in this is e.g. this IP 127.0.0.1 <- String[9] i want to replace with 11.111.11.11 <- string[12]. With my code below it only replaces the first number of the old IP but not the complete IP... I found a way to replace the ip in the format string[9] so the last three characters are missing (.11)... i think of my code as something completely wrong... because i've been working with c++ for only about 2 weeks i hope someone from here can help me... Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "pch.h"
#include <string>
using namespace std;

#define Offset 0x00B310CC

void RewriteValues() {
	char* ip;
	ip = (char*)Offset;
	*ip = (const char) *"11.111.11.11";
}


BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		RewriteValues();
		break;
	}
	return TRUE;
}
Last edited on
Have you tried:

1
2
3
void RewriteValues() {
    strcpy((char*)Offset, "11.111.11.11");  // but is there enough room?
}

This makes 127.0.0.1 -> 11.111.11
.11 is missing.
Is it possible to change from string[9] to string[12]

Enough space is available:
31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00
127.0.0.1.......
I don't know how to get this to work. Those zeroes are not necessarily unused space. The could be initial zero values for a variable.

What is the byte just before the first 31 above? If it's 09 then it probably represents the length of the string, which means that you would need to write the new length there as well. Maybe something like this:

1
2
3
4
void RewriteValues() {
    *((char*)Offset - 1) = 12;
    strncpy((char*)Offset, "11.111.11.11", 12);
}

Last edited on
This is Working:
strncpy((char*)Offset, "11.111.11.11", 12);
the Problem was, CheatEngine what i open first CE and scan for the old ip then hook, then its not possible to run beacause it is not changing the string length anymore..

Thank you Very much.
Registered users can post here. Sign in or register to post.