添加oem解析 未完成
This commit is contained in:
19
bin/base.py
Normal file
19
bin/base.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 获取执行文件所在的目录
|
||||||
|
def bin_path():
|
||||||
|
if(sys.argv[0].endswith('.exe')):
|
||||||
|
path=os.path.dirname(os.path.realpath(sys.executable))
|
||||||
|
return os.path.join(path,'bin')
|
||||||
|
else:
|
||||||
|
path=os.path.abspath(__file__)
|
||||||
|
path=os.path.split(path)[0]
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -4,6 +4,7 @@ import sys
|
|||||||
import struct
|
import struct
|
||||||
import json
|
import json
|
||||||
from bin.log import myprint
|
from bin.log import myprint
|
||||||
|
from bin.base import bin_path
|
||||||
|
|
||||||
|
|
||||||
# kunlun1,kunlun2,kunlun3的img类型
|
# kunlun1,kunlun2,kunlun3的img类型
|
||||||
@@ -157,8 +158,8 @@ def tran_img_headerv0(data:bytearray):
|
|||||||
ret["sha256"]=data[32:].hex()
|
ret["sha256"]=data[32:].hex()
|
||||||
t=str(ret)
|
t=str(ret)
|
||||||
t=t.replace(',','\n')
|
t=t.replace(',','\n')
|
||||||
return t
|
return t,ret
|
||||||
return ""
|
return "",{}
|
||||||
|
|
||||||
def tran_img_headerv1(data:bytearray):
|
def tran_img_headerv1(data:bytearray):
|
||||||
size=len(data)
|
size=len(data)
|
||||||
@@ -186,8 +187,8 @@ def tran_img_headerv1(data:bytearray):
|
|||||||
ret["sha256"]=data[32:].hex()
|
ret["sha256"]=data[32:].hex()
|
||||||
t=str(ret)
|
t=str(ret)
|
||||||
t=t.replace(',','\n')
|
t=t.replace(',','\n')
|
||||||
return t
|
return t,ret
|
||||||
return ""
|
return "",{}
|
||||||
|
|
||||||
|
|
||||||
# 判断是不是pkt_header
|
# 判断是不是pkt_header
|
||||||
@@ -215,12 +216,13 @@ def img_header_check(data:bytearray):
|
|||||||
|
|
||||||
|
|
||||||
# 转化为hex文本
|
# 转化为hex文本
|
||||||
def bin_to_hex(bin:bytearray,f):
|
def bin_to_hex(bin:bytearray,f,oem_file=None):
|
||||||
all_size=len(bin)
|
all_size=len(bin)
|
||||||
pack_size=32
|
pack_size=32
|
||||||
turned=0
|
turned=0
|
||||||
turned_old=0
|
turned_old=0
|
||||||
out_text=''
|
out_text=''
|
||||||
|
kunlun=''
|
||||||
if(pkt_header_check(bin)):
|
if(pkt_header_check(bin)):
|
||||||
out_text=tran_pkg_header(bin[0:96])+'\n'
|
out_text=tran_pkg_header(bin[0:96])+'\n'
|
||||||
f.write(out_text)
|
f.write(out_text)
|
||||||
@@ -238,14 +240,24 @@ def bin_to_hex(bin:bytearray,f):
|
|||||||
hdr_data=bytearray()
|
hdr_data=bytearray()
|
||||||
hdr_v=img_header_check(hdr_data)
|
hdr_v=img_header_check(hdr_data)
|
||||||
if(hdr_v=='V0'):
|
if(hdr_v=='V0'):
|
||||||
out_text=tran_img_headerv0(hdr_data)+'\n'
|
kunlun='kl1'
|
||||||
|
out_text,ret=tran_img_headerv0(hdr_data)
|
||||||
|
out_text+='\n'
|
||||||
f.write(out_text)
|
f.write(out_text)
|
||||||
elif(hdr_v=='V1'):
|
elif(hdr_v=='V1'):
|
||||||
out_text=tran_img_headerv1(hdr_data)+'\n'
|
kunlun='kl3'
|
||||||
|
out_text,ret=tran_img_headerv1(hdr_data)
|
||||||
|
out_text+='\n'
|
||||||
f.write(out_text)
|
f.write(out_text)
|
||||||
|
# 截取oem部分
|
||||||
|
if(oem_file is not None):
|
||||||
|
if(_ImgType[hdr_data[1]]=="imgV1OEM"):
|
||||||
|
size=int(ret["imgSize"])
|
||||||
|
oem_bin=bin[turned_old+32:turned_old+32+size]
|
||||||
|
oem_file.write(oem_bin)
|
||||||
out_text=f"[{hex(turned_old)}] {data.hex(' ')}\n"
|
out_text=f"[{hex(turned_old)}] {data.hex(' ')}\n"
|
||||||
f.write(out_text)
|
f.write(out_text)
|
||||||
|
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,enc=0):
|
||||||
@@ -258,8 +270,19 @@ def bin_to_hex_file(bin_file_name:str,hex_file_name:str,enc=0):
|
|||||||
for index in range(len(bin)):
|
for index in range(len(bin)):
|
||||||
bin[index]=bin[index]^pat
|
bin[index]=bin[index]^pat
|
||||||
with open(hex_file_name,mode='w+',encoding="utf-8") as f:
|
with open(hex_file_name,mode='w+',encoding="utf-8") as f:
|
||||||
bin_to_hex(bin,f)
|
# oem_bin 去除原始后缀 .bin.txt 添加新后缀 -oem.bin
|
||||||
|
oem_name=hex_file_name[0:-8]+'-oem.bin'
|
||||||
|
with open(oem_name,mode='wb+') as oem_f:
|
||||||
|
kl=bin_to_hex(bin,f,oem_f)
|
||||||
|
# 调用oem_tool 打印oem信息
|
||||||
|
myprint(bin_path())
|
||||||
|
oem_tool=os.path.join(bin_path(),f"{kl}_oem.exe")
|
||||||
|
if(os.path.exists(oem_tool)):
|
||||||
|
cmd_str=f"{oem_tool} --parse={oem_name}"
|
||||||
|
myprint(cmd_str)
|
||||||
|
os.system(cmd_str)
|
||||||
|
else:
|
||||||
|
myprint(f"oem_tool not found: {oem_tool}")
|
||||||
|
|
||||||
def bin_file_decrypt(bin_file:str):
|
def bin_file_decrypt(bin_file:str):
|
||||||
with open(bin_file,mode='rb') as f:
|
with open(bin_file,mode='rb') as f:
|
||||||
|
BIN
bin/kl3_oem.exe
Normal file
BIN
bin/kl3_oem.exe
Normal file
Binary file not shown.
@@ -15,6 +15,7 @@ from bin.log import log_init
|
|||||||
from bin.bin_to_hex import bin_to_hex_file
|
from bin.bin_to_hex import bin_to_hex_file
|
||||||
from bin.bin_to_hex import bin_file_decrypt
|
from bin.bin_to_hex import bin_file_decrypt
|
||||||
from bin.bin_to_hex import clear_tmp
|
from bin.bin_to_hex import clear_tmp
|
||||||
|
from bin.base import bin_path
|
||||||
|
|
||||||
|
|
||||||
def init_send(s_port:serial.Serial, send_str:str):
|
def init_send(s_port:serial.Serial, send_str:str):
|
||||||
@@ -223,14 +224,6 @@ def burn_fun():
|
|||||||
print_device_str(ser_read_data)
|
print_device_str(ser_read_data)
|
||||||
|
|
||||||
|
|
||||||
# 获取执行文件所在的目录
|
|
||||||
def bin_path():
|
|
||||||
if(sys.argv[0].endswith('.exe')):
|
|
||||||
path=os.path.dirname(os.path.realpath(sys.executable))
|
|
||||||
else:
|
|
||||||
path=os.path.abspath(__file__)
|
|
||||||
path=os.path.split(path)[0]
|
|
||||||
return os.path.join(path,'bin')
|
|
||||||
|
|
||||||
def global_def():
|
def global_def():
|
||||||
global init_str
|
global init_str
|
||||||
|
Reference in New Issue
Block a user