-
-
Save heinrich5991/7f43ee829c6ca8653d97 to your computer and use it in GitHub Desktop.
This file contains 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
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