Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ Convert sparse Android data image (.dat) into filesystem ext4 image (.img)


## Requirements
This binary requires Python 2.7 or newer installed on your system.
It currently supports Windows, Linux, MacOS & ARM architectures.
This binary requires Python 2.7 or newer installed on your system.

**Note:** newer Google's [Brotli](https://github.com/google/brotli) format (`system.new.dat.br`) must be decompressed to a valid sparse data image before using `sdat2img` binary.
It currently supports Windows, Linux, MacOS & ARM architectures.



Expand Down
21 changes: 19 additions & 2 deletions sdat2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#====================================================

from __future__ import print_function
import sys, os, errno
import sys, os, errno, tempfile
import brotli

def main(TRANSFER_LIST_FILE, NEW_DATA_FILE, OUTPUT_IMAGE_FILE):
__version__ = '1.2'
Expand Down Expand Up @@ -89,7 +90,20 @@ def parse_transfer_list_file(path):
else:
raise

new_data_file = open(NEW_DATA_FILE, 'rb')
original_brotli = False
target_data_file = NEW_DATA_FILE
if target_data_file.endswith('.br'):
original_brotli = True
print("Decompressing {} with brotli".format(target_data_file))
with open(target_data_file, 'rb') as infile:
data = infile.read()
data = brotli.decompress(data)

tmp = tempfile.NamedTemporaryFile(delete=False)
tmp.write(data)
target_data_file = tmp.name

new_data_file = open(target_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

Expand Down Expand Up @@ -117,6 +131,9 @@ def parse_transfer_list_file(path):

output_img.close()
new_data_file.close()
if original_brotli:
os.unlink(target_data_file)

print('Done! Output image: {}'.format(os.path.realpath(output_img.name)))

if __name__ == '__main__':
Expand Down