Python Ctypes Windows访问冲突读取内存位置

2024-09-24 00:27:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python编写一个应用程序,它使用Deviare用户模式钩住COM引擎。我挂接的函数之一是CreateProcessA,但我似乎在将挂接函数的适当指针传递到cTypesKernel32.CreateProcess调用时遇到了困难。我的目标是停止对CreateProcess的合法调用,并在挂起状态下重新创建它。在

如果需要,函数参数的Deviare文档如下:Deviare - Parameters

另外,用于创建过程的MSDN: kernel32.CreateProcessA

下面是我的ctypes调用,在此之前我不实例化任何东西,也不使用“args”设置函数定义,在这种情况下有必要吗?在

“parameters”是DeviceAre中的一个对象,其中包含传递给挂接函数(CreateProcessA)的函数参数

retval = ctypes.windll.kernel32.CreateProcessA(
ctypes.wintypes.LPCWSTR(parameters.GetAt(0).Value),
ctypes.wintypes.LPCWSTR(parameters.GetAt(1).Value),
ctypes.c_ulong(parameters.GetAt(2).PointerVal),
ctypes.c_ulong(parameters.GetAt(3).PointerVal),
ctypes.wintypes.BOOL(parameters.GetAt(4).Value),
ctypes.wintypes.DWORD(0x4),
ctypes.wintypes.LPVOID(parameters.GetAt(6).PointerVal),
ctypes.wintypes.LPCWSTR(parameters.GetAt(7).Value),
ctypes.cast(parameters.GetAt(8).PointerVal, ctypes.POINTER(ctypes.c_ulong)),
ctypes.cast(parameters.GetAt(9).PointerVal, ctypes.POINTER(ctypes.c_ulong)))

我的错误和一些有用的/类型化的参数被传递到新的CreateProcess调用:

^{pr2}$

有时访问冲突的位置在lpstartupinfo的开头,有时在lpstartupinfo的中间。我不知道为什么,除非我的环境有问题。在

我已经确认LPSTARTUPINFO和LPPROCESS_信息在调试器中的位置是正确的。在


Tags: 函数value函数参数ctypesparameterscastcreateprocessulong