File tree Expand file tree Collapse file tree 2 files changed +58
-8
lines changed Expand file tree Collapse file tree 2 files changed +58
-8
lines changed Original file line number Diff line number Diff line change 5
5
PID=
6
6
GDB=$( which gdb 2> /dev/null || :)
7
7
ADDRESS=
8
+ verbose=
8
9
9
10
if [[ -z ${GDB} ]]; then
10
11
echo >&2 " ERROR: Need gdb"
@@ -16,25 +17,70 @@ if [[ $(uname -m) != aarch64 ]]; then
16
17
exit 1
17
18
fi
18
19
19
- usage ()
20
- {
20
+ __usage__ () {
21
21
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
23
28
"
29
+ exit ${1-0}
24
30
}
25
31
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
29
75
30
76
if [[ -z ${PID} ]]; then
31
- usage
77
+ __usage__
32
78
echo >&2 " ERROR: Need pass PID"
33
79
exit 1
34
80
fi
35
81
36
82
if [[ -z ${ADDRESS} ]] || [[ ${ADDRESS: 0: 2} != 0x ]]; then
37
- usage
83
+ __usage__
38
84
echo >&2 " ERROR: Must pass a address with 0x prefix"
39
85
exit 1
40
86
fi
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ while true; do
46
46
-p|--pid)
47
47
shift
48
48
pid=$1
49
+ if ! [[ -d /proc/${pid} ]]; then
50
+ echo >&2 " ERROR: PID=${pid} is not exist."
51
+ exit 1
52
+ fi
49
53
shift
50
54
;;
51
55
-u|--patch)
You can’t perform that action at this time.
0 commit comments