Spaces:
Runtime error
Runtime error
import pefile | |
import tkinter as tk | |
from tkinter import filedialog | |
def extract_pe_info(file_path): | |
try: | |
pe = pefile.PE(file_path) | |
info = { | |
'AddressOfEntryPoint': hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint), | |
'MajorLinkerVersion': pe.OPTIONAL_HEADER.MajorLinkerVersion, | |
'MajorImageVersion': pe.OPTIONAL_HEADER.MajorImageVersion, | |
'MajorOperatingSystemVersion': pe.OPTIONAL_HEADER.MajorOperatingSystemVersion, | |
'DllCharacteristics': hex(pe.OPTIONAL_HEADER.DllCharacteristics), | |
'SizeOfStackReserve': pe.OPTIONAL_HEADER.SizeOfStackReserve, | |
'NumberOfSections': pe.FILE_HEADER.NumberOfSections, | |
'SizeOfImage': pe.OPTIONAL_HEADER.SizeOfImage, | |
'SizeOfHeaders': pe.OPTIONAL_HEADER.SizeOfHeaders, | |
'Subsystem': pe.OPTIONAL_HEADER.Subsystem, | |
'Magic': pe.FILE_HEADER.Machine, | |
'Characteristics': hex(pe.FILE_HEADER.Characteristics), | |
'TimeDateStamp': pe.FILE_HEADER.TimeDateStamp, | |
'ImageBase': hex(pe.OPTIONAL_HEADER.ImageBase), | |
'CheckSum': pe.OPTIONAL_HEADER.CheckSum, | |
'SizeOfCode': pe.OPTIONAL_HEADER.SizeOfCode, | |
'SizeOfInitializedData': pe.OPTIONAL_HEADER.SizeOfInitializedData, | |
'SizeOfUninitializedData': pe.OPTIONAL_HEADER.SizeOfUninitializedData, | |
'AddressOfEntryPoint': hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint), | |
'ImageBase': hex(pe.OPTIONAL_HEADER.ImageBase), | |
'MajorImageVersion': pe.OPTIONAL_HEADER.MajorImageVersion, | |
'MajorSubsystemVersion': pe.OPTIONAL_HEADER.MajorSubsystemVersion, | |
'SizeOfImage': pe.OPTIONAL_HEADER.SizeOfImage, | |
'SizeOfHeaders': pe.OPTIONAL_HEADER.SizeOfHeaders, | |
'Subsystem': pe.OPTIONAL_HEADER.Subsystem, | |
'SizeOfHeapReserve': pe.OPTIONAL_HEADER.SizeOfHeapReserve, | |
'NumberOfRvaAndSizes': pe.OPTIONAL_HEADER.NumberOfRvaAndSizes, | |
'DataDirectory': pe.OPTIONAL_HEADER.DATA_DIRECTORY, | |
} | |
return info | |
except Exception as e: | |
return str(e) | |
def inspect_pe_attributes(file_path): | |
try: | |
pe = pefile.PE(file_path) | |
# Récupérer la liste des entrées DATA_DIRECTORY | |
data_directory_entries = pe.OPTIONAL_HEADER.DATA_DIRECTORY | |
# Parcourir la liste pour trouver l'entrée du répertoire des ressources | |
for entry in data_directory_entries: | |
if entry.name == "IMAGE_DIRECTORY_ENTRY_RESOURCE": | |
resource_size = entry.Size | |
return resource_size | |
except Exception as e: | |
return f"Erreur d'inspection du fichier {file_path}: {str(e)}" | |
def upload_file(): | |
file_path = filedialog.askopenfilename() | |
if file_path: | |
pe_info = extract_pe_info(file_path) | |
print(pe_info) | |
# Création de l'interface graphique | |
root = tk.Tk() | |
root.title("PE File Info Extractor") | |
upload_button = tk.Button(root, text="Upload PE File", command=upload_file) | |
upload_button.pack(pady=20) | |
root.mainloop() | |