Skip to content
This repository has been archived by the owner on Mar 6, 2022. It is now read-only.

Commit

Permalink
Support selective extraction of partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
chirayudesai committed Sep 16, 2019
1 parent d69244d commit 254cbdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Incremental firmware images are not supported (source_copy, source_bsdiff operat
## Usage

```
$ extract_android_ota_payload.py <payload.bin> [target_dir]
<payload.bin> : file extracted from the OTA zip file or the OTA zip file
<target_dir> : output directory for the extracted file
$ extract_android_ota_payload.py <payload.bin> [target_dir] [partition.img]
<payload.bin> : file extracted from the OTA zip file or the OTA zip file
<target_dir> : output directory for the extracted file
<partition_img> : name of partition to be extracted
```

## Example
Expand Down
22 changes: 19 additions & 3 deletions extract_android_ota_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def parse_payload(payload_f, partition, out_f):
else:
raise PayloadError('Unhandled operation type (%d)' % operation.type)

def main(filename, output_dir):
def main(filename, output_dir, partition):
if filename.endswith('.zip'):
print("Extracting 'payload.bin' from OTA file...")
ota_zf = zipfile.ZipFile(filename)
Expand All @@ -117,6 +117,8 @@ def main(filename, output_dir):

for p in payload.manifest.partitions:
name = p.partition_name + '.img'
if (partition is not None and name != partition):
continue
print("Extracting '%s'" % name)
fname = os.path.join(output_dir, name)
out_f = open(fname, 'w')
Expand All @@ -131,15 +133,29 @@ def main(filename, output_dir):
try:
filename = sys.argv[1]
except:
print('Usage: %s payload.bin [output_dir]' % sys.argv[0])
print('Usage: %s payload.bin [output_dir] [partition.img]' % sys.argv[0])
sys.exit()

try:
output_dir = sys.argv[2]
except IndexError:
output_dir = os.getcwd()

try:
partition = sys.argv[3]
except IndexError:
try:
partition = sys.argv[2]
except IndexError:
partition = None

if partition is not None and not partition.endswith('.img'):
partition = None

if output_dir.endswith('.img'):
output_dir = os.getcwd()

if not os.path.exists(output_dir):
os.makedirs(output_dir)

main(filename, output_dir)
main(filename, output_dir, partition)

0 comments on commit 254cbdc

Please sign in to comment.