在python中运行程序时出现问题

时间:2017-11-13 18:41:54

标签: python

我有以下文件

my_test.py

import my_debugger
debugger =my_debugger.debugger()
debugger.load("C:\\windows\\system32\\calc.exe")

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):
 creation_flags = DEBUG_PROCESS
 startupinfo = STARTUPINFO()
 process_information = PROCESS_INFORMATION
 startupinfo.dwflags =0x1
 startupinfo.wShowWindow = 0x0
 startupinfo.cb = sizeof(startupinfo)

 if kernel32.CreateProcessA(path_to_exe, None, None, None, None, byref(startupinfo),byref(process_information)):
     print( "[*] we have succedfully lanunched the prcoess")
     print ("[*] PID:  %d" % process_information.dwProcessId)
 else:
     print("[*} error: 0x%08x." % kernel32.GetLastError())

my_debugger_defines.py

from ctypes import *

# mirosoft types to ctypes

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 createpressa() fuction
class STARTUPINFO(Structure):
_fields_ = [
    ("cb",    DWORD),
    ("lpReserved",   LPTSTR),
    ("lpDesktop",   LPTSTR),
    ("lpTitle",     LPTSTR),
    ("dwX",        DWORD),
    ("dwY",        DWORD),
        ("dwXSize",    DWORD),
    ("dwYsize",    DWORD),
    ("dsXCountChars",   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_test.py时出现以下错误

C:\download\New folder (6) (1)\Programowanie>python my_test.py

追踪(最近一次通话):   文件“my_test.py”,第3行,in     debugger.load( “C:\ Windows \ System32下\ CALC.EXE”)   文件“C:\ download \ New folder(6)(1)\ Programowanie \ my_debugger.py”,第19行,加载     如果kernel32.CreateProcessA(path_to_exe,None,None,None,None,byref(startupinfo),byref(process_information)): TypeError:byref()参数必须是ctypes实例,而不是'_ctypes.PyCStructType'

C:\ download \ New folder(6)(1)\ Programowanie>

你知道如何修复错误吗?

0 个答案:

没有答案