#!/usr/bin/env python
# -*- coding: utf-8 -*-
#====================================================
# FILE: sdat2img.py
# AUTHORS: xpirt - luxi78 - howellzhu
# DATE: 2016-07-23 10:59:46 CST
#====================================================
import sys, os, errno
try:
TRANSFER_LIST_FILE = str(sys.argv[1])
NEW_DATA_FILE = str(sys.argv[2])
except IndexError:
print('\nUsage: sdat2img.py <transfer_list> <system_new_file> [system_img]\n')
print(' <transfer_list>: transfer list file')
print(' <system_new_file>: system new dat file')
print(' [system_img]: output system image\n\n')
print('Visit xda thread for more information.\n')
try:
input = raw_input
except NameError: pass
input('Press ENTER to exit...')
sys.exit()
try:
OUTPUT_IMAGE_FILE = str(sys.argv[3])
except IndexError:
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 on parsing 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')
# Transfer list file version
# - version 1: android 5.0.x
# - version 2: android 5.1.x
# - version 3: android 6.0.x
version = int(trans_list.readline())
# Total number of blocks
new_blocks = int(trans_list.readline())
# Skip next 2 lines, we don't need that stuff now
if version >= 2:
trans_list.readline()
trans_list.readline()
commands = []
for line in trans_list:
line = line.split(' ')
cmd = line[0]
if cmd in ['erase', 'new', 'zero']:
commands.append([cmd, rangeset(line[1])])
else:
# Skip lines starting with numbers, they are not commands anyway
if not cmd[0].isdigit():
print('Command "%s" is not valid.' % cmd)
trans_list.close()
sys.exit(1)
trans_list.close()
return version, new_blocks, commands
def main(argv):
version, new_blocks, commands = parse_transfer_list_file(TRANSFER_LIST_FILE)
# Don't clobber existing files to avoid accidental data loss
try:
output_img = open(OUTPUT_IMAGE_FILE, 'wb')
except IOError as e:
if e.errno == errno.EEXIST:
print('Error: the output file "{}" already exists'.format(e.filename))
print('Remove it, rename it, or choose a different file name.')
sys.exit(e.errno)
else:
raise
new_data_file = open(NEW_DATA_FILE, 'rb')
all_block_sets = [i for command in commands for i in command[1]]
max_file_size = max(pair[1] for pair in all_block_sets)*BLOCK_SIZE
for command in commands:
if command[0] == 'new':
for block in command[1]:
begin = block[0]
end = block[1]
block_count = end - begin
print('Copying {} blocks into position {}...'.format(block_count, begin))
# Position output file
output_img.seek(begin*BLOCK_SIZE)
# Copy one block at a time
while(block_count > 0):
output_img.write(new_data_file.read(BLOCK_SIZE))
block_count -= 1
else:
print('Skipping command %s' % command[0])
# Make file larger if necessary
if(output_img.tell() < max_file_size):
output_img.truncate(max_file_size)
output_img.close()
new_data_file.close()
print('\nDone! Output image: %s' % os.path.realpath(output_img.name))
if __name__ == '__main__':
main(sys.argv)
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
SystemExtractor.7z (32个子文件)
dat
bin
brotli.exe 762KB
msvcr100.dll 756KB
python
_multiprocessing.pyd 24KB
_hashlib.pyd 1014KB
_lzma.pyd 149KB
_socket.pyd 60KB
pyvenv.cfg 17B
unicodedata.pyd 845KB
vcruntime140.dll 84KB
python.exe 39KB
python35.zip 2.15MB
_ssl.pyd 1.38MB
pyexpat.pyd 154KB
sdat2img.py 4KB
sqlite3.dll 591KB
_elementtree.pyd 152KB
python35.dll 2.98MB
_overlapped.pyd 33KB
winsound.pyd 23KB
pythonw.exe 39KB
_decimal.pyd 208KB
_msi.pyd 31KB
_sqlite3.pyd 62KB
select.pyd 22KB
_bz2.pyd 74KB
_ctypes.pyd 99KB
python3.dll 51KB
sdat2img.bat 54B
Imgextractor.exe 189KB
br
请把system.new.dat.br放到该文件夹 0B
extract
解包dat.cmd 2KB
解包br.cmd 1KB
共 32 条
- 1
Byroncn
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5