Commit 94a70ba8 by devttys0

Addded idainstall and idauninstall to setup.py

parent 02dd825f
...@@ -89,7 +89,17 @@ $ sudo cp bin/unstuff /usr/local/bin/ ...@@ -89,7 +89,17 @@ $ sudo cp bin/unstuff /usr/local/bin/
Installing the IDA Plugin 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 Uninstalling Binwalk
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import os import os
import sys import sys
import shutil
import tempfile import tempfile
import subprocess import subprocess
from distutils.core import setup, Command from distutils.core import setup, Command
...@@ -64,13 +64,93 @@ def remove_binwalk_module(pydir=None, pybin=None): ...@@ -64,13 +64,93 @@ def remove_binwalk_module(pydir=None, pybin=None):
if pybin: if pybin:
try: try:
print("removing '%s'" % pybin) sys.stdout.write("removing '%s'\n" % pybin)
os.unlink(pybin) os.remove(pybin)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
pass pass
except Exception as e: except Exception as e:
pass 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): class UninstallCommand(Command):
description = "Uninstalls the Python module" description = "Uninstalls the Python module"
user_options = [ user_options = [
...@@ -130,6 +210,6 @@ setup(name = MODULE_NAME, ...@@ -130,6 +210,6 @@ setup(name = MODULE_NAME,
package_data = {MODULE_NAME : install_data_files}, package_data = {MODULE_NAME : install_data_files},
scripts = [os.path.join("scripts", MODULE_NAME)], scripts = [os.path.join("scripts", MODULE_NAME)],
cmdclass = {'clean' : CleanCommand, 'uninstall' : UninstallCommand} cmdclass = {'clean' : CleanCommand, 'uninstall' : UninstallCommand, 'idainstall' : IDAInstallCommand, 'idauninstall' : IDAUnInstallCommand}
) )
...@@ -10,8 +10,8 @@ class binwalk_t(idaapi.plugin_t): ...@@ -10,8 +10,8 @@ class binwalk_t(idaapi.plugin_t):
wanted_hotkey = "" wanted_hotkey = ""
def init(self): def init(self):
self.menu_context_1 = idaapi.add_menu_item("Search/", "executable opcodes", "", 0, self.opcode_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/", "file signatures", "", 0, self.signature_scan, (None,)) self.menu_context_2 = idaapi.add_menu_item("Search/", "binwalk signatures", "", 0, self.signature_scan, (None,))
return idaapi.PLUGIN_KEEP return idaapi.PLUGIN_KEEP
def term(self): def term(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment