|
@@ -14,13 +14,14 @@ import configparser
|
|
|
import mmap
|
|
|
import os
|
|
|
|
|
|
-def patch_to_null(mbin, target):
|
|
|
+def patch_to_null(mbin, target, fully_zero = True):
|
|
|
mbin.seek(0)
|
|
|
offset = mbin.find(target.encode('ascii'))
|
|
|
if offset == -1:
|
|
|
return False
|
|
|
mbin.seek(offset)
|
|
|
- mbin.write_byte(0)
|
|
|
+ # read up to the next null terminator and zero out the range if we fullclear it
|
|
|
+ mbin.write(b'\0' * (mbin.find(b'\0', offset) - offset if fully_zero else 1))
|
|
|
return True
|
|
|
|
|
|
if __name__ == '__main__':
|
|
@@ -42,6 +43,7 @@ if __name__ == '__main__':
|
|
|
config.read([ "str0.ini" ] + args.config, encoding = "utf8")
|
|
|
|
|
|
for target in config.getpyliteral(os.path.basename(args.binary.name), "strings"):
|
|
|
- if not patch_to_null(mbin, target):
|
|
|
+ fully_zero = config.getboolean(os.path.basename(args.binary.name), "fully_zero", fallback = False)
|
|
|
+ if not patch_to_null(mbin, target, fully_zero):
|
|
|
print(f'{args.binary.name}: Failed to locate string "{target}"')
|
|
|
mbin.flush()
|