Last active
December 9, 2024 03:12
-
-
Save PotatoPwn/cb72f1fe7a8235f109da0c40b3c61a9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pefile | |
| import os | |
| import json | |
| def Error_Info(OrdinalOffset: int, Ordinalname : str): | |
| if Ordinalname is None: | |
| return f"Ordinal_{OrdinalOffset}" | |
| else: | |
| return Ordinalname.decode() | |
| def GetExportInformation(FileName: str): | |
| try: | |
| directory = [pefile.DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_EXPORT"]] | |
| file_content = pefile.PE(FileName, fast_load=True) | |
| file_content.parse_data_directories(directories=directory) | |
| exportslist = [] | |
| for exports in file_content.DIRECTORY_ENTRY_EXPORT.symbols: | |
| export_name = Error_Info(OrdinalOffset=exports.ordinal, Ordinalname=exports.name) | |
| exportslist.append(export_name) | |
| return exportslist | |
| except Exception as e: | |
| return [] | |
| def GetImportInformation(FileName: str): | |
| try: | |
| file_content = pefile.PE(FileName, fast_load=True) | |
| file_content.parse_data_directories() | |
| imports = [] | |
| for entry in file_content.DIRECTORY_ENTRY_IMPORT: | |
| dll_name = entry.dll.decode() if entry.dll else "Unknown" | |
| functions = [imp.name.decode() for imp in entry.imports if imp.name] | |
| imports.append({"dll": dll_name, "functions": functions}) | |
| return imports | |
| except Exception as e: | |
| return [] | |
| if __name__ == "__main__": | |
| results = {} | |
| file_names = os.listdir() | |
| for file in file_names: | |
| try: | |
| print(f"Processing file: {file}") | |
| imports = GetImportInformation(file) | |
| exports = GetExportInformation(file) | |
| results[file] = { | |
| "imports": imports, | |
| "exports": exports | |
| } | |
| except Exception as e: | |
| print(f"Failed to process {file}: {str(e)}") | |
| results[file] = { | |
| "error": "Failed to process this file." | |
| } | |
| with open("Results.json", "w") as json_file: | |
| json.dump(results, json_file, indent=4) | |
| print("Output written to Results.json") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment