[C] 纯文本查看 复制代码#include
#include
#define EXENAME L"IPposition.exe"
#define DLLNAME L"winHttp.dll"
#define OFFSET 0x00001234
struct PSINFO
{
HANDLE hProcess;
DWORD dBaseAddr;
};
//DLL入口
BOOL DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
return TRUE;
}
//获取指定进程指定dll的基地址
BOOL GetDllHandle(PSINFO * psInfo)
{
DWORD ret = 0;
DWORD dllAddr;
HANDLE hProcess;
PROCESSENTRY32 pe = { sizeof(PROCESSENTRY32) };
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Process32First(hSnapshot, &pe);
while (Process32Next(hSnapshot, &pe))
{
if (wcsicmp(pe.szExeFile, EXENAME) == 0)
{
ret = pe.th32ProcessID;
break;
}
}
CloseHandle(hSnapshot);
if (ret)
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ret);
if (hProcess == INVALID_HANDLE_VALUE)
{
return FALSE;
}
MODULEENTRY32 me32 = { sizeof(MODULEENTRY32) };//存放快照信息的结构体
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ret);
Module32First(hSnapshot, &me32);
while (Module32Next(hSnapshot, &me32))
{
if (wcsicmp(me32.szModule, DLLNAME) == 0)
{
dllAddr = (DWORD)me32.modBaseAddr;
break;
}
}
if (dllAddr!=0)
{
psInfo->hProcess = hProcess;
psInfo->dBaseAddr = dllAddr;
CloseHandle(hSnapshot);
return TRUE;
}
}
return FALSE;
}
//导出函数,修改内存
extern "C" __declspec(dllexport) BOOL WINAPI pj()
{
PSINFO psInfo;
BYTE buf[] = "\x90\x90\x90";
if (GetDllHandle(&psInfo))
{
return WriteProcessMemory(psInfo.hProcess, (LPVOID)(psInfo.dBaseAddr + OFFSET), buf, 3, NULL);
}
return FALSE;
}