Skip to content

Instantly share code, notes, and snippets.

@adrianosela
Created October 26, 2019 23:17
Show Gist options
  • Save adrianosela/a19ac0e09269f2f75773a1acce9444ef to your computer and use it in GitHub Desktop.
Save adrianosela/a19ac0e09269f2f75773a1acce9444ef to your computer and use it in GitHub Desktop.
import os
import sys
import hashlib
import binascii
def change_pw(path, hash, password):
# build hash for new password
new_pw_hash = hashlib.sha1(password.encode())
# read program file bytes
s = open(path, 'rb').read()
# replace old hash with new hash in file bytes
s = s.replace(binascii.unhexlify(hash), binascii.unhexlify(new_pw_hash.hexdigest()))
# write the bytes to a new file
f = open(path + ".patched", 'wb')
f.write(s)
path = sys.argv[1]
pw_hash = sys.argv[2]
new_pw = sys.argv[3]
change_pw(path, pw_hash, new_pw)
print("program patched!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment