This commit is contained in:
OusmBlueNinja 2024-12-28 23:56:35 -06:00
parent ce620d1f98
commit b829de1268
4 changed files with 80 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.exe

44
README.md Normal file
View File

@ -0,0 +1,44 @@
# DLL Extractor
This Python script extracts the DLL dependencies of a Windows executable file and filters out DLLs that are commonly included with the operating system.
## Features
- Identifies all DLLs required by a specified `.exe` file.
- Filters out DLLs that are part of the standard Windows OS (e.g., `KERNEL32.dll`, `USER32.dll`).
## Requirements
- Python 3.6 or later
- `pefile` library
## Installation
Install the required Python library:
```bash
pip install pefile
```
## Usage
Run the script with the path to an executable file as an argument:
```bash
python get_dll_dependencies.py <path_to_exe>
```
### Example
```bash
python get_dll_dependencies.py my_program.exe
```
Output:
```
Non-OS DLL Dependencies:
glew32.dll
glfw3.dll
libyaml-cpp.dll
lua54.dll
```
## Notes
- The script assumes the executable is a valid PE (Portable Executable) file.
- It gracefully handles errors such as missing files or invalid PE formats.
## License
This project is open-source and available under the MIT License.

37
main.py
View File

@ -1,10 +1,19 @@
import os
import pefile
import sys
import shutil
# Common DLLs that come with the OS
OS_DLLS = {
"KERNEL32.dll", "USER32.dll", "GDI32.dll", "ADVAPI32.dll",
"SHELL32.dll", "OLE32.dll", "OLEAUT32.dll", "COMDLG32.dll",
"SHLWAPI.dll", "MSVCRT.dll", "NTDLL.dll", "RPCRT4.dll",
"WININET.dll", "WS2_32.dll", "CRYPT32.dll", "OPENGL32.dll"
}
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
@ -24,6 +33,19 @@ def get_dll_dependencies(exe_path):
print(f"An error occurred: {e}")
return []
def find_and_copy_dlls(dlls, output_folder):
"""Find DLL files and copy them to the output folder."""
os.makedirs(output_folder, exist_ok=True)
found = []
for dll in dlls:
for path in os.environ['PATH'].split(os.pathsep):
dll_path = os.path.join(path, dll)
if os.path.exists(dll_path):
shutil.copy(dll_path, os.path.join(output_folder, dll))
found.append(dll)
break
return found
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python get_dll_dependencies.py <path_to_exe>")
@ -32,8 +54,17 @@ if __name__ == "__main__":
dependencies = get_dll_dependencies(exe_path)
if dependencies:
print("DLL Dependencies:")
for dll in dependencies:
non_os_dependencies = [dll for dll in dependencies if dll.upper() not in OS_DLLS]
print("Non-OS DLL Dependencies:")
for dll in non_os_dependencies:
print(f" {dll}")
if non_os_dependencies:
found_dlls = find_and_copy_dlls(non_os_dependencies, "found_dlls")
print("\nCopied DLLs:")
for dll in found_dlls:
print(f" {dll}")
else:
print("No non-OS DLL dependencies found.")
else:
print("No DLL dependencies found or failed to retrieve dependencies.")

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
pefile