python - 使用 python 内省(introspection) DLL

标签 python ctypes

我目前正在尝试使用 python 对 DLL 进行一些内省(introspection)。我想自动创建一个基于DLL的图形测试界面。

我可以很容易地在 python 中加载我的 DLL,并且调用一些函数。主要问题是,如果我在对象上调用“dir”而不调用任何方法,我就会得到结果

>>> dir(myLib)
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__',
'__format__', '__getattr__', '__getattribute__', '__getitem__', '__hash__', '__i
nit__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__s
etattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_func_fl
ags_', '_func_restype_', '_handle', '_name']

当我手动调用一个函数(如“Read_Version”)时,我得到了 dir 函数的结果

>>> dir(myLib)
['Read_Version', '_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__',
'__format__', '__getattr__', '__getattribute__', '__getitem__', '__hash__', '__i
nit__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__s
etattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_func_fl
ags_', '_func_restype_', '_handle', '_name']

看来内省(introspection)仅适用于我已经调用的函数,这并不是真正的“有用”;)。

您还有其他想法来获取 DLL 中的函数吗? (当然是用Python)

我在 Windows 下使用 python 2.6。

最佳答案

据我所知,没有简单的方法可以做到这一点。您必须使用一些外部工具(例如 link/dump/exports)或使用 PE/DLL 解析器(例如 pefile )。

关于python - 使用 python 内省(introspection) DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1642938/

相关文章:

Python += 与全局变量函数内的 .extend()

python - 在 python 中使用 Win32 IPHelper API 的问题

linux - os.read 在 inotify 文件描述符 : reading 32 bytes works but 31 raises an exception 上

Python3k ctypes printf

python - 在 Fabric 中如何从远程路径创建全局列表

jquery - 通过 AJAX 发送的列表并与 Django 中看似相同的列表进行比较返回 false

python - 如何使用 QStyledItemDelegate 只绘制背景,而不覆盖文本?

python - 用装饰器包装的函数的关键字参数不起作用

Python:ctypes 指向局部变量的指针;如何确保他们不被释放?

python - 使用 SWIG 用指针参数包装 C 函数