Post from elitepvpers:
This tutorial for people who know how to Hook/Inject using Detours!. If you don't know how to do that! stop reading immediately lol...
the trick is we are going to hook the snprintf function , and edit it's string before the client showing it...
string servname = "[Abanoub]"; // my real name and in this case the server name.
std::regex e ("\\[([^\\]]*)\\](.*)"); //a regular expression to edit our string and add our server name to it , read about regex!
//our function that we are going to call instead of the original one
int _cdecl my_snprintf(char* str, size_t len, const char* format, ...)
{
int value = vsnprintf(str, len, format, args);
string strs(str);
//we got the string , now we will look if that the string we need to edit if so, then we going to procced if not return the value, we have nothing to do here.
if(strs.find("Ping") != string::npos){
string newstr = std::regex_replace(string(str),e, servname + "$2"); // here we are replacing the client server name with ours , and then add the new value and return it
strcpy(str,newstr.c_str());
value = newstr.length();
}
return value;
}
//and inside your main dll entry function you wanna add this
LPVOID _snprintf = lib_func("msvcr90.dll", "_snprintf");
//and then after updating/getting the thread attach our function
DetourAttach(&(PVOID&)_snprintf, my_snprintf);