Skip to content

Commit 4d3da77

Browse files
committed
scripts: modify-return.sh: use getopt
$ ./modify-return.sh -p $(pidof return) --addr 0x4006d4 Signed-off-by: Rong Tao <[email protected]>
1 parent 575aebc commit 4d3da77

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

scripts/modify-return.sh

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
PID=
66
GDB=$(which gdb 2>/dev/null || :)
77
ADDRESS=
8+
verbose=
89

910
if [[ -z ${GDB} ]]; then
1011
echo >&2 "ERROR: Need gdb"
@@ -16,25 +17,70 @@ if [[ $(uname -m) != aarch64 ]]; then
1617
exit 1
1718
fi
1819

19-
usage()
20-
{
20+
__usage__() {
2121
echo "
22-
modify-address.sh <PID> <ADDRESS>
22+
modify-return [-p <PID>] [--address <ADDRESS>]
23+
24+
-p, --pid [PID] specify pid
25+
-a, --address [ADDRESS] specify address to modify
26+
-v, --verbose set -x
27+
-h, --help print this info
2328
"
29+
exit ${1-0}
2430
}
2531

26-
PID=$1
27-
shift 1
28-
ADDRESS=$1
32+
TEMP=$(getopt \
33+
--options p:a:vh \
34+
--long pid: \
35+
--long address: \
36+
--long verbose \
37+
--long help \
38+
-n modify-return -- "$@")
39+
40+
test $? != 0 && __usage__ 1
41+
42+
eval set -- "$TEMP"
43+
44+
while true; do
45+
case $1 in
46+
-p|--pid)
47+
shift
48+
PID=$1
49+
if ! [[ -d /proc/${PID} ]]; then
50+
echo >&2 "ERROR: PID=${PID} is not exist."
51+
exit 1
52+
fi
53+
shift
54+
;;
55+
-a|--address)
56+
shift
57+
ADDRESS=$1
58+
shift
59+
;;
60+
-v|--verbose)
61+
shift
62+
set -x
63+
verbose=yes
64+
;;
65+
-h|--help)
66+
shift
67+
__usage__
68+
;;
69+
--)
70+
shift
71+
break
72+
;;
73+
esac
74+
done
2975

3076
if [[ -z ${PID} ]]; then
31-
usage
77+
__usage__
3278
echo >&2 "ERROR: Need pass PID"
3379
exit 1
3480
fi
3581

3682
if [[ -z ${ADDRESS} ]] || [[ ${ADDRESS:0:2} != 0x ]]; then
37-
usage
83+
__usage__
3884
echo >&2 "ERROR: Must pass a address with 0x prefix"
3985
exit 1
4086
fi

tests/hello/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ while true; do
4646
-p|--pid)
4747
shift
4848
pid=$1
49+
if ! [[ -d /proc/${pid} ]]; then
50+
echo >&2 "ERROR: PID=${pid} is not exist."
51+
exit 1
52+
fi
4953
shift
5054
;;
5155
-u|--patch)

0 commit comments

Comments
 (0)