标签:return Windows pid part0 debug include event 调试 hThread
simple example
先写一个拥有最基本的处理调试事件能力的程序,当它发现程序有一个软件断点即0xcc指令时,使当前线程恢复执行
#include <Windows.h>
#include <iostream>
BOOL Debug(DWORD pid)
{
if (pid == 0)
{
MessageBox(NULL, "please enter pid", "!!!!", MB_OK);
return FALSE;
}
if (!DebugActiveProcess(pid))
{
MessageBox(NULL, "debug process wrong", "!!!!", MB_OK);
return FALSE;
}
while (TRUE)
{
DEBUG_EVENT debug_event;
WaitForDebugEvent(&debug_event, INFINITE);
switch (debug_event.dwDebugEventCode)
{
case EXCEPTION_DEBUG_EVENT:
if (debug_event.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT)
{
MessageBox(NULL, "find a break point", "!!!!", MB_OK);
HANDLE hThread = debug_event.u.CreateProcessInfo.hThread;
CONTEXT context;
GetThreadContext(hThread, &context);
context.Eip++;
SetThreadContext(hThread, &context);
}
default:
break;
}
ContinueDebugEvent(pid, debug_event.dwThreadId, DBG_CONTINUE);
}
return TRUE;
}
int main()
{
DWORD pid, tid;
std::cout << "please enter the process id" << std::endl;
std::cin >> pid;
Debug(pid);
return 0;
}
接着我们写一个目标程序,我们用内联汇编写一行int 3指令,即0xcc
#include <iostream>
#include <string>
void bug()
{
_asm int 3;
std::cout << "now you clear the break point" << std::endl;
}
int main()
{
while (true)
{
std::cout << "you want a bug?(yes/no)" << std::endl;
std::string answer;
std::cin >> answer;
if (answer == "yes")
bug();
else if (answer == "no")
continue;
}
return 0;
}
接下来进行测试,我们先打开被测程序,输入yes后,程序断了下来,然后就卡死了
我们重新打开该程序,然后找到其pid,并用调试器附加上去
之后我们再次输入yes
可以看到在弹窗后,我们的程序正常的执行了下去。
标签:return,Windows,pid,part0,debug,include,event,调试,hThread 来源: https://blog.csdn.net/qq_35713009/article/details/90982593
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。