blob: 74b67d7b9484b7c047e3fb5111ae25bfb05df4bc (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/bin/sh
squashfs_size_ratio()
{
local fn="$1"
#FSIZE="$(stat -c "%s" "$fn")"
word5() { echo $5; }
FSIZE="$(word5 `ls -l "$fn"`)"
echo $(( $FSIZE * 3367 / 1000 ))
}
squashfs_size_magicdb()
{
get()
{
local len=$1
local off=$2
local fn="$3"
#local OUT=( $(od -t d$len -N$len -j $off "$fn") )
#echo "${OUT[1]}"
od -t u$len -N$len -j $off "$fn" | head -n1 | sed 's/.* //'
}
# getReversedEndian()
# {
# local len=$1
# local off=$2
# local fn="$3"
# #local B=( $(od -t x$len -N$len -j $off "$fn") )
# #B="${B[1]}"
# local B="$(od -t x$len -N$len -j $off "$fn" | head -n1 | cut -d' ' -f2)"
# local D=
# local C=$(( $len * 2 ))
# while [ $C -gt 0 ]
# do
# C=$(( $C - 2 ))
# D="$D${B:$C:2}"
# done
# D="0x$D"
# echo $D
# }
getReversedEndian()
{
local len=$1
local off=$2
local fn="$3"
local D=
local C=$len
while [ $C -gt 0 ]
do
C=$(( $C - 1 ))
D="$(od -t x1 -N1 -j $(($off+$C)) "$fn" | head -n1 | cut -d' ' -f2)$D"
done
D=$((0x$D))
echo $D
}
local fn="$1"
local M=$(get 4 0 "$fn")
local N=$(getReversedEndian 4 0 "$fn")
if [ $M -eq 1936814952 ]
then
# Proper endian.
local get=get
elif [ $N -eq 1936814952 ]
then
# Reversed endian.
local get=getReversedEndian
else
error not squashfs
fi
local T=$($get 2 28 "$fn")
if [ $T -lt 3 ]
then
local BC=$($get 4 8 "$fn")
else
local BC=$($get 8 63 "$fn")
fi
echo $BC
}
squashfs_size_ratio "$1"
|