🔨 Delete after encrypt. Lerdge encrypt only once
This commit is contained in:
parent
2c6fe45847
commit
b4904cc53e
|
@ -21,24 +21,23 @@ def encryptByte(byte):
|
||||||
def encrypt_file(input, output_file, file_length):
|
def encrypt_file(input, output_file, file_length):
|
||||||
input_file = bytearray(input.read())
|
input_file = bytearray(input.read())
|
||||||
for i in range(len(input_file)):
|
for i in range(len(input_file)):
|
||||||
result = encryptByte(input_file[i])
|
input_file[i] = encryptByte(input_file[i])
|
||||||
input_file[i] = result
|
|
||||||
|
|
||||||
output_file.write(input_file)
|
output_file.write(input_file)
|
||||||
return
|
|
||||||
|
|
||||||
# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
|
# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
|
||||||
def encrypt(source, target, env):
|
def encrypt(source, target, env):
|
||||||
fwname = board.get("build.encrypt")
|
fwpath = target[0].path
|
||||||
print("Encrypting %s to %s" % (target[0].path, fwname))
|
enname = board.get("build.encrypt")
|
||||||
firmware = open(target[0].path, "rb")
|
print("Encrypting %s to %s" % (fwpath, enname))
|
||||||
renamed = open(target[0].dir.path + "/" + fwname, "wb")
|
fwfile = open(fwpath, "rb")
|
||||||
length = os.path.getsize(target[0].path)
|
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()
|
fwfile.close()
|
||||||
renamed.close()
|
enfile.close()
|
||||||
|
os.remove(fwpath)
|
||||||
|
|
||||||
if 'encrypt' in board.get("build").keys():
|
if 'encrypt' in board.get("build").keys():
|
||||||
if board.get("build.encrypt") != "":
|
if board.get("build.encrypt") != "":
|
||||||
|
|
|
@ -48,22 +48,24 @@ def encrypt_mks(source, target, env, new_name):
|
||||||
|
|
||||||
key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E]
|
key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E]
|
||||||
|
|
||||||
firmware = open(target[0].path, "rb")
|
fwpath = target[0].path
|
||||||
renamed = open(target[0].dir.path + "/" + new_name, "wb")
|
fwfile = open(fwpath, "rb")
|
||||||
length = os.path.getsize(target[0].path)
|
enfile = open(target[0].dir.path + "/" + new_name, "wb")
|
||||||
|
length = os.path.getsize(fwpath)
|
||||||
position = 0
|
position = 0
|
||||||
try:
|
try:
|
||||||
while position < length:
|
while position < length:
|
||||||
byte = firmware.read(1)
|
byte = fwfile.read(1)
|
||||||
if position >= 320 and position < 31040:
|
if position >= 320 and position < 31040:
|
||||||
byte = chr(ord(byte) ^ key[position & 31])
|
byte = chr(ord(byte) ^ key[position & 31])
|
||||||
if sys.version_info[0] > 2:
|
if sys.version_info[0] > 2:
|
||||||
byte = bytes(byte, 'latin1')
|
byte = bytes(byte, 'latin1')
|
||||||
renamed.write(byte)
|
enfile.write(byte)
|
||||||
position += 1
|
position += 1
|
||||||
finally:
|
finally:
|
||||||
firmware.close()
|
fwfile.close()
|
||||||
renamed.close()
|
enfile.close()
|
||||||
|
os.remove(fwpath)
|
||||||
|
|
||||||
def add_post_action(action):
|
def add_post_action(action):
|
||||||
env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action);
|
env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action);
|
||||||
|
|
|
@ -263,13 +263,13 @@ platform = ${common_stm32.platform}
|
||||||
extends = stm32_variant
|
extends = stm32_variant
|
||||||
board = marlin_STM32F407ZGT6
|
board = marlin_STM32F407ZGT6
|
||||||
board_build.variant = MARLIN_LERDGE
|
board_build.variant = MARLIN_LERDGE
|
||||||
board_build.encrypt = firmware.bin
|
|
||||||
board_build.offset = 0x10000
|
board_build.offset = 0x10000
|
||||||
build_flags = ${stm32_variant.build_flags}
|
build_flags = ${stm32_variant.build_flags}
|
||||||
-DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4
|
-DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4
|
||||||
-DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DLERDGE_TFT35
|
-DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DLERDGE_TFT35
|
||||||
build_unflags = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
|
build_unflags = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
|
||||||
extra_scripts = ${stm32_variant.extra_scripts}
|
extra_scripts = ${common_stm32.extra_scripts}
|
||||||
|
pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
|
||||||
buildroot/share/PlatformIO/scripts/lerdge.py
|
buildroot/share/PlatformIO/scripts/lerdge.py
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue