From ce620d1f989dc5638c767466e3e434722e68129c Mon Sep 17 00:00:00 2001 From: Spencer Conlon Date: Sun, 29 Dec 2024 05:42:51 +0000 Subject: [PATCH] Add main.py --- main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..24f522c --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +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 ") + 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.")