在将dll文件注入到进程之前,我想检查它是否实际上是我要注入的进程。有没有一种方法可以实现,所以如果注射过程错误,我可以中止注射过程? 预先感谢您的帮助!
int APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
if (process == theprocessiwant)
{
//call my stuff....
}
}
return true;
}
答案 0 :(得分:0)
好的,谢谢您的建议,我找到了一种可行的方法!
DWORD targetProcessId;
int APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (_stricmp(entry.szExeFile, "target.exe") == 0)
{
targetProcessId = entry.th32ProcessID;
}
}
}
CloseHandle(snapshot);
if (reason == DLL_PROCESS_ATTACH)
{
if (GetCurrentProcessId() == targetProcessId)
{
//MY Code
}
}
return true;
}
答案 1 :(得分:0)
GetModuleFileNameA将为您提供已注入其进程的可执行文件的完整路径。将此路径与预定义的可执行路径进行比较。