代码之家  ›  专栏  ›  技术社区  ›  shiva Ram G Athreya

如何使用Python3从dll中查找函数名?

  •  0
  • shiva Ram G Athreya  · 技术社区  · 7 年前

    我正在学习如何互动 Python3 具有 hardware 使用朴素的窗口 dll 文件夹。但是使用ctypes我可以找到 动态链接库 但是,无法从中找到公开的功能 动态链接库 .

    我搜索了一下 google , stackoverflow

    例如:

    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']

    任何见解都将有助于找到 动态链接库 .

    0 回复  |  直到 7 年前
        1
  •  0
  •   Andrew E    7 年前

    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