forked from fix-macosx/net-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sslsplit-create-standalone.sh
executable file
·48 lines (38 loc) · 1.12 KB
/
sslsplit-create-standalone.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
#!/bin/sh
#
# Ugly script to rewrite all external library references
# using @rpath
#
if [ ! -f "$1" ] || [ -z "$2" ]; then
echo "Usage: <path to sslsplit> <output dir>"
exit 1
fi
BINARY=$1
OUTPUT_DIR=$2
BIN_DIR=$OUTPUT_DIR/bin
LIB_DIR=$OUTPUT_DIR/lib/sslsplit
OUTPUT_BINARY=$BIN_DIR/`basename $BINARY`
if [ ! -d "${LIB_DIR}" ]; then
mkdir -p "${LIB_DIR}" || exit 1
fi
if [ ! -d "${BIN_DIR}" ]; then
mkdir -p "${BIN_DIR}" || exit 1
fi
unwritten_libraries() {
local target=$1
otool -L "$target" | tail +2 | egrep '(libssl|libcrypto|libz|libevent)' | grep -v '@rpath/' | awk '{print $1}'
}
rewrite_dependencies() {
local target=$1
local rpath=$2
install_name_tool -add_rpath "$rpath" "$target" || exit 1
for l in $(unwritten_libraries $target); do
install_name_tool -change "$l" @rpath/$(basename $l) "$target" || exit 1
if [ "$l" -nt "$LIB_DIR/"`basename $l` ]; then
install -m 644 "$l" "${LIB_DIR}/" || exit 1
rewrite_dependencies "${LIB_DIR}/$(basename $l)" "@loader_path"
fi
done
}
install -m 755 "${BINARY}" "${OUTPUT_BINARY}" || exit 1
rewrite_dependencies "${OUTPUT_BINARY}" "@loader_path/../lib/sslsplit"