开发者

When loading a dll in Python does the dir function shows its methods?

开发者 https://www.devze.com 2022-12-17 04:51 出处:网络
Does this code shows the methods from a dll? from ctypes import * x = cdll.LoadLibrary(\"olari.dll\") dir(x)

Does this code shows the methods from a dll?

from ctypes import *
x = cdll.LoadLibrary("olari.dll")
dir(x)

if not, how can we see the .d开发者_如何学Pythonll methods in python?


No, it doesn't. But It can cache when you call, and will show in dir after that.

You could take a look this SO Thread, even in Win32, seems like need to parse PE Header. I think python need to do similar way.

UPDATE:

I found pefile read/write module written in python, there you can find exported entries.

for entry in pe.DIRECTORY_ENTRY_IMPORT:
  print entry.dll
  for imp in entry.imports:
    print '\t', hex(imp.address), imp.name
Output
comdlg32.dll
        0x10012A0L PageSetupDlgW
        0x10012A4L FindTextW
        0x10012A8L PrintDlgExW
[snip]
SHELL32.dll
        0x1001154L DragFinish
        0x1001158L DragQueryFileW

imp.name will be the one you are looking for. You could use that name in ctypes like

>>> ctypes.windll.comdlg32.PageSetupDlgW
<_FuncPtr object at 0x00A97210>
>>> ctypes.windll.comdlg32.FindTextW
<_FuncPtr object at 0x00A97288>
...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号