2010-03-18 6 views
0

Je lis le chapeau gris Python ,, j'atteins pour cette ::Débogueur simple, voulez travailler?

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() 
     process_information = PROCESS_INFORMATION() 
     startupinfo.dwFlags = 0x1 
     startupinfo.wShowWindows = 0x0 
     startupinfo.cb = sizeof(startupinfo) 
     if kernel32.CreateProcessA(path_to_exe, 
            None, 
            None, 
            None, 
            None, 
            creation_flags, 
            None, 
            None, 
            byref(startupinfo), 
            byref(process_information)): 
      print "[*] We have successfully launched the process!" 
      print "[*] PID: %d"%(process_information.dwProcessId) 
      self.h_process = self.open_process(process_information.dwProcessId) 

     else: 
      print "[*] Error: 0x%08x."%(kernel32.GetLastError()) 

    def open_process(self,pid): 
     h_process = self.open_process(pid) 
     if kernel32.DebugActiveProcess(pid): 
      self.debugger_active = True 
      self.pid = int(pid) 
      self.run() 
     else: 
      print "[*] Unable to attach to the 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): 
      raw_input("Press a Key to continue...") 
      self.debugger_active = False 
      kernel32.ContinueDebugEvent(\ 
       debug_event.dwProcessId, \ 
       debug_event.dwThreadId, \ 
       continue_status) 
    def detach(self): 
     if kernel32.DebugActiveProcessStop(self.pid): 
      print "[*] Finished debugging. Exiting..." 
      return True 
     else: 
      print "There was an error" 
      return False 

lorsqu'il est exécuté my_test.py ::

import my_dbg 

debugger = my_dbg.debugger() 
pid = raw_input('Enter the PID of the process to attach to: ') 
debugger.open_process(int(pid)) 
debugger.detach() 

je reçois cette erreur ::

Traceback (most recent call last): 
    File "C:/Python26/dbgpy/my_test.py", line 5, in <module> 
    debugger.attach(int(pid)) 
    File "C:/Python26/dbgpy\my_dbg.py", line 37, in attach 
    h_process = self.attach(pid) 
    ........... 
    ........... 
    ........... 
    File "C:/Python26/dbgpy\my_dbg.py", line 37, in attach 
    h_process = self.attach(pid) 
    File "C:/Python26/dbgpy\my_dbg.py", line 37, in attach 
    h_process = self.attach(pid) 
RuntimeError: maximum recursion depth exceeded 

c'est parce que la boucle et quelque chose d'autre, mais qu'est-ce que c'est ?? Je suis en cours d'exécution sur Windows en utilisant Python2.6.4 .. :)

mise à jour ::

trouvé le problème tient à remercier tous ,, ce travail de code :) grand

from ctypes import * 
from my_dbg_def import * 
kernel32 = windll.kernel32 
class debugger(): 
    def __init__(self): 
     self.h_process = None 
     self.pid = None 
     self.debugger_active = False 

    def open_process(self,pid): 
     h_process = kernel32.OpenProcess(PROCESS_ALL_ACCESS,pid,False) 
     return h_process 

    def attach(self,pid): 

     self.h_process = self.open_process(pid) 

     if kernel32.DebugActiveProcess(pid): 
      self.debugger_active = True 
      self.pid = int(pid) 

     else: 
      print "[*] Unable to attach to the 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): 
      raw_input("Press a key to continue...") 
      self.debugger_active = False 
      kernel32.ContinueDebugEvent(\ 
      debug_event.dwProcessId, \ 
      debug_event.dwThreadId, \ 
      continue_status) 
    def detach(self): 
     if kernel32.DebugActiveProcessStop(self.pid): 
      print "[*] Finished debugging. Exiting..." 
      return True 
     else: 
      print "There was an error" 
      return False 
+1

Vous n'avez pas collé le code à votre méthode d'attachement, où la récursion se produit apparemment, il est donc impossible d'être utile. SVP éditez votre Q pour montrer ce code. –

Répondre

1

I supposons qu'à un certain point, vous ayez changé le nom de attach à open_process (comme il semble d'après la sortie de la traceback).
Dans ce cas, l'erreur est ici:

def open_process(self,pid): 
    h_process = self.open_process(pid) 

Comme vous pouvez le voir, il est récursivement appelle.
Il me semble que vous l'avez pour copier &, alors peut-être vous pouvez le supprimer en toute sécurité.