2016-10-28 2 views
0

im пытается запустить исходный код примитивного отладчика в python , но im сталкивается с ошибкой, и я не знаю, почему это так. Вы можете иметь исходный код здесь. благодарим вас заранее.мой отладчик python сталкивается с ошибкой

my_debugger_defines.py

from ctypes import * 
# Let's map the Microsoft types to ctypes for clarity 
WORD = c_ushort 
DWORD = c_ulong 
LPBYTE = POINTER(c_ubyte) 
LPTSTR = POINTER(c_char) 
HANDLE = c_void_p 
# Constants 
DEBUG_PROCESS = 0x00000001 
CREATE_NEW_CONSOLE = 0x00000010 
# Structures for CreateProcessA() function 
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), 
    ] 

my_debugger.py

from ctypes import * 
from my_debugger_defines import * 
kernel32 = windll.kernel32 
class debugger(): 
    def __init__(self): 
     pass 
    def load(self,path_to_exe): 
     # dwCreation flag determines how to create the process 
     # set creation_flags = CREATE_NEW_CONSOLE if you want 
     # to see the calculator GUI 
     creation_flags = DEBUG_PROCESS 
     # instantiate the structs 
     startupinfo = STARTUPINFO() 
     process_information = PROCESS_INFORMATION() 
     # The following two options allow the started process 
     # to be shown as a separate window. This also illustrates 
     # how different settings in the STARTUPINFO struct can affect 
     # the debuggee. 
     startupinfo.dwFlags = 0x1 
     startupinfo.wShowWindow = 0x0 
     # We then initialize the cb variable in the STARTUPINFO struct 
     # which is just the size of the struct itself 
     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 
     else: 
      print "[*] Error: {}".format(kernel32.GetLastError()) 

my_test.py

import my_debugger 
debugger = my_debugger.debugger() 
debugger.load("C:\\WINDOWS\\system32\\calcs.exe") 

работает my_test.py в консоли Windows дает мне ошибку такого рода

[*] Error: 0x00000002

+0

Я не готов к любви. – runningviolent

+1

lol no homo на самом деле я понятия не имею, как любители python обратились к любителям! – Millw0

+0

Почти дубликат [Как получить сообщение об ошибке из кода ошибки, возвращаемого GetLastError()?] (Http://stackoverflow.com/q/1387064/2800918) – CAB

ответ

1

У вас есть дополнительные 's'. Пытаться;

debugger.load("C:\\WINDOWS\\system32\\calc.exe") 
+0

О, черт побери! такая ошибка новобранец :)) большое спасибо CAB за ее работу сейчас – Millw0

Смежные вопросы