Skip to content

Instantly share code, notes, and snippets.

@dmknght
Created November 9, 2021 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmknght/dedbece794d0e5a1bdf7c4bae318d082 to your computer and use it in GitHub Desktop.
Save dmknght/dedbece794d0e5a1bdf7c4bae318d082 to your computer and use it in GitHub Desktop.
Patch sublime_text build 4121 Windows. Tested with portable version
import os
sublime_binary_path = "/home/dmknght/Desktop/sublime_text_windows/sublime_text.exe"
version_magic_string = "/updates/4/stable_update_check?version=4121&platform=windows&arch=x64"
sz_magic_string = 69
version_magic_string_offset = 0x007533d5 # (Real offset from xxd)
is_file_read = os.access(sublime_binary_path, os.R_OK)
if not is_file_read:
print(f"File {sublime_binary_path} is not readable. Exit!")
exit(1)
is_file_write = os.access(sublime_binary_path, os.W_OK)
if not is_file_write:
print(f"File {sublime_binary_path} is not writable. Only check for patch.")
f = open(sublime_binary_path, "rb")
f.seek(version_magic_string_offset)
data = f.read(sz_magic_string)
if data.decode() == version_magic_string:
print("File matched sublime_text build 4121")
else:
print("File doesn't have build 4121 magic string")
f.close()
offset = 0x000a6a89 # 74 1d, patch to 75 1d
if is_file_write:
f = open(sublime_binary_path, "rb+")
f.seek(offset)
if f.read(2) == b"\x74\x1d":
print("Patching binary")
f.seek(offset)
f.write(b"\x75")
f.close()
else:
f = open(sublime_binary_path, "rb")
f.seek(offset)
if f.read(2) == b"\x74\x1d":
print("Binary is not patched")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment