我正在读Gray Hat Python,我抄袭了书中的代码,但它似乎不起作用。其他人对这本书也有问题,但不是在我所处的阶段。我从这里复制了书中描述的my_debugger_defines.py:http://dpunkt.de/leseproben/3245/Quellcodes.zip里面也有一个my_debugger.py,我也试过了,不工作。是的,我正在按照要求使用Python2.5,问题是它会显示:"*无法连接到进程。出现错误“,老实说,我不知道问题出在哪里。这是我的my_debugger.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下面是我测试它的代码
import my_debugger
debugger = my_debugger.debugger()
pid = raw_input("Enter PID of process to attach to:")
debugger.attach(int(pid))
debugger.detach()感谢您的帮助:)
发布于 2014-01-16 13:14:47
我刚刚在使用Windows7时遇到了这个问题,这与这些调试功能不适用于64位程序有关。
您可以通过更改行来获得有关它是什么错误的报告,如下所示:
print "[*] Unable to attach to the process [%d] - %s" % (int(pid), FormatError(kernel32.GetLastError()))如果您尝试附加到用户以外的其他32位程序,例如系统,这不起作用-您得到‘访问被拒绝’。
我在“免疫调试器”上试过了(比如,我加载了免疫并附加到它的进程),这确实起作用了,所以我假设它适用于你拥有的所有*32个进程。
发布于 2015-12-19 13:42:08
如果您运行的是Windows 7(64位操作系统),请从Windows/sysWOW64目录运行calc,这是32位文件,您可以通过查看任务管理器来辨别它的32位版本,它会在32位版本旁边显示*32,无论如何,当我使用该calc时,该程序对我有效
发布于 2016-11-03 14:25:58
我也用C语言编写了一个简单的调试器,但当我使用DebugActiveProcess(pi.dwProcessId)时,它显示了错误代码87。我的程序的问题是bits.It取决于您是否在64位操作系统上以64位模式编译调试器。由于Python是一种解释型语言,您必须了解它是如何编译的.if python是32位编译的,那么您必须选择32位程序进行调试
https://stackoverflow.com/questions/20807108
复制相似问题