Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created October 5, 2024 16:13
Show Gist options
  • Save mgedmin/0eb041267cd92b975b81667849f87f32 to your computer and use it in GitHub Desktop.
Save mgedmin/0eb041267cd92b975b81667849f87f32 to your computer and use it in GitHub Desktop.
A rewrite of https://bpa.st/GBRPM
import argparse
import pathlib
import sys
old_bytes = bytes([0x80, 0x79, 0x05, 0x00, 0x0f, 0x94, 0xc2])
new_bytes = bytes([0xc6, 0x41, 0x05, 0x01, 0xb2, 0x00, 0x90])
def main():
parser = argparse.ArgumentParser(description="sublime text patcher")
parser.add_argument("filename", help="path to sublime text binary")
args = parser.parse_args()
path = pathlib.Path(args.filename)
try:
buffer = path.read_bytes()
except IOError as e:
sys.exit(f"error: failed to open file: {e}")
if old_bytes not in buffer:
sys.exit('error: byte sequence not found')
buffer = buffer.replace(old_bytes, new_bytes)
path.rename(path.with_suffix('.orig'))
path.write_bytes(buffer)
print(f"{path} patched successfully!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment