forked from dsixda/Android-Kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_ext3_img
More file actions
executable file
·299 lines (229 loc) · 5.8 KB
/
extract_ext3_img
File metadata and controls
executable file
·299 lines (229 loc) · 5.8 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
############################################################################
#
# Copyright (c) 2013 - dsixda ([email protected])
#
# Android Kitchen is 100% free. This script file is intended for personal
# and/or educational use only. It may not be duplicated for monetary
# benefit or any other purpose without the permission of the developer.
#
############################################################################
img_dir=$1
img_file=$2
if [ "$img_dir" == "" ] || [ "$img_file" == "" ]
then
echo "Error: extract_ext3_img is missing information."
echo " Syntax: extract_ext3_img <file_directory> <img_file_name>"
echo
exit 1
fi
img_path=$img_dir/$img_file
if [ ! -e $img_path ]
then
echo "Error: $img_path not found!"
echo
exit 1
fi
base_dir=`pwd`
if [ `uname | grep CYGWIN` ]
then
dos_path=`cygpath -wp $img_dir`
while :
do
clear
echo
echo "Unpack the $img_file"
echo "-----------------------"
echo
echo "Enter a choice below to unpack your image file, assuming it"
echo "uses an EXT filesystem. You might find that one option works"
echo "better than the other."
echo
echo "e.g. EXT3: Older devices such as HTC Desire HD"
echo " EXT4: Newer devices such as HTC Desire S"
echo
echo " 1 - Run Explore2fs (Best choice for EXT3)"
echo " 2 - Run Ext2Explore (EXT3/EXT4)"
echo " 3 - I'm finished unpacking / Abort"
echo
echo
echo "NOTE: If any of the tools listed above have problems with"
echo " extraction, then try the other option(s) listed."
echo
echo -n "Select number: "
read enterNumber
if [ "$enterNumber" == "1" ]
then
scripts/show_explore2fs $img_dir $img_file
elif [ "$enterNumber" == "2" ]
then
scripts/show_ext2explore $img_dir $img_file
elif [ "$enterNumber" == "3" ]
then
break
else
echo "Invalid option"
fi
if [ "$enterNumber" == "1" ] || [ "$enterNumber" == "2" ]
then
echo
echo "--> If you're satisfied with extraction, select option 3 in next menu"
echo
scripts/press_enter
fi
done
cd $img_dir
rm -f unyaffs*stackdump
cd $base_dir
elif [ `uname | grep Linux` ]
then
echo
echo "Mounting $img_file to loopback device and then extracting files ..."
cd $img_dir
user_=`whoami`
mkdir ../tmp
# For ext4 (To prevent hanging when unmounting, use: ro,noexec,noload)
sudo mount -o loop,ro,noexec,noload $img_file ../tmp 2>/dev/null
res=$?
if [ "$res" != "0" ]
then
# For ext3
sudo mount -o loop $img_file ../tmp 2>/dev/null
res=$?
fi
if [ "$res" == "0" ]
then
if [ "$img_file" == "ext4_cache.img" ] || [ "$img_file" == "cache.rfs" ]
then
sudo cp ../tmp/recovery/sec_csc.zip .
elif [ "$img_file" == "csc.rfs" ]
then
sudo cp ../tmp/csc.zip .
else
sudo cp -R ../tmp/* .
fi
sudo umount ../tmp
rmdir ../tmp
sudo chown -R $user_ *
else
echo "Error: Unable to mount $img_file"
fi
rm -f unyaffs*stackdump
cd $base_dir
elif [ `sw_vers | grep -o Mac` ]
then
#
# Mac support
# - Thanks to he8us for adding the FUSE routine
#
cd $img_dir
rfs_list=`ls | grep -i \\.rfs$`
# Mount files for RFS
if [ "$rfs_list" != "" ]
then
mount_dir=/Volumes/RFS
echo "We'll need to do some superuser stuff here"
if [ -d $mount_dir ]
then
#sudo umount $mount_dir 2>/dev/null
sudo diskutil umount force $mount_dir 2>/dev/null
fi
sudo mkdir $mount_dir 2>/dev/null
sudo hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount $img_file > temp.log
mydisk=`more temp.log | sed -e 's/[ \t]*$//g'`
rm -f temp.log
sudo mount_msdos $mydisk $mount_dir
# Check FUSE - for EXT2/EXT3
else
res=`which fuse-ext2 2>/dev/null`
result=$?
if [ "$result" != "0" ]
then
fuse_cmd="/usr/local/bin/fuse-ext2"
res=`which $fuse_cmd 2>/dev/null`
result=$?
if [ "$result" != "0" ]
then
echo
echo "Your system does not have FUSE installed."
echo "Read the Android Kitchen FAQ to install MacFUSE, followed by fuse-ext2."
exit 1
fi
else
fuse_cmd=fuse-ext2
fi
mount_dir=/tmp/for_kitchen
fi
#
# Now extract the files for Mac
#
cd $base_dir
cd $img_dir
# Check for CSC plugin script
if [ "`echo $img_dir | grep csc_`" != "" ] && [ "`echo $img_dir | grep WORKING_`" == "" ]
then
mkdir system
mv $img_file system
cd system
csc_plugin=1
fi
echo
echo "Ready to extract files from $img_file"
mv $img_file ../$img_file
cd ..
# For FUSE
if [ "$rfs_list" == "" ]
then
if [ -d $mount_dir ]
then
umount $mount_dir
rm -rf $mount_dir
fi
mkdir $mount_dir
echo "Trying to mount the filesystem"
buffer=`$fuse_cmd $img_file $mount_dir`
echo $buffer
fi
listing=`ls $mount_dir`
echo "File system listed, analyzing $mount_dir ..."
if [ "$listing" != "" ]
then
echo "Copying files"
if [ "$img_file" == "ext4_cache.img" ] || [ "$img_file" == "cache.rfs" ]
then
cp $mount_dir/recovery/sec_csc.zip system/
elif [ "$img_file" == "csc.rfs" ]
then
cp $mount_dir/csc.zip system/
else
cp -r $mount_dir/* $img_dir/
fi
else
echo "Error: Mount point empty"
echo $listing
fi
if [ "$rfs_list" == "" ]
then
umount $mount_dir
rm -rf $mount_dir
else
#sudo umount $mount_dir
sudo diskutil umount force $mount_dir
hdiutil detach $mydisk
fi
# Check again for CSC plugin
if [ "$csc_plugin" == "1" ]
then
mv system/*.zip .
rm -rf system
else
mv $img_file $img_dir/$img_file
cd system
fi
if [ "$listing" != "" ]
then
rm -f unyaffs*stackdump
cd $base_dir
else
exit 1
fi
fi