Created
May 12, 2019 14:22
-
-
Save FrankSpierings/330288e04cad7d7cd6d64408c0a9a425 to your computer and use it in GitHub Desktop.
Overwrite Strings in Binary
This file contains hidden or 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 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