From 94a70ba847a827b5f9f29c6b0b7e3bac061a7404 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Fri, 15 May 2015 13:28:48 -0400 Subject: [PATCH] Addded idainstall and idauninstall to setup.py --- INSTALL.md | 12 +++++- setup.py | 88 +++++++++++++++++++++++++++++++++++++++++-- src/scripts/binida.py | 4 +- 3 files changed, 97 insertions(+), 7 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 3d30bdad3..7af455612 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -89,7 +89,17 @@ $ sudo cp bin/unstuff /usr/local/bin/ Installing the IDA Plugin ========================= -If IDA is installed on your system, you may optionally install the binwalk IDA plugin by simply copying the `src/scripts/binida.py` file into IDA's `plugins` directory. +If IDA is installed on your system, you may optionally install the binwalk IDA plugin: + +```bash +$ python setup.py idainstall --idadir=/home/user/ida +``` + +Likewise, the binwalk IDA plugin can be uninstalled: + +```bash +$ python setup.py idauninstall --idadir=/home/user/ida +``` Uninstalling Binwalk diff --git a/setup.py b/setup.py index b69e632b6..b9785cc56 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -from __future__ import print_function import os import sys +import shutil import tempfile import subprocess from distutils.core import setup, Command @@ -64,13 +64,93 @@ def remove_binwalk_module(pydir=None, pybin=None): if pybin: try: - print("removing '%s'" % pybin) - os.unlink(pybin) + sys.stdout.write("removing '%s'\n" % pybin) + os.remove(pybin) except KeyboardInterrupt as e: pass except Exception as e: pass +class IDAUnInstallCommand(Command): + description = "Uninstalls the binwalk IDA plugin module" + user_options = [ + ('idadir=', None, 'Specify the path to your IDA install directory.'), + ] + + def initialize_options(self): + self.idadir = None + self.mydir = os.path.dirname(os.path.realpath(__file__)) + + def finalize_options(self): + pass + + def run(self): + if self.idadir is None: + sys.stderr.write("Please specify the path to your IDA install directory with the '--idadir' option!\n") + return + + binida_dst_path = os.path.join(self.idadir, 'plugins', 'binida.py') + binwalk_dst_path = os.path.join(self.idadir, 'python', 'binwalk') + + if os.path.exists(binida_dst_path): + sys.stdout.write("removing %s\n" % binida_dst_path) + os.remove(binida_dst_path) + if os.path.exists(binwalk_dst_path): + sys.stdout.write("removing %s\n" % binwalk_dst_path) + shutil.rmtree(binwalk_dst_path) + +class IDAInstallCommand(Command): + description = "Installs the binwalk IDA plugin module" + user_options = [ + ('idadir=', None, 'Specify the path to your IDA install directory.'), + ] + + def initialize_options(self): + self.idadir = None + self.mydir = os.path.dirname(os.path.realpath(__file__)) + + def finalize_options(self): + pass + + def run(self): + if self.idadir is None: + sys.stderr.write("Please specify the path to your IDA install directory with the '--idadir' option!\n") + return + + binida_src_path = os.path.join(self.mydir, 'scripts', 'binida.py') + binida_dst_path = os.path.join(self.idadir, 'plugins') + + if not os.path.exists(binida_src_path): + sys.stderr.write("ERROR: could not locate IDA plugin file '%s'!\n" % binida_src_path) + return + if not os.path.exists(binida_dst_path): + sys.stderr.write("ERROR: could not locate the IDA plugins directory '%s'! Check your --idadir option.\n" % binida_dst_path) + return + + binwalk_src_path = os.path.join(self.mydir, 'binwalk') + binwalk_dst_path = os.path.join(self.idadir, 'python') + + if not os.path.exists(binwalk_src_path): + sys.stderr.write("ERROR: could not locate binwalk source directory '%s'!\n" % binwalk_src_path) + return + if not os.path.exists(binwalk_dst_path): + sys.stderr.write("ERROR: could not locate the IDA python directory '%s'! Check your --idadir option.\n" % binwalk_dst_path) + return + + binida_dst_path = os.path.join(binida_dst_path, 'binida.py') + binwalk_dst_path = os.path.join(binwalk_dst_path, 'binwalk') + + if os.path.exists(binida_dst_path): + os.remove(binida_dst_path) + if os.path.exists(binwalk_dst_path): + shutil.rmtree(binwalk_dst_path) + + sys.stdout.write("copying %s -> %s\n" % (binida_src_path, binida_dst_path)) + shutil.copyfile(binida_src_path, binida_dst_path) + + sys.stdout.write("copying %s -> %s\n" % (binwalk_src_path, binwalk_dst_path)) + shutil.copytree(binwalk_src_path, binwalk_dst_path) + class UninstallCommand(Command): description = "Uninstalls the Python module" user_options = [ @@ -130,6 +210,6 @@ def run(self): package_data = {MODULE_NAME : install_data_files}, scripts = [os.path.join("scripts", MODULE_NAME)], - cmdclass = {'clean' : CleanCommand, 'uninstall' : UninstallCommand} + cmdclass = {'clean' : CleanCommand, 'uninstall' : UninstallCommand, 'idainstall' : IDAInstallCommand, 'idauninstall' : IDAUnInstallCommand} ) diff --git a/src/scripts/binida.py b/src/scripts/binida.py index e94505922..01fccf11b 100755 --- a/src/scripts/binida.py +++ b/src/scripts/binida.py @@ -10,8 +10,8 @@ class binwalk_t(idaapi.plugin_t): wanted_hotkey = "" def init(self): - self.menu_context_1 = idaapi.add_menu_item("Search/", "executable opcodes", "", 0, self.opcode_scan, (None,)) - self.menu_context_2 = idaapi.add_menu_item("Search/", "file signatures", "", 0, self.signature_scan, (None,)) + self.menu_context_1 = idaapi.add_menu_item("Search/", "binwalk opcodes", "", 0, self.opcode_scan, (None,)) + self.menu_context_2 = idaapi.add_menu_item("Search/", "binwalk signatures", "", 0, self.signature_scan, (None,)) return idaapi.PLUGIN_KEEP def term(self):