Skip to content

Instantly share code, notes, and snippets.

@zoogie
Last active May 7, 2019 12:23
Show Gist options
  • Save zoogie/ccae68b60d86b25ee8801f3fbc212301 to your computer and use it in GitHub Desktop.
Save zoogie/ccae68b60d86b25ee8801f3fbc212301 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
#adapted from https://github.com/plutooo/smilehax/blob/master/scripts/make_script.py
#all credits to plutooo
import sys
import struct
import hashlib
import hmac
HMAC_KEY = \
'''nqmby+e9S?{%U*-V]51n%^xZMk8>b{?x]&?(NmmV[,g85:%6Sqd"'U")/8u77UL2'''
if(len(sys.argv) != 3):
print("Usage: python3 SMILEBASIC_FILENAME output_filename")
exit(0)
buf = open(sys.argv[1], 'rb').read()
data_len = len(buf)
message = buf[:data_len-20]
footer_old = buf[data_len-20:]
h = hmac.new(bytearray(HMAC_KEY, 'utf-8'), digestmod=hashlib.sha1)
footer_calculated=h.update(message)
footer_calculated=h.digest()
print("message size: %d bytes (header+script)" % (data_len-20))
print("hmac old footer: %s" % footer_old.hex())
print("hmac calculated footer: %s" % footer_calculated.hex())
if footer_old == footer_calculated:
print("hmac is already correct, exiting...")
exit(0)
print("copying modified %s to %s" % (sys.argv[1],sys.argv[2]))
out = open(sys.argv[2], 'wb')
out.write(message+footer_calculated)
print("done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment