miclus How do I cheat?
Reputation: 0
Joined: 25 Dec 2010 Posts: 1
|
Posted: Sat Dec 25, 2010 7:31 pm Post subject: |
|
|
Hey, guys. I found this code on another forum by a Dark_Mage:
| Code: |
HMODULE GetRemoteModuleHandle(unsigned long pId, char *module)
{
MODULEENTRY32 modEntry;
HANDLE tlh = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId);
modEntry.dwSize = sizeof(MODULEENTRY32);
Module32First(tlh, &modEntry);
do
{
if(!stricmp(modEntry.szModule, module))
return modEntry.hModule;
modEntry.dwSize = sizeof(MODULEENTRY32);
}
while(Module32Next(tlh, &modEntry));
return NULL;
}
|
Anyway, it works for me ok on my XP machine, but doesn't work on my 98 machine. Does anyone know some equivalent code that will work on Windows 98?
Edit: Ok, the problem was the PID I got was invalid due to Windows 98 using full paths for the process list. Anyway, I made some code if anyone needs help getting the process ID or module handle:
| Code: |
/*
This code illustrates how to get a process ID and module handle
for a given process (by name).
*/
#include <iostream>
#include <string>
#include <windows.h>
#include <Tlhelp32.h>
//This function returns a process ID for a given process name.
//Thanks to Darawk for his code.
DWORD GetProcessID(const char* processName)
{
HANDLE H = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 P;
P.dwSize = sizeof(PROCESSENTRY32);
Process32First(H, &P);
do
{
//On older OS's, such as Win98, the process
//list includes path information. So, we strip that info out.
std::string x = P.szExeFile, y = P.szExeFile;
size_t f = x.rfind("\\");
if (f != std::string::npos)
y = x.substr(f + 1);
if(!stricmp(processName, y.c_str()))
return P.th32ProcessID;
} while(Process32Next(H, &P));
return 0;
}
//This function returns the module handle for a given process ID and module name.
//Thanks to Darawk for his code.
HMODULE GetRemoteModuleHandle(DWORD PID, const char* moduleName)
{
HANDLE H = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
MODULEENTRY32 M;
M.dwSize = sizeof(MODULEENTRY32);
Module32First(H, &M);
do
{
if(!stricmp(M.szModule, moduleName))
return M.hModule;
M.dwSize = sizeof(MODULEENTRY32);
} while(Module32Next(H, &M));
return NULL;
}
//Example usage.
int main()
{
char name[81];
HANDLE H;
DWORD PID;
while (1)
{
std::cout << "\n\nEnter a process name: ";
std::cin.getline(name, 80);
PID = GetProcessID(name);
H = GetRemoteModuleHandle(PID, name);
std::cout << "\nProcess ID: " << PID;
std::cout << "\nModule Handle: " << H;
}
return 0;
}
|
|
|