資源簡介
android鏡像system.new.dat解包解壓縮sdat2img。
使用說明:需安裝python環(huán)境,將system.new.dat,system.transfer.list和解壓文件放在同一目錄下,linux系統(tǒng)下,直接執(zhí)行.py文件;windows下,直接雙擊執(zhí)行.bat文件
代碼片段和文件信息
#!/usr/bin/env?python
#encoding:utf8
#===============================================================================
#??????????FILE:?sdat2img.py
#????????AUTHOR:?luxi78@gmail.com?
#???????CREATED:?2014年12月21日?15時(shí)25分15秒?CST
#??????REVISION:??---
#===============================================================================
import?sys
TRANSFER_LIST_FILE?=?‘system.transfer.list‘
NEW_DATA_FILE?=?‘system.new.dat‘
OUTPUT_IMAGE_FILE?=?‘system.img‘
BLOCK_SIZE?=?4096
def?rangeset(src):
????src_set?=?src.split(‘‘)
????num_set?=??[int(item)?for?item?in?src_set]
????if?len(num_set)?!=?num_set[0]+1:
????????print?‘Error?for?parsiing?following?data?to?rangeset:\n%s‘?%?src
????????sys.exit(1)
????return?tuple?([?(num_set[i]?num_set[i+1])?for?i?in?range(1?len(num_set)?2)?])
def?parse_transfer_list_file(path):
????trans_list?=?open(TRANSFER_LIST_FILE?‘r‘)
????version?=?int(trans_list.readline())
????new_blocks?=?int(trans_list.readline())
????for?line?in?trans_list:
????????line?=?line.split(‘?‘)????????
????????cmd?=?line[0]????????
????????if?‘0\n‘?==?cmd:????????????
????????????print?‘read?0\\n‘
????????elif?‘erase‘?==?cmd:
????????????erase_block_set?=?rangeset(line[1])
????????elif?‘new‘?==?cmd:
????????????new_block_set?=?rangeset(line[1])
????????else:
????????????print?‘Error?command?%s‘?%?cmd
????????????trans_list.close()
????????????sys.exit(1)
????trans_list.close()
????return?version?new_blocks?erase_block_set?new_block_set?
def?init_output_file_size(output_file_obj?erase_block_set):
????max_block_num?=?max(pair[1]?for?pair?in?erase_block_set)
????output_file_obj.seek(max_block_num*BLOCK_SIZE?-?1)
????output_file_obj.write(‘\0‘)
????output_file_obj.flush()
def?main(argv):
????version?new_blocks?erase_block_set?new_block_set?=??parse_transfer_list_file(TRANSFER_LIST_FILE)
????output_img?=?file(?OUTPUT_IMAGE_FILE?‘wb‘)
????init_output_file_size(output_img?erase_block_set)
????new_data_file?=?file(NEW_DATA_FILE?‘rb‘)
???
????for?block?in?new_block_set:
????????begin?=?block[0]
????????end?=?block[1]
????????block_count?=?end?-?begin
????????print?“Reading?%d?blocks...“?%?block_count
????????data?=?new_data_file.read(block_count*BLOCK_SIZE)
????????print?“writing?to?%d...“?%?begin
????????output_img.seek(begin*BLOCK_SIZE)
????????output_img.write(data)
????????print?“finish!“
????output_img.close()
????new_data_file.close()
if?__name__?==?“__main__“:
????main(sys.argv)
評論
共有 條評論