Skip to content

Instantly share code, notes, and snippets.

@hfaran hfaran/patch_q4.py

Created Nov 2, 2015
Embed
What would you like to do?
CPEN442 Assignment4 Q4c
from hashlib import sha1
import click # pip install click
@click.command()
@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",
type=click.Path())
@click.password_option()
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(f.read())
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:
f.write(program)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.