Add main.py

This commit is contained in:
Spencer Conlon 2024-12-29 05:42:51 +00:00
commit ce620d1f98

39
main.py Normal file
View File

@ -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 <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.")