├── README.md └── mingw-ldd.py /README.md: -------------------------------------------------------------------------------- 1 | ### mingw-ldd 2 | 3 | Tool to list dependencies of a dll using python and winedump. 4 | 5 | Kudos to yan12125 for the original script: 6 | https://gist.github.com/yan12125/63c7241596e628553d21 7 | 8 | ## Requirements 9 | 10 | - Python 11 | - wine 12 | 13 | ## Usage 14 | 15 | $ ./mingw-ldd.py /usr/i686-w64-mingw32/bin/libpng16-16.dll 16 | libgcc_s_sjlj-1.dll => /usr/i686-w64-mingw32/bin/libgcc_s_sjlj-1.dll 17 | KERNEL32.dll => not found 18 | msvcrt.dll => not found 19 | libwinpthread-1.dll => /usr/i686-w64-mingw32/bin/libwinpthread-1.dll 20 | zlib1.dll => /usr/i686-w64-mingw32/bin/zlib1.dll 21 | 22 | ## See also 23 | 24 | You can also checkout another similar tool: 25 | https://github.com/LRN/ntldd 26 | -------------------------------------------------------------------------------- /mingw-ldd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # WTFPL - Do What the Fuck You Want to Public License 3 | from __future__ import print_function 4 | import pefile 5 | import os 6 | import sys 7 | 8 | 9 | def get_dependency(filename): 10 | deps = [] 11 | pe = pefile.PE(filename) 12 | for imp in pe.DIRECTORY_ENTRY_IMPORT: 13 | deps.append(imp.dll.decode()) 14 | return deps 15 | 16 | 17 | def dep_tree(root, prefix=None): 18 | if not prefix: 19 | arch = get_arch(root) 20 | #print('Arch =', arch) 21 | prefix = '/usr/'+arch+'-w64-mingw32/bin' 22 | #print('Using default prefix', prefix) 23 | dep_dlls = dict() 24 | 25 | def dep_tree_impl(root, prefix): 26 | for dll in get_dependency(root): 27 | if dll in dep_dlls: 28 | continue 29 | full_path = os.path.join(prefix, dll) 30 | if os.path.exists(full_path): 31 | dep_dlls[dll] = full_path 32 | dep_tree_impl(full_path, prefix=prefix) 33 | else: 34 | dep_dlls[dll] = 'not found' 35 | 36 | dep_tree_impl(root, prefix) 37 | return (dep_dlls) 38 | 39 | 40 | def get_arch(filename): 41 | type2arch= {pefile.OPTIONAL_HEADER_MAGIC_PE: 'i686', 42 | pefile.OPTIONAL_HEADER_MAGIC_PE_PLUS: 'x86_64'} 43 | pe = pefile.PE(filename) 44 | try: 45 | return type2arch[pe.PE_TYPE] 46 | except KeyError: 47 | sys.stderr.write('Error: unknown architecture') 48 | sys.exit(1) 49 | 50 | if __name__ == '__main__': 51 | filename = sys.argv[1] 52 | for dll, full_path in dep_tree(filename).items(): 53 | print(' ' * 7, dll, '=>', full_path) 54 | 55 | --------------------------------------------------------------------------------