Skip to content

Commit 21935a3

Browse files
committed
Simple tool to extract a tar from an unencrypted adb backup
1 parent 273c6ae commit 21935a3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Extract a `tar` from an `adb backup` file
2+
3+
Backup file goes into stdin, tar file comes out on stdout.
4+
5+
## Limitations
6+
7+
- Does not support encrypted backups (pull requests welcome!)
8+
- Does not support uncompressed backups (not sure how to create these?)
9+
10+
## Examples
11+
12+
To view the contents of a backup
13+
14+
```
15+
./extract.py < backup | tar -tv
16+
```
17+
18+
To extract all files from a backup
19+
20+
```
21+
./extract.py < backup | tar -x
22+
```
23+
24+
# Further info
25+
26+
(Details of backup file structure)[https://android.stackexchange.com/questions/23357/is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file]
27+
(Further Details)[https://nelenkov.blogspot.co.uk/2012/06/unpacking-android-backups.html] - could be used as a reference to implement backup decryption

extract.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/python3
2+
3+
import collections
4+
import struct
5+
import zlib
6+
import sys
7+
8+
def read_header(inp):
9+
buf = inp.read(24)
10+
11+
lines = buf.decode('ascii').split('\n')
12+
if lines[0] != 'ANDROID BACKUP':
13+
raise ValueError('Header invalid')
14+
if lines[1] != '4':
15+
raise ValueError('Unsupported version')
16+
if lines[2] != '1':
17+
raise ValueError('Uncompressed not supported')
18+
if lines[3] != 'none':
19+
raise ValueError('Encryption not supported!')
20+
21+
def flate_stream(inp):
22+
d = zlib.decompressobj()
23+
buf = inp.read(4096)
24+
while buf:
25+
yield d.decompress(buf)
26+
buf = inp.read(4096)
27+
yield d.flush()
28+
29+
if __name__ == '__main__':
30+
hdr = read_header(sys.stdin.buffer)
31+
for buf in flate_stream(sys.stdin.buffer):
32+
sys.stdout.buffer.write(buf)
33+

0 commit comments

Comments
 (0)