Skip to content

Commit

Permalink
chore: go to newline when using '||'
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoninoScordino committed Nov 2, 2024
1 parent 9994180 commit 3c4a9be
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions extract_and_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,16 @@ if [[ -f "${PWD}/boot.img" ]]; then

# Unpack 'boot.img' through 'unpackbootimg'
echo "[INFO] Extracting 'boot.img' content..."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || echo "[ERROR] Extraction unsuccessful."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || \
echo "[ERROR] Extraction unsuccessful."

# Decrompress 'boot.img-ramdisk'
## Run only if 'boot.img-ramdisk' is not empty
if file boot.img-ramdisk | grep -q LZ4 || file boot.img-ramdisk | grep -q gzip; then
echo "[INFO] Extracting ramdisk..."
unlz4 "${OUTPUT}/boot.img-ramdisk" "${OUTPUT}/ramdisk.lz4" > /dev/null
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || echo "[ERROR] Failed to extract ramdisk."
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || \
echo "[ERROR] Failed to extract ramdisk."

## Clean-up
rm -rf "${OUTPUT}/ramdisk.lz4"
Expand All @@ -364,30 +366,30 @@ if [[ -f "${PWD}/boot.img" ]]; then

# Generate non-stack symbols
echo "[INFO] Generating 'kallsyms.txt'..."
uvx --from git+https://github.com/marin-m/vmlinux-to-elf@da14e789596d493f305688e221e9e34ebf63cbb8 kallsyms-finder "${IMAGE}" > kallsyms.txt || {
uvx --from git+https://github.com/marin-m/vmlinux-to-elf@da14e789596d493f305688e221e9e34ebf63cbb8 kallsyms-finder "${IMAGE}" > kallsyms.txt || \
echo "[ERROR] Failed to generate 'kallsyms.txt'"
}

# Generate analyzable '.elf'
echo "[INFO] Extracting 'boot.elf'..."
uvx --from git+https://github.com/marin-m/vmlinux-to-elf@da14e789596d493f305688e221e9e34ebf63cbb8 vmlinux-to-elf "${IMAGE}" boot.elf > /dev/null || {
uvx --from git+https://github.com/marin-m/vmlinux-to-elf@da14e789596d493f305688e221e9e34ebf63cbb8 vmlinux-to-elf "${IMAGE}" boot.elf > /dev/null ||
echo "[ERROR] Failed to generate 'boot.elf'"
}

# Create necessary directories
mkdir -p "${OUTPUT}/dts" "${OUTPUT}/dtb"

# Extract device-tree blobs from 'boot.img'
echo "[INFO] boot.img: Extracting device-tree blobs..."
extract-dtb "${IMAGE}" -o "${OUTPUT}/dtb" > /dev/null || echo "[INFO] No device-tree blobs found."
extract-dtb "${IMAGE}" -o "${OUTPUT}/dtb" > /dev/null || \
echo "[INFO] No device-tree blobs found."
rm -rf "${OUTPUT}/dtb/00_kernel"

# Do not run 'dtc' if no DTB was found
if [ "$(find "${OUTPUT}/dtb" -name "*.dtb")" ]; then
echo "[INFO] Decompiling device-tree blobs..."
# Decompile '.dtb' to '.dts'
for dtb in $(find "${PWD}/boot/dtb" -type f); do
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || echo "[ERROR] Failed to decompile."
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || \
echo "[ERROR] Failed to decompile."
done
fi
fi
Expand All @@ -407,12 +409,14 @@ if [[ -f "${PWD}/vendor_boot.img" ]]; then

## Unpack 'vendor_boot.img' through 'unpackbootimg'
echo "[INFO] Extracting 'vendor_boot.img' content..."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || echo "[ERROR] Extraction unsuccessful."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || \
echo "[ERROR] Extraction unsuccessful."

# Decrompress 'vendor_boot.img-vendor_ramdisk'
echo "[INFO] Extracting ramdisk..."
unlz4 "${OUTPUT}/vendor_boot.img-vendor_ramdisk" "${OUTPUT}/ramdisk.lz4" > /dev/null
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || echo "[ERROR] Failed to extract ramdisk."
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || \
echo "[ERROR] Failed to extract ramdisk."

## Clean-up
rm -rf "${OUTPUT}/ramdisk.lz4"
Expand All @@ -423,15 +427,17 @@ if [[ -f "${PWD}/vendor_boot.img" ]]; then

# Extract device-tree blobs from 'vendor_boot.img'
echo "[INFO] vendor_boot.img: Extracting device-tree blobs..."
extract-dtb "${IMAGE}" -o "${OUTPUT}/dtb" > /dev/null || echo "[INFO] No device-tree blobs found."
extract-dtb "${IMAGE}" -o "${OUTPUT}/dtb" > /dev/null || \
echo "[INFO] No device-tree blobs found."
rm -rf "${OUTPUT}/dtb/00_kernel"

