Last active
December 9, 2024 03:12
-
-
Save PotatoPwn/cb72f1fe7a8235f109da0c40b3c61a9f to your computer and use it in GitHub Desktop.
Revisions
-
PotatoPwn revised this gist
Dec 9, 2024 . 1 changed file with 20 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,16 +2,26 @@ 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: @@ -45,7 +55,7 @@ def GetImportInformation(FileName: str): "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") -
PotatoPwn revised this gist
Dec 9, 2024 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -45,8 +45,7 @@ def GetImportInformation(FileName: str): "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") -
PotatoPwn created this gist
Dec 9, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ import pefile import os import json 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) exports = [e.name.decode() for e in file_content.DIRECTORY_ENTRY_EXPORT.symbols if e.name] return sorted(exports) 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." } # Save the results to a JSON file with open("pe_info.json", "w") as json_file: json.dump(results, json_file, indent=4) print("Output written to pe_info.json")