Unicorn mode for BSD proposal.

Darwin fix
This commit is contained in:
David Carlier 2019-10-31 21:20:09 +00:00
parent e2442f7471
commit a09cfd57a4

View File

@ -43,9 +43,11 @@ echo
echo "[*] Performing basic sanity checks..." 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 exit 1
fi fi
@ -64,7 +66,39 @@ if [ ! -f "../afl-showmap" ]; then
fi 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"
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` T=`which "$i" 2>/dev/null`
@ -77,10 +111,10 @@ for i in wget python automake autoconf sha384sum; do
done done
if ! which easy_install > /dev/null; then if ! which $EASY_INSTALL > /dev/null; then
# work around for unusual installs # 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'." echo "[-] Error: Python setup-tools not found. Run 'sudo apt-get install python-setuptools'."
exit 1 exit 1
@ -100,7 +134,7 @@ echo "[+] All checks passed!"
ARCHIVE="`basename -- "$UNICORN_URL"`" 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 if [ ! "$CKSUM" = "$UNICORN_SHA384" ]; then
@ -108,7 +142,7 @@ if [ ! "$CKSUM" = "$UNICORN_SHA384" ]; then
rm -f "$ARCHIVE" rm -f "$ARCHIVE"
wget -O "$ARCHIVE" -- "$UNICORN_URL" || exit 1 wget -O "$ARCHIVE" -- "$UNICORN_URL" || exit 1
CKSUM=`sha384sum -- "$ARCHIVE" 2>/dev/null | cut -d' ' -f1` CKSUM=`CKSUMCMD "$ARCHIVE" 2>/dev/null | cut -d' ' -f1`
fi fi
@ -127,7 +161,7 @@ echo "[*] Uncompressing archive (this will take a while)..."
rm -rf "unicorn" || exit 1 rm -rf "unicorn" || exit 1
mkdir "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." echo "[+] Unpacking successful."
@ -149,7 +183,7 @@ echo "[+] Configuration complete."
echo "[*] Attempting to build Unicorn (fingers crossed!)..." 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!" echo "[+] Build process successful!"
@ -157,10 +191,10 @@ echo "[*] Installing Unicorn python bindings..."
cd bindings/python || exit 1 cd bindings/python || exit 1
if [ -z "$VIRTUAL_ENV" ]; then if [ -z "$VIRTUAL_ENV" ]; then
echo "[*] Info: Installing python unicorn using --user" echo "[*] Info: Installing python unicorn using --user"
python setup.py install --user || exit 1 $PYTHONBIN setup.py install --user || exit 1
else else
echo "[*] Info: Installing python unicorn to virtualenv: $VIRTUAL_ENV" echo "[*] Info: Installing python unicorn to virtualenv: $VIRTUAL_ENV"
python setup.py install || exit 1 $PYTHONBIN setup.py install || exit 1
fi fi
export LIBUNICORN_PATH='$(pwd)' # in theory, this allows to switch between afl-unicorn and unicorn so files. export LIBUNICORN_PATH='$(pwd)' # in theory, this allows to switch between afl-unicorn and unicorn so files.
@ -175,7 +209,7 @@ cd ../samples/simple || exit 1
# Run afl-showmap on the sample application. If anything comes out then it must have worked! # Run afl-showmap on the sample application. If anything comes out then it must have worked!
unset AFL_INST_RATIO 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 ] if [ -s .test-instr0 ]
then then