- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试调试处于挂起状态的子进程。问题是,当我尝试这样做时,应用程序不会启动(它启动但立即退出)。这有助于防止逆向工程,但我做不到。
static void DebuggingTest(PROCESS_INFORMATION pi, int imageBase, int sizeOfHeaders)
{
int oldProtection = 0;
const uint STATUS_GUARD_PAGE_VIOLATION = 0x80000001;
const int DBG_CONTINUE = 0x00010002;
DEBUG_EVENT evt = new DEBUG_EVENT();
if (!DebugActiveProcess(Convert.ToInt32(pi.dwProcessId)))
throw new Win32Exception();
else
MessageBox.Show(pi.dwProcessId + " process is being debugged.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
while (true)
{
if (!WaitForDebugEvent(out evt, -1))
throw new Win32Exception();
else
MessageBox.Show("WaitForDebugEvent executed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
switch (evt.dwDebugEventCode)
{
case DebugEventType.CREATE_PROCESS_DEBUG_EVENT:
//if (!VirtualProtectEx(pi.hProcess, imageBase, sizeOfHeaders, 320, ref oldProtection))
// throw new Exception();
ResumeThread(pi.hThread);
MessageBox.Show("CREATE_PROCESS_DEBUG_EVENT executed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
case DebugEventType.EXCEPTION_DEBUG_EVENT:
if (evt.Exception.ExceptionRecord.ExceptionCode == STATUS_GUARD_PAGE_VIOLATION)
{
if (!VirtualProtectEx(pi.hProcess, imageBase, sizeOfHeaders, 320, ref oldProtection))
throw new Exception();
}
MessageBox.Show("EXCEPTION_DEBUG_EVENT executed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
case DebugEventType.EXIT_PROCESS_DEBUG_EVENT:
if (!DebugActiveProcessStop(Convert.ToInt32(pi.dwProcessId)))
throw new Win32Exception();
if (!TerminateProcess(pi.hProcess, 0))
throw new Win32Exception();
MessageBox.Show("EXIT_PROCESS_DEBUG_EVENT executed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
case DebugEventType.LOAD_DLL_DEBUG_EVENT:
if (CloseHandle(evt.LoadDll.hFile))
MessageBox.Show("CloseHandle executed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
}
if (ContinueDebugEvent(evt.dwProcessId, evt.dwThreadId, DBG_CONTINUE))
MessageBox.Show("Last ContinueDebugEvent executed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
编辑:VirtualProtectEx 调用失败,这是实际问题。如果我评论他们的行,应用程序就会执行。它也很滞后,可能是因为调试循环。有解决方案吗?
Edit2:除了 DEBUG_PROCESS 之外,我按照你的建议编辑了代码,因为它停止了整个进程,我什至无法通过任务管理器杀死它,杀死它的唯一方法是重新启动 PC .也许,我做错了什么,但我不知道是什么。所以消息框出现的顺序是:执行 DebugActiveProcess -> 执行 WaitForDebugEvent -> 执行 CREATE_PROCESS_DEBUG_EVENT -> 最后执行 ContinueDebugEvent。然后等待... -> CloseHandle -> ContinueDebug ...
最佳答案
1) 当你想通过 CreateProcess
创建调试进程时设置 DEBUG_PROCESS
在dwCreationFlags
2) 在这种情况下永远不要调用 DebugActiveProcess
- 这个 api 内部在进程中创建远程线程 - DbgUiRemoteBreakIn
- 所以进程不是在它的主线程中而是在这个线程中开始初始化.在 xp 上说这导致进程初始化总是失败。后者(从 win7 开始?)已修复。
3) ContinueDebugEvent
需要在每次调试事件后调用always。在 EXIT_PROCESS_DEBUG_EVENT
- also - 需要了解此消息在退出时发送给你的最后一个进程中的线程。并且他等待您的调用 ContinueDebugEvent
- 当您收到 EXIT_PROCESS_DEBUG_EVENT
时,进程仍然存在并且没有终止 - 因此您必须在之后对 ContinueDebugEvent
进行一次普通调用开关
4) 你尝试用 VirtualProtectEx
做的事情必须产生无限的 STATUS_GUARD_PAGE_VIOLATION
异常。所以即使不多看——“保护”的主要逻辑是无效的
5) 句柄 LOAD_DLL_DEBUG_EVENT
是强制性的 - 您必须关闭句柄(hFile 到加载的 DLL)
6) 在 CREATE_PROCESS_DEBUG_EVENT
上,您还必须关闭文件句柄
7) 当我们使用 DEBUG_PROCESS
标志调用 CreateProcess
时 - 使用 CREATE_SUSPENDED
- 绝对没有意义 - 为什么??通常这个标志用于处理进程的一些任务,在线程开始以用户模式执行之前和调用 ResumeThread
之后。但是当我们在进程中使用 DEBUG_PROCESS
初始线程时,当它开始执行时(但在内核模式下)发送给我们 CREATE_PROCESS_DEBUG_EVENT
并等待回复(直到调试器不调用 ContinueDebugEvent
。因此,我们可以在 CREATE_PROCESS_DEBUG_EVENT
处理程序中完成所有带有进程的特殊任务。对 Windows 内部工作方式的误解会导致严重错误
关于c# - DebugActiveProcess 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44422619/
下面是一段代码,它完成了主要任务——附加到一个事件进程。尽管看起来子进程没有在开关中作为 CREATE_PROCESS_DEBUG_EVENT 被捕获。只有 CREATE(EXIT)_THREAD_D
我正在尝试调试处于挂起状态的子进程。问题是,当我尝试这样做时,应用程序不会启动(它启动但立即退出)。这有助于防止逆向工程,但我做不到。 static void DebuggingTest(PROCES
我有点想把它留作思想实验(我在聊天中询问过它,但被引导到这里)。但如果有帮助,我可以提供代码。这是场景! 进程 1 正在运行并不断调试进程 2,我已将一个 DLL 注入(inject)进程 2 并绕过
我已经使用 DebugActiveProcess 附加了一个进程。之后我使用了 WaitForDebugEvent,但应用程序似乎陷入了某个无限循环,我无法调试附加的进程。 下面是我的代码:
我最近问了一个问题,得到了一个答案,为我的 boofuzz 同行解决了我当时的问题 viewable here 。不幸的是,我现在收到另一个错误:pdx:[50] DebugActiveProcess
我是一名优秀的程序员,十分优秀!