-
Notifications
You must be signed in to change notification settings - Fork 63
/
tffs_from_supportdata
executable file
·44 lines (44 loc) · 1.5 KB
/
tffs_from_supportdata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
FIRST_LINE="##### BEGIN SECTION TFFS_DUMP TFFS Dump"
LAST_LINE="##### END SECTION TFFS_DUMP"
decode_to_tar()
{
local input="$1"
sed -e "1,/^$FIRST_LINE/d" "$input" | sed -e "/^$LAST_LINE/,\$d" | base64 -d
}
usage()
{
printf "Extract a TFFS image dump from extended support data file.\n\n"
printf "Usage:\n\n"
printf "$0 <support-data-file> <output-dir> <tffs-index>\n\n"
printf "'support-data-file' is the name of an \"extended support data\" file,\n"
printf "which was created on a FRITZ!Box device. 'output-dir' is the name of\n"
printf "an existing sub-directory, where the extracted data will be stored.\n"
printf "'tffs-index' is the suffix of the TFFS image name ('1' or '2').\n\n"
printf "This script is not supposed to handle dumps from devices with a\n"
printf "NAND-based TFFS driver.\n\n"
printf "This script is only a proof-of-concept, how to extract the TFFS dump\n"
printf "from support data - it doesn't contain any sophisticated error handling.\n"
}
INPUT="$1"
OUTPUT="$2"
INDEX=$3
[ $# -lt 3 ] && usage && exit 1
tmp=$(mktemp)
[ $? -ne 0 ] && tmp=/var/tmp/tmp.$(date +%s).$$
trap "rm -r $tmp" EXIT HUP
rm $tmp
mkdir -p $tmp
tarfile=$tmp/tffs-dump.tar
decode_to_tar "$INPUT" >$tarfile
for file in $(tar -t -f $tarfile); do
[ $file == var/tmp/tffs-dump/ ] && continue
out=${file##*/}
out=${out%.gz}
out=${out/\(/}
out=${out/\)/}
[ -z "$(expr "$out" : ".*\($INDEX\).*")" ] && continue
tar -x -O -f $tarfile $file | gunzip -c >$OUTPUT/$out
break
done