forked from cmatthew/Lind-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlind
executable file
·83 lines (75 loc) · 2.27 KB
/
lind
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
#!/bin/bash
# script configuration variables
extra_args=('-a')
ldr_cmd=('sel_ldr')
ldr_args=()
gdb_arg_str=('')
print_arg_str=''
usage="usage: ${0##*/} -[fghsvx] [-a <sel_ldr extra args>] [-l <blob library>] -- [nacl_file] [args]"
# check for xtrace flag
while getopts :a:l:dfghsvx opt; do
case "$opt" in
# append custom args
a)
readarray -td' ' extra_args < <(printf '%s ' "${extra_args[@]}" "$OPTARG");;
# enable gdb debug hook
d)
[[ "${extra_args[*]}" != *-g* ]] && extra_args+=('-g');;
# enable fuzz testing (quit after leading nacl app)
f)
[[ "${extra_args[*]}" != *-F* ]] && extra_args+=('-F');;
# enable gdb debug args
g)
gdb_arg_str=('run');;
# add blob library
l)
extra_args+=('-B' "$OPTARG");;
# enable signal handling
s)
[[ "${extra_args[*]}" != *-S* ]] && extra_args+=('-S');;
# increase verbosity
v)
extra_args+=('-v');;
# use xtrace
x)
set -o xtrace;;
# show sel_ldr usage
h)
printf '%s\n' "$usage" >&2
sel_ldr --help 2>&1 | sed '1 d' >&2
exit;;
# show error and usage
:|?)
printf 'illegal option: -%s\n' "$OPTARG" >&2
printf '%s\n' "$usage" >&2
exit 1;;
esac
done
shift "$((OPTIND - 1))"
export LIND_PREFIX="${LIND_PREFIX:-$HOME}"
export LIND_BASE="${LIND_BASE:-$LIND_PREFIX/lind_project}"
export LIND_SRC="${LIND_SRC:-$LIND_BASE/lind}"
export REPY_PATH="${REPY_PATH:-$LIND_SRC/repy}"
export NACL_SDK_ROOT="${NACL_SDK_ROOT:-$REPY_PATH/sdk}"
export PYTHON="${PYTHON:-python2}"
export PNACLPYTHON="${PNACLPYTHON:-python2}"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-/lib/glibc}"
cd "$REPY_PATH/repy" || exit 1
print_arg_str+="${extra_args[*]} -- \"$LD_LIBRARY_PATH/runnable-ld.so\" --library-path \"$LD_LIBRARY_PATH\" $*"
ldr_args+=("${extra_args[@]}" -- "$LD_LIBRARY_PATH/runnable-ld.so" --library-path "$LD_LIBRARY_PATH" "$@")
if [[ -n "${gdb_arg_str[*]}" ]]; then
# concatenate so we can pass the argument list to gdb
gdb_arg_str=("${gdb_arg_str[@]}" "${ldr_args[@]}")
# add quotes to improve clarity when printing final command
print_arg_str="-q -ex '${gdb_arg_str[*]}' sel_ldr"
ldr_cmd=('gdb')
ldr_args=('-q' '-ex' "$(printf '%q ' "${gdb_arg_str[@]}")" 'sel_ldr')
fi
printf '\nexecuting: [%s %s]\n' "${ldr_cmd[*]}" "$print_arg_str" >&2
"${ldr_cmd[@]}" "${ldr_args[@]}"
# ignore SIGTERM
ret=$?
if ((!ret || ret == 143)); then
exit
fi
exit "$ret"