This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpack
executable file
·83 lines (61 loc) · 1.75 KB
/
unpack
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
#!/usr/bin/env bash
file=$1
# Set constants used when calculating payloads
FOOTER_SIZE=52
FILE_SIZE=`stat --format "%s" "$file"`
offset=$(($FILE_SIZE - 4))
MAGIC_OFFSET=$offset
offset=$(($offset - 4))
CHECKSUM_OFFSET=$offset
offset=$(($offset - 4))
VERSION_OFFSET=$offset
offset=$(($offset - 4))
PREPAYLOAD_OFFSET=$offset
offset=$(($offset - 4))
PREPAYLOAD_SIZE_OFFSET=$offset
offset=$(($offset - 4))
LAUNCHER_SIZE_OFFSET=$offset
offset=$(($offset - 4))
PAYLOAD_OFFSET=$offset
offset=$(($offset - 4))
PAYLOAD_SIZE_OFFSET=$offset
offset=$(($offset - 4))
set_lengths() {
local file=`realpath $1`
LAUNCHER_SIZE=`od -An -t u4 -N 4 -j $LAUNCHER_SIZE_OFFSET "$file" | tr -d ' '`
PAYLOAD_SIZE=`od -An -t u4 -N 4 -j $PAYLOAD_SIZE_OFFSET "$file" | tr -d ' '`
PREPAYLOAD_SIZE=`od -An -t u4 -N 4 -j $PREPAYLOAD_SIZE_OFFSET "$file" | tr -d ' '`
SKIP_BYTES=$(($PREPAYLOAD_SIZE + $LAUNCHER_SIZE))
return 0
}
extract_installer() {
local file=`realpath $1`
local dir="installer"
rm -rf $dir
mkdir "$dir"
if [ ! -d "$dir" ]; then
echo "Unable to create installer directory"
exit 1
fi
echo -n "Extracting VMware installer..."
(cd $dir && dd if="$file" ibs=$SKIP_BYTES obs=1024 skip=1 | gunzip -c | tar -xf -)
if [ ! -e "$bootstrapper" ]; then
echo "done."
fi
}
extract_prepayload() {
local file=`realpath $1`
local dir="prepayload"
rm -rf $dir
mkdir "$dir"
if [ ! -d "$dir" ]; then
echo "Unable to create payload directory"
exit 1
fi
echo -n "Extracting VMware installer..."
(cd $dir && dd if="$file" ibs=$LAUNCHER_SIZE obs=1024 skip=1 | gunzip -c | tar -xf -)
}
echo "Extracting: $file"
set_lengths $file
extract_installer $file
extract_prepayload $file