added clarifying comments, nothing about the actual patch changed
This commit is contained in:
1 parent
75f5a86abf
commit
38b99a4ebb
1 file changed
+28
-1
@@ -7,20 +7,47 @@ if len(sys.argv) > 1:
|
|||||||
else:
|
else:
|
||||||
path = '/home/' + getpass.getuser() + '/.local/share/Steam/steamapps/common/Trials Rising/datapack/trialsrising.exe'
|
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'
|
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'
|
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:
|
try:
|
||||||
with open(path, 'rb') as file:
|
with open(path, 'rb') as file:
|
||||||
|
# read the .exe file
|
||||||
data = file.read()
|
data = file.read()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"Error: The file '{path}' was not found.")
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
# Perform the replacement, limited to 1 occurrence
|
# Perform the replacement, limited to 1 occurrence
|
||||||
patched_data = data.replace(original_bytes, new_and_improved_bytes, 1)
|
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:
|
if patched_data != data:
|
||||||
# Write the modified data back to the file
|
# Write the modified data back to the file
|
||||||
with open(path, 'wb') as file:
|
with open(path, 'wb') as file:
|
||||||
|
|||||||
Reference in new issue
Block a user