diff options
| author | Rusty Wagner <rusty@vector35.com> | 2017-06-23 18:36:37 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2017-06-23 18:36:37 -0400 |
| commit | c51f3bed6bdef577253feee0e85a71fda1931bd7 (patch) | |
| tree | 1cf26ff28e0b9bfb6bfbed044ba7ca520d63f862 /scripts | |
| parent | 4b988c0d24c8d8c8dc67485f3aaeb7106eb4af18 (diff) | |
| parent | cca0fe6ea60eb7f6b35cc433a6fff96cc65b3ff8 (diff) | |
Merge branch 'dev'
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/install_api.py | 85 | ||||
| -rwxr-xr-x | scripts/linux-setup.sh | 205 |
2 files changed, 251 insertions, 39 deletions
diff --git a/scripts/install_api.py b/scripts/install_api.py new file mode 100755 index 00000000..53679ba5 --- /dev/null +++ b/scripts/install_api.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# Thanks to @withzombies for letting us adapt his script +# + +import sys +import os +from site import getsitepackages, getusersitepackages, check_enableusersite + +try: + import binaryninja + print("Binary Ninja API already Installed") + sys.exit(1) +except ImportError: + pass + +if sys.platform.startswith("linux"): + userpath = os.path.expanduser("~/.binaryninja") + lastrun = os.path.join(userpath, "lastrun") + if os.path.isfile(lastrun): + lastrunpath = open(lastrun).read().strip() + api_path = os.path.join(lastrunpath, "python") + print("Found install folder of {}".format(api_path)) + else: + print("Running on linux, but ~/.binaryninja/lastrun does not exist") + sys.exit(0) +elif sys.platform == "darwin": + api_path = "/Applications/Binary Ninja.app/Contents/Resources/python" +else: + # Windows + api_path = "r'C:\Program Files\Vector35\BinaryNinja\python'" + + +def validate_path(path): + try: + os.stat(path) + except OSError: + return False + + old_path = sys.path + sys.path.append(path) + + try: + from binaryninja import core_version + print("Found Binary Ninja core version: {}".format(core_version)) + except ImportError: + sys.path = old_path + return False + + return True + + +while not validate_path(api_path): + print("\nBinary Ninja not found. Please provide the path to Binary " + \ + "Ninja's install directory: \n [{}] : ".format(api_path)) + + new_path = sys.stdin.readline().strip() + if len(new_path) == 0: + print("\nInvalid path") + continue + + if not new_path.endswith('python'): + new_path = os.path.join(new_path, 'python') + + api_path = new_path + +if ( len(sys.argv) > 1 and sys.argv[1].lower() == "root" ): + #write to root site + install_path = getsitepackages()[0] + if not os.access(install_path, os.W_OK): + print("Root install specified but cannot write to {}".format(install_path)) + sys.exit(1) +else: + if check_enableusersite(): + install_path = getusersitepackages() + if not os.path.exists(install_path): + os.makedirs(install_path) + else: + print("Warning, trying to write to user site packages, but check_enableusersite fails.") + sys.exit(1) + +binaryninja_pth_path = os.path.join(install_path, 'binaryninja.pth') +open(binaryninja_pth_path, 'wb').write(api_path) + +print("Binary Ninja API installed using {}".format(binaryninja_pth_path)) diff --git a/scripts/linux-setup.sh b/scripts/linux-setup.sh index 2f5bd489..e56d74dc 100755 --- a/scripts/linux-setup.sh +++ b/scripts/linux-setup.sh @@ -1,73 +1,123 @@ #!/bin/bash -# Note is setup script currently does three things: +# Note is setup script currently does four things: # # 1. It creates a binaryninja.desktop file in ~/.local/share/applications and # copies it to the desktop # 2. It creates a .xml file to add a mime type for .bndb files. # 3. It adds a binaryninja: url handler. +# 4. Creates .pth python file to add binary ninja to your python path -APP="binaryninja" -FILECOMMENT="Binary Ninja Analysis Database" -APPCOMMENT="Binary Ninja: A Reverse Engineering Platform" -BNPATH=$(dirname $(readlink -f "$0")) -EXEC="${BNPATH}/binaryninja" -PNG="${BNPATH}/docs/images/logo.png" -EXT="bndb" -SHARE=/usr/share #For system -SUDO="sudo" #For system -SHARE=~/.local/share #For user only -SUDO="" #For user only -DESKTOPFILE=$SHARE/applications/${APP}.desktop -MIMEFILE=$SHARE/mime/packages/application-x-$APP.xml -IMAGEPATH=$SHARE/pixmaps +setvars() +{ + APP="binaryninja" + FILECOMMENT="Binary Ninja Analysis Database" + APPCOMMENT="Binary Ninja: A Reverse Engineering Platform" + BNPATH=$(dirname $(readlink -f "$0")) + EXEC="${BNPATH}/binaryninja" + PNG="${BNPATH}/docs/images/logo.png" + EXT="bndb" + if [ "$ROOT" == "root" ] + then + SHARE="/usr/share" #For system + SUDO="sudo " #For system + else + SHARE="~/.local/share" #For user only + SUDO="" #For user only + fi + DESKTOPFILE="${SHARE}/applications/${APP}.desktop" + MIMEFILE="${SHARE}/mime/packages/application-x-${APP}.xml" + IMAGEFILE="${SHARE}/pixmaps/application-x-${APP}.png" +} + +usage() +{ + echo "Usage: $0 -[ulpdmrsh] + -u: For uninstall, removes all associations (does NOT remove ~/.binaryninja) + -l: Disable creation ~/.binaryninja/lastrun file + -p: Disable adding python path .pth file + -d: Disable adding desktop launcher + -m: Disable adding mime associations + -r: Run as root to set system wide preferences (requires sudo permissions) + -s: Run in headless mode (equivalent to -d -m) + -h: Display this help +" 1>&2 + exit 1 +} + +lastrun() +{ + #Contains the last run location, but on systems without a UI this ensures + #the UI doesn't have to run once for the core to be available. + if [ -f ~/.binaryninja/lastrun ] + then + echo lastrun already exists, remove to create a new one + else + echo ${BNPATH} > ~/.binaryninja/lastrun + fi +} + +pythonpath() +{ + echo Configuring python path + ${SUDO}python ${BNPATH}/install_api.py $ROOT +} createdesktopfile() { - mkdir -p $SHARE/{mime/packages,applications,pixmaps} + mkdir -p ${SHARE}/{mime/packages,applications,pixmaps} echo Creating .desktop file # Desktop File - echo "[Desktop Entry] -Name=$APP -Exec=$EXEC %u -MimeType=application/x-$APP;x-scheme-handler/$APP; -Icon=$PNG + read -d '' DESKTOP << EOF +[Desktop Entry] +Name=${APP} +Exec=${EXEC} %u +MimeType=application/x-${APP};x-scheme-handler/${APP}; +Icon=${PNG} Terminal=false Type=Application Categories=Utility; -Comment=$APPCOMMENT -" | $SUDO tee $DESKTOPFILE >/dev/null - $SUDO chmod +x $DESKTOPFILE - - $SUDO update-desktop-database $SHARE/applications +Comment=${APPCOMMENT} +EOF + if [ "${ROOT}" == "root" ] + then + echo ${DESKTOP} | $SUDO tee ${DESKTOPFILE} >/dev/null + $SUDO chmod +x ${DESKTOPFILE} + $SUDO update-desktop-database ${SHARE}/applications + else + echo ${DESKTOP} > ~/Desktop/${APP}.desktop + fi } createmime() { echo Creating MIME settings - if [ ! -f $DESKTOPFILE ] + if [ ! -f ${DESKTOPFILE} -a ! -f ~/Desktop/${APP}.desktop ] then createdesktopfile fi echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\"> - <mime-type type=\"application/x-$APP\"> - <comment>$FILECOMMENT</comment> - <icon name=\"application-x-$APP\"/> + <mime-type type=\"application/x-${APP}\"> + <comment>${FILECOMMENT}</comment> + <icon name=\"application-x-${APP}\"/> <magic-deleteall/> - <glob pattern=\"*.$EXT\"/> + <glob pattern=\"*.${EXT}\"/> <sub-class-of type=\"application/x-sqlite3\" /> </mime-type> -</mime-info>"| $SUDO tee $MIMEFILE >/dev/null +</mime-info>"| $SUDO tee ${MIMEFILE} >/dev/null #echo Copying icon - #$SUDO cp $PNG $IMAGEPATH/$APP.png - $SUDO cp $PNG $IMAGEPATH/application-x-$APP.png + #$SUDO cp $PNG $IMAGEFILE + if [ "${ROOT}" == "root" ] + then + $SUDO cp ${PNG} ${IMAGEFILE} + $SUDO update-mime-database ${SHARE}/mime + fi - $SUDO update-mime-database $SHARE/mime } addtodesktop() @@ -75,7 +125,84 @@ addtodesktop() cp $DESKTOPFILE ~/Desktop } -#TODO: Make these optional... -createdesktopfile -createmime -addtodesktop +uninstall() +{ + rm -i -r $DESKTOPFILE $MIMEFILE $IMAGEFILE + if [ "$ROOT" == "root" ] + then + $SUDO update-mime-database ${SHARE}/mime + fi + exit 0 +} + + + +ROOT=user +CREATEDESKTOP=true +CREATEMIME=true +ADDTODESKTOP=true +CREATELASTRUN=true +PYTHONPATH=true +UNINSTALL=false + +while [[ $# -ge 1 ]] +do + flag="$1" + + case $flag in + -u) + UNINSTALL=true + ;; + -l) + CREATELASTRUN=false + ;; + -p) + PYTHONPATH=false + ;; + -d) + ADDTODESKTOP=false + ;; + -m) + CREATEMIME=false + ;; + -r) + ROOT=root + ;; + -s) + ADDTODESKTOP=false + CREATEMIME=false + CREATEDESKTOP=false + ;; + -h|*) + usage + ;; + esac + shift +done + +setvars + +if [ "$UNINSTALL" == "true" ] +then + uninstall +fi +if [ "$CREATEDESKTOP" == "true" ] +then + createdesktopfile +fi +if [ "$CREATEMIME" == "true" ] +then + createmime +fi +if [ "$ADDTODESKTOP" == "true" ] +then + addtodesktop +fi +if [ "$CREATELASTRUN" == "true" ] +then + lastrun +fi +if [ "$PYTHONPATH" == "true" ] +then + pythonpath +fi |
