سورس کد من به این شکل است :
فایل my_debugger:
from ctypes import *
from my_debugger_define import *keel32 = windll.keel32
class debugger():
def __init__(self):
pass
self.h_Process = None
self.pid = None
self.debugger_active = False
def load(self,path_to_exe):
creation_flags = DEBUG_PROCESS
startupinfo = STARTUPINFO()
process_information = PROCESS_INFORMATION()
startupinfo.dwFlags = 0x1
startupinfo.wShowWindow = 0x0
startupinfo.cb = sizeof(startupinfo)
if keel32.CreateProcessA(path_to_exe,
None,
None,
None,
None,
creation_flags,
None,
None,
byref(startupinfo),
byref(process_information)):
self.h_Process = self.open_Process(process_information.dwProcessId)
print "[*] We have successfully launched the process!"
print "[*] PID: %d" % process_information.dwProcessId
else:
print "[*] Error: 0x%08x." % keel32.GetLastError()def open_Process(self, pid):
PROCESS_ALL_ACCESS = (0x000F0000L | 0x00100000L | 0xFFF)
h_Process = keel32.OpenProcess(PROCESS_ALL_ACCESS, False, pid)
retu h_Processdef attach(self, pid):
self.h_Process = self.open_Process(pid)
# We attempt to attach to the Process
# if this fails we exit the call
if keel32.DebugActiveProcess(pid):
self.debugger_active = True
self.pid = int(pid)
self.run()
else:
print "[*] Unable to attach to the Process."def run(self):
# Now we have to poll the debuggee for
# debugging events
while self.debugger_active == True:
self.get_debug_event()def get_debug_event(self):
debug_event = DEBUG_EVENT()
continue_status = DBG_CONTINUE
if keel32.WaitForDebugEvent(byref(debug_event), INFINITE):
# We aren't going to build any event handlers
# just yet. Let's just resume the Process for now.
raw_input("Press a key to continue...")
self.debugger_active = False
keel32.ContinueDebugEvent(debug_event.dwProcessI d,debug_event.dwThreadId,continue_status)def detach(self):
if keel32.DebugActiveProcessStop(self.pid):
print "[*] Finished debugging. Exiting..."
retu True
else:
print "There was an error"
retu False
فایل my_debugger_define :
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),
]
من تو ویندوز xp sp3 تو pycharm این کد رو اجرا میکنم اما این اررور رو برمیگردونه :
File "C:GrayHatPymy_debbuger.py", line 58, in get_debug_event
debug_event = DEBUG_EVENT()
NameError: global name 'DEBUG_EVENT' is not defined
مشکل از کجاست ؟؟؟
در ضمن این کد مربوط به کتاب Grayaht for paython هست...
برچسب:
نویسنده: محمد رضا جوادیان