forked from nnsee/payload-dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Find on https://forum.xda-developers.com/nokia-7-plus/how-to/guide-how-to-extract-payload-bin-ota-t3830962 * also on https://gist.github.com/ius/42bd02a5df2226633a342ab7a9c60f15 * can't find original git repo and autor
- Loading branch information
0 parents
commit 6ee284b
Showing
6 changed files
with
789 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore everything | ||
* | ||
|
||
# But not these files... | ||
!payload_dumper.py | ||
!requirements.txt | ||
!update_metadata_pb2.py | ||
!output/.gitkeep | ||
!README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# payload dumper | ||
Script work with Nokia 7 plus | ||
|
||
### System requirement | ||
|
||
- Python3, pip | ||
- google protobuf for python `pip install protobuf` | ||
|
||
### Guide | ||
|
||
- Make you sure you have Python 3.6 installed. | ||
- Download payload_dumper.py and update_metadata_pb2.py here. | ||
- Extract your OTA zip and place payload.bin in the same folder as these files. | ||
- Open PowerShell, Command Prompt, or Terminal depending on your OS. | ||
- Enter the following command: python -m pip install protobuf | ||
- When that’s finished, enter this command: python payload_dumper.py payload.bin | ||
- This will start to extract the images within the payload.bin file to the current folder you are in. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python | ||
import struct | ||
import hashlib | ||
import bz2 | ||
import sys | ||
|
||
try: | ||
import lzma | ||
except ImportError: | ||
from backports import lzma | ||
|
||
import update_metadata_pb2 as um | ||
|
||
flatten = lambda l: [item for sublist in l for item in sublist] | ||
|
||
def u32(x): | ||
return struct.unpack('>I', x)[0] | ||
|
||
def u64(x): | ||
return struct.unpack('>Q', x)[0] | ||
|
||
def verify_contiguous(exts): | ||
blocks = 0 | ||
|
||
for ext in exts: | ||
if ext.start_block != blocks: | ||
return False | ||
|
||
blocks += ext.num_blocks | ||
|
||
return True | ||
|
||
def data_for_op(op): | ||
p.seek(data_offset + op.data_offset) | ||
data = p.read(op.data_length) | ||
|
||
# assert hashlib.sha256(data).digest() == op.data_sha256_hash, 'operation data hash mismatch' | ||
|
||
if op.type == op.REPLACE_XZ: | ||
dec = lzma.LZMADecompressor() | ||
data = dec.decompress(data) | ||
elif op.type == op.REPLACE_BZ: | ||
dec = bz2.BZ2Decompressor() | ||
data = dec.decompress(data) | ||
|
||
return data | ||
|
||
def dump_part(part): | ||
print(part.partition_name) | ||
|
||
out_file = open('output/%s.img' % part.partition_name, 'wb') | ||
h = hashlib.sha256() | ||
|
||
for op in part.operations: | ||
data = data_for_op(op) | ||
h.update(data) | ||
out_file.write(data) | ||
|
||
# assert h.digest() == part.new_partition_info.hash, 'partition hash mismatch' | ||
|
||
p = open(sys.argv[1], 'rb') | ||
|
||
magic = p.read(4) | ||
assert magic == b'CrAU' | ||
|
||
file_format_version = u64(p.read(8)) | ||
assert file_format_version == 2 | ||
|
||
manifest_size = u64(p.read(8)) | ||
|
||
metadata_signature_size = 0 | ||
|
||
if file_format_version > 1: | ||
metadata_signature_size = u32(p.read(4)) | ||
|
||
manifest = p.read(manifest_size) | ||
metadata_signature = p.read(metadata_signature_size) | ||
|
||
data_offset = p.tell() | ||
|
||
dam = um.DeltaArchiveManifest() | ||
dam.ParseFromString(manifest) | ||
|
||
for part in dam.partitions: | ||
# for op in part.operations: | ||
# assert op.type in (op.REPLACE, op.REPLACE_BZ, op.REPLACE_XZ), \ | ||
# 'unsupported op' | ||
|
||
# extents = flatten([op.dst_extents for op in part.operations]) | ||
# assert verify_contiguous(extents), 'operations do not span full image' | ||
|
||
dump_part(part) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
protobuf==3.6.0 | ||
six==1.11.0 |
Oops, something went wrong.