Files
PSA-EDC16C34-C3/main.py
2025-02-03 03:22:24 -08:00

88 lines
3.3 KiB
Python

import tkinter as tk
from tkinter import filedialog, ttk, scrolledtext
import re
class PatternFinderGUI:
def __init__(self, root):
self.root = root
self.root.title("PSA EDC17 PIN Finder")
self.root.geometry("600x300")
# File Selection Frame
file_frame = ttk.LabelFrame(root, text="File Selection", padding=10)
file_frame.pack(fill=tk.X, padx=5, pady=5)
self.file_path = tk.StringVar()
ttk.Entry(file_frame, textvariable=self.file_path, width=60).pack(side=tk.LEFT, padx=5)
ttk.Button(file_frame, text="Browse", command=self.browse_file).pack(side=tk.LEFT, padx=5)
ttk.Button(file_frame, text="Search PIN", command=self.search_patterns).pack(side=tk.RIGHT)
# Results Frame
results_frame = ttk.LabelFrame(root, text="Results", padding=10)
results_frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
self.results_text = scrolledtext.ScrolledText(results_frame, width=80, height=10)
self.results_text.pack(fill=tk.BOTH, expand=True)
def find_repeated_patterns(self, filepath):
try:
target_content = ""
bytes_per_line = 16
start_offset = 0x3000 # Hex offset for line 3000
end_offset = 0x4000 # Hex offset for line 4000
with open(filepath, 'rb') as file:
file.seek(start_offset)
data = file.read(end_offset - start_offset)
for i in range(0, len(data), bytes_per_line):
line = data[i:i + bytes_per_line]
ascii_line = ''.join(chr(b) if 32 <= b <= 126 else '.' for b in line)
target_content += ascii_line.upper()
pattern = r'[A-Z0-9]{4}'
matches = re.findall(pattern, target_content)
results = {}
for match in matches:
count = target_content.count(match)
if count == 2:
results[match] = count
return results
except Exception as e:
print(f"Error: {e}")
return None
def browse_file(self):
filepath = filedialog.askopenfilename(
title="Select file",
filetypes=[("Binary files", "*.bin"), ("All files", "*.*")]
)
if filepath:
self.file_path.set(filepath)
def search_patterns(self):
filepath = self.file_path.get()
if not filepath:
self.results_text.insert(tk.END, "Please select a file first\n")
return
results = self.find_repeated_patterns(filepath)
self.results_text.delete(1.0, tk.END)
if results:
self.results_text.insert(tk.END, "Found PIN that appear exactly twice:\n\n")
for pattern, count in results.items():
self.results_text.insert(tk.END, f"Pattern: {pattern}\n")
else:
self.results_text.insert(tk.END, "No matching PIN found or error occurred\n")
def main():
root = tk.Tk()
app = PatternFinderGUI(root)
root.mainloop()
if __name__ == "__main__":
main()