新增以下提交
1.自动判断bin文件是否需要解密 2.添加下载指定ram.bin的功能,支持命令行交互 3.去除手动指定上传还是下载的命令选项
This commit is contained in:
@@ -214,6 +214,18 @@ def img_header_check(data:bytearray):
|
||||
return "V0"
|
||||
return ""
|
||||
|
||||
# 判断是不是加密了
|
||||
def pkt_encrypt_check(data:bytearray):
|
||||
magic_data=data[12:16]
|
||||
pat=magic_data[0]
|
||||
for i in range(len(magic_data)):
|
||||
magic_data[i]=magic_data[i]^pat
|
||||
magic=(magic_data[0]<<24)|(magic_data[1]<<16)|(magic_data[2]<<8)|(magic_data[3])
|
||||
if (magic==_PKT_HEADER_MAGIC_NO):
|
||||
if(pat!=0):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# 转化为hex文本
|
||||
def bin_to_hex(bin:bytearray,f,oem_file=None):
|
||||
@@ -261,11 +273,11 @@ def bin_to_hex(bin:bytearray,f,oem_file=None):
|
||||
return kunlun
|
||||
|
||||
|
||||
def bin_to_hex_file(bin_file_name:str,hex_file_name:str,enc=0):
|
||||
def bin_to_hex_file(bin_file_name:str,hex_file_name:str):
|
||||
with open(bin_file_name,mode='rb') as f:
|
||||
bin=bytearray(f.read())
|
||||
if(enc):
|
||||
myprint("start decrypt")
|
||||
if(pkt_encrypt_check(bin)):
|
||||
myprint("start decrypt:")
|
||||
pat=(bin[12]^0x00)&0xff
|
||||
myprint(f"decrypt image:{hex(pat)}({_PatternType.get(pat,'unknown')})")
|
||||
for index in range(len(bin)):
|
||||
@@ -291,7 +303,7 @@ def bin_file_decrypt(bin_file:str):
|
||||
with open(bin_file,mode='rb') as f:
|
||||
bin=bytearray(f.read())
|
||||
# 自动判断是否需要解密
|
||||
if ((bin[12]==bin[13])and(bin[12]!=0x00)):
|
||||
if (pkt_encrypt_check(bin)):
|
||||
pat=(bin[12]^0x00)&0xff
|
||||
myprint(f"decrypt image:{hex(pat)}({_PatternType.get(pat,'unknown')})")
|
||||
for index in range(len(bin)):
|
||||
@@ -313,8 +325,4 @@ def clear_tmp():
|
||||
|
||||
# bin_to_hex.py input_file
|
||||
if __name__ == "__main__":
|
||||
if(len(sys.argv)>=3):
|
||||
enc=1
|
||||
else:
|
||||
enc=0
|
||||
bin_to_hex_file(sys.argv[1],"work/"+sys.argv[1]+".txt",enc)
|
||||
bin_to_hex_file(sys.argv[1],"work/"+sys.argv[1]+".txt")
|
||||
|
BIN
bin/bootram_kl1_build.bin
Normal file
BIN
bin/bootram_kl1_build.bin
Normal file
Binary file not shown.
12
bin/log.py
12
bin/log.py
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
# 同一个进程中所有调用这个文件的 .py 文件都使用这个变量
|
||||
@@ -23,6 +23,16 @@ def myprint_dec(func):
|
||||
|
||||
myprint=myprint_dec(print)
|
||||
|
||||
def mywrite(data:str):
|
||||
if(_log_fp is not None):
|
||||
txt=data.replace('\r','\n')
|
||||
txt=txt.replace('\n\n','\n')
|
||||
txt=txt.replace('\n\n','\n')
|
||||
_log_fp.write(txt)
|
||||
_log_fp.flush()
|
||||
sys.stdout.write(data)
|
||||
sys.stdout.flush()
|
||||
|
||||
def log_init(file_name:str):
|
||||
global _log_fp
|
||||
if _log_fp is None:
|
||||
|
Reference in New Issue
Block a user