设为首页 收藏本站
查看: 1123|回复: 0

How to debug user-mode process using kernel-mode windbg in Win7

[复制链接]

尚未签到

发表于 2015-5-17 09:51:45 | 显示全部楼层 |阅读模式
  It is easy and straightforward to debug a user-mode process by a user-mode Windbg. However, for some reason, we may prefer to debug a user-mode process by the kernel-mode Windbg.

Here I have tow examples by using notepad.exe
The first scenario is that, the notepad.exe is already running, and we want to set a breakpoint on it.
Remember! If we want to set a breakpoint on particular process, the current debugging process context must be the context of the process. So the only thing we need to do is to switch to the right process context.
1. we use the !process to find the process context of notepad.exe
1: kd> !process 0 0 notepad.exe
PROCESS b75d67e8  SessionId: 1  Cid: 0a30    Peb: 7ffd5000  ParentCid: 08f4
    DirBase: 77fdf660  ObjectTable: aad050f0  HandleCount:  77.
    Image: notepad.exe

The bolder part is the process context.


2. Now we know the process context and next step is to use  .process /i to switch to it
0: kd> .process /i b75d67e8
You need to continue execution (press 'g' ) for the context
to be switched. When the debugger breaks in again, you will be in
the new process context.


3. the Windbg will automatic break again after press 'g', now windbg is in right process context of notepad.exe. the next step is same as usual to reload symbol and and set a breakpoint.
2: kd> .reload /user
Loading User Symbols



2: kd> bp notepad!LoadFile
2: kd> bl
0 e 00862820     0001 (0001) notepad!LoadFile


we successful set a user-mode breakpoint on notepad.exe. and if we open a file by notepad, the windbg will break the process.

The second scenario is to break at the start up of notepad launched by user.
we know it is explorer.exe to create process, we need find somewhere the process is already created but not run. The kernel mode function nt!EtwpTraceLoadImage is good place to do it. This function will be called very time when process load modules.
Remember, the nt!EtwpTraceLoadImage is a kernel mode function which is called by any process. So when windbg is breaking at the function, we need verify the current process name.
if you have private symbols of nt module, you can just look the local windows of windbg, the first item is ImageName。
if you don't have private symbols, use !peb or .process to get know current process name.

after successful break into nt!EtwpTraceLoadImage on notepad.exe, the windbg is in the right process context we want, however, we may still failed to set breakpoint because current is in process initial time and some module may not be loaded into memory. so we must wait to all modules are loaded into memory.
By executing nt!EtwpTraceLoadImage several times, you may find a similar call stack

b7eb7b34 82ea127f nt!EtwpTraceLoadImage
b7eb7be8 82e91d4a nt!MiMapViewOfImageSection+0x670
b7eb7c58 82e91e3a nt!MiMapViewOfSection+0x22e
b7eb7c88 82e92599 nt!MmMapViewOfSection+0x2a
b7eb7d04 82c881ea nt!NtMapViewOfSection+0x204
b7eb7d04 77da70b4 nt!KiFastCallEntry+0x12a
001cf73c 77da5c34 ntdll!KiFastSystemCallRet
001cf740 77dc067d ntdll!NtMapViewOfSection+0xc
001cf794 77dc075a ntdll!LdrpMapViewOfSection+0xc7
001cf82c 77dbfbc1 ntdll!LdrpFindOrMapDll+0x303
001cf9ac 77dc232c ntdll!LdrpLoadDll+0x2b2
001cf9e0 77dc7d03 ntdll!LdrLoadDll+0x92
001cfb50 77dc6077 ntdll!LdrpInitializeProcess+0xfe7
001cfba0 77dc3663 ntdll!_LdrpInitialize+0x78
001cfbb0 00000000 ntdll!LdrInitializeThunk+0x10

just set a break point at the return address of ntdll!LdrpInitializeProcess, at that time, all static modules are loaded into memory and we can reload symbols and set breakpoint now.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-67690-1-1.html 上篇帖子: vlc编译(win7+cygwin) 下篇帖子: win7 64位系统使用VS2010生成时出现中文目录乱码问题的解决方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表