forked from jotaki/Extract-Kernel-Initramfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.sh
41 lines (35 loc) · 1.19 KB
/
archive.sh
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
####
# find cpio archive relative of position
####
function find_archive()
{
local image="$1" archive=($2) total=${#archive[@]} a=0
local pos= output="$3" sig=${archive[0]} found=
echo_debug "Function: find_archive('$1', $2, '$3')"
echo "Detected $((total - 1)) potential archives"
echo_debug "Using signature '$sig'"
use_signature "$sig" # shouldn't fail.
for((a = 1; a < $total; a++)) {
echo "Trying #$a"
pos=$((${archive[$a]} + SIG_ADJ))
echo_debug " reverse_offset=$pos command=$COMMAND"
echo_debug " \$ tail -c +$pos \"$image\" | $COMMAND" \
"2>/dev/null > \"$output\""
# tail bytes and pass through to $COMMAND
tail -c +$pos "$image" | $COMMAND 2>/dev/null > "$output"
if [ $? -ne 0 ]; then
cat /dev/null > "$output"
echo_debug "Try #$a of $((total - 1)) for '$CSCHEME' failed."
echo " > ... Failed"
continue;
else
echo " > ... Success"
found=1; break
fi
}
use_signature --zap
if [ -z "$found" ]; then
echo_error "All archive extraction attempts failed. Aborting"
return 1;
fi
}