Ir para conteúdo
  • Quem está por aqui   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.

Python Script for Strdef.bin editor


aakarsh98
 Compartilhar

Posts Recomendados

import struct
import tkinter as tk
from tkinter import filedialog, messagebox, simpledialog, ttk

# Constants
NUM_STRINGS = 2000
CHARS_PER_STRING = 128

# Read the binary file and return list of strings
def read_strdef_bin(filepath):
    with open(filepath, 'rb') as f:
        data = f.read(NUM_STRINGS * CHARS_PER_STRING)
    strings = [data[i*CHARS_PER_STRING:(i+1)*CHARS_PER_STRING].decode('latin1').rstrip('\x00') for i in range(NUM_STRINGS)]
    return strings

# Write the list of strings back to binary format
def write_strdef_bin(filepath, strings):
    with open(filepath, 'wb') as f:
        for s in strings:
            encoded = s.encode('latin1')[:CHARS_PER_STRING]
            padded = encoded + b'\x00' * (CHARS_PER_STRING - len(encoded))
            f.write(padded)

# GUI application class
class StrDefEditorApp:
    def __init__(self, root):
        self.root = root
        self.root.title("STRDEF.BIN Editor")
        self.file_path = ""
        self.strings = []

        self.create_widgets()

    def create_widgets(self):
        frame = ttk.Frame(self.root)
        frame.pack(fill='both', expand=True)

        self.listbox = tk.Listbox(frame, font=('Courier', 10))
        self.listbox.pack(side='left', fill='both', expand=True)
        self.listbox.bind('<<ListboxSelect>>', self.edit_string)

        scrollbar = tk.Scrollbar(frame)
        scrollbar.pack(side='right', fill='y')
        self.listbox.config(yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.listbox.yview)

        menubar = tk.Menu(self.root)
        filemenu = tk.Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open", command=self.open_file)
        filemenu.add_command(label="Save", command=self.save_file)
        menubar.add_cascade(label="File", menu=filemenu)
        self.root.config(menu=menubar)

    def open_file(self):
        path = filedialog.askopenfilename(filetypes=[("BIN files", "*.bin")])
        if not path:
            return
        self.file_path = path
        self.strings = read_strdef_bin(path)
        self.listbox.delete(0, tk.END)
        for i, s in enumerate(self.strings):
            self.listbox.insert(tk.END, f"{i:04}: {s}")

    def save_file(self):
        if not self.file_path or not self.strings:
            return
        write_strdef_bin(self.file_path, self.strings)
        messagebox.showinfo("Saved", "Changes saved to file.")

    def edit_string(self, event):
        selection = self.listbox.curselection()
        if not selection:
            return
        index = selection[0]
        old_value = self.strings[index]
        new_value = simpledialog.askstring("Edit String", f"Edit string at index {index}:", initialvalue=old_value)
        if new_value is not None:
            self.strings[index] = new_value
            self.listbox.delete(index)
            self.listbox.insert(index, f"{index:04}: {new_value}")

# Run the app
def run_app():
    root = tk.Tk()
    app = StrDefEditorApp(root)
    root.mainloop()

run_app()
Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar Agora
 Compartilhar

×
×
  • Criar Novo...

Informação Importante

Nós fazemos uso de cookies no seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies , caso contrário, vamos supor que você está bem para continuar.