-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathextract_images_custom.sh
86 lines (66 loc) · 2.85 KB
/
extract_images_custom.sh
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
#!/bin/bash
[ -f "util_functions.sh" ] && . ./util_functions.sh || { echo "util_functions.sh not found" && exit 1; }
print_message "Extracting images from archives..." info
for file in ./*; do
if [ -f "$file" ]; then
if [ "${file: -4}" == ".zip" ]; then
filename="${file##*/}"
basename="${filename%.*}"
devicename="${basename%%-*}"
print_message "Processing \"$filename\"" debug
extraction_start=$(date +%s)
if unzip -l "$file" | grep -q "payload.bin"; then
unzip -q "$file" -d "extracted_archive_images"
mv -f "extracted_archive_images/payload.bin" "extracted_archive_images/$basename.bin"
else
unzip -q "$file" -d "extracted_archive_images"
fi
rm "$file"
extraction_end=$(date +%s)
extraction_runtime=$((extraction_end - extraction_start))
print_message "Extraction time: $extraction_runtime seconds" debug
fi
fi
done
if [ -d "extracted_archive_images" ]; then
print_message "\nExtracting/Dumping images from \"extracted_archive_images\"..." info
for file in ./extracted_archive_images/*; do
if [ -f "$file" ]; then
if [ "${file: -4}" == ".zip" ] || [ "${file: -4}" == ".bin" ]; then
filename="${file##*/}"
basename="${filename%.*}"
print_message "Processing \"$filename\"" debug
extraction_start=$(date +%s)
if [ "${file: -4}" == ".bin" ]; then
python3 ota_dumper/extract_android_ota_payload.py "$file" "extracted_images/$basename"
else
for image_name in "${IMAGES2EXTRACT[@]}"; do
print_message "Extracting \"$image_name\"..." debug
unzip -q "$file" -d "extracted_images/$basename" "$image_name.img"
done
fi
extraction_end=$(date +%s)
extraction_runtime=$((extraction_end - extraction_start))
print_message "Extraction time: $extraction_runtime seconds" debug
fi
fi
done
rm -rf "extracted_archive_images"
fi
print_message "\nExtracting images and directories..." info
for dir in ./extracted_images/*; do
if [ -d "$dir" ]; then
dir=${dir%*/}
print_message "Processing \"${dir##*/}\"" debug
extraction_start=$(date +%s)
for image_name in "${IMAGES2EXTRACT[@]}"; do
extract_image "$dir" "$image_name"
rm "$dir/$image_name.img"
done
extraction_end=$(date +%s)
extraction_runtime=$((extraction_end - extraction_start))
print_message "Extraction time: $extraction_runtime seconds" debug
print_message "Building props..." info
./props.sh "$dir"
fi
done