''' In Windows, dependencies of a DLL can be obtained from its PE import table. A useful Python solution is to use the pefile package, which reads the DLL without loading or executing it. It gives only direct dependencies. The pefile package does not guarantee the complete runtime dependency list. Install pefile: pip install pefile Run: python getDependenciesDLL.py C:\Projects\dll_third_party.dll ''' import sys from pathlib import Path import pefile def get_dll_dependencies(dll_path): """ Return the DLLs directly imported by a PE file (.dll/.exe). """ pe = pefile.PE(dll_path) dependencies = [] if hasattr(pe, "DIRECTORY_ENTRY_IMPORT"): for entry in pe.DIRECTORY_ENTRY_IMPORT: dll_name = entry.dll.decode( "utf-8", errors="replace" ) dependencies.append(dll_name) pe.close() return sorted(set(dependencies)) def main(): if len(sys.argv) != 2: print("Usage:") print(" python dll_dependencies.py ") sys.exit(1) dll_path = Path(sys.argv[1]) if not dll_path.exists(): print(f"ERROR: File not found: {dll_path}") sys.exit(1) try: dependencies = get_dll_dependencies(dll_path) print(f"\nDLL: {dll_path}") print("\nDirect dependencies:") if not dependencies: print(" No imported DLLs found.") else: for dependency in dependencies: print(f" {dependency}") except pefile.PEFormatError as e: print(f"ERROR: Not a valid PE/DLL file: {e}") sys.exit(1) except Exception as e: print(f"ERROR: {e}") sys.exit(1) if __name__ == "__main__": main()