title: windll.kernel32.OpenProcess(PROCESS_ALL_ACCESS, PID, False): Process_all_Access not defined
body: <p>me again. I'm continuing my journey with C and Python.</p>
  
  <p>Today, I happened to be making a debugger.
  Currently, this is what I have</p>
  
  <pre><code>    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)
  </code></pre>
  
  <hr>
  
  <p>This is where the error spot is, PROCESS_ALL_ACCESS is not defined. However, in the ctypes library, there is an input of that keyword. I have attempted using strings, byte strings, but to no avail. Here is some additional information <a href="http://msdn.microsoft.com/en-us/library/ms684320.aspx" rel="nofollow">about the OpenProcess function</a> and <a href="http://msdn.microsoft.com/en-us/library/ms684880.aspx" rel="nofollow">about the Process Security and Access Rights</a></p>
  
  <hr>
  
  <pre><code>            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()
  </code></pre>
  
  <p>So really, I'm asking: What's a bug fix?</p>
  
  <p>Much Appreciated!
  -Norton</p>
  
  <p>EDIT:
  Oh yes!
  here is my Debugdeclares script:</p>
  
  <pre><code>    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),
          ]
  </code></pre>