Skip to content

Instantly share code, notes, and snippets.

@hfaran
Created November 2, 2015 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hfaran/98d998e8e4957da11d0b to your computer and use it in GitHub Desktop.
Save hfaran/98d998e8e4957da11d0b to your computer and use it in GitHub Desktop.
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