Skip to content

Instantly share code, notes, and snippets.

@ImanCol
Created March 19, 2023 03:05
Show Gist options
  • Select an option

  • Save ImanCol/dd99133c5487ba19500a0adb2acca4bb to your computer and use it in GitHub Desktop.

Select an option

Save ImanCol/dd99133c5487ba19500a0adb2acca4bb to your computer and use it in GitHub Desktop.

Revisions

  1. ImanCol created this gist Mar 19, 2023.
    67 changes: 67 additions & 0 deletions patch.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    import tkinter as tk
    from tkinter import filedialog
    import hashlib
    import os
    import sys
    import ctypes
    import subprocess

    # Función para verificar si se tienen permisos de administrador
    def is_admin():
    try:
    return ctypes.windll.shell32.IsUserAnAdmin()
    except:
    return False

    # Función para parchear el archivo DLL
    def patch_dll():
    file_path = file_var.get()
    try:
    with open(file_path, 'rb') as file:
    data = file.read()

    m = hashlib.sha1()
    m.update(data)
    file_hash = m.hexdigest()

    previously_patched_hash = '2241a9985e5e65b675bfa384ecc1463432418cb2'
    if file_hash == previously_patched_hash:
    status_label.config(text='El archivo ya ha sido parcheado previamente.')
    else:
    expected_hash = 'f0a7daa52e9d9f7761a1afaad45c09c9bc9e9eba'
    if file_hash == expected_hash:
    with open(file_path, 'r+b') as file:
    file.seek(0x3ACD5)
    file.write(b'\x32')
    status_label.config(text='Archivo DLL parcheado correctamente.')
    else:
    status_label.config(text='El archivo no es el esperado. Busque el archivo UnityEditor.Switch.Extensions.Native.dll')
    except IOError:
    status_label.config(text='Error al abrir el archivo DLL.')

    # Si no se tienen permisos de administrador, se solicitan
    if not is_admin():
    args = ' '.join([f'"{arg}"' for arg in sys.argv])
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, args, None, 1)
    sys.exit()

    # Creación de la ventana
    root = tk.Tk()
    root.title('Parche de archivo DLL')

    # Creación de los elementos de la ventana
    file_var = tk.StringVar()
    file_label = tk.Label(root, text='Seleccione un archivo DLL: UnityEditor.Switch.Extensions.Native.dll')
    file_label.pack()
    file_entry = tk.Entry(root, textvariable=file_var)
    file_entry.pack()
    file_button = tk.Button(root, text='Buscar archivo', command=lambda: file_var.set(tk.filedialog.askopenfilename(filetypes=[('dll file', 'UnityEditor.Switch.Extensions.Native.dll')], title="Seleccione UnityEditor.Switch.Extensions.Native.dll")))
    file_button.pack()

    patch_button = tk.Button(root, text='Parchear archivo', command=patch_dll)
    patch_button.pack()

    status_label = tk.Label(root, text='')
    status_label.pack()

    root.mainloop()