Modified the script from post 79:
* Fixed serial number conversion (did not work with my serial number). Serial number can now be free format (no leading zeroes needed)
* Enter serial number and option via command line:
-s <serial>
-o <option>
* Only print the KEY: line
This allows direct redirection into a .hlk file.
Example call:
python makeoptions.py -s 123456789 -o 07 >outfile.hlk
from Crypto.Cipher import AES
import binascii
from optparse import OptionParser
#---------------START---------------------------
parser = OptionParser()
parser.add_option("-s", "--serial", dest="serial_str", help="Serial Number", metavar="SERIAL")
parser.add_option("-o", "--option", dest="option_str", help="Option", metavar="OPTION")
parser.add_option("-l", "--list", dest="list_options", help="List Options", metavar="LIST", action = "store_true")
(options, args) = parser.parse_args()
if options.list_options :
print('Option list for HMO1202:')
print('\tOffset 02 - HOO10 - Serial trigger\n',
'\tOffset 07 - HOO11 - serial trigger with CAN and LIN\n',
'\tOffset 08 - HOO12 - Serial trigger analogue\n',
'\tOffset 11 - Remove all licences / demo time expired\n',
'\tOffset 26 - HOO312 - Bandwidth 200 MHz\n',
'\tOffset 28 - HOO313 - Bandwidth 300 MHz\n') #may be different depend of model
exit()
#--------MAKE OPTION STRING:START--------
# Convert decimal to hex string
serhex="%08x" % int(options.serial_str)
#print("hex = %s" % serhex)
# reverse
LE_serial=""
while serhex != "" :
LE_serial += serhex[-2:]
serhex = serhex[:-2]
#print (LE_serial)
#--input option offset:START--
option_str = LE_serial+options.option_str+'0000000000000000000000' #make result option string
#print(option_str)
#--------MAKE OPTION STRING:END--------
#--------ENCODE OPTION STRING WITH AES-256 in ECB MODE:START--------
key = '86BAFEC912C42A0D424E01DEBEE7A1530722004569CA0D052F617380FFAD59FE'
key = bytes.fromhex(key) #from 64 hex characters (256-bit) key we make key for AES encode (ECB mode) that consist of 32 bytes (256-bit)
option_str = bytes.fromhex(option_str) #from 32 hex characters (128-bit) message we make message for AES encode that consist of 16 bytes (128-bit)
cipher = AES.new(key, AES.MODE_ECB) # call AES-256 (key lenght is 256 bits(!!!)) cipher protocol in ECB mode (only secret key needed)
option_str_en = cipher.encrypt(option_str) #encrypting result option string
#--------ENCODE OPTION STRING WITH AES-256 in ECB MODE:END--------
#--print results:START--
#print("DONE !")
result = (binascii.hexlify(option_str_en)).decode("utf-8") #making from encoded option key regular string to output
print(f'KEY:{result}')
#--print results:END--
#---------------END---------------------------