Commit 458df42e by devttys0

Added ability to pass raw strings to be scanned via API

parent 11ad600c
...@@ -354,10 +354,10 @@ class Module(object): ...@@ -354,10 +354,10 @@ class Module(object):
# Values in self.target_file_list are either already open files (BlockFile instances), or paths # Values in self.target_file_list are either already open files (BlockFile instances), or paths
# to files that need to be opened for scanning. # to files that need to be opened for scanning.
if isinstance(next_target_file, binwalk.core.common.BlockFile): if isinstance(next_target_file, str):
fp = next_target_file
else:
fp = self.config.open_file(next_target_file) fp = self.config.open_file(next_target_file)
else:
fp = next_target_file
self.status.clear() self.status.clear()
self.status.total = fp.length self.status.total = fp.length
......
# Module to process general user input options (scan length, starting offset, etc). # Module to process general user input options (scan length, starting offset, etc).
import io
import os import os
import sys import sys
import argparse import argparse
...@@ -67,6 +68,10 @@ class General(Module): ...@@ -67,6 +68,10 @@ class General(Module):
short=None, short=None,
type=binwalk.core.common.BlockFile, type=binwalk.core.common.BlockFile,
kwargs={'files' : []}), kwargs={'files' : []}),
# Hidden, API-only arguments
Option(long="string",
kwargs={'subclass' : binwalk.core.common.StringFile}),
] ]
KWARGS = [ KWARGS = [
...@@ -82,6 +87,7 @@ class General(Module): ...@@ -82,6 +87,7 @@ class General(Module):
Kwarg(name='files', default=[]), Kwarg(name='files', default=[]),
Kwarg(name='show_help', default=False), Kwarg(name='show_help', default=False),
Kwarg(name='keep_going', default=False), Kwarg(name='keep_going', default=False),
Kwarg(name='subclass', default=io.FileIO),
] ]
PRIMARY = False PRIMARY = False
...@@ -89,6 +95,10 @@ class General(Module): ...@@ -89,6 +95,10 @@ class General(Module):
def load(self): def load(self):
self.target_files = [] self.target_files = []
# A special case for when we're loaded into IDA
if self.subclass == io.FileIO and binwalk.core.idb.LOADED_IN_IDA:
self.subclass = binwalk.core.idb.IDBFileIO
# Order is important with these two methods # Order is important with these two methods
self._open_target_files() self._open_target_files()
self._set_verbosity() self._set_verbosity()
...@@ -141,7 +151,7 @@ class General(Module): ...@@ -141,7 +151,7 @@ class General(Module):
if swap is None: if swap is None:
swap = self.swap_size swap = self.swap_size
return binwalk.core.common.BlockFile(fname, length=length, offset=offset, swap=swap, block=block, peek=peek) return binwalk.core.common.BlockFile(fname, subclass=self.subclass, length=length, offset=offset, swap=swap, block=block, peek=peek)
def _open_target_files(self): def _open_target_files(self):
''' '''
...@@ -151,7 +161,7 @@ class General(Module): ...@@ -151,7 +161,7 @@ class General(Module):
# Validate the target files listed in target_files # Validate the target files listed in target_files
for tfile in self.files: for tfile in self.files:
# Ignore directories. # Ignore directories.
if not os.path.isdir(tfile): if not self.subclass == io.FileIO or not os.path.isdir(tfile):
# Make sure we can open the target files # Make sure we can open the target files
try: try:
self.target_files.append(self.open_file(tfile)) self.target_files.append(self.open_file(tfile))
......
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