Commit 827f3e7d by devttys0

Plugin classes no longer need to be named 'Plugin'

parent 68a99e87
import os
import sys
import imp
import inspect
import binwalk.core.settings
from binwalk.core.compat import *
......@@ -95,7 +96,6 @@ class Plugins(object):
SCAN = 'scan'
PRESCAN = 'pre_scan'
POSTSCAN = 'post_scan'
PLUGIN = 'Plugin'
MODULE_EXTENSION = '.py'
def __init__(self, parent=None):
......@@ -126,6 +126,12 @@ class Plugins(object):
except Exception as e:
sys.stderr.write("WARNING: %s.%s failed: %s\n" % (callback.__module__, callback.__name__, e))
def _find_plugin_class(self, plugin):
for (name, klass) in inspect.getmembers(plugin, inspect.isclass):
if issubclass(klass, Plugin) and klass != Plugin:
return klass
raise Exception("Failed to locate Plugin class in " + plugin)
def list_plugins(self):
'''
Obtain a list of all user and system plugin modules.
......@@ -150,16 +156,16 @@ class Plugins(object):
plugins = {
'user' : {
'modules' : [],
'descriptions' : {},
'modules' : [],
'descriptions' : {},
'enabled' : {},
'path' : None,
'path' : None,
},
'system' : {
'modules' : [],
'descriptions' : {},
'modules' : [],
'descriptions' : {},
'enabled' : {},
'path' : None,
'path' : None,
}
}
......@@ -172,7 +178,7 @@ class Plugins(object):
try:
plugin = imp.load_source(module, os.path.join(plugins[key]['path'], file_name))
plugin_class = getattr(plugin, self.PLUGIN)
plugin_class = self._find_plugin_class(plugin)
plugins[key]['enabled'][module] = True
plugins[key]['modules'].append(module)
......@@ -201,7 +207,7 @@ class Plugins(object):
try:
plugin = imp.load_source(module, file_path)
plugin_class = getattr(plugin, self.PLUGIN)
plugin_class = self._find_plugin_class(plugin)
class_instance = plugin_class(self.parent)
if not class_instance._enabled:
......
import binwalk.core.C
from binwalk.core.common import *
import binwalk.core.plugin
from binwalk.core.common import *
class Plugin(binwalk.core.plugin.Plugin):
class CompressdPlugin(binwalk.core.plugin.Plugin):
'''
Searches for and validates compress'd data.
'''
......
import binwalk.core.plugin
class Plugin(binwalk.core.plugin.Plugin):
class CPIOPlugin(binwalk.core.plugin.Plugin):
'''
Ensures that ASCII CPIO archive entries only get extracted once.
'''
......
......@@ -4,7 +4,7 @@ import binwalk.core.plugin
from binwalk.core.compat import *
from binwalk.core.common import BlockFile
class Plugin(binwalk.core.plugin.Plugin):
class LZMAModPlugin(binwalk.core.plugin.Plugin):
'''
Finds and extracts modified LZMA files commonly found in cable modems.
Based on Bernardo Rodrigues' work: http://w00tsec.blogspot.com/2013/11/unpacking-firmware-images-from-cable.html
......
......@@ -2,7 +2,7 @@ import time
import math
import binwalk.core.plugin
class Plugin(binwalk.core.plugin.Plugin):
class TarPlugin(binwalk.core.plugin.Plugin):
MODULES = ['Signature']
......
......@@ -2,7 +2,7 @@ import binwalk.core.C
import binwalk.core.plugin
from binwalk.core.common import BlockFile
class Plugin(binwalk.core.plugin.Plugin):
class ZlibPlugin(binwalk.core.plugin.Plugin):
'''
Searches for and validates zlib compressed data.
'''
......
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