Last active
July 24, 2024 22:04
-
-
Save Mothblocks/db5462aa84d7d6b1d1b1276b820f62da to your computer and use it in GitHub Desktop.
Given a byondcore.dll, will include full filenames in compilation. Will use absolute path, but you can provide a number of bytes to offset by for the path if you want to remove your user information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dm_full_file_patch.py <byondcore.dll> [bytes to offset strings by] | |
# By default, this will create absolute paths, which work perfectly fine in Tracy no matter where it is. | |
# However, if you want to trim file paths to only what is necessary, you can specify a number of bytes to offset. | |
# For example, if your tgstation is inside C:/Users/Mothblocks/tgstation/, you will want to cut it by 30 (the length of that text). | |
# This is useful if you want to send screenshots or upload the Tracy profile without giving away potential PII like your username. | |
import shutil | |
import sys | |
pattern = [ | |
0x50, | |
0xE8, | |
'?', | |
'?', | |
'?', | |
'?', | |
0x83, | |
0xC4, | |
0x04, | |
0x5D, | |
0xC2, | |
0x04, | |
0x00, | |
0xB8, | |
'?', | |
'?', | |
'?', | |
'?', | |
] | |
if len(sys.argv) < 2: | |
print("Usage: dm_full_file_patch.py <byondcore.dll> [bytes to offset strings by]") | |
sys.exit(1) | |
extra_offset = 0 if len(sys.argv) < 3 else int(sys.argv[2]) | |
if extra_offset > 255 or extra_offset < 0: | |
print("Invalid offset") | |
sys.exit(1) | |
def find_offset(): | |
with open(sys.argv[1], "rb") as file: | |
while True: | |
offset = file.tell() - 1 | |
found = True | |
for check in pattern: | |
byte = file.read(1) | |
if len(byte) == 0: | |
raise Exception("Reached EOF, pattern not found =(") | |
if check == '?': | |
continue | |
if check != byte[0]: | |
found = False | |
break | |
if found: | |
return offset | |
offset = find_offset() | |
print(f"Found pattern at offset 0x{offset:x}") | |
shutil.copy(sys.argv[1], sys.argv[1] + ".bak") | |
with open(sys.argv[1], "r+b") as file: | |
file.seek(offset + 1) | |
# add eax, extra_offset | |
file.write(b'\x83') | |
file.write(b'\xC0') | |
file.write(bytes([extra_offset])) | |
for _ in range(6): | |
file.write(b'\x90') | |
print(f"Patched, backup saved to {sys.argv[1]}.bak") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment