Skip to content

Instantly share code, notes, and snippets.

@jsenin
Created May 6, 2020 19:35
Show Gist options
  • Save jsenin/18df1f0c26924afcd240750ad9fa2d09 to your computer and use it in GitHub Desktop.
Save jsenin/18df1f0c26924afcd240750ad9fa2d09 to your computer and use it in GitHub Desktop.
hg253v2 image builder
import sys
import binascii
# wget https://raw.githubusercontent.com/SySS-Research/syss-crc/master/syss_crc.py
from syss_crc import CRC
def do_crc(data):
crc = CRC()
crc.set_config_by_name('CRC-32/JAMCRC')
return crc.compute(data)
def long_2_hex(value):
value = '{:x}'.format(value)
return binascii.unhexlify(value)
header_size = 0x80 # 128
header = b'X' * header_size
image_size = 0x100
image = b'Y' * image_size
label_size = 0x10
label = b'Z' * label_size
filename = sys.argv[1]
with open(filename, 'wb') as f:
f.write(header)
f.write(image)
crc32 = do_crc(header+image)
print("ulCRC ", hex(crc32), crc32)
print("# must be fd995ea4 CRC-32/JAMCRC")
f.write(long_2_hex(crc32))
f.write(label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment