Skip to content

Instantly share code, notes, and snippets.

@heinrich5991
Created October 31, 2015 20:07
Show Gist options
  • Save heinrich5991/7f43ee829c6ca8653d97 to your computer and use it in GitHub Desktop.
Save heinrich5991/7f43ee829c6ca8653d97 to your computer and use it in GitHub Desktop.
import argparse
import os
SERVERBROWSE_FWERROR = b'\xff\xff\xff\xfffwer'
def make_executable(path):
"""
Taken from http://stackoverflow.com/a/30463972.
Has obvious race conditions, but whatever...
"""
old_mode = os.stat(path).st_mode
new_mode = old_mode | ((old_mode & 0o444) >> 2) # copy R bits to X
if new_mode != old_mode:
os.chmod(path, new_mode)
def main():
parser = argparse.ArgumentParser(description="Patch a Teeworlds server executable to work around a bug in the registering code.")
parser.add_argument('file', metavar="FILE", help="Filename of the executable to patch")
filename = parser.parse_args().file
file = open(filename, 'rb')
contents = file.read()
fixed = contents.replace(SERVERBROWSE_FWERROR, os.urandom(len(SERVERBROWSE_FWERROR)))
fixed_filename = filename + "_fixed.exe"
open(fixed_filename, 'wb').write(fixed)
make_executable(fixed_filename)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment