#!/usr/bin/env zsh # Note: # CMake, Clang, clang-format, Ninja, git and sed are required to build # # Note that currently there is a bug (https://github.com/google/binexport/issues/117) # that requires applying this patch, remove when resolved # if [[ "$OSTYPE" == "darwin"* ]]; then SED_CMD="sed -i '' -E -e" else SED_CMD="sed -i -E -e" fi if [ -d ~/Downloads ] then DOWNLOADS=~/Downloads else mdir ~/downloads DOWNLOAD=~/downloads fi BE_PATH=$DOWNLOADS/binexport if [ -d ~/.binaryninja ] && [ -f ~/.binaryninja/lastrun ] then BN_USER=~/.binaryninja BN_PATH=`cat ~/.binaryninja/lastrun` BINARY_HASH=$(sed 's/^.*\///' < $BN_PATH/api_REVISION.txt 2>/dev/null) CORES=$(nproc --all) PLUGIN_DEST=~/.binaryninja/plugins/binexport12_binaryninja.so PLUGIN_SRC=~/Downloads/binexport/build/binaryninja/binexport12_binaryninja.so elif [ -d ~/Library/Application\ Support/Binary\ Ninja ] && [ -f ~/Library/Application\ Support/Binary\ Ninja/lastrun ] then BN_USER=~/Library/Application\ Support/Binary\ Ninja BN_PATH=`cat ~/Library/Application\ Support/Binary\ Ninja/lastrun` BINARY_HASH=$(sed 's/^.*\///' < $BN_PATH/../Resources/api_REVISION.txt 2>/dev/null) CORES=$(sysctl -n hw.logicalcpu) PLUGIN_DEST=~/Library/Application\ Support/Binary\ Ninja/plugins/binexport12_binaryninja.dylib PLUGIN_SRC=~/Downloads/binexport/build/binaryninja/binexport12_binaryninja.dylib else echo "Failed to find appropriate Binary Ninja user directory." exit 1 fi BN_API_PATH=$DOWNLOADS/binaryninja-api echo "Configuration:" echo " DOWNLOADS: $DOWNLOADS" echo " BE_PATH: $BE_PATH" echo " BN_API_PATH: $BN_API_PATH" echo " BN_PATH: $BN_PATH" echo " BINARY_HASH: $BINARY_HASH" if [ -z "$BINARY_HASH" ] then echo "Failed to find appropriate hash for Binary Ninja" exit 1 fi echo "\u001b[36m[+] Cloning BinExport & Binary Ninja API..." echo "\u001b[0m" if [ -d $BE_PATH ] then pushd $BE_PATH if git fetch --all then git reset --hard origin/main # Because previous runs of this script will dirty the repo echo "BinExport exists, repo updated" else echo Not a repo, remove $BE_PATH to continue exit fi popd else git clone https://github.com/google/binexport.git $BE_PATH fi if [ ! -d $BN_API_PATH ] then git clone --recursive --branch dev https://github.com/Vector35/binaryninja-api.git $BN_API_PATH fi pushd $BN_API_PATH if git fetch --all then if git checkout "$BINARY_HASH" then git pull echo "Binary Ninja API exists, repo updated" else echo Not a repo or could not match binary hash exit fi fi popd echo "\u001b[36m[+] Updating the git hash..." echo "\u001b[0m" $SED_CMD "s/(1bd42a73e612f50c68d802acda674c21a30e980c|6e2b374dece03f6fb48a1615fa2bfee809ec2157)/$BINARY_HASH/g" $BE_PATH/cmake/BinExportDeps.cmake $SED_CMD "s/2023-05-18/2023-09-24/g" $BE_PATH/cmake/BinExportDeps.cmake echo "\u001b[36m[+] Running regenerate-api-stubs..." echo "\u001b[0m" pushd $BE_PATH/binaryninja/stubs/ ./regenerate-api-stubs.sh $BN_API_PATH popd pushd $BE_PATH echo "\u001b[36m[+] Building BinExport..." echo "\u001b[0m" rm -rf build && mkdir build && cd build cmake .. -G Ninja -DCMAKE_CXX_FLAGS="-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" -DBINEXPORT_BINARYNINJA_CHANNEL=DEV -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$PWD" -DBINEXPORT_ENABLE_IDAPRO=OFF -DBINEXPORT_ENABLE_BINARYNINJA=ON cmake --build . --config Release -- "-j$CORES" popd if [ -f $PLUGIN_DEST ] then echo "\u001b[36m[+] Not linking the plugin, file already exists\u001b[0m" else echo "\u001b[36m[+] Linking BinExport plugin to Binary Ninja plugin folder\u001b[0m" ln -sf $PLUGIN_SRC $PLUGIN_DEST fi echo "\u001b[32;1m[+] Done!" echo "\u001b[0m"