Skip to content

Commit 734f567

Browse files
feat: Implement motorola's SINGLE_N_LONELY format
Co-authored-by: HemanthJabalpuri <[email protected]>
1 parent 9da5dca commit 734f567

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

extractor.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ kdz_extract="$toolsdir/kdztools/unkdz.py"
8686
dz_extract="$toolsdir/kdztools/undz.py"
8787
ruu="$toolsdir/$HOST/bin/RUU_Decrypt_Tool"
8888
aml_extract="$toolsdir/aml-upgrade-package-extract"
89+
star="$toolsdir/$HOST/bin/star"
8990

9091
romzip="$(realpath $1)"
9192
romzipext="${romzip##*.}"
@@ -499,5 +500,30 @@ for partition in $PARTITIONS; do
499500
fi
500501
done
501502

503+
# Specifically check if input is 'radio.img'
504+
if $(7z l -ba "${romzip}" | grep -q radio.img); then
505+
## Extract 'radio.img' from archive'
506+
echo "[INFO] Extracting 'radio.img'..."
507+
7z x "${romzip}" radio.img -o${PWD} >> $tmpdir/zip.log
508+
509+
## Check if this comes from motorola
510+
if [[ $(head -c15 ${PWD}/radio.img) == "SINGLE_N_LONELY" ]]; then
511+
## Extract 'radio.img.sparse'
512+
"${star}" "${PWD}/radio.img" ${PWD} 2>/dev/null
513+
514+
## Delete everything that's not 'NON-HLOS.bin'
515+
find "${PWD}/" -type f ! -name 'NON-HLOS.bin' -delete
516+
517+
## Move 'NON-HLOS.bin' to 'radio.img.sparse'
518+
mv "${PWD}/NON-HLOS.bin" "${PWD}/radio.img.sparse"
519+
520+
## Convert from sparse to RAW
521+
${simg2img} "${PWD}/radio.img.sparse" "${outdir}/radio.img" 2>/dev/null
522+
523+
## Remove old sparsed image
524+
rm -rf ${PWD}/radio.img.sparse
525+
fi
526+
fi
527+
502528
cd "$LOCALDIR"
503529
rm -rf "$tmpdir"

tools/Linux/bin/star

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
# SPDX-FileCopyrightText: 2023 Hemanth Jabalpuri
4+
# SPDX-License-Identifier: CC0-1.0
5+
6+
# This basic program is used for unpacking Motorola archives which are made using single image tar(star) utility
7+
# can run in dash. dd, od, tr are used mainly(busybox also compatible)
8+
#
9+
# Created : 1st Feb 2023
10+
# Author : HemanthJabalpuri
11+
12+
if [ $# -lt 2 ]; then
13+
echo "Usage: star.sh file outdir"
14+
exit
15+
fi
16+
17+
f="$1"
18+
outdir="$2"
19+
20+
mkdir -p "$outdir" 2>/dev/null
21+
22+
getData() {
23+
dd if="$f" bs=1 skip=$1 count=$2 2>/dev/null
24+
}
25+
26+
getLong() {
27+
getData $1 8 | od -A n -t u8 | tr -d " "
28+
}
29+
30+
magic=$(getData 0 15)
31+
if [ "$magic" != "SINGLE_N_LONELY" ]; then
32+
echo " Unsupported"; exit 1
33+
fi
34+
35+
seekoff=256
36+
for i in $(seq 64); do
37+
name="$(getData $seekoff 248)"
38+
[ "$name" = "LONELY_N_SINGLE" ] && break
39+
length="$(getLong $((seekoff+248)))"
40+
offset="$((seekoff+256))"
41+
pad=$((length%4096))
42+
[ "$pad" -ne 0 ] && pad=$((4096-pad))
43+
echo "Name: $name, Offset: $offset, Size: $length, Padding: $pad"
44+
45+
dd if="$f" of="$outdir/$name" iflag=skip_bytes,count_bytes status=none bs=4096 skip=$offset count=$length
46+
seekoff="$((offset+length+pad))"
47+
done

0 commit comments

Comments
 (0)