Python灰帽子-进程快照代码在win7下会报错

windows7下面运行脚本的顺序:

1 启动脚本

2 修改calc的显示内容

3 snap

4 再次修改calc的显示内容,注意:最小化calc窗口

5 restore,会报以下错误:

PDBG_ERR> -- IGNORING ERROR --

PDBG_ERR> process_restore: [87] WriteProcessMemory(000e0000, ..., 212992): 参数
错误。
resuming operation.

6 恢复calc窗口,会发现显示内容已经恢复了

应该是权限的问题。虚拟机的windows xp测试了一下,正常工作,没有错误。

#filename:snapshot.py
from pydbg import *
from pydbg.defines import *
import threading
import time
import sys

class snapshotter(object):
	def __init__(self, exe_path):
		self.exe_path = exe_path
		self.pid = None
		self.dbg = None
		self.running = True
		
		pydbg_thread = threading.Thread(target=self.start_debugger)
		pydbg_thread.setDaemon(0)
		pydbg_thread.start()
		
		while self.pid == None:
			time.sleep(1)
		
		monitor_thread = threading.Thread(target=self.monitor_debugger)
		monitor_thread.setDaemon(0)
		monitor_thread.start()
		
	def monitor_debugger(self):
		while self.running == True:
			input = raw_input("enter: 'snap', 'restore', 'quit'")
			input = input.lower().strip()
			
			self.process_pid(input)
			if input == 'quit':
				print "exiting the snapshotter."
				self.running = False
				self.dbg.terminate_process()
	
	def process_pid(self, input):
		print "suspending all threads"
		self.dbg.suspend_all_threads()
		if input == 'snap':
				print "obtaining snapshot."
				self.dbg.process_snapshot()
		elif input == 'restore':
				print "restore operation."
				self.dbg.process_restore()
		else:
			None
		print "resuming operation."
		self.dbg.resume_all_threads()
	
	def start_debugger(self):
		self.dbg = pydbg()
		pid = self.dbg.load(self.exe_path)
		self.pid = self.dbg.pid
		self.dbg.run()
		
exe_path = "c:\\windows\\system32\\calc.exe"
snapshotter(exe_path)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值