Pykd——Python extension for WinDbg



本文转载于: http://blog.csdn.net/n1ghtSir/article/details/48636163

 

在使用windbg脚本的时候,感觉很不方便。有时候想根据断点触发时的栈信息判断是否需要继续,但是没法定义变量来获取那些值,即便使用$tn和$un之类的伪变量获取那些值也很难进行复杂的判断或者运算。所以还是需要有更灵活的语言来辅助,所以找到了Pykd,虽然Immunity可以取代它,但有时不得不用windbg,接下来就让我们来学习下这个插件。

一、安装

从官网(https://pykd.codeplex.com/releases)下载对应版本双击便是。假如是手动安装,只需要将pykd.pyd复制到windbg安装目录的winext目录。

打开windbg,在命令行输入:

.load pykd.pyd
!py help
!pycmd

测试是否安装成功。

二、使用

可以在!pycmd中进行命令交互,也可以输入脚本:!py file1.py。下面重点说下常用的API:

Functions

 

Classes

常量:

Breakpoint事件类型lastEvent()返回
ChangeDebuggeeState事件类型lastEvent()返回
ChangeEngineState  事件类型 lastEvent()返回
ChangeSymbolState  事件类型 lastEvent()返回
CreateProcess 事件类型lastEvent()返回
CreateThread 事件类型lastEvent()返回
Exception 事件类型lastEvent()返回
ExitProcess 事件类型lastEvent()返回
ExitThread 事件类型lastEvent()返回
LoadModule 事件类型lastEvent()返回
SessionStatus 事件类型lastEvent()返回
SystemError 事件类型lastEvent()返回
UnloadModule 事件类型lastEvent()返回


BaseException 异常类型
SymbolException 异常类型
TypeException 异常类型
WaitEventException 异常类型
MemoryException  异常类型
WrongEventTypeException 异常类型


DebugAccessIo Debug Access Type
Read Debug Access Type
Execute Debug Access Type
Write Debug Access Type


Debug Attributes of the file
InfoInferred Attributes of the file
FileFlag Attributes of the file
SpecialBuild Attributes of the file
Patched Attributes of the file
PreRelease Attributes of the file
PrivateBuild Attributes of the file

FixedFileInfo Version information for a file

 

根据以上API,我们完全可以写一个自动化调试脚本。

例1:获取某进程所有加载模块

复制代码
from pykd import *
startProcess("c:\\windows\\system32\\calc.exe",1)
modules=dbgCommand('lm 1m').split('\n')
for md in modules:
    try:
        obj_md=module(str(md))
        print obj_md
    except BaseException:
        pass
while 1:
    go()
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值