华为官方固件包UPDATE.APP解包,大多依靠一个perl语言脚本split_updata.pl。JoeyJiao的split_updata.pl最新版本,可以解开华为p6的包,但文件名识别不了。源码地址:https://github.com/JoeyJiao/split_updata.pl
找到一个python版本的,可以解包并精确给出文件名。原始为python2版本,自行小修改成python3版本。
代码源自scue及jnjn,原始代码看这里:http://jnjn.blog.163.com/blog/static/275999382013311515491/
修改版如下:
#!/usr/bin/env python
# Version: 0.2.201308040830
# Author: linkscue
# Function: unpack any hauwei honor2 Update.app
# Thanks to McSpoon(zhaoxing-go@163.com)
# 20130411: Modified for alignment to 4 byte boundary by jnjn@163.com
# 20130804: Modified for python3 by atuo @ oschina.net
import os
import sys
import struct
from functools import reduce
print("Usage: unpack $huawei_app_file")
try:
sys.argv[1]
except IndexError:
File="UPDATE.APP"
else:
File=sys.argv[1];
verify_code=0xa55aaa55
verify_bin=struct.pack("I",verify_code)
print("I: unpack",File)
f=open(File,'rb')
cont=f.read()
f.close()
start=0
sub_file=1
search=verify_bin
while True:
index = cont.find(search, start)
if index == -1:
break
if ((index) % 4 != 0 ):
print("skipping a 55aa5aa5 at offset: 0x%08x\n" % (index))
start = index + 1
else:
packet_addr=cont[index+4:index+8]
data_addr=cont[index+24:index+28]
img_name=cont[index+60:index+76]
packet_size_tuple=struct.unpack("I",packet_addr)
data_size_tuple=struct.unpack("I",data_addr)
packet_size=int(reduce(lambda rst, d: rst * 10 + d, packet_size_tuple))
data_size=int(reduce(lambda rst, d: rst * 10 + d, data_size_tuple))
temp=cont[index+packet_size:index+packet_size+data_size]
filename=str(sub_file)+'_'+img_name.strip(b'\x00').decode('ascii')+'.img'
print( "%2d I: verify code found at: 0x%08x, size: %10d bytes, --> %-20s" \
% (sub_file,index,data_size,filename) )
f1=open(filename,'wb')
f1.write(temp)
f1.close()
start = index + 1
sub_file += 1