-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-files.sh
executable file
·98 lines (84 loc) · 2.67 KB
/
extract-files.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
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#
# Copyright (C) 2023 Paranoid Android
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
### Setup
DUMP=
MY_DIR="${BASH_SOURCE%/*}"
SRC_ROOT="${MY_DIR}/../../.."
TMP_DIR=$(mktemp -d)
EXTRACT_KERNEL=true
declare -a MODULE_FOLDERS=("vendor_ramdisk" "vendor_dlkm" "system_dlkm")
while [ "${#}" -gt 0 ]; do
case "${1}" in
-n | --no-kernel )
EXTRACT_KERNEL=false
;;
* )
DUMP="${1}"
;;
esac
shift
done
[ -f "${MY_DIR}/Module.symvers" ] || touch "${MY_DIR}/Module.symvers"
[ -f "${MY_DIR}/System.map" ] || touch "${MY_DIR}/System.map"
# Check if dump is specified and exists
if [ -z "${DUMP}" ]; then
echo "Please specify the dump!"
exit 1
elif [ ! -d "${DUMP}" ]; then
echo "Unable to find dump at ${DUMP}!"
exit 1
fi
echo "Extracting files from ${DUMP}:"
### Kernel
if ${EXTRACT_KERNEL}; then
echo "Extracting boot image.."
${SRC_ROOT}/system/tools/mkbootimg/unpack_bootimg.py \
--boot_img "${DUMP}/boot.img" \
--out "${TMP_DIR}/boot.out" > /dev/null
cp -f "${TMP_DIR}/boot.out/kernel" ${MY_DIR}/kernel
echo " - kernel"
fi
### DTBS
# Cleanup / Preparation
rm -rf "${MY_DIR}/dtbs"
mkdir "${MY_DIR}/dtbs"
echo "Extracting vendor_boot image..."
${SRC_ROOT}/system/tools/mkbootimg/unpack_bootimg.py \
--boot_img "${DUMP}/vendor_boot.img" \
--out "${TMP_DIR}/vendor_boot.out" > /dev/null
curl -sSL "https://raw.githubusercontent.com/PabloCastellano/extract-dtb/master/extract_dtb/extract_dtb.py" > ${TMP_DIR}/extract_dtb.py
# Copy
python3 "${TMP_DIR}/extract_dtb.py" "${TMP_DIR}/vendor_boot.out/dtb" -o "${TMP_DIR}/dtbs" > /dev/null
find "${TMP_DIR}/dtbs" -type f -name "*.dtb" \
-exec cp {} "${MY_DIR}/dtbs" \; \
-exec printf " - dtbs/" \; \
-exec basename {} \;
cp -f "${DUMP}/dtbo.img" "${MY_DIR}/dtbs/dtbo.img"
echo " - dtbs/dtbo.img"
### Modules
# Cleanup / Preparation
for MODULE_FOLDER in "${MODULE_FOLDERS[@]}"; do
rm -rf "${MY_DIR}/${MODULE_FOLDER}"
mkdir "${MY_DIR}/${MODULE_FOLDER}"
done
# Copy
for MODULE_FOLDER in "${MODULE_FOLDERS[@]}"; do
MODULE_SRC="${DUMP}/${MODULE_FOLDER}"
if [ "${MODULE_FOLDER}" == "vendor_ramdisk" ]; then
lz4 -qd "${TMP_DIR}/vendor_boot.out/vendor_ramdisk00" "${TMP_DIR}/vendor_ramdisk.cpio"
7z x "${TMP_DIR}/vendor_ramdisk.cpio" -o"${TMP_DIR}/vendor_ramdisk" > /dev/null
MODULE_SRC="${TMP_DIR}/vendor_ramdisk"
fi
[ -d "${MODULE_SRC}" ] || break
find "${MODULE_SRC}/lib/modules" -type f \
-exec cp {} "${MY_DIR}/${MODULE_FOLDER}/" \; \
-exec printf " - ${MODULE_FOLDER}/" \; \
-exec basename {} \;
done
# Clear temp dir
rm -rf "${TMP_DIR}"