DWORD __stdcall MyDbgUiRemoteBreakin(LPVOID lparam)
{
OutputDebugStringA(
"attach\r\n"
);
TerminateProcess(GetCurrentProcess(),-1);
return
0;
}
DWORD __stdcall MyDbgBreakPoint()
{
OutputDebugStringA(
"attach 2\r\n"
);
//m_Attach2Count
++;
//if
(m_Attach2Count>1)
{
TerminateProcess(GetCurrentProcess(),-1);
}
return
0;
}
DWORD WINAPI AntiDbgAttach(LPVOID lparam)
{
//
挂钩一些特殊函数!
BYTE myHookCodeDbgUiRemoteBreakin[5]={0};
BYTE myHookCodeDbgBreakPoint[5]={0};
VOID *ptrDbgUiRemoteBreakin = (VOID *)GetProcAddress(GetModuleHandle(TEXT(
"ntdll.dll"
)),
"DbgUiRemoteBreakin"
);
InlineHook(ptrDbgUiRemoteBreakin,(void *)MyDbgUiRemoteBreakin,(void **)&OldDbgUiRemoteBreakin);
void *ptrDbgBreakPoint = (void *)GetProcAddress(GetModuleHandle(TEXT(
"ntdll.dll"
)),
"DbgBreakPoint"
);
InlineHook(ptrDbgBreakPoint,(void *)MyDbgBreakPoint,(void **)&OldDbgBreakPoint);
RtlCopyMemory(myHookCodeDbgBreakPoint,ptrDbgBreakPoint,5);
RtlCopyMemory(myHookCodeDbgUiRemoteBreakin,ptrDbgUiRemoteBreakin,5);
while
(1)
{
if
(memcmp(ptrDbgUiRemoteBreakin,myHookCodeDbgUiRemoteBreakin,5)!=0)
{
OutputDebugStringA(
"find patch DbgUiRemoteBreakin"
);
TerminateProcess(GetCurrentProcess(),-1);
}
if
(memcmp(ptrDbgBreakPoint,myHookCodeDbgBreakPoint,5)!=0)
{
OutputDebugStringA(
"find patch DbgBreakPoint"
);
WriteReadOnlyMemory((LPBYTE)ptrDbgBreakPoint,myHookCodeDbgBreakPoint,5);
}
Sleep(3000);
}
return
0;
}