40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import pefile
|
|
import sys
|
|
|
|
def get_dll_dependencies(exe_path):
|
|
"""Extract DLL dependencies from an executable file."""
|
|
try:
|
|
# Load the PE file
|
|
pe = pefile.PE(exe_path)
|
|
|
|
# Check for the IMPORT_DIRECTORY entry
|
|
if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):
|
|
dlls = [entry.dll.decode('utf-8') for entry in pe.DIRECTORY_ENTRY_IMPORT]
|
|
return dlls
|
|
else:
|
|
print("No DLL dependencies found in the executable.")
|
|
return []
|
|
except FileNotFoundError:
|
|
print(f"File not found: {exe_path}")
|
|
return []
|
|
except pefile.PEFormatError:
|
|
print(f"The file is not a valid PE executable: {exe_path}")
|
|
return []
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
return []
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python get_dll_dependencies.py <path_to_exe>")
|
|
else:
|
|
exe_path = sys.argv[1]
|
|
dependencies = get_dll_dependencies(exe_path)
|
|
|
|
if dependencies:
|
|
print("DLL Dependencies:")
|
|
for dll in dependencies:
|
|
print(f" {dll}")
|
|
else:
|
|
print("No DLL dependencies found or failed to retrieve dependencies.")
|