python-3.x - 如何使用Python3从dll中查找函数名称?

标签 python-3.x dllimport

我正在学习如何使用原生 Windows dll 文件与 Python3硬件进行交互。但是使用 ctypes 我可以找到 dll 文件,但是无法找到 dll 中公开的功能。

我在 googlestackoverflow 等各个地方进行了搜索,但无法找到问题的解决方案。

例如:

import ctypes
data = ctypes.CDLL("WWanAPI.dll")

当我尝试 dir(data) 功能时,我得到了以下响应: ['_FuncPtr'、'__class__'、'__delattr__'、'__dict__'、'__dir__'、'__doc__'、'__eq__'、'__format__'、'__ge__'、'__getattr__'、'__getattribute__'、'__getitem__ ', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__'、'__sizeof__'、'__str__'、'__subclasshook__'、'__weakref__'、'_func_flags_'、'_func_restype_'、'_handle'、'_name']

任何见解都将有助于找到 dll 的所有功能。

最佳答案

ctypes 模块不提供此类功能,因为 Windows 没有提供用于迭代 DLL 内容的函数。

您想要的是检查 DLL 的内容。它只是一个文件,并且位于“可移植可执行文件”( PE format ) 中,因此您需要可以读取该格式文件的机制。

如果您只需要一个命令行工具,请查看 dumpbin。

一个很好的答案:https://stackoverflow.com/a/24732280/963195 以及这里的各种好的答案:Is there a way to find all the functions exposed by a dll

...这是一个 Python 模块:

https://github.com/erocarrera/pefile

关于python-3.x - 如何使用Python3从dll中查找函数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58839481/

相关文章:

python - 为什么 Python 中的命名表达式需要专用语法(:=, 海象运算符)?

python - AccessToken匹配查询不存在

add-in - C# : Excel 2007 Addin, 如何 Hook Windows 激活和停用事件

c# - 在 C# 中使用委托(delegate)作为 C DllImported 函数的回调

python - 社区中在同一代码库中使用 python 2.x 和 3.x 的首选方法是什么?

python - Discord.py 记录删除和编辑的消息

c# - 使用 Matrox 命令捕获帧

C# : Pass int array to c++ dll

c# - Blazor 项目中的 C++ DLL

python - 如何进行二维切片?