I've been leeching around for almost a month.. Here's something that's helped me.
This is the reader I'm using at the moment, it's in C++. It's very basic and may prove useful to someone just starting out, it will read numeric types from one wow process.
The thread that I taxed most of the code from is here ->.
All credit goes to Kynox for this code.. Even though I butchered it.
Code:
/*A memory Class used to read numeric values from
specific memory locations */
class Memory //Mostly brought to you by Kynox
{
public:
Memory(){
/*Precondition: none
*Postcondition: an instance of the class memory
*is invoked and debug priveleges attempted. */
AddDebugPrivileges();
}
template <class T>
static T Read(DWORD Offset)
//Precondition: Program has debug privileges
// A valid wow offset for reading.
//Postcondition: Returns the value of the offset.
{
T TSave = NULL; //Variable which takes the read.
//Calling function to find current valid wow handle
HANDLE hWowHandle = RefreshWowHandle();
if(hWowHandle != NULL)
{
int sz = sizeof(T); //Debug Variable
DWORD sizeRead;
bool valid;
valid = ReadProcessMemory(hWowHandle,(LPCVOID) Offset,(LPVOID) &TSave, sizeof(T), &sizeRead);
//The following if statement tests the validity of the read.
if(valid == FALSE || sizeRead != sizeof(T)){
CloseHandle(hWowHandle);
TSave = NULL;
return TSave; //Null returned for a bad read.
}
else{
CloseHandle(hWowHandle);
return TSave;//Valid read
}
}
else{//Condition is met when a valid handle is not found.
TSave = NULL;
return TSave;//Null returned for a bad read.
}
}
static bool AddDebugPrivileges()
// Adjusting Privileges for Read/Write
//I got this code from Kynox @ mmowned.
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES, &hToken);
if(!LookupPrivilegeValueA( NULL, "SeDebugPrivilege", &tp.Privileges[0].Luid ))
{
CloseHandle(hToken);
return 1;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if( !AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
{
CloseHandle(hToken);
return 1;
}
CloseHandle(hToken);
return 0;
}
static HANDLE RefreshWowHandle()
//Function to get a handle to the WoW process for reading
//Postcondition: Returns a current and valid handle
{
DWORD Pid; //ProcessId
HANDLE newHandle;
//attempt to get game handle by FindWindow.
if(FindWindow(NULL, "World of Warcraft") != NULL)
{
HWND hWnd = FindWindow(NULL, "World of Warcraft");
if (hWnd == NULL)
{
newHandle = NULL;
return newHandle; //error returns handle as NULL
}
GetWindowThreadProcessId(hWnd, &Pid);
if (Pid == 0)
{
newHandle = NULL;
return newHandle; //error returns handle as NULL
}
newHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
if (newHandle == NULL)
{
newHandle = NULL;
return newHandle; //error returns handle as NULL
}
return newHandle;//Returns a handle to this wow process
}
else
{
newHandle = NULL;
return newHandle; //error, Couldn't find the window.
}
}
};
This is probably a terrible way to go about out of process memory reading and all criticism is welcome. Any tips as to how to make this modular for string types would also be appreciated.