Created
December 4, 2019 02:12
-
-
Save dmitrodem/3f427665d065c4c2149e94153ccde61f to your computer and use it in GitHub Desktop.
Update 70mai firmware hash
This file contains 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
#!/usr/bin/env python3 | |
from hashlib import md5 | |
import sys | |
import codecs | |
import argparse | |
import logging | |
logging.basicConfig(level = logging.DEBUG) | |
log = logging.getLogger("update_hash") | |
SIGNATURE = codecs.decode(b"41495453010000000000000000000000", "hex") | |
def update_hash(rfd, wfd): | |
fw = rfd.read() | |
if fw[:0x10] != SIGNATURE: | |
raise ValueError | |
oldhash = fw[0x10:0x20] | |
h = md5() | |
h.update("VDRAC999".encode("ascii")) | |
h.update(fw[0x20:]) | |
newhash = h.digest() | |
log.info("Old hash = {}".format(codecs.encode(oldhash, "hex").decode("ascii"))) | |
log.info("New hash = {}".format(codecs.encode(newhash, "hex").decode("ascii"))) | |
wfd.write(SIGNATURE) | |
wfd.write(newhash) | |
wfd.write(fw[0x20:]) | |
if __name__ == "__main__": | |
p = argparse.ArgumentParser(description = "Update 70mai firmware hash") | |
p.add_argument("infile", nargs = "?", type = argparse.FileType("rb"), default = sys.stdin.buffer) | |
p.add_argument("outfile", nargs = "?", type = argparse.FileType("wb"), default = sys.stdout.buffer) | |
args = p.parse_args() | |
update_hash(args.infile, args.outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment