-
Notifications
You must be signed in to change notification settings - Fork 51
/
adel_dump_partitions.py
150 lines (119 loc) · 4.63 KB
/
adel_dump_partitions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/python2.7
import os
import sys
import argparse
import subprocess
CACHE_PARTITION = "/dev/block/mmcblk0p7"
DATA_PARTITION = "/dev/block/mmcblk0p10"
EMMC_PARTITION = "/dev/block/mmcblk0p11"
SYSTEM_PARTITION = "/dev/block/mmcblk0p9"
SDCARD_PARTITION = "/dev/block/mmcblk0p1"
def determine_dst_path(src, dst):
return dst + "/" + src.rsplit('/')[-1]
def get_adb_checksum(path):
return subprocess.check_output(["adb", "shell", "sha256sum", path]).rsplit(' ')[0]
def get_checksum(path):
return subprocess.check_output(["sha256sum", path]).rsplit(' ')[0]
def dump_partition(src, dst):
subprocess.call(["adb", "pull", str(src), str(determine_dst_path(src, dst))])
def comp_checksums(c1, c2):
if c1 == c2:
return "OK"
else:
return "FAILED"
def dump_partitions(debug, path):
if debug is True:
print "Building checksums before dumping ..."
print "WARNING: This may take a while."
print ""
sys.stdout.write('/cache\t' + CACHE_PARTITION + '\t')
sys.stdout.flush()
cache_c0 = get_adb_checksum(CACHE_PARTITION)
sys.stdout.write(cache_c0 + '\n')
sys.stdout.write('/data\t' + DATA_PARTITION + '\t')
sys.stdout.flush()
data_c0 = get_adb_checksum(DATA_PARTITION)
sys.stdout.write(data_c0 + '\n')
sys.stdout.write('/emmc\t' + EMMC_PARTITION + '\t')
sys.stdout.flush()
emmc_c0 = get_adb_checksum(EMMC_PARTITION)
sys.stdout.write(emmc_c0 + '\n')
sys.stdout.write('/system\t' + SYSTEM_PARTITION + '\t')
sys.stdout.flush()
system_c0 = get_adb_checksum(SYSTEM_PARTITION)
sys.stdout.write(system_c0 + '\n')
sys.stdout.write('/sdcard\t' + SDCARD_PARTITION + '\t')
sys.stdout.flush()
sdcard_c0 = get_adb_checksum(SDCARD_PARTITION)
sys.stdout.write(sdcard_c0 + '\n')
print ""
print ""
print "Starting to dump partitions ..."
print ""
sys.stdout.write('/cache\t' + CACHE_PARTITION + '\t')
sys.stdout.flush()
dump_partition(CACHE_PARTITION, path)
sys.stdout.write('DONE\n')
sys.stdout.write('/data\t' + DATA_PARTITION + '\t')
sys.stdout.flush()
dump_partition(DATA_PARTITION, path)
sys.stdout.write('DONE\n')
sys.stdout.write('/emmc\t' + EMMC_PARTITION + '\t')
sys.stdout.flush()
dump_partition(EMMC_PARTITION, path)
sys.stdout.write('DONE\n')
sys.stdout.write('/system\t' + SYSTEM_PARTITION + '\t')
sys.stdout.flush()
dump_partition(SYSTEM_PARTITION, path)
sys.stdout.write('DONE\n')
sys.stdout.write('/sdcard\t' + SDCARD_PARTITION + '\t')
sys.stdout.flush()
dump_partition(SDCARD_PARTITION, path)
sys.stdout.write('DONE\n')
if debug is True:
print ""
print ""
print "Checking integrity of dumps ..."
print ""
sys.stdout.write('/cache\t' + CACHE_PARTITION + '\t')
sys.stdout.flush()
cache_c1 = get_checksum(determine_dst_path(CACHE_PARTITION, path))
sys.stdout.write(cache_c1 + '\t' + comp_checksums(cache_c0, cache_c1) + '\n')
sys.stdout.write('/data\t' + DATA_PARTITION + '\t')
sys.stdout.flush()
data_c1 = get_checksum(determine_dst_path(DATA_PARTITION, path))
sys.stdout.write(data_c1 + '\t' + comp_checksums(data_c0, data_c1) + '\n')
sys.stdout.write('/emmc\t' + EMMC_PARTITION + '\t')
sys.stdout.flush()
emmc_c1 = get_checksum(determine_dst_path(EMMC_PARTITION, path))
sys.stdout.write(emmc_c1 + '\t' + comp_checksums(emmc_c0, emmc_c1) + '\n')
sys.stdout.write('/system\t' + SYSTEM_PARTITION + '\t')
sys.stdout.flush()
system_c1 = get_checksum(determine_dst_path(SYSTEM_PARTITION, path))
sys.stdout.write(system_c1 + '\t' + comp_checksums(system_c0, system_c1) + '\n')
sys.stdout.write('/sdcard\t' + SDCARD_PARTITION + '\t')
sys.stdout.flush()
sdcard_c1 = get_checksum(determine_dst_path(SDCARD_PARTITION, path))
sys.stdout.write(sdcard_c1 + '\t' + comp_checksums(sdcard_c0, sdcard_c1) + '\n')
print ""
print ""
print "Partitions dumped."
def main(debug, path):
os.system("clear")
print """\033[0;32m
_____ ________ ___________.____
/ _ \ \______ \ \_ _____/| |
/ /_\ \ | | \ | __)_ | |
/ | \| ` \| \| |___
\____|__ /_______ /_______ /|_______ \
\/ \/ \/ \/
Android Data Extractor Lite - Partition Dumper
\033[m"""
dump_partitions(debug, path)
if __name__ == "__main__":
usage = "adel_dump_partitions.py [-i] [-o directory]"
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-i', '--integrity', action='store_true', help="When set integrity checks are made")
parser.add_argument('-o', '--output', default=".", nargs=1, help="Directory, where to save the dumps")
options = parser.parse_args(sys.argv[1:])
main(options.integrity, options.output[0])