又是我。我将继续我的 C 和 Python 之旅。
今天正好在做一个调试器。目前,这就是我所拥有的
from ctypes import *
from Debugdeclares 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):
creation_flags = DEBUG_PROCESS
startupinfo = STARTUPINFO()
processinfo = PROCESS_INFORMATION()
startupinfo.dwFlags = 0x1
startupinfo.wShowWindow = 0x0
startupinfo.cb = sizeof(startupinfo)
if kernel32.CreateProcessA(path_to_exe,None,None,None,None,creation_flags,None,None,byref(startupinfo),byref(processinfo)):
print("[n] Process launched")
print("[n] Process location: %s" % (path_to_exe))
print("[n] PID: %d" % (processinfo.dwProcessId))
self.h_process = self.open_process(processinfo.dwProcessId)
return processinfo.dwProcessId
else:
print("[n] Error: 0x%08x." % (kernel32.GetLastError()))
def open_process(self, pid):
h_process = kernel32.OpenProcess(PROCESS_ALL_ACCESS,pid,False)
这是错误点所在,未定义 PROCESS_ALL_ACCESS。但是,在 ctypes 库中,有一个该关键字的输入。我曾尝试使用字符串、字节字符串,但无济于事。以下是有关 OpenProcess 功能以及有关进程安全性和访问权限的一些附加信息
return h_process
def attach(self, pid):
self.h_process = self.open_process(pid)
if kernel32.DebugActiveProcess(pid) == True:
self.debugger_active = True
self.pid = int(pid)
self.run()
else:
print("[n] Unable to Attach Process")
def run(self):
while self.debugger_active == True:
self.get_debug_event()
def get_debug_event(self):
debug_event = DEBUG_EVENT()
continue_status = DBG_CONTINUE
if kernel32.WaitForDebugEvent(byref(debug_event), INFINITE):
input("[n] Nothing to see yet...")
self.debugger_active = False
kernel32.ContinueDebugEvent( \
debug_event.dwProcessId, \
debug_event.dwThreadId, \
continue_status )
def detach(self):
if kernel32.DebugActiveProcessStop(self.pid):
print("[n] Finished debugging. Exiting...")
return True
else:
print("[n] There was an error")
return False
debugger = debugger()
pid = debugger.load(b"C:\\WINDOWS\\system32\\calc.exe")
debugger.attach(pid)
debugger.detach()
所以真的,我在问:什么是错误修复?
非常感激!-诺顿
编辑:哦,是的!这是我的 Debugdeclares 脚本:
from ctypes import *
WORD = c_ushort
DWORD = c_ulong
LPBYTE = POINTER(c_ubyte)
LPTSTR = POINTER(c_char)
HANDLE = c_void_p
DEBUG_PROCESS = 0x00000001
CREATE_NEW_CONSOLE = 0x00000010
class STARTUPINFO(Structure):
_fields_ = [
("cb", DWORD),
("lpReserved", LPTSTR),
("lpDesktop", LPTSTR),
("lpTitle", LPTSTR),
("dwX", DWORD),
("dwY", DWORD),
("dwXSize", DWORD),
("dwYSize", DWORD),
("dwXCountChars", DWORD),
("dwYCountChars", DWORD),
("dwFillAttribute",DWORD),
("dwFlags", DWORD),
("wShowWindow", WORD),
("cbReserved2", WORD),
("lpReserved2", LPBYTE),
("hStdInput", HANDLE),
("hStdOutput", HANDLE),
("hStdError", HANDLE),
]
class PROCESS_INFORMATION(Structure):
_fields_ = [
("hProcess", HANDLE),
("hThread", HANDLE),
("dwProcessId", DWORD),
("dwThreadId", DWORD),
]