|
@@ -0,0 +1,47 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+"""
|
|
|
+Finds the location of strings and patches the first character to the null terminator,
|
|
|
+preventing the messages from being displayed in the server console.
|
|
|
+
|
|
|
+This can be executed while the server is running (on Linux, may not be successful on Windows).
|
|
|
+"""
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import argparse
|
|
|
+import ast
|
|
|
+import configparser
|
|
|
+import mmap
|
|
|
+import os
|
|
|
+
|
|
|
+def patch_to_null(mbin, target):
|
|
|
+ offset = mbin.find(target.encode('ascii'))
|
|
|
+ if offset == -1:
|
|
|
+ return False
|
|
|
+ mbin.seek(offset)
|
|
|
+ mbin.write_byte(0)
|
|
|
+ mbin.flush()
|
|
|
+ return True
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ parser = argparse.ArgumentParser(
|
|
|
+ description = "Patches various strings out of the given binary")
|
|
|
+
|
|
|
+ parser.add_argument('binary', help = "Binary file to patch", type = argparse.FileType(mode = 'rb+'))
|
|
|
+
|
|
|
+ args = parser.parse_args()
|
|
|
+
|
|
|
+ mbin = mmap.mmap(args.binary.fileno(), length = 0, access = mmap.ACCESS_WRITE)
|
|
|
+
|
|
|
+ config = configparser.ConfigParser(converters = {
|
|
|
+
|
|
|
+ 'pyliteral': ast.literal_eval,
|
|
|
+ }, interpolation = None)
|
|
|
+ config.read("str0.ini", encoding = "utf8")
|
|
|
+
|
|
|
+ for target in config.getpyliteral(os.path.basename(args.binary.name), "strings"):
|
|
|
+ if not patch_to_null(mbin, target):
|
|
|
+ print(f'{args.binary.name}: Failed to locate string "{target}"')
|