Skip to content

Commit

Permalink
tests/{dlfcn,hello}: Add/Modify test.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Tao <rongtao@cestc.cn>
  • Loading branch information
Rtoax committed Feb 27, 2024
1 parent 47eb996 commit 5506224
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 11 additions & 0 deletions tests/dlfcn/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

pid=( $(pidof hello hello-pie || true) )
[[ -z "${pid}" ]] && echo "ERROR: run hello or hello-pie first." && exit 1
[[ ${#pid[@]} -gt 1 ]] && echo "ERROR: too much processes are running." && exit 1

# Get libc ELF base address in memory
libc_base_addr=$( grep libc.so.6 /proc/${pid}/maps | head -n1 | tr '-' ' ' | awk '{print $1}' )

./pdlsym_tst -p ${pid} -a 0x${libc_base_addr} -s printf
17 changes: 11 additions & 6 deletions tests/hello/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ test [-h|--help] [-u|--patch]
-p, --pid [PID] specify pid
-u, --patch [ULPATCH] specify ulpatch file
-d, --debug debug mode
-d, --debug debug mode for ulpatch
-v, --verbose set -x
-h, --help print this info
"
exit ${1-0}
}

TEMP=$(getopt \
--options p:u:dh \
--options p:u:dvh \
--long pid: \
--long patch: \
--long debug \
--long verbose \
--long help \
-n ulpatch-hello-test -- "$@")

Expand All @@ -47,6 +48,10 @@ while true; do
shift
debug=$1
;;
-v|--verbose)
shift
set -x
;;
-h|--help)
shift
__usage__
Expand All @@ -58,9 +63,9 @@ while true; do
esac
done

[[ -z ${pid} ]] && pid=$(pidof hello || true)
[[ -z ${pid} ]] && pid=$(pidof hello-pie || true)
[[ -z ${pid} ]] && echo "ERROR: Run ./hello or ./hello-pie first or specify -p" && exit 1
[[ -z ${pid} ]] && pid=( $(pidof hello hello-pie || true) )
[[ -z "${pid}" ]] && echo "ERROR: Run ./hello or ./hello-pie first or specify -p" && exit 1
[[ ${#pid[@]} -gt 1 ]] && echo "ERROR: too much processes are running." && exit 1

[[ -z ${patch} ]] && echo "ERROR: Must specify ulpatch with -u" && exit 1
[[ ! -e ${patch} ]] && echo "ERROR: ${patch} is not exist." && exit 1
Expand Down

0 comments on commit 5506224

Please sign in to comment.