forked from luiscalmeida/gandacena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xtractor
executable file
·151 lines (144 loc) · 3.49 KB
/
xtractor
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
#!/bin/bash
if [[ $# == 0 ]] || [[ $# > 2 ]];
then
echo "Usage: ./xtractor -dd [dd image]";
echo "Usage: ./xtractor -vmdk [vmdk image]";
echo " "
echo -e "\\tNote: If you have an error stating that 'Transport endpoint is not connected' please"
echo -e "\\trun 'fusermount -uz mnt', and then you can run the script"
echo " "
echo -e "\\tIf you want to see each step of this script detailed on the scren open the script"
echo -e "\\tand change 'verbose=false' to 'verbose=true' in line 35"
exit 1;
fi
if [[ $# == 1 ]];
then
if [[ $1 == "-h" || $1 == "--help" ]];
then
echo "Usage: ./xtractor -dd [dd image]";
echo "Usage: ./xtractor -vmdk [vmdk image]";
echo " "
echo -e "\\tNote: If you have an error stating that 'Transport endpoint is not connected' please"
echo -e "\\trun 'fusermount -uz mnt', and then you can run the script"
echo " "
echo -e "\\tIf you want to see each step of this script detailed on the scren open the script"
echo -e "\\tand change 'verbose=false' to 'verbose=true' in line 35"
exit 1;
else
echo "Unknown usage. Type xtractor -h or --help for instructions"
exit 1
fi
fi
verbose=false
umount mnt 2>/dev/null
`fusermount -uz mnt 2>/dev/null`
rm -r mnt 2>/dev/null
mkdir ./mnt 2>/dev/null
if [ $1 == "-dd" ]; #Process for dd images
then
mmls_result=`mmls $2 2>/dev/null`
ntfs_result=`echo "$mmls_result" | grep NTFS`
if [ -z "$ntfs_result" ];
then echo "There's no NTFS file system in $1.";
exit 1;
fi
biggest_ntfs=`echo "$ntfs_result" | cut -d" " -f12`
if [ $verbose == true ];
then
echo "NTFS LENGTHS"
echo "$biggest_ntfs"
echo " "
fi
max=0
index=0
index_stop=0
for line in `echo "$biggest_ntfs"`;
do
((index++))
if [ $verbose == true ];
then
echo "FOR LINE ON NTFS LENGTHS"
echo $line;
fi
value=$((10#$line))
if [[ $max < $value ]]; then
max=$value;
index_stop=$index;
fi
done
if [ $verbose == true ];
then
echo " "
echo "MAX SIZE NTFS LENGTH: $max"
echo " "
echo "MAX SIZE NTFS LENGTH INDEX : $index_stop"
echo " "
echo "GREP NTFS RESULT"
echo "$ntfs_result"
echo " "
fi
index=0
offset=`echo "$ntfs_result" | cut -d" " -f6`
if [ $verbose == true ];
then
echo "MAX SIZE NTFS OFFSET:"
echo "$offset"
echo " "
fi
for linee in `echo "$offset"`;
do
if [ "$verbose" == true ];
then
echo "FOR LINE IN MAX SIZE NTFS OFFSET"
echo "$linee"
fi
((index++))
if [[ $index == $index_stop ]]; then
offset=`echo "$linee"`
fi
done
if [ $verbose == true ];
then
echo " "
echo "MAX SIZE NTFS CONFIRMATION OFFSET"
echo "$offset"
fi
clean_offset=$((10#$offset))
if [ $verbose == true ];
then
echo "MAX SIZE NTFS CONFIRMATION CLEAN OFFSET"
echo "$clean_offset"
echo " "
fi
offset_bytes=$(($clean_offset * 512))
if [ $verbose == true ];
then
echo "OFFSET * BYTES(512) = $offset_bytes"
echo " "
echo "MOUNTING NTFS.."
fi
`mount -t ntfs -o ro,loop,offset=$offset_bytes $2 ./mnt/`
elif [ $1 == "-vmdk" ]; # Process for vmdk images
then
if ! type guestmount > /dev/null;
then
echo "You must install libguestfs-tools."
echo "Run 'sudo apt-get install libguestfs-tools' on your terminal.";
echo "The reason is this tool uses 'guestmount' in order to mount .vmdk files"
exit 1
else
echo "Be patient. This can take a few seconds"
`guestmount -a $2 -i ./mnt` #-i --ro
fi
fi
echo "File System mounted successfully"
if [ $verbose == true ];
then
echo " "
echoi
echo `pwd`
fi
python ./main.py
umount mnt 2>/dev/null
`fusermount -uz mnt 2>/dev/null`
rm -r mnt 2>/dev/nullls