check if binwalk has already been run

This commit is contained in:
ading2210 2023-10-03 10:39:24 -07:00
parent ffbe350dd4
commit 791de19297
2 changed files with 13 additions and 6 deletions

View File

@ -23,14 +23,14 @@ invoke_terminal() {
enable_debug_console() { enable_debug_console() {
local tty="$1" local tty="$1"
info -e '\033[1;33m[cros_debug] enabled on '${tty}'.\033[m' echo -e '\033[1;33m[cros_debug] enabled on '${tty}'.\033[m'
invoke_terminal "${tty}" "[Bootstrap Debug Console]" "/bin/busybox sh" invoke_terminal "${tty}" "[Bootstrap Debug Console]" "/bin/busybox sh"
} }
main() { main() {
info "...:::||| Bootstrapping ChromeOS Factory Shim |||:::..." echo "...:::||| Bootstrapping ChromeOS Factory Shim |||:::..."
info "TTY: ${TTY}, LOG: ${LOG_TTY}, INFO: ${INFO_TTY}, DEBUG: ${DEBUG_TTY}" echo "TTY: ${TTY}, LOG: ${LOG_TTY}, echo: ${echo_TTY}, DEBUG: ${DEBUG_TTY}"
echo "idk please work" echo "idk please work"
enable_debug_console "/dev/pts/0" enable_debug_console "/dev/pts/0"

View File

@ -50,20 +50,27 @@ kernel_loop="${shim_loop}p2" #KERN-A should always be p2
echo "copying shim kernel to new file in /tmp" echo "copying shim kernel to new file in /tmp"
kernel_dir=/tmp/shim_kernel kernel_dir=/tmp/shim_kernel
rm -rf $kernel_dir
mkdir $kernel_dir -p mkdir $kernel_dir -p
dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=none dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=none
echo "extracting data from kernel" echo "extracting data from kernel"
previous_dir=$(pwd) previous_dir=$(pwd)
cd $kernel_dir cd $kernel_dir
if [ -e "${kernel_dir}/binwalk.out" ]; then
#don't run binwalk again if we don't need to
binwalk_out=$(cat $kernel_dir/binwalk.out)
else
binwalk_out=$(binwalk --extract kernel.bin --run-as=root) binwalk_out=$(binwalk --extract kernel.bin --run-as=root)
echo $binwalk_out > $kernel_dir/binwalk.out
fi
#i can't be bothered to learn how to use sed #i can't be bothered to learn how to use sed
extracted_file=$(echo $binwalk_out | pcregrep -o1 "\d+\s+0x([0-9A-F]+)\s+gzip compressed data") extracted_file=$(echo $binwalk_out | pcregrep -o1 "\d+\s+0x([0-9A-F]+)\s+gzip compressed data")
echo "extracting initramfs archive from kernel (this may take a while)" echo "extracting initramfs archive from kernel (this may take a while)"
cd _kernel.bin.extracted/ cd _kernel.bin.extracted/
if [ ! -e "_${extracted_file}.extracted/" ]; then
binwalk --extract $extracted_file --run-as=root > /dev/null binwalk --extract $extracted_file --run-as=root > /dev/null
fi
cd "_${extracted_file}.extracted/" cd "_${extracted_file}.extracted/"
cpio_file=$(file ./* | pcregrep -o1 "([0-9A-F]+):\s+ASCII cpio archive") cpio_file=$(file ./* | pcregrep -o1 "([0-9A-F]+):\s+ASCII cpio archive")