Created
May 6, 2020 19:35
-
-
Save jsenin/18df1f0c26924afcd240750ad9fa2d09 to your computer and use it in GitHub Desktop.
hg253v2 image builder
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
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