[讨论]关于模仿OD单步执行的问题
DWORD NTAPI ExceptionHandler(EXCEPTION_POINTERS * ExceptionInfo) //异常接受函数
{
//if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP) //硬件断点执行触发的是单步调试
//MessageBox(NULL,"111","111",NULL);
DWORD Temp;
VirtualProtect((LPVOID)0x86bd40,1,PAGE_EXECUTE_READWRITE,&Temp); //恢复属性 因为下面有判断需要访问
MEMORY_BASIC_INFORMATION Bit;
VirtualQuery((LPVOID)0x86bd40,&Bit,sizeof(MEMORY_BASIC_INFORMATION)); //获取页面首地址
if((DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress == 0x86db40) //判断当前发送异常的位置是否是我要的位置
{
//MessageBox(NULL,"111","111",NULL);
ExceptionInfo->ContextRecord->Eax = 1;
ExceptionInfo->ContextRecord->Esp = ExceptionInfo->ContextRecord->Esp + 0x10;
ExceptionInfo->ContextRecord->Eip = ExceptionInfo->ContextRecord->Eip + 0x5;
ExceptionInfo->ContextRecord->EFlags |= 0x100;
return EXCEPTION_CONTINUE_EXECUTION;
}
if((DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress >= (DWORD)Bit.BaseAddress &&
(DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress < (DWORD)Bit.BaseAddress+0x1000)//如果异常出现在我所修改的页面保护中 就设置TF标志位 让他进行单步
{
//char ch[MAXBYTE];
//sprintf(ch,"%08x",(DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress);
//MessageBox(NULL,ch,"222",NULL);
//MessageBox(NULL,"222","222",NULL);
ExceptionInfo->ContextRecord->EFlags |= 0x100;
return EXCEPTION_CONTINUE_EXECUTION;
}
VirtualProtect((LPVOID)0x86bd40,1,PAGE_NOACCESS,&Temp);
if(OldAddrs == (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress)
{
// VirtualProtect((LPVOID)0x86bd40,1,PAGE_NOACCESS,&Temp); //如果不属于我下端的页面地址中所引发的异常 我就修改页面保护为不可访问 然后不处理
OldAddrs = 0;
return EXCEPTION_CONTINUE_SEARCH; //抛给游戏
}
else
{
OldAddrs = (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress;
return EXCEPTION_CONTINUE_EXECUTION; //我来处理
}
// OldAddrs = (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress;
// return EXCEPTION_CONTINUE_EXECUTION;
// VirtualProtect((LPVOID)0x86bd40,1,PAGE_NOACCESS,&Temp); //如果不属于我下端的页面地址中所引发的异常 我就修改页面保护为不可访问 然后不处理
// return EXCEPTION_CONTINUE_SEARCH;
}
我先把所有不在范围内的异常返回 看是否可以继续执行如果是程序本身的 他没处理异常肯定是不能继续执行的也就是说会再次抛出异常 我处理之后直接抛给程序自身去处理 但是不是所有的异常都可以return EXCEPTION_CONTINUE_EXECUTION 导致程序直接报错误提示 有什么好点的办法可以直接过滤掉程序本身的异常啊