|
内部资料~现在公开~
void hkKeAttachProcess(PEPROCESS Process)
{
void* oricall;
DWORD calleraddr;
ULONG pid;
BOOL find;
PLDR_DATA_TABLE_ENTRY pldr;
__asm mov eax,[ebp+4];
__asm mov calleraddr,eax;
oricall = phkKeAttachProcess->oritocall;
pid = *(PULONG)((ULONG)Process + pIdOffset);
find = FALSE;
//if (KeGetCurrentIrql()<DISPATCH_LEVEL)
//{
// //////////////////////////////////////////////////////////////////////////
// //event 模式
// //////////////////////////////////////////////////////////////////////////
//}
if (!g_PsLoadedModuleList) goto pass;
if(!PrtFindRule(PROTECT_PROCESS,(PWSTR)pid)||PsGetCurrentProcessId()==(HANDLE)pid)
goto pass;
pldr = (PLDR_DATA_TABLE_ENTRY)g_PsLoadedModuleList;
while (pldr->InLoadOrderModuleList.Flink != g_PsLoadedModuleList)
{
if (MmIsAddressValid((PVOID)pldr->FullDllName.Buffer))
{
DbgPrint("Base:0x%08x,Name:%ws,Size:0x%08x", pldr->DllBase, pldr->FullDllName.Buffer, pldr->SizeOfImage);
if (calleraddr>=(DWORD)pldr->DllBase&&calleraddr<=(DWORD)pldr->DllBase+(DWORD)pldr->SizeOfImage)
{
//////////////////////////////////////////////////////////////////////////
//对于我们保护的进程
//检查模块名字是否是我们希望能够attach的
//列表
//不是我们希望attach的就将Process = IoGetCurrentProcess();
//////////////////////////////////////////////////////////////////////////
find = TRUE;
if (Find_attach_filter((HANDLE)pid,pldr->BaseDllName.Buffer,sizeof(WCHAR)*wcslen(pldr->BaseDllName.Buffer)))
{
Process = IoGetCurrentProcess();
}
}
}
pldr = (PLDR_DATA_TABLE_ENTRY)pldr->InLoadOrderModuleList.Flink;
}
if (!find)
{
//////////////////////////////////////////////////////////////////////////
//未知模块,直接Trap死人
//////////////////////////////////////////////////////////////////////////
Process = IoGetCurrentProcess();
}
pass:
__asm
{
push Process
call dword ptr oricall
}
return ;
}
void hkKeStackAttachProcess(PEPROCESS Process,PKAPC_STATE apc)
{
void* oricall;
DWORD calleraddr;
ULONG pid;
BOOL find;
PLDR_DATA_TABLE_ENTRY pldr;
__asm mov eax,[ebp+4];
__asm mov calleraddr,eax;
oricall = phkKeStackAttachProcess->oritocall;
pid = *(PULONG)((ULONG)Process + pIdOffset);
find = FALSE;
//if (KeGetCurrentIrql()<DISPATCH_LEVEL)
//{
// //////////////////////////////////////////////////////////////////////////
// //event 模式
// //////////////////////////////////////////////////////////////////////////
//}
if (!g_PsLoadedModuleList) goto pass;
if(!PrtFindRule(PROTECT_PROCESS,(PWSTR)pid)||PsGetCurrentProcessId()==(HANDLE)pid)
goto pass;
pldr = (PLDR_DATA_TABLE_ENTRY)g_PsLoadedModuleList;
while (pldr->InLoadOrderModuleList.Flink != g_PsLoadedModuleList)
{
if (MmIsAddressValid((PVOID)pldr->FullDllName.Buffer))
{
DbgPrint("Base:0x%08x,Name:%ws,Size:0x%08x", pldr->DllBase, pldr->FullDllName.Buffer, pldr->SizeOfImage);
if (calleraddr>=(DWORD)pldr->DllBase&&calleraddr<=(DWORD)pldr->DllBase+(DWORD)pldr->SizeOfImage)
{
//////////////////////////////////////////////////////////////////////////
//对于我们保护的进程
//检查模块名字是否是我们希望能够attach的
//dxg.ntos.ndis.tdi.afd.tcp win32k,ddi驱动等都是应该允许的,这个是个列表
//估计需要ring3维护传入
//不是我们希望attach的就将Process = IoGetCurrentProcess();
//////////////////////////////////////////////////////////////////////////
find = TRUE;
if (Find_attach_filter((HANDLE)pid,pldr->BaseDllName.Buffer,sizeof(WCHAR)*wcslen(pldr->BaseDllName.Buffer)))
{
Process = IoGetCurrentProcess();
}
}
}
pldr = (PLDR_DATA_TABLE_ENTRY)pldr->InLoadOrderModuleList.Flink;
}
if (!find)
{
//////////////////////////////////////////////////////////////////////////
//未知模块,直接Trap死人
//////////////////////////////////////////////////////////////////////////
Process = IoGetCurrentProcess();
}
pass:
__asm
{
push apc
push Process
call dword ptr oricall
}
return ;
}
|
|