使用pydbg扩展断点处理过程

debugee:

from ctypes import *
import time

msvcrt = cdll.msvcrt
counter = 0

while 1:
    msvcrt.printf("Loop iteration %d!\n",counter)
    time.sleep(2)
    counter += 1

使用pydbg来扩展处理过程

在msvcrt.printf处下断处理

#coding=utf-8

from pydbg import *
from pydbg.defines import *

import struct,random

def printf_randomizer(dbg):

    parameter_addr=dbg.context.Esp+0x8
    counter=dbg.read_process_memory(parameter_addr,4)

    counter=struct.unpack("L",counter)[0]
    print "counter: %d",int(counter)

    random_counter=random.randint(1,900)
    random_counter=struct.pack("L",random_counter)[0]

    dbg.write_process_memory(parameter_addr,random_counter)

    return DBG_CONTINUE

dbg=pydbg()

pid=raw_input('>')
dbg.attach(int(pid))

printf_address=dbg.func_resolve("msvcrt","printf")
dbg.bp_set(printf_address,description="printf_address",handler=printf_randomizer)

dbg.run()

结果如下:

C:\Users\test\Desktop\pythonblack\4>python printf_loop.py
Loop iteration 0!
Loop iteration 1!
Loop iteration 2!
Loop iteration 3!
Loop iteration 4!
Loop iteration 5!
Loop iteration 6!
Loop iteration 7!
Loop iteration 8!
Loop iteration 21!
Loop iteration 36!
Loop iteration 103!
Loop iteration 86!
Loop iteration 185!
Loop iteration 116!
Loop iteration 46!
Loop iteration 153!
Loop iteration 122!
Loop iteration 238!
C:\Users\test\Desktop\pythonblack\4>python printf_random.py
>4472
counter: %d 9
counter: %d 10
counter: %d 11
counter: %d 12
counter: %d 13
counter: %d 14
counter: %d 15
counter: %d 16
counter: %d 17
counter: %d 18
counter: %d 19
counter: %d 20
counter: %d 21
counter: %d 22
counter: %d 23
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值