From 5b191d800a3b2b0af27c3dc8784078f950c35a52 Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Thu, 24 Aug 2023 10:41:05 +0300 Subject: [PATCH] motorola: Import star extract script imported from https://github.com/HemanthJabalpuri/star at e77390046256de0c4044fa480b2815011a3fa8ed Change-Id: Iea4cdd8655d3aab9cfd3e55bdcafdba072b90462 --- motorola/star.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 motorola/star.sh diff --git a/motorola/star.sh b/motorola/star.sh new file mode 100755 index 0000000..b89a125 --- /dev/null +++ b/motorola/star.sh @@ -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