|
|
@ -12,37 +12,36 @@ from SCons.Script import DefaultEnvironment |
|
|
|
board = DefaultEnvironment().BoardConfig() |
|
|
|
|
|
|
|
def encryptByte(byte): |
|
|
|
byte = 0xFF & ((byte << 6) | (byte >> 2)) |
|
|
|
i = 0x58 + byte |
|
|
|
j = 0x05 + byte + (i >> 8) |
|
|
|
byte = (0xF8 & i) | (0x07 & j) |
|
|
|
return byte |
|
|
|
byte = 0xFF & ((byte << 6) | (byte >> 2)) |
|
|
|
i = 0x58 + byte |
|
|
|
j = 0x05 + byte + (i >> 8) |
|
|
|
byte = (0xF8 & i) | (0x07 & j) |
|
|
|
return byte |
|
|
|
|
|
|
|
def encrypt_file(input, output_file, file_length): |
|
|
|
input_file = bytearray(input.read()) |
|
|
|
for i in range(len(input_file)): |
|
|
|
result = encryptByte(input_file[i]) |
|
|
|
input_file[i] = result |
|
|
|
|
|
|
|
output_file.write(input_file) |
|
|
|
return |
|
|
|
input_file = bytearray(input.read()) |
|
|
|
for i in range(len(input_file)): |
|
|
|
input_file[i] = encryptByte(input_file[i]) |
|
|
|
output_file.write(input_file) |
|
|
|
|
|
|
|
# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt |
|
|
|
def encrypt(source, target, env): |
|
|
|
fwname = board.get("build.encrypt") |
|
|
|
print("Encrypting %s to %s" % (target[0].path, fwname)) |
|
|
|
firmware = open(target[0].path, "rb") |
|
|
|
renamed = open(target[0].dir.path + "/" + fwname, "wb") |
|
|
|
length = os.path.getsize(target[0].path) |
|
|
|
fwpath = target[0].path |
|
|
|
enname = board.get("build.encrypt") |
|
|
|
print("Encrypting %s to %s" % (fwpath, enname)) |
|
|
|
fwfile = open(fwpath, "rb") |
|
|
|
enfile = open(target[0].dir.path + "/" + enname, "wb") |
|
|
|
length = os.path.getsize(fwpath) |
|
|
|
|
|
|
|
encrypt_file(firmware, renamed, length) |
|
|
|
encrypt_file(fwfile, enfile, length) |
|
|
|
|
|
|
|
firmware.close() |
|
|
|
renamed.close() |
|
|
|
fwfile.close() |
|
|
|
enfile.close() |
|
|
|
os.remove(fwpath) |
|
|
|
|
|
|
|
if 'encrypt' in board.get("build").keys(): |
|
|
|
if board.get("build.encrypt") != "": |
|
|
|
marlin.add_post_action(encrypt) |
|
|
|
if board.get("build.encrypt") != "": |
|
|
|
marlin.add_post_action(encrypt) |
|
|
|
else: |
|
|
|
print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter") |
|
|
|
exit(1) |
|
|
|
print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter") |
|
|
|
exit(1) |
|
|
|