[WinDBG 技巧] 列举所有Handle(句柄)以及查看Handle 信息

来源:互联网 发布:beyonce 知乎 编辑:程序博客网 时间:2024/05/15 23:44

WinDBG的 !handle 命令可以让你方便调试句柄(handle)。

 

查看进程内所有句柄, 输入命令行 

0:014> !handle
Handle 4
  Type          Directory
Handle 8
  Type          Process
Handle c
  Type          Key
Handle 10
  Type          Mutant
Handle 14
  Type          ALPC Port
Handle 18
  Type          Key
Handle 1c
  Type          Event
Handle 20
  Type          Key

 ... (省略)

 

Handle 7e0
  Type          Mutant
392 Handles
Type            Count
None            17
Event           134
Section         47
File            35
Directory       3
Mutant          34
WindowStation   2
Semaphore       24
Key             47
Token           1
Process         3
Thread          27
Desktop         1
IoCompletion    4
Timer           5
Job             1
KeyedEvent      1
TpWorkerFactory 6


从WinDBG输出结果我们可以看到所有句柄的类型和值,以及统计信息(一共392个handle,其中有35个文件句柄,47个注册表句柄 .... )。

 

 

如果想查看某个句柄的详细信息, 可以用命令:

 

0:014> !handle 0x5c8 f
Handle 5c8
  Type          Key
  Attributes    0
  GrantedAccess 0x20019:
         ReadControl
         QueryValue,EnumSubKey,Notify
  HandleCount   2
  PointerCount  3
  Name          /REGISTRY/USER/S-1-5-21-2127521184-1604012920-1887927527-2966534/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts
  Object Specific Information
    Key last write time:  16:52:14. 5/20/2009
    Key name FileExts

 

0x5c8 是句柄的值, 参数f 表示显示全部信息。 我们可以看到句柄0x5c8 是注册表句柄,路径为/REGISTRY/USER/S-1-5-21-2127521184-1604012920-1887927527-2966534/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts。

 

 

值得一提的是,WinDBG 还提供了!htrace 命令,可以很方便来用检查句柄泄露(Handle Leak), 下次再写篇blog 专门介绍 !htrace

 

 

>> 原创文章的版权属于作者,转载请注明出处(http://blog.csdn.net/WinGeek/), 谢谢。 <<

 

 

原创粉丝点击