MCPcopy
hub / github.com/USArmyResearchLab/Dshell / main

Function main

dshell/decode.py:166–372  ·  view source on GitHub ↗
(plugin_args=None, **kwargs)

Source from the content-addressed store, hash-verified

164
165
166def main(plugin_args=None, **kwargs):
167 global plugin_chain
168
169 if not plugin_args:
170 plugin_args = {}
171
172 # dictionary of all available plugins: {name: module path}
173 plugin_map = get_plugins()
174
175 # Attempt to catch segfaults caused when certain linktypes (e.g. 204) are
176 # given to pcapy
177 faulthandler.enable()
178
179 if not plugin_chain:
180 logger.error("No plugin selected")
181 sys.exit(1)
182
183 plugin_chain[0].defrag_ip = kwargs.get("defrag", False)
184
185 # Setup logging
186 log_format = "%(levelname)s (%(name)s) - %(message)s"
187 if kwargs.get("verbose", False):
188 log_level = logging.INFO
189 elif kwargs.get("debug", False):
190 log_level = logging.DEBUG
191 elif kwargs.get("quiet", False):
192 log_level = logging.CRITICAL
193 else:
194 log_level = logging.WARNING
195 logging.basicConfig(format=log_format, level=log_level)
196
197 # since pypacker handles its own exceptions (loudly), this attempts to keep
198 # it quiet
199 logging.getLogger("pypacker").setLevel(logging.CRITICAL)
200
201 if kwargs.get("allcc", False):
202 # Activate all country code (allcc) mode to display all 3 GeoIP2 country
203 # codes
204 dshell.core.geoip.acc = True
205
206 dshell.core.geoip.check_file_dates()
207
208 # If alternate output module is selected, tell each plugin to use that
209 # instead
210 if kwargs.get("omodule", None):
211 try:
212 # TODO: Create a factory classmethod in the base Output class (e.g. "from_name()") instead.
213 omodule = import_module("dshell.output."+kwargs["omodule"])
214 omodule = omodule.obj
215 for plugin in plugin_chain:
216 # TODO: Should we have a single instance of the Output module used by all plugins?
217 oomodule = omodule()
218 plugin.out = oomodule
219 except ImportError as e:
220 logger.error("Could not import module named '{}'. Use --list-output flag to see available modules".format(kwargs["omodule"]))
221 sys.exit(1)
222
223 # Check if any user-defined output arguments are provided

Callers 1

main_command_lineFunction · 0.85

Calls 14

get_pluginsFunction · 0.90
QueueOutputWrapperClass · 0.90
process_filesFunction · 0.85
errorMethod · 0.80
debugMethod · 0.80
reset_fhMethod · 0.80
_premoduleMethod · 0.80
true_writeMethod · 0.80
check_file_datesMethod · 0.45
set_oargsMethod · 0.45
set_formatMethod · 0.45
handle_plugin_optionsMethod · 0.45

Tested by

no test coverage detected