forked from askac/dumpifs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packifs.sh
113 lines (86 loc) · 1.82 KB
/
packifs.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh
ucltool=`dirname $0`/uuu
lzotool=`dirname $0`/zzz
compressUse=$ucltool
fixdecifs=`dirname $0`/fixdecifs
fixencifs=`dirname $0`/fixencifs
tempBody=__temp__B
tempBody2=__temp__B2
if [ $# -lt 3 ];then
cat << EOF
Usage: $0 <head offset(dec)> <decompressed.ifs> <destination ifs> [format: ucl|lzo]
head offset could be found when dump a ifs file.
EOF
exit
fi
if [ $1 -lt 260 ];then
echo "Invalid offset. Atleast 260"
exit
fi
offsetH=$1
srcIfs=$2
dstIfs=$3
if [ -e $tempBody ];then
echo "Temperate file $tempBody exist!"
exit
fi
if [ -e $tempBody2 ];then
echo "Temperate file $tempBody2 exist!"
exit
fi
if [ -e $dstIfs ];then
echo "Destination file $dstIfs exist!"
exit
fi
if [ "x$4" = "xucl" ]
then
packuse=1
echo "Pack using ucl"
elif [ "x$4" = "xlzo" ]
then
packuse=2
echo "Pack using lzo"
else
cat << EOF
Compress method?
1. ucl
2. lzo
EOF
read packuse
fi
if [ "$packuse" -lt 1 -o "$packuse" -gt 2 ];then
echo "Invalid option $packuse"
exit
fi
if [ $packuse -eq 1 ];then
compressUse=$ucltool
fi
if [ $packuse -eq 2 ];then
compressUse=$lzotool
fi
echo "Fix checksum of decompressed"
$fixdecifs $srcIfs Y
echo "Select $packuse . Use compress tool $compressUse"
dd if=$srcIfs of=$dstIfs bs=$offsetH count=1
dd if=$srcIfs of=$tempBody bs=$offsetH skip=1
$compressUse $tempBody $tempBody2
echo "Add padding"
echo -n "0000" | xxd -r -p >> $tempBody2
echo "Compress using $compressUse done."
echo "Packing $dstIfs"
dd of=$dstIfs if=$tempBody2 bs=$offsetH seek=1
finalSize=`du -b $dstIfs | awk '{print($1)}'`
if [ 0 != $(($finalSize %4)) ]
then
padlen=$((4 - ($finalSize %4) + 4))
else
padlen=4
fi
echo "finalSize is $finalSize padlen is $padlen"
finalSize=`du -b $dstIfs | awk '{print($1)}'`
dd if=/dev/zero of=$dstIfs bs=1 count=$padlen seek=$finalSize
$fixencifs $dstIfs Y
echo "Done"
rm $tempBody
rm $tempBody2
ls -l $dstIfs