<转载>windbg的一些命令
本文来自:http://blog.csdn.net/tianzhhy/article/details/6160622
1.strct
strct命令是windbg附带的kdex2x86.dll动态链接库提供的命令。
首先我们进入我们的windbg目录的nt4fre目录,将其kdex2x86.dll拷贝到windbg目录下,或者任何环境变量的目录下,我直接将其拷贝到system32目录下。拷贝完成后,我们就可以来用kdex2x86提供的strct命令了。
我们打开windbg随便附加一个进程如记事本,计算器等。然后输入!kdex2x86.strct 结构名, 即可查看相关结构的数据类型。
举例: kd> !kdex2x86.strct peb
或者
load kdex2x86.dll
!strct _EPROCESS
要使用其它扩展命令的话操作方法类似~具体可看windbg帮助文件
2.object
从命名对象地址空间,找到 i8042 prt 的 DRIV ER_OBJECT 的地址。
kd> !object /driver/i8042prt
Object: 8250bda0 Type: (825a73b0) Driver
ObjectHeader: 8250bd88 (old version)
HandleCount: 0 PointerCount: 5
Directory Object: e143e888 Name: i8042prt
3.drvobj
列出这个驱动创建的所有设备。
kd> !drvobj /driver/i8042prt
Driver object (8250bda0) is for:
/Driver/i8042prt
Driver Extension List: (id , addr)
Device Object list:
824ffc88 8245e020
4.devobj 、devstack
当你有了一个设备列表,传入设备指针给!devobj或!devstack来得到更多信息。
kd> !devobj 824ffc88
Device object (824ffc88) is for:
/Driver/i8042prt DriverObject 8250bda0
Current Irp 00000000 RefCount 0 Type 00000027 Flags 00002004
DevExt 824ffd40 DevObjExt 824fffd0
ExtensionFlags (0000000000)
AttachedDevice (Upper) 824ffb40 /Driver/vmmouse
AttachedTo (Lower) 8253a2c0 /Driver/ACPI
Device queue is not busy.
从获得的信息来看,这是用于鼠标的那个设备对象。
kd> !devobj 8245e020
Device object (8245e020) is for:
/Driver/i8042prt DriverObject 8250bda0
Current Irp 00000000 RefCount 0 Type 00000027 Flags 00002004
DevExt 8245e0d8 DevObjExt 8245e368
ExtensionFlags (0000000000)
AttachedDevice (Upper) 8245eeb8 /Driver/DKbFltr
AttachedTo (Lower) 8253a3d8 /Driver/ACPI
Device queue is not busy.
从获得的信息来看,这是用于键盘的那个设备对象。
kd> !devstack 824ffc88
!DevObj !DrvObj !DevExt ObjectName
824ff968 /Driver/Mouclass 824ffa20 PointerClass0
824ffb40 /Driver/vmmouse 824ffbf8
> 824ffc88 /Driver/i8042prt 824ffd40
8253a2c0 /Driver/ACPI 8259ab80 0000007b
!DevNode 82502708 :
DeviceInst is "ACPI/PNP0F13/4&5289e18&0"
ServiceName is "i8042prt"
5.dt nt!_IRP
显示IRP数据结构。
kd> dt nt!_IRP
+0x000 Type : Int2B
+0x002 Size : Uint2B
+0x004 MdlAddress : Ptr32 _MDL
+0x008 Flags : Uint4B
+0x00c AssociatedIrp : __unnamed
+0x010 ThreadListEntry : _LIST_ENTRY
+0x018 IoStatus : _IO_STATUS_BLOCK
+0x020 RequestorMode : Char
+0x021 PendingReturned : UChar
+0x022 StackCount : Char
+0x023 CurrentLocation : Char
+0x024 Cancel : UChar
+0x025 CancelIrql : UChar
+0x026 ApcEnvironment : Char
+0x027 AllocationFlags : UChar
+0x028 UserIosb : Ptr32 _IO_STATUS_BLOCK
+0x02c UserEvent : Ptr32 _KEVENT
+0x030 Overlay : __unnamed
+0x038 CancelRoutine : Ptr32 void
+0x03c UserBuffer : Ptr32 Void
+0x040 Tail : __unnamed
6.dt nt!_driver_object
驱动对象数据结构。
kd> dt nt!_driver_object 8250bda0
+0x000 Type : 0n4
+0x002 Size : 0n168
+0x004 DeviceObject : 0x824ffc88 _DEVICE_OBJECT
+0x008 Flags : 0x12
+0x00c DriverStart : 0xf86e4000 Void
+0x010 DriverSize : 0xb900
+0x014 DriverSection : 0x8259f678 Void
+0x018 DriverExtension : 0x8250be48 _DRIVER_EXTENSION
+0x01c DriverName : _UNICODE_STRING "/Driver/i8042prt"
+0x024 HardwareDatabase : 0x80671b60 _UNICODE_STRING "/REGISTRY/MACHINE/HARDWARE/DESCRIPTION/SYSTEM"
+0x028 FastIoDispatch : (null)
+0x02c DriverInit : 0xf86ed285 long +fffffffff86ed285
+0x030 DriverStartIo : 0xf86e4910 void +fffffffff86e4910
+0x034 DriverUnload : 0xf86eaeb6 void +fffffffff86eaeb6
+0x038 MajorFunction : [28] 0xf86e7aa6 long +fffffffff86e7aa6
7.dt nt!_device_object
设备对象数据结构。
kd> dt nt!_device_object 824ffc88
+0x000 Type : 0n3
+0x002 Size : 0x348
+0x004 ReferenceCount : 0n0
+0x008 DriverObject : 0x8250bda0 _DRIVER_OBJECT
+0x00c NextDevice : 0x8245e020 _DEVICE_OBJECT
+0x010 AttachedDevice : 0x824ffb40 _DEVICE_OBJECT
+0x014 CurrentIrp : (null)
+0x018 Timer : (null)
+0x01c Flags : 0x2004
+0x020 Characteristics : 0
+0x024 Vpb : (null)
+0x028 DeviceExtension : 0x824ffd40 Void
+0x02c DeviceType : 0x27
+0x030 StackSize : 5 ''
+0x034 Queue : __unnamed
+0x05c AlignmentRequirement : 0
+0x060 DeviceQueue : _KDEVICE_QUEUE
+0x074 Dpc : _KDPC
+0x094 ActiveThreadCount : 0
+0x098 SecurityDescriptor : (null)
+0x09c DeviceLock : _KEVENT
+0x0ac SectorSize : 0
+0x0ae Spare1 : 1
+0x0b0 DeviceObjectExtension : 0x824fffd0 _DEVOBJ_EXTENSION
+0x0b4 Reserved : (null)
8.lm t n
列出可以调试的驱动程序
9.!process命令
!process 0 0 查看系统全部进程信息 (在虚拟机器远程调试才行)
!process cid ParentCid 其中cid就是pid的十六进制表示
10.dt _eprocess 81bef448
查看特定地址的eprocess结构内容
11.产生如下错误:
*** Fatal System Error: 0x0000007e
(0xC0000005,0xF9FDB318,0xFA06EB88,0xFA06E884)
找到原因:Fatal System Error: 0x0000007e错误对应:
Bug Check 0x7E: SYSTEM_THREAD_EXCEPTION_NOT_HANDLED
然后看0xC0000005对应:
0xC0000005: STATUS_ACCESS_VIOLATION
A memory access violation occurred.
所以结论是:A memory access violation occurred.
12.查询符号
kd> x nt!KeServiceDescriptorTable*
80553fe0 nt!KeServiceDescriptorTableShadow = <no type information>
80554020 nt!KeServiceDescriptorTable = <no type information>
kd> ln 80553fe0
(80553fe0) nt!KeServiceDescriptorTableShadow | (80554020) nt!KeServiceDescriptorTable
Exact matches:
nt!KeServiceDescriptorTableShadow = <no type information>
13. 查看 event 对象的信号状态
!object /BaseNamedObjects
dt -b nt!_KEVENT xxxxxxxx
14. 查看 LastError 值
!gle
15. 指定进制形式,0x/0n/0t/0y 分别表示 16/10/8/2 进制?
0x12345678+0n10
Evaluate expression: 305419906 = 12345682
16. 过滤命令窗口输出信息.
prompt_allow -reg +dis -ea -src -sym
17. .formats 命令以多种格式显示表达式的值
kd> .formats @eax
Evaluate expression:
Hex: 00000001
Decimal: 1
Octal: 00000000001
Binary: 00000000 00000000 00000000 00000001
Chars: ....
Time: Thu Jan 01 08:00:01 1970
Float: low 1.4013e-045 high 0
Double: 4.94066e-324
18. 异常处理相关有 sx, sxd, sxe, sxi, sxn, sxr 几条命令可用来设置异常和事件的处理方式。比如:
kd> sxe ld 可以在加载 dll 时中断下来
19. 可在桌面上建立一个 WinDbg.exe 的快捷方式,然后在该快捷方式的属性力设置如下命令行
C:/WinDBG/windbg.exe -c ".prompt_allow +dis -reg -ea -src -sym; .enable_unicode 1; .enable_long_status 1; .logopen /t c:/dbglog/dbglog.txt"
我的设置C:/WinDDK/7600.16385.1/Debuggers/windbg.exe -b -k com:port=//./pipe/com_1,baud=115200,pipe
20. 本机内核调试通过File/Kernel Debug… 菜单可以打开内核调试选择窗口,
选择最后一个 Local 选项页,确定后可以以内核方式调试本地机器。
这时所有会挂起系统的命令都用不了了,但可以读写系统内存。
另外,有一个方便的用途是用来查看系统结构,比如:dt nt!_EPROCESS
参考:
http://blog.csdn.net/goodwinds/archive/2008/06/06/2517477.aspx
http://www.cnblogs.com/adylee/archive/2010/10/15/1852081.html
http://dev.firnow.com/course/3_program/vc/vc_js/20100630/267653.html
http://hi.baidu.com/_achillis/blog/item/7a409a124ad34bd6f6039ecc.html
还有一篇!object不工作的讨论:
http://www.osronline.com/showthread.cfm?link=161424
might have been caused by lack of symbols for the new Object Manager structures
浙公网安备 33010602011771号