# Decompile '.dtb' to '.dts'
if [ "$(find "${OUTPUT}/dtb" -name "*.dtb")" ]; then
echo "[INFO] Decompiling device-tree blobs..."
# Decompile '.dtb' to '.dts'
for dtb in $(find "${OUTPUT}/dtb" -type f); do
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || echo "[ERROR] Failed to decompile."
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || \
echo "[ERROR] Failed to decompile."
done
fi
fi
Expand All @@ -451,12 +457,14 @@ if [[ -f "${PWD}/vendor_kernel_boot.img" ]]; then

# Unpack 'vendor_kernel_boot.img' through 'unpackbootimg'
echo "[INFO] Extracting 'vendor_kernel_boot.img' content..."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || echo "[ERROR] Extraction unsuccessful."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || \
echo "[ERROR] Extraction unsuccessful."

# Decrompress 'vendor_kernel_boot.img-vendor_ramdisk'
echo "[INFO] Extracting ramdisk..."
unlz4 "${OUTPUT}/vendor_kernel_boot.img-vendor_ramdisk" "${OUTPUT}/ramdisk.lz4" > /dev/null
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || echo "[ERROR] Failed to extract ramdisk."
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || \
echo "[ERROR] Failed to extract ramdisk."

## Clean-up
rm -rf "${OUTPUT}/ramdisk.lz4"
Expand All @@ -467,15 +475,17 @@ if [[ -f "${PWD}/vendor_kernel_boot.img" ]]; then

# Extract device-tree blobs from 'vendor_kernel_boot.img'
echo "[INFO] vendor_kernel_boot.img: Extracting device-tree blobs..."
extract-dtb "${IMAGE}" -o "${OUTPUT}/dtb" > /dev/null || echo "[INFO] No device-tree blobs found."
extract-dtb "${IMAGE}" -o "${OUTPUT}/dtb" > /dev/null || \
echo "[INFO] No device-tree blobs found."
rm -rf "${OUTPUT}/dtb/00_kernel"

# Decompile '.dtb' to '.dts'
if [ "$(find "${OUTPUT}/dtb" -name "*.dtb")" ]; then
echo "[INFO] Decompiling device-tree blobs..."
# Decompile '.dtb' to '.dts'
for dtb in $(find "${OUTPUT}/dtb" -type f); do
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || echo "[ERROR] Failed to decompile."
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || \
echo "[ERROR] Failed to decompile."
done
fi
fi
Expand All @@ -494,12 +504,14 @@ if [[ -f "${PWD}/init_boot.img" ]] && [[ "${USE_ALT_DUMPER}" == "false" ]]; then

# Unpack 'init_boot.img' through 'unpackbootimg'
echo "[INFO] Extracting 'init_boot.img' content..."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || echo "[ERROR] Extraction unsuccessful."
${UNPACKBOOTIMG} -i "${IMAGE}" -o "${OUTPUT}" > /dev/null || \
echo "[ERROR] Extraction unsuccessful."

# Decrompress 'init_boot.img-ramdisk'
echo "[INFO] Extracting ramdisk..."
unlz4 "${OUTPUT}/init_boot.img-ramdisk" "${OUTPUT}/ramdisk.lz4" > /dev/null
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || echo "[ERROR] Failed to extract ramdisk."
7zz -snld x "${OUTPUT}/ramdisk.lz4" -o"${OUTPUT}/ramdisk" > /dev/null || \
echo "[ERROR] Failed to extract ramdisk."

## Clean-up
rm -rf "${OUTPUT}/ramdisk.lz4"
Expand All @@ -519,13 +531,15 @@ if [[ -f "${PWD}/dtbo.img" ]]; then

# Extract device-tree blobs from 'dtbo.img'
echo "[INFO] dbto.img: Extracting device-tree blobs..."
extract-dtb "${IMAGE}" -o "${OUTPUT}" > /dev/null || echo "[INFO] No device-tree blobs found."
extract-dtb "${IMAGE}" -o "${OUTPUT}" > /dev/null || \
echo "[INFO] No device-tree blobs found."
rm -rf "${OUTPUT}/00_kernel"

# Decompile '.dtb' to '.dts'
echo "[INFO] Decompiling device-tree blobs..."
for dtb in $(find "${OUTPUT}" -type f); do
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || echo "[ERROR] Failed to decompile."
dtc -q -I dtb -O dts "${dtb}" >> "${OUTPUT}/dts/$(basename "${dtb}" .dtb).dts" || \
echo "[ERROR] Failed to decompile."
done
fi

Expand Down

0 comments on commit 3c4a9be

Please sign in to comment.