about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2019-10-31 21:20:09 +0000
committerDavid Carlier <devnexen@gmail.com>2019-11-01 14:45:03 +0000
commitc3b2fee07413fcab6f13d0c66ea0ca30760b2b1b (patch)
tree73fd85ca68bdedc850f2879a3b5ce522b7045188
parente2442f747179bef2f96ca11db5fe89a6c6a4bcaa (diff)
downloadafl++-c3b2fee07413fcab6f13d0c66ea0ca30760b2b1b.tar.gz
Unicorn mode for BSD proposal.
Darwin fix
-rwxr-xr-xunicorn_mode/build_unicorn_support.sh61
1 files changed, 48 insertions, 13 deletions
diff --git a/unicorn_mode/build_unicorn_support.sh b/unicorn_mode/build_unicorn_support.sh
index 3bd404b8..88dae90b 100755
--- a/unicorn_mode/build_unicorn_support.sh
+++ b/unicorn_mode/build_unicorn_support.sh
@@ -43,9 +43,11 @@ echo
 
 echo "[*] Performing basic sanity checks..."
 
-if [ ! "`uname -s`" = "Linux" ]; then
+PLT=`uname -s`
 
-  echo "[-] Error: Unicorn instrumentation is supported only on Linux."
+if [ ! "$PLT" = "Linux" ] && [ ! "$PLT" = "Darwin" ] && [ ! "$PLT" = "FreeBSD" ] && [ ! "$PLT" = "NetBSD" ] && [ ! "$PLT" = "OpenBSD" ]; then
+
+  echo "[-] Error: Unicorn instrumentation is unsupported on $PLT."
   exit 1
   
 fi
@@ -64,7 +66,39 @@ if [ ! -f "../afl-showmap" ]; then
 
 fi
 
-for i in wget python automake autoconf sha384sum; do
+if [ "$PLT" = "Linux" ]; then
+  CKSUMCMD='sha384sum --'
+  PYTHONBIN=python2
+  MAKECMD=make
+  TARCMD=tar
+  EASY_INSTALL=easy_install
+fi
+
+if [ "$PLT" = "Darwin" ]; then
+  CKSUMCMD="shasum -a 384 --tag"
+  PYTHONBIN=python2.7
+  MAKECMD=make
+  TARCMD=tar
+  EASY_INSTALL=easy_install-2.7
+fi
+
+if [ "$PLT" = "FreeBSD" ]; then
+  CKSUMCMD="sha384 -q"
+  PYTHONBIN=python2.7
+  MAKECMD=gmake
+  TARCMD=gtar
+  EASY_INSTALL=easy_install-2.7
+fi
+
+if [ "$PLT" = "NetBSD" ] || [ "$PLT" = "OpenBSD" ]; then
+  CKSUMCMD="cksum -a sha384 -q"
+  PYTHONBIN=python2.7
+  MAKECMD=gmake
+  TARCMD=gtar
+  EASY_INSTALL=easy_install-2.7
+fi
+
+for i in wget $PYTHONBIN automake autoconf $MAKECMD $TARCMD; do
 
   T=`which "$i" 2>/dev/null`
 
@@ -77,10 +111,10 @@ for i in wget python automake autoconf sha384sum; do
 
 done
 
-if ! which easy_install > /dev/null; then
+if ! which $EASY_INSTALL > /dev/null; then
 
   # work around for unusual installs
-  if [ '!' -e /usr/lib/python2.7/dist-packages/easy_install.py ]; then
+  if [ '!' -e /usr/lib/python2.7/dist-packages/easy_install.py ] && [ '!' -e /usr/local/lib/python2.7/dist-packages/easy_install.py ] && [ '!' -e /usr/pkg/lib/python2.7/dist-packages/easy_install.py ]; then
 
     echo "[-] Error: Python setup-tools not found. Run 'sudo apt-get install python-setuptools'."
     exit 1
@@ -100,15 +134,16 @@ echo "[+] All checks passed!"
 
 ARCHIVE="`basename -- "$UNICORN_URL"`"
 
-CKSUM=`sha384sum -- "$ARCHIVE" 2>/dev/null | cut -d' ' -f1`
+CKSUM=`$CKSUMCMD "$ARCHIVE" 2>/dev/null | cut -d' ' -f1`
 
 if [ ! "$CKSUM" = "$UNICORN_SHA384" ]; then
 
   echo "[*] Downloading Unicorn v1.0.1 from the web..."
   rm -f "$ARCHIVE"
-  wget -O "$ARCHIVE" -- "$UNICORN_URL" || exit 1
+  # NetBSD does not support SSL in the userland, we gotta trust github url
+  wget --no-check-certificate -O "$ARCHIVE" -- "$UNICORN_URL" || exit 1
 
-  CKSUM=`sha384sum -- "$ARCHIVE" 2>/dev/null | cut -d' ' -f1`
+  CKSUM=`CHKSUMCMD "$ARCHIVE" 2>/dev/null | cut -d' ' -f1`
 
 fi
 
@@ -127,7 +162,7 @@ echo "[*] Uncompressing archive (this will take a while)..."
 
 rm -rf "unicorn" || exit 1
 mkdir "unicorn" || exit 1
-tar xzf "$ARCHIVE" -C ./unicorn --strip-components=1 || exit 1
+$TARCMD xzf "$ARCHIVE" -C ./unicorn --strip-components=1 || exit 1
 
 echo "[+] Unpacking successful."
 
@@ -149,7 +184,7 @@ echo "[+] Configuration complete."
 
 echo "[*] Attempting to build Unicorn (fingers crossed!)..."
 
-UNICORN_QEMU_FLAGS='--python=python2' make -j `nproc` || exit 1
+UNICORN_QEMU_FLAGS="--python=$PYTHONBIN" $MAKECMD -j4 || exit 1
 
 echo "[+] Build process successful!"
 
@@ -157,10 +192,10 @@ echo "[*] Installing Unicorn python bindings..."
 cd bindings/python || exit 1
 if [ -z "$VIRTUAL_ENV" ]; then
   echo "[*] Info: Installing python unicorn using --user"
-  python setup.py install --user || exit 1
+  $PYTHONBIN setup.py install --user || exit 1
 else
   echo "[*] Info: Installing python unicorn to virtualenv: $VIRTUAL_ENV"
-  python setup.py install || exit 1
+  $PYTHONBIN setup.py install || exit 1
 fi
 export LIBUNICORN_PATH='$(pwd)' # in theory, this allows to switch between afl-unicorn and unicorn so files.
 
@@ -175,7 +210,7 @@ cd ../samples/simple || exit 1
 
 # Run afl-showmap on the sample application. If anything comes out then it must have worked!
 unset AFL_INST_RATIO
-echo 0 | ../../../afl-showmap -U -m none -q -o .test-instr0 -- python simple_test_harness.py ./sample_inputs/sample1.bin || exit 1
+echo 0 | ../../../afl-showmap -U -m none -q -o .test-instr0 -- $PYTHONBIN simple_test_harness.py ./sample_inputs/sample1.bin || exit 1
 
 if [ -s .test-instr0 ]
 then