我目前正在尝试使用python对DLL进行一些内省。我想自动创建一个基于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']

当我手动调用一个函数(如<!> quot; Read_Version <!> quot;)时,我有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']

似乎内省只对我已经调用过的函数起作用,而且这不是真的<!> quot; usefull <!> quot; ;)

您是否有其他想法来获取DLL中的函数? (当然是在python中)

我在Windows下使用python 2.6。

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top