From 38b99a4ebbe7783a1354e47eb35ca714825f0365 Mon Sep 17 00:00:00 2001 From: Kyle Mohr <6644803+kylefmohr@users.noreply.github.com> Date: Tue, 10 Mar 2026 20:41:57 -0500 Subject: [PATCH] added clarifying comments, nothing about the actual patch changed --- patch.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/patch.py b/patch.py index 5f30900..d7cf35e 100644 --- a/patch.py +++ b/patch.py @@ -7,20 +7,47 @@ if len(sys.argv) > 1: else: path = '/home/' + getpass.getuser() + '/.local/share/Steam/steamapps/common/Trials Rising/datapack/trialsrising.exe' +# Some explanation: these bytes first serve as hex representations of the program instructions we want to change +# But if that was all they needed to be, they could each be 3 hex characters long: +# original_bytes = b'\x48\x89\x54' +# new_and_improved_bytes = b'\xB0\x01\xC3' +# However the issue is that this sequence of original_bytes shows up many many times in the executable, +# so we would end up patching many places that don't need to be patched, +# causing unintended functionality (likely) or else just causing the program to crash (extremely likely) original_bytes = b'\x48\x89\x54\x24\x10\x55\x56\x57\x48\x81\xEC\xF0\x00\x00\x00\x48\xC7\x44\x24\x78' +# translated (from Ghidra (used to disassemble this program)): 15a0b00dc(*) +# 14178b6c0 48 89 54 MOV qword ptr [RSP + 0x10],RDX +# 24 10 +# 14178b6c5 55 PUSH RBP +# 14178b6c6 56 PUSH RSI +# 14178b6c7 57 PUSH RDI +# 14178b6c8 48 81 ec SUB RSP,0xf0 +# f0 00 00 00 +# 14178b6cf 48 c7 44 MOV qword ptr [RSP + 0x78],-0x2 +# 24 78 fe +# ff ff ff new_and_improved_bytes = b'\xB0\x01\xC3\x24\x10\x55\x56\x57\x48\x81\xEC\xF0\x00\x00\x00\x48\xC7\x44\x24\x78' +# Translated: +# mov al, 1 +# ret +# (then the rest of these bytes don't matter because they will never be reached) +# or in pseudocode, `return True;` + try: with open(path, 'rb') as file: + # read the .exe file data = file.read() except FileNotFoundError: print(f"Error: The file '{path}' was not found.") + print("Hint: specify the path to the .exe as a command line argument, like this:") + print(f"python {sys.argv[0]} /path/to/trialsrising.exe") sys.exit(1) # Perform the replacement, limited to 1 occurrence patched_data = data.replace(original_bytes, new_and_improved_bytes, 1) -# Check if anything was actually changed +# Ensure we actually changed *something* if patched_data != data: # Write the modified data back to the file with open(path, 'wb') as file: