2

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 .dll methods in python?

Idan K
  • 19,983
  • 9
  • 62
  • 83
aF.
  • 62,344
  • 41
  • 131
  • 195

1 Answers1

2

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>
...
Community
  • 1
  • 1
YOU
  • 114,140
  • 31
  • 183
  • 213
  • what code do I need to put before the one you gave for this to work? – aF. Jan 18 '10 at 11:17
  • Hi, you need to install that python library first - http://code.google.com/p/pefile/downloads/list – YOU Jan 18 '10 at 11:19