Skip to content

Instantly share code, notes, and snippets.

@kvba0000
Last active February 4, 2024 20:51
Show Gist options
  • Save kvba0000/ec5a35a73a7f2780c2cc5f43d4f9440c to your computer and use it in GitHub Desktop.
Save kvba0000/ec5a35a73a7f2780c2cc5f43d4f9440c to your computer and use it in GitHub Desktop.
Bitflip script written in Python with chunk reading function. Mainly used to de-anti-decompile Gamemaker fangames like MTO (Mysterytale Online).
from os import fstat
from time import sleep
filename = "data.win"
new_filename = f"new_{filename}"
chunk_size = 1024
# Main progress
wf = open(new_filename, "wb")
with open(filename, "rb") as f:
file_stats = fstat(f.fileno())
file_size = file_stats.st_size
c = 0
while True:
chunk = f.read(chunk_size)
if not chunk:
break
c += chunk_size
print(f"Bitflipping {filename}... {c}/{file_size}")
binary = "".join(f"{byte:08b}" for byte in chunk)
n_binary = "".join(map(lambda b: '0' if b == '1' else '1', [*binary]))
new_binary = bytes(int(n_binary[i:i+8], 2) for i in range(0, len(n_binary), 8))
wf.write(new_binary)
sleep(0.01)
f.close()
print(f"Bitflip done. Output saved to {new_filename}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment