From 082bc175c07c595ce9fbeeeda2d382b5018982f5 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Tue, 25 Jul 2023 23:55:25 +0200 Subject: [PATCH] feat: Add script for extracting the boot.img from an OTA update --- src/android/extract-bootimg.sh | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/android/extract-bootimg.sh diff --git a/src/android/extract-bootimg.sh b/src/android/extract-bootimg.sh new file mode 100644 index 0000000..2ba71e3 --- /dev/null +++ b/src/android/extract-bootimg.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# I keep forgetting how to extract the boot.img from an Android OTA update +# for patching by Magisk. +set -e + +while [[ $# -gt 0 ]]; do + case $1 in + --payload-dumper) + # Specify the path to the payload_dumper binary + PAYLOAD_DUMPER=$2 + shift + shift + ;; + --diff) + PAYLOAD_DUMPER_EXTRA_ARGS="${PAYLOAD_DUMPER_EXTRA_ARGS} --diff" + shift + ;; + *) + # The last argument is the file + UPDATE_FILE=$1 + shift + ;; + esac +done + +if [[ ! -f "$UPDATE_FILE" ]]; then + echo "Android update file $UPDATE_FILE does not exist" + exit 1 +fi + +out_dir=./payload-dumper-output +if [[ -d "$out_dir" ]]; then + echo "Output path $out_dir already exists. Refusing to work!" + exit 1 +fi +mkdir "$out_dir" + +# Print some basic info +PAYLOAD_DUMPER=${PAYLOAD_DUMPER:-payload_dumper} +echo "INFO: payload_dumper: $PAYLOAD_DUMPER" +echo + +# Extract only the payload.bin file +echo "Extracting payload..." +unzip -q -C "$UPDATE_FILE" -d "$out_dir" payload.bin + +# Use payload_dumper to get to the boot.img +echo "Dumping data from payload..." +${PAYLOAD_DUMPER} ${PAYLOAD_DUMPER_EXTRA_ARGS} --out "$out_dir" "${out_dir}/payload.bin"