From 2508008b53b3e3a891a3d4ba4d73d554a91e5c16 Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Sat, 21 Mar 2020 10:31:39 +0100 Subject: qemu_mode, build script: avoid which, add patch to prereqs, list all missing prereqs in one invocation --- qemu_mode/build_qemu_support.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'qemu_mode/build_qemu_support.sh') diff --git a/qemu_mode/build_qemu_support.sh b/qemu_mode/build_qemu_support.sh index 09c04e7f..8dff0461 100755 --- a/qemu_mode/build_qemu_support.sh +++ b/qemu_mode/build_qemu_support.sh @@ -62,15 +62,15 @@ if [ ! -f "../afl-showmap" ]; then fi +PREREQ_NOTFOUND= +for i in libtool wget python automake autoconf sha384sum bison iconv patch; do -for i in libtool wget python automake autoconf sha384sum bison iconv; do - - T=`which "$i" 2>/dev/null` + T=`type "$i" | awk '{print $NF}' 2>/dev/null` if [ "$T" = "" ]; then echo "[-] Error: '$i' not found, please install first." - exit 1 + PREREQ_NOTFOUND=1 fi @@ -79,7 +79,7 @@ done if [ ! -d "/usr/include/glib-2.0/" -a ! -d "/usr/local/include/glib-2.0/" ]; then echo "[-] Error: devel version of 'glib2' not found, please install first." - exit 1 + PREREQ_NOTFOUND=1 fi @@ -90,6 +90,10 @@ if echo "$CC" | grep -qF /afl-; then fi +if [ "$PREREQ_NOTFOUND" == "1" ]; then + exit 1 +fi + echo "[+] All checks passed!" ARCHIVE="`basename -- "$QEMU_URL"`" -- cgit 1.4.1 From dabce05ec601b07ba04ef1056e40edfe54a41111 Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Sat, 21 Mar 2020 10:46:23 +0100 Subject: qemu_mode/build script: add more missing prereqs --- qemu_mode/build_qemu_support.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu_mode/build_qemu_support.sh') diff --git a/qemu_mode/build_qemu_support.sh b/qemu_mode/build_qemu_support.sh index 8dff0461..021e107b 100755 --- a/qemu_mode/build_qemu_support.sh +++ b/qemu_mode/build_qemu_support.sh @@ -63,7 +63,7 @@ if [ ! -f "../afl-showmap" ]; then fi PREREQ_NOTFOUND= -for i in libtool wget python automake autoconf sha384sum bison iconv patch; do +for i in libtool wget python automake autoconf sha384sum bison flex iconv patch pkg-config; do T=`type "$i" | awk '{print $NF}' 2>/dev/null` -- cgit 1.4.1 From 6cbd0f1faf576a3ba9021720b0ca63a3cdd260ab Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Sat, 21 Mar 2020 18:51:43 +0100 Subject: avoid calling awk for 'which' replacement, use POSIX 'command -v' instead --- afl-cmin | 4 ++-- afl-plot | 2 +- gcc_plugin/Makefile | 2 +- llvm_mode/Makefile | 2 +- qemu_mode/build_qemu_support.sh | 2 +- test/test.sh | 10 +++++----- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'qemu_mode/build_qemu_support.sh') diff --git a/afl-cmin b/afl-cmin index d96a103f..d38e7a97 100755 --- a/afl-cmin +++ b/afl-cmin @@ -264,7 +264,7 @@ BEGIN { if (target_bin && !exists_and_is_executable(target_bin)) { - "type "target_bin" | awk '{print $NF}' 2>/dev/null" | getline tnew + "command -v "target_bin" 2>/dev/null" | getline tnew if (!tnew || !exists_and_is_executable(tnew)) { print "[-] Error: binary '"target_bin"' not found or not executable." > "/dev/stderr" exit 1 @@ -313,7 +313,7 @@ BEGIN { if (0 == system("test -f afl-cmin")) { showmap = "./afl-showmap" } else { - "type afl-showmap | awk '{print $NF}' 2>/dev/null" | getline showmap + "command -v afl-showmap 2>/dev/null" | getline showmap } } else { showmap = ENVIRON["AFL_PATH"] "/afl-showmap" diff --git a/afl-plot b/afl-plot index b17af364..6ad3f790 100755 --- a/afl-plot +++ b/afl-plot @@ -68,7 +68,7 @@ BANNER="`cat "$1/fuzzer_stats" | grep '^afl_banner ' | cut -d: -f2- | cut -b2-`" test "$BANNER" = "" && BANNER="(none)" -GNUPLOT=`type gnuplot | awk '{print $NF}' 2>/dev/null` +GNUPLOT=`command -v gnuplot 2>/dev/null` if [ "$GNUPLOT" = "" ]; then diff --git a/gcc_plugin/Makefile b/gcc_plugin/Makefile index f1e86d38..506d690d 100644 --- a/gcc_plugin/Makefile +++ b/gcc_plugin/Makefile @@ -44,7 +44,7 @@ PLUGIN_FLAGS = -fPIC -fno-rtti -I"$(shell $(CC) -print-file-name=plugin)/include HASH=\# GCCVER = $(shell $(CC) --version 2>/dev/null | awk 'NR == 1 {print $$NF}') -GCCBINDIR = $(shell dirname `type $(CC) | awk '{print $$NF}'` 2>/dev/null ) +GCCBINDIR = $(shell dirname `command -v $(CC)` 2>/dev/null ) ifeq "$(shell echo '$(HASH)include @$(HASH)include @int main() { int _id = shmget(IPC_PRIVATE, 65536, IPC_CREAT | IPC_EXCL | 0600); shmctl(_id, IPC_RMID, 0); return 0;}' | tr @ '\n' | $(CC) -x c - -o .test2 2>/dev/null && echo 1 || echo 0 ; rm -f .test2 )" "1" SHMAT_OK=1 diff --git a/llvm_mode/Makefile b/llvm_mode/Makefile index 0dd4f0b5..2b1660a3 100644 --- a/llvm_mode/Makefile +++ b/llvm_mode/Makefile @@ -162,7 +162,7 @@ ifeq "$(shell uname)" "OpenBSD" CLANG_LFL += `$(LLVM_CONFIG) --libdir`/libLLVM.so endif -ifeq "$(shell echo 'int main() {return 0; }' | $(CC) -x c - -fuse-ld=`type ld | awk '{print $$NF}'` -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1" +ifeq "$(shell echo 'int main() {return 0; }' | $(CC) -x c - -fuse-ld=`command -v ld` -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1" CFLAGS += -DAFL_CLANG_FUSELD=1 endif diff --git a/qemu_mode/build_qemu_support.sh b/qemu_mode/build_qemu_support.sh index 021e107b..4cf84477 100755 --- a/qemu_mode/build_qemu_support.sh +++ b/qemu_mode/build_qemu_support.sh @@ -86,7 +86,7 @@ fi if echo "$CC" | grep -qF /afl-; then echo "[-] Error: do not use afl-gcc or afl-clang to compile this tool." - exit 1 + PREREQ_NOTFOUND=1 fi diff --git a/test/test.sh b/test/test.sh index 49dfb1a9..5246a3ec 100755 --- a/test/test.sh +++ b/test/test.sh @@ -223,7 +223,7 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && { # on FreeBSD need to set AFL_CC test `uname -s` = 'FreeBSD' && { if type clang >/dev/null; then - export AFL_CC=`type clang | awk '{print $NF}'` + export AFL_CC=`command -v clang` else export AFL_CC=`$LLVM_CONFIG --bindir`/clang fi @@ -401,7 +401,7 @@ test -e ../afl-clang-lto -a -e ../afl-llvm-lto-instrumentation.so && { # on FreeBSD need to set AFL_CC test `uname -s` = 'FreeBSD' && { if type clang >/dev/null; then - export AFL_CC=`type clang | awk '{print $NF}'` + export AFL_CC=`command -v clang` else export AFL_CC=`$LLVM_CONFIG --bindir`/clang fi @@ -471,7 +471,7 @@ test -e ../afl-clang-lto -a -e ../afl-llvm-lto-instrumentation.so && { } $ECHO "$BLUE[*] Testing: gcc_plugin" -export AFL_CC=`type gcc | awk '{print $NF}'` +export AFL_CC=`command -v gcc` test -e ../afl-gcc-fast -a -e ../afl-gcc-rt.o && { ../afl-gcc-fast -o test-instr.plain.gccpi ../test-instr.c > /dev/null 2>&1 AFL_HARDEN=1 ../afl-gcc-fast -o test-compcov.harden.gccpi test-compcov.c > /dev/null 2>&1 @@ -617,7 +617,7 @@ test -e ../libradamsa.so && { test `uname -s` = 'FreeBSD' && { if type clang >/dev/null; then - export AFL_CC=`type clang | awk '{print $NF}'` + export AFL_CC=`command -v clang` else export AFL_CC=`$LLVM_CONFIG --bindir`/clang fi @@ -835,7 +835,7 @@ test -d ../unicorn_mode/unicornafl && { test -e ../unicorn_mode/samples/simple/simple_target.bin -a -e ../unicorn_mode/samples/compcov_x64/compcov_target.bin && { { # travis workaround - PY=`type python | awk '{print $NF}'` + PY=`command -v python` test "$PY" = "/opt/pyenv/shims/python" -a -x /usr/bin/python && PY=/usr/bin/python mkdir -p in echo 0 > in/in -- cgit 1.4.1 From 087bc6daebae057c303483059e5916b90f4c5d0c Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Sat, 21 Mar 2020 19:22:55 +0100 Subject: qemu_mode and unicorn_mode build scripts: replace type with command -v --- qemu_mode/build_qemu_support.sh | 2 +- unicorn_mode/build_unicorn_support.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu_mode/build_qemu_support.sh') diff --git a/qemu_mode/build_qemu_support.sh b/qemu_mode/build_qemu_support.sh index 4cf84477..a0bd245c 100755 --- a/qemu_mode/build_qemu_support.sh +++ b/qemu_mode/build_qemu_support.sh @@ -65,7 +65,7 @@ fi PREREQ_NOTFOUND= for i in libtool wget python automake autoconf sha384sum bison flex iconv patch pkg-config; do - T=`type "$i" | awk '{print $NF}' 2>/dev/null` + T=`command -v "$i" 2>/dev/null` if [ "$T" = "" ]; then diff --git a/unicorn_mode/build_unicorn_support.sh b/unicorn_mode/build_unicorn_support.sh index 540c524a..ee2f6d77 100755 --- a/unicorn_mode/build_unicorn_support.sh +++ b/unicorn_mode/build_unicorn_support.sh @@ -93,7 +93,7 @@ fi PREREQ_NOTFOUND= for i in $PYTHONBIN automake autoconf git $MAKECMD $TARCMD; do - T=`type "$i" | awk '{print $NF}' 2>/dev/null` + T=`command -v "$i" 2>/dev/null` if [ "$T" = "" ]; then -- cgit 1.4.1 From a5af81506f639bf6f979f2afb22e9849004f23b3 Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Sat, 21 Mar 2020 19:31:15 +0100 Subject: qemu_mode/unicorn_mode scripts: fix '==' in '[' --- qemu_mode/build_qemu_support.sh | 2 +- unicorn_mode/build_unicorn_support.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu_mode/build_qemu_support.sh') diff --git a/qemu_mode/build_qemu_support.sh b/qemu_mode/build_qemu_support.sh index a0bd245c..9e45686b 100755 --- a/qemu_mode/build_qemu_support.sh +++ b/qemu_mode/build_qemu_support.sh @@ -90,7 +90,7 @@ if echo "$CC" | grep -qF /afl-; then fi -if [ "$PREREQ_NOTFOUND" == "1" ]; then +if [ "$PREREQ_NOTFOUND" = "1" ]; then exit 1 fi diff --git a/unicorn_mode/build_unicorn_support.sh b/unicorn_mode/build_unicorn_support.sh index ee2f6d77..9d178d06 100755 --- a/unicorn_mode/build_unicorn_support.sh +++ b/unicorn_mode/build_unicorn_support.sh @@ -123,7 +123,7 @@ if echo "$CC" | grep -qF /afl-; then fi -if [ "$PREREQ_NOTFOUND" == "1" ]; then +if [ "$PREREQ_NOTFOUND" = "1" ]; then exit 1 fi -- cgit 1.4.1 From aac7c7d75d9e6657ba6ac4a6267660f15745ec92 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Sun, 22 Mar 2020 12:09:52 +0100 Subject: detect arm in build_qemu_support.sh --- Makefile | 5 ----- qemu_mode/build_qemu_support.sh | 12 ++++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'qemu_mode/build_qemu_support.sh') diff --git a/Makefile b/Makefile index a24092fc..9913c603 100644 --- a/Makefile +++ b/Makefile @@ -64,11 +64,6 @@ ifneq "$(shell uname -m)" "x86_64" endif endif -#support for qemu on arm -ifneq "$(findstring arm, $(shell uname -m))" "" - export CPU_TARGET=arm -endif - CFLAGS ?= -O3 -funroll-loops $(CFLAGS_OPT) override CFLAGS += -Wall -g -Wno-pointer-sign -I include/ \ -DAFL_PATH=\"$(HELPER_PATH)\" -DBIN_PATH=\"$(BIN_PATH)\" \ diff --git a/qemu_mode/build_qemu_support.sh b/qemu_mode/build_qemu_support.sh index 9e45686b..bd42c58e 100755 --- a/qemu_mode/build_qemu_support.sh +++ b/qemu_mode/build_qemu_support.sh @@ -143,8 +143,16 @@ echo "[*] Configuring QEMU for $CPU_TARGET..." ORIG_CPU_TARGET="$CPU_TARGET" -test "$CPU_TARGET" = "" && CPU_TARGET="`uname -m`" -test "$CPU_TARGET" = "i686" && CPU_TARGET="i386" +if [ "$ORIG_CPU_TARGET" = "" ]; then + CPU_TARGET="`uname -m`" + test "$CPU_TARGET" = "i686" && CPU_TARGET="i386" + test "$CPU_TARGET" = "arm64v8" && CPU_TARGET="aarch64" + case "$CPU_TARGET" in + *arm*) + CPU_TARGET="arm" + ;; + esac +fi cd qemu-$VERSION || exit 1 -- cgit 1.4.1