BOOL WINAPI CreateProcessAHook( __in LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
__in LPSECURITY_ATTRIBUTES lpProcessAttributes,
__in LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in BOOL bInheritHandles,
__in DWORD dwCreationFlags,
__in LPVOID lpEnvironment,
__in LPCTSTR lpCurrentDirectory,
__in LPSTARTUPINFO lpStartupInfo,
__out LPPROCESS_INFORMATION lpProcessInformation)
{
//
修改输入参数,调用原函数
int ret=OLD_CreateProcessA(lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags | CREATE_SUSPENDED,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation);
GetModuleFileName(g_hModule,g_szPath,MAX_PATH);
memset(g_bWriteCode,0,1000);
CONTEXT ThreadContext;
ThreadContext.ContextFlags = CONTEXT_FULL;
GetThreadContext(lpProcessInformation->hThread,&ThreadContext);
LPVOID lpAddress = VirtualAllocEx(lpProcessInformation->hProcess,NULL,1000,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
if
(!lpAddress)
{
DebugPrintf(
"VirtualAllocEx Error %d"
,GetLastError());
return
ret;
}
BYTE szBuffer[1000];
BYTE *bP;
RtlZeroMemory(szBuffer,1000);
szBuffer[0] = 0x9C;
szBuffer[1] = 0x60;
szBuffer[2] = 0xE8;
*(DWORD*)(szBuffer+3) = 0x104;
RtlCopyMemory(szBuffer + 7,g_szPath,MAX_PATH);
bP = &szBuffer[0x104+7];
*bP = 0xB8;
*(DWORD*)(bP+1) = (DWORD)LoadLibraryA;
*(bP+5) = 0xFF;
*(bP+6) = 0xD0;
*(bP+7) = 0x61;
*(bP+8) = 0x9d;
*(bP+9) = 0x68;
*(DWORD*)(bP+10) = ThreadContext.Eip;
*(bP+14) = 0xc3;
DebugPrintf(
"lpAddress = %x"
,lpAddress);
if
(!WriteProcessMemory(lpProcessInformation->hProcess, lpAddress, szBuffer, 1000, NULL))
{
DebugPrintf(
"WriteProcessMemory Error,%d"
,GetLastError());
return
ret;
}
FlushInstructionCache(lpProcessInformation->hProcess, lpAddress, 1000);
ThreadContext.Eip = (DWORD)lpAddress;
SetThreadContext(lpProcessInformation->hThread, &ThreadContext);
ResumeThread(lpProcessInformation->hThread);
return
ret;
}