我在读灰帽子Python
我从书上抄了代码,但似乎不起作用。
其他人对这本书也有问题,但不是在我所处的阶段。
我复制了我的调试器_定义.py如书中所述:http://dpunkt.de/leseproben/3245/Quellcodes.zip
有一个我的_调试器.py我也试过了,没用。
是的,我正在根据需要使用Python2.5
问题是它显示出:“[*]无法附加到进程。
有个错误“
我真的不知道问题出在哪里。
这是我的版本_调试器.py(不用担心德国人的评论)from ctypes import *
from my_debugger_defines import *
kernel32 = windll.kernel32
class debugger():
def __init__(self):
self.h_process = None
self.pid = None
self.debugger_active = False
def load(self, path_to_exe):
#Bestimmt wie der Prozess zu erzeugen ist, zb CREATE_NEW_CONSOLE
creation_flags = DEBUG_PROCESS
#Strukturen instanzieren
startupinfo = STARTUPINFO()
process_information = PROCESS_INFORMATION()
#die beiden flags ermoeglichen es den prozess in einem eigenen fenster da zu stellen
startupinfo.dwFlags = 0x1
startupinfo.wShowWindow = 0x0
#cb Countbyte
startupinfo.cb = sizeof(startupinfo)
if kernel32.CreateProcessA(path_to_exe,
None,
None,
None,
None,
creation_flags,
None,
None,
byref(startupinfo),
byref(process_information)
):
print "[*] Process erfolgreich gestarted"
print "[*] PID: %d" % process_information.dwProcessId
else:
print "[*] Erorr: 0x%08x" % kernel32.GetLastError()
#Anfordern des gewuenschten Access fuer einen Prozess mit der angegeben pid
def open_process(self, pid):
h_process = kernel32.OpenProcess(PROCESS_ALL_ACCESS,False,pid)
return h_process
def attach(self, pid):
#oeffnen des Processhandels mit dem gewuenschten recht
self.h_process = self.open_process(pid)
#Versuch sich an den Process anzukopeln
if kernel32.DebugActiveProcess(pid):
self.debugger_active = True
self.pid = int(pid)
else:
print "[*] Unable to attach to the process"
def run(self):
#Waren auf DebugEvents
while self.debugger_active:
self.get_debug_event()
def get_debug_event(self):
debug_event = DEBUG_EVENT()
continue_status = DBG_CONTINUE
if kernel32.WaitForDebugEvent(byref(debug_event), INFINITE):
raw_input("Press a key to continue...")
self.debugger_active = False
kernel32.ContiuneDebugEvent(\
debug_event.dwProcessId, \
debug_event.dwThreadId, \
continue_status)
def detach(self):
if kernel32.DebugActiveProcessStop(self.pid):
print "[*] Finished debugging. Exiting..."
return True
else:
print "Error"
return False
这是我用来测试的代码
^{pr2}$
感谢您的帮助:)