Skip to content

Instantly share code, notes, and snippets.

@z3ntu
Created July 30, 2021 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z3ntu/3b5d21163711d7e309af0a5952bc1189 to your computer and use it in GitHub Desktop.
Save z3ntu/3b5d21163711d7e309af0a5952bc1189 to your computer and use it in GitHub Desktop.
repack boot.img unpacked with unpackbootimg -- https://github.com/osm0sis/mkbootimg
#!/bin/bash
prefix="$1"
shift
if [ -z "$prefix" ]; then
echo "ERROR: provide prefix!"
exit 1
fi
files=$(grep "write_.*_to_file" unpackbootimg.c | grep -v "void write_" | sed 's/.*write_\(\w\+\)_to_file("\(\w\+\)",.*/\1 \2/' | sort | uniq)
cmd="mkbootimg"
while IFS= read -r line; do
arr=($line)
argtype=${arr[0]}
filename=${arr[1]}
if [ ! -f $prefix$filename ]; then
continue
fi
if [ "$argtype" == "string" ]; then
cmd="$cmd --$filename \"$(cat $prefix$filename)\""
elif [ "$argtype" == "buffer" ]; then
cmd="$cmd --$filename $prefix$filename"
else
echo "ERROR: Unknown argtype $argtype!"
exit 1
fi
done <<< "$files"
cmd="$cmd $@"
eval $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment