[D]《Python灰帽子:黑客与逆向工程师的Python编程之道》第4.3.1节例子程序运行错误!请高人指点。

ycangmsw 2012-04-04 01:01:01
第4.3.1源程序如下,通过pydbg获取和保存“C:\\WINDOWS\\System32\\calc.exe”快照,但在输入“restore”指令后提示错误:PDBG_ERR> -- IGNORING ERROR --
PDBG_ERR> process_restore: [87] WriteProcessMemory(000d0000, ..., 212992): 参数错误。
在pydbg源代码里也没看出问题,有晓得的帮帮忙啊!

#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

# Start the debugger thread, and loop until it sets the PID
# of our target process
pydbg_thread = threading.Thread(target=self.start_debugger)
pydbg_thread.setDaemon(0)
pydbg_thread.start()
while self.pid == None:
time.sleep(1)

# We now have a PID and the target is running; let's get a
# second thread running to do the snapshots
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' or 'quit'")
input = input.lower().strip()
if input == "quit":
print "
  • Exiting the snapshotter."
    self.running = False
    self.dbg.terminate_process
  • ()
    elif input == "snap":
    print "
  • Suspending all threads."
    self.dbg.suspend_all_threads
  • ()
    print "
  • Obtaining snapshot."
    self.dbg.process_snapshot
  • ()
    print "
  • Resuming operation."
    self.dbg.resume_all_threads
  • ()
    elif input == "restore":
    print "
  • Suspending all threads."
    self.dbg.suspend_all_threads
  • ()
    print "
  • Restoring snapshot."
    self.dbg.process_restore
  • ()
    print "
  • Resuming operation."
    self.dbg.resume_all_threads
  • ()

    def start_debugger(self):
    self.dbg = pydbg()
    pid = self.dbg.load(self.exe_path) #pydbg.load()
    self.pid = self.dbg.pid
    self.dbg.run()

    exe_path = "C:\\WINDOWS\\System32\\calc.exe"
    snapshotter(exe_path)

-----------
Double行动:
原帖分数:100
加分:100
...全文
730 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
bugs2k 2012-07-02
  • 打赏
  • 举报
回复
还没有看过这本书,请问这本书如何?
Harry_monkey 2012-07-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 6 楼 的回复:

原来是操作系统的原因,在XP下可以,但在WIN7下不行。XP下要在窗口刷新后才能看到“restore”的效果。

那个在XP下你说的刷新是怎么个刷新法?
[/Quote]

刷新就是把窗口最小化,在还原就行。
出了这个错误不要紧,仍然有“restore”的效果。
restore时重新将很多内容写入内存,只有一个写入失败没有影响最后要显示的效果
chen_999876 2012-05-16
  • 打赏
  • 举报
回复
你没有保存快照,一上来就恢复,到哪里去恢复啊!
先要在你想要保存快照的地方snap,然后进行相应的操作,当要恢复快照的时候再restore,这样就恢复到了保存快照的地方
liuchen513 2012-05-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

原来是操作系统的原因,在XP下可以,但在WIN7下不行。XP下要在窗口刷新后才能看到“restore”的效果。
[/Quote]
那个在XP下你说的刷新是怎么个刷新法?
loveisbug 2012-04-09
  • 打赏
  • 举报
回复
译者说他调试过所有代码,直接问译者吧。
ycangmsw 2012-04-09
  • 打赏
  • 举报
回复
原来是操作系统的原因,在XP下可以,但在WIN7下不行。XP下要在窗口刷新后才能看到“restore”的效果。
坚强的豁着 2012-04-07
  • 打赏
  • 举报
回复
没看懂这些方法,估计要看看这些模块的文档吧
ycangmsw 2012-04-04
  • 打赏
  • 举报
回复
呵呵。谢谢啦
fibbery 2012-04-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
我晕!编辑时好好的,怎么完了格式全乱了!各将就着看吧,谢谢!
[/Quote]

使用
将代码包围起来。
ycangmsw 2012-04-04
  • 打赏
  • 举报
回复
我晕!编辑时好好的,怎么完了格式全乱了!各将就着看吧,谢谢!

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