Skip to content

Commit

Permalink
Addded idainstall and idauninstall to setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed May 15, 2015
1 parent 02dd825 commit 94a70ba
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 7 deletions.
12 changes: 11 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 84 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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}
)

4 changes: 2 additions & 2 deletions src/scripts/binida.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 94a70ba

Please sign in to comment.