Skip to content

Instantly share code, notes, and snippets.

@FrankSpierings
Created May 12, 2019 14:22
Show Gist options
  • Save FrankSpierings/330288e04cad7d7cd6d64408c0a9a425 to your computer and use it in GitHub Desktop.
Save FrankSpierings/330288e04cad7d7cd6d64408c0a9a425 to your computer and use it in GitHub Desktop.
Overwrite Strings in Binary
import re
import os
import time
filename = 'test.exe'
new_filename = '{0}.backup.{1}'.format(filename, int(time.time()))
pattern = b'GCC: .*?\x00'
f = open(filename, 'rb')
data = f.read()
f.close()
matches = re.findall(pattern, data)
matches = set(matches)
for match in matches:
# replacement = b"X" * (len(match)-1) + b'\x00'
replacement = b"\x00" * (len(match))
data = data.replace(match, replacement)
print("Renaming {0} to {1}".format(filename, new_filename))
os.rename(filename, new_filename)
f = open(filename, 'wb')
f.write(data)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment