Python Ctypes:访问冲突写入

Python Ctypes:访问冲突写入,python,ctypes,Python,Ctypes,我在研究ctypes的一些函数时遇到了这个问题: import ctypes hello = open("hello.exe") shellcode = hello.read() shellcode_buffer = ctypes.create_string_buffer(shellcode, len(shellcode)) shellcode_func = ctypes.cast(shellcode_buffer, ctypes.CFUNCTYPE(ctypes.c_void_p))

我在研究ctypes的一些函数时遇到了这个问题:

import ctypes

hello = open("hello.exe")
shellcode = hello.read()

shellcode_buffer = ctypes.create_string_buffer(shellcode, len(shellcode))

shellcode_func = ctypes.cast(shellcode_buffer, ctypes.CFUNCTYPE(ctypes.c_void_p))

shellcode_func()
我用这种方式从powershell创建了hello.exe

Add-Type -outputtype consoleapplication -outputassembly helloworld.exe 'public class helloworld{public static void Main(){System.Console.WriteLine("hello world");}}'
运行python时,我得到了这个错误

WindowsError: exception: access violation writing 0x70098553

该函数看起来不像C。您确定它与
ctypes.CFUNCTYPE
兼容吗?首先,它应该使用标准的C调用约定,
cdecl
,您提供的可能是
stdcall
。请改为尝试
ctypes.WINFUNCTYPE
。该函数看起来不像C。您确定它与
ctypes.CFUNCTYPE
兼容吗?首先,它应该使用标准的C调用约定,
cdecl
,您提供的可能是
stdcall
。请改为尝试
ctypes.WINFUNCTYPE