Commit c297fbc3 by Craig Heffner

Added load_file method support for plugins

parent 1e0491ee
__all__ = ['scan', 'execute', 'ModuleException']
from binwalk.core.module import Modules, ModuleException
from binwalk.core.module import Modules
from binwalk.core.exceptions import ModuleException
# Convenience functions
def scan(*args, **kwargs):
......
......@@ -9,12 +9,7 @@ import struct
import datetime
import binwalk.core.common
import binwalk.core.compat
class ParserException(Exception):
'''
Exception thrown specifically for signature file parsing errors.
'''
pass
from binwalk.core.exceptions import ParserException
class SignatureResult(binwalk.core.module.Result):
'''
......
......@@ -17,6 +17,7 @@ import binwalk.core.settings
import binwalk.core.plugin
from threading import Thread
from binwalk.core.compat import *
from binwalk.core.exceptions import *
class Option(object):
'''
......@@ -319,6 +320,13 @@ class Module(object):
def _plugins_pre_scan(self):
self.plugins.pre_scan_callbacks(self)
def _plugins_load_file(self, fp):
try:
self.plugins.load_file_callbacks(fp)
return True
except IgnoreFileException:
return False
def _plugins_new_file(self, fp):
self.plugins.new_file_callbacks(fp)
......@@ -398,7 +406,8 @@ class Module(object):
if not fp:
break
else:
if self.config.file_name_filter(fp) == False:
if (self.config.file_name_filter(fp) == False or
self._plugins_load_file(fp) == False):
fp.close()
fp = None
continue
......@@ -588,13 +597,6 @@ class Status(object):
for (k,v) in iterator(self.kwargs):
setattr(self, k, v)
class ModuleException(Exception):
'''
Module exception class.
Nothing special here except the name.
'''
pass
class Modules(object):
'''
Main class used for running and managing modules.
......
......@@ -7,6 +7,7 @@ import inspect
import binwalk.core.common
import binwalk.core.settings
from binwalk.core.compat import *
from binwalk.core.exceptions import IgnoreFileException
class Plugin(object):
'''
......@@ -80,6 +81,7 @@ class Plugins(object):
SCAN = 'scan'
NEWFILE = 'new_file'
LOADFILE = 'load_file'
PRESCAN = 'pre_scan'
POSTSCAN = 'post_scan'
MODULE_EXTENSION = '.py'
......@@ -88,6 +90,7 @@ class Plugins(object):
self.scan = []
self.pre_scan = []
self.new_file = []
self.load_file = []
self.post_scan = []
self.parent = parent
self.settings = binwalk.core.settings.Settings()
......@@ -108,6 +111,8 @@ class Plugins(object):
callback(obj)
except KeyboardInterrupt as e:
raise e
except IgnoreFileException as e:
raise e
except Exception as e:
binwalk.core.common.warning("%s.%s failed: %s" % (callback.__module__, callback.__name__, e))
......@@ -215,6 +220,13 @@ class Plugins(object):
pass
try:
self.load_file.append(getattr(class_instance, self.LOADFILE))
except KeyboardInterrupt as e:
raise e
except Exception as e:
pass
try:
self.pre_scan.append(getattr(class_instance, self.PRESCAN))
except KeyboardInterrupt as e:
raise e
......@@ -243,6 +255,9 @@ class Plugins(object):
def pre_scan_callbacks(self, obj):
return self._call_plugins(self.pre_scan)
def load_file_callbacks(self, fp):
return self._call_plugins(self.load_file, fp)
def new_file_callbacks(self, fp):
return self._call_plugins(self.new_file, fp)
......
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