motorola: Import star extract script
imported from https://github.com/HemanthJabalpuri/star at e77390046256de0c4044fa480b2815011a3fa8ed Change-Id: Iea4cdd8655d3aab9cfd3e55bdcafdba072b90462
This commit is contained in:
committed by
Michael Bestas
parent
24067c9b5f
commit
5b191d800a
46
motorola/star.sh
Executable file
46
motorola/star.sh
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
# This basic program is used for unpacking Motorola archives which are made using single image tar(star) utility
|
||||||
|
# can run in dash. dd, od, tr are used mainly(busybox also compatible)
|
||||||
|
#
|
||||||
|
# Created : 1st Feb 2023
|
||||||
|
# Author : HemanthJabalpuri
|
||||||
|
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
echo "Usage: star.sh file outdir"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
f="$1"
|
||||||
|
outdir="$2"
|
||||||
|
|
||||||
|
mkdir -p "$outdir" 2>/dev/null
|
||||||
|
|
||||||
|
getData() {
|
||||||
|
dd if="$f" bs=1 skip=$1 count=$2 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
getLong() {
|
||||||
|
getData $1 8 | od -A n -t u8 | tr -d " "
|
||||||
|
}
|
||||||
|
|
||||||
|
magic=$(getData 0 15)
|
||||||
|
if [ "$magic" != "SINGLE_N_LONELY" ]; then
|
||||||
|
echo " Unsupported"; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
seekoff=256
|
||||||
|
for i in $(seq 64); do
|
||||||
|
name="$(getData $seekoff 248)"
|
||||||
|
[ "$name" = "LONELY_N_SINGLE" ] && break
|
||||||
|
length="$(getLong $((seekoff+248)))"
|
||||||
|
offset="$((seekoff+256))"
|
||||||
|
pad=$((length%4096))
|
||||||
|
[ "$pad" -ne 0 ] && pad=$((4096-pad))
|
||||||
|
echo "Name: $name, Offset: $offset, Size: $length, Padding: $pad"
|
||||||
|
|
||||||
|
dd if="$f" of="$outdir/$name" iflag=skip_bytes,count_bytes status=none bs=4096 skip=$offset count=$length
|
||||||
|
seekoff="$((offset+length+pad))"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user