我可以在ntdll.dll!_LdrpInitializeProcess中设置断点吗?

发布于 2024-11-15 15:02:51 字数 558 浏览 2 评论 0原文

调试 Windows 进程时,有时尽早中断会很方便。

初始调用堆栈看起来像这样:(例如,当您在 DLL_PROCESS_ATTACH 上的 DllMain 函数中设置断点时,您会得到这个)

    ...
    ntdll.dll!_LdrpCallInitRoutine@16()  + 0x14 bytes   
    ntdll.dll!_LdrpRunInitializeRoutines@4()  + 0x205 bytes 
>   ntdll.dll!_LdrpInitializeProcess@20()  - 0x96d bytes    
    ntdll.dll!__LdrpInitialize@12()  + 0x6269 bytes 
    ntdll.dll!_KiUserApcDispatcher@20()  + 0x7 bytes    

因此在这些 ntdll 例程之一中设置断点应该确实会中断这个过程很早。

但是,我不知道如何在调试器中启动进程之前设置断点。在 Visual Studio (2005) 中可能吗?如何?可以在WinDbg中完成吗?

When debugging a Windows process, it would sometimes be convenient to break as early as possible.

Inital Callstack looks like this: (you get this e.g. when you set a breakpoint in a DllMain function on DLL_PROCESS_ATTACH)

    ...
    ntdll.dll!_LdrpCallInitRoutine@16()  + 0x14 bytes   
    ntdll.dll!_LdrpRunInitializeRoutines@4()  + 0x205 bytes 
>   ntdll.dll!_LdrpInitializeProcess@20()  - 0x96d bytes    
    ntdll.dll!__LdrpInitialize@12()  + 0x6269 bytes 
    ntdll.dll!_KiUserApcDispatcher@20()  + 0x7 bytes    

so setting a breakpoint in one of these ntdll routines should really break the process very early.

However, I can't figure out how to set a breakpoint there prior to starting the process in the debugger. Is it possible in Visual Studio (2005)? How? Can it be done in WinDbg?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

镜花水月 2024-11-22 15:02:51

我会使用类似 GFlags 来启动进程启动时的调试器。

以下是 test.exe 的示例 gflags 设置

在此处输入图像描述

这是调试器输出。注意 ntdll!LdrpInitializeProcess 的调用堆栈

命令行:“C:\temp\test.exe”
符号搜索路径为:
srv*;srvc:\symbolshttp://msdl.microsoft.com/下载/符号
可执行搜索路径为:ModLoad:
0000000000d20000 0000000000d28000
image00000000<代码>00d20000 (1b40.464):
Break指令异常-代码
80000003(第一次机会)
ntdll!LdrpDoDebuggerBreak+0x30:
0000000077c7cb60 cc 整数
3 0:000> k 子 SP RetAddr
呼叫站点 00000000<代码>0012ed70
00000000 77c32ef5
ntdll!LdrpDoDebuggerBreak+0x30
000000000012edb0 0000000077c11a17
ntdll!LdrpInitializeProcess+0x1b4f
000000000012f2a0 0000000077bfc32e
ntdll! ?? ::FNODOBFM::<代码>字符串'+0x29220
000000000012f310 00000000`00000000
ntdll!LdrInitializeThunk+0xe

或者您可以在 Windbg 之类的调试器中打开进程,默认情况下它会中断到 ntdll!LdrpInitializeProcess

华泰

I would use something like GFlags to launch the debugger when the process starts.

Here is a sample gflags settings for test.exe

enter image description here

And here is the debugger output. Notice the call-stack with ntdll!LdrpInitializeProcess

CommandLine: "C:\temp\test.exe"
Symbol search path is:
srv*;srvc:\symbolshttp://msdl.microsoft.com/download/symbols
Executable search path is: ModLoad:
0000000000d20000 0000000000d28000
image0000000000d20000 (1b40.464):
Break instruction exception - code
80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00000000
77c7cb60 cc int
3 0:000> k Child-SP RetAddr
Call Site 000000000012ed70
00000000
77c32ef5
ntdll!LdrpDoDebuggerBreak+0x30
000000000012edb0 0000000077c11a17
ntdll!LdrpInitializeProcess+0x1b4f
000000000012f2a0 0000000077bfc32e
ntdll! ?? ::FNODOBFM::string'+0x29220
00000000
0012f310 00000000`00000000
ntdll!LdrInitializeThunk+0xe

Or you could open the process within the debugger like Windbg which would break into ntdll!LdrpInitializeProcess by default.

HTH

成熟的代价 2024-11-22 15:02:51

我已经找到了如何在 Visual Studio 中执行此操作。

这里的问题是,在任何汇编函数中设置断点都会被记住为“数据断点”。一旦进程停止,这些断点就会被禁用,所以即使我在此函数中设置了一个断点(我可以这样做,因为如果我在任何 DllMain 函数中设置断点,我的函数就在堆栈上),该断点也将被禁用一段时间新进程运行。

但是对于ntdll.dll(和kernel32.dll)来说,加载地址几乎是固定的并且不会改变(至少在重新启动之前不会改变)。

因此,在开始该过程之前,我只需重新启用与该 NtDll 函数对应的地址的数据断点,调试器就会在那里停止。

I have found out how to do it in Visual Studio.

The problem here is, that setting a breakpoint in any assembly function will be remembered as a "Data Breakpoint". These breakpoints are disabled as soon as the process stops, so even if I set one in this function (I can do this because I have the function on the stack if I set a breakpoint in any DllMain function) this breakpoint will be disabled for a new process run.

However for ntdll.dll (and kernel32.dll) the load addresses are pretty much fixed and won't change (and least not until reboot).

So, before starting the process, I just have to re-enable the Data Breakpoint for the address that corresponds to this NtDll function and the debugger will then stop there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文