Skip to content

Instantly share code, notes, and snippets.

@securitytube
Created November 1, 2014 11:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save securitytube/bac5d8228b49caa5c3ee to your computer and use it in GitHub Desktop.
Save securitytube/bac5d8228b49caa5c3ee to your computer and use it in GitHub Desktop.
Export DLL Functions into a DEF file for use with Mingw32/64
#!/usr/bin/python
"""
Author - Vivek Ramachandran
Learn Pentesting Online -- http://PentesterAcademy.com/topics and http://SecurityTube-Training.com
Free Infosec Videos -- http://SecurityTube.net
"""
import sys, pefile
dllName = sys.argv[1]
newDllName = sys.argv[2].replace(".dll", "")
pe = pefile.PE(dllName)
if not hasattr(pe, 'DIRECTORY_ENTRY_EXPORT') :
print "No Export table! Is this a DLL??"
sys.exit(-1)
# Lets create a DEF file for gcc/ld (mingw)
print "LIBRARY \"" + dllName.replace(".dll","") + "\""
print "EXPORTS\n"
for exp in pe.DIRECTORY_ENTRY_EXPORT.symbols:
if exp.name :
print "%s=%s.%s @%d" % (exp.name, newDllName, exp.name, exp.ordinal)
else :
print "ord%d=%s.ord%d @%d NONAME" %(exp.ordinal, newDllName, exp.ordinal, exp.ordinal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment