Skip to content

Instantly share code, notes, and snippets.



Created Nov 2, 2015
What would you like to do?
CPEN442 Assignment4 Q4c
from hashlib import sha1
import click # pip install click
@click.option('-i', '--input-program', required=True,
help="Path to 12563110.program2.exe", type=click.Path())
@click.option('-o', '--output-program', required=True,
help="Path to new 12563110.program2.exe to write",
def main(input_program, output_program, password):
np_hash = sha1(password).digest()
# In [31]: s.find('\x30\xa7\xf7\xbd')
# Out[31]: 75795
OFFSET = 75795
# Read whole program into memory as a bytearray and patch the hash
with open(input_program, "r+b") as f:
program = bytearray(
for i, byte in enumerate(np_hash):
program[OFFSET+i] = byte
# Write the patched program to the output path
with open(output_program, "w+b") as f:
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment