Commit 0d9524ba by devttys0

Code cleanup, minor bug fixes

parent 43ddf9b9
...@@ -352,9 +352,9 @@ class Magic(object): ...@@ -352,9 +352,9 @@ class Magic(object):
tags['description'] = self.bspace.sub('', " ".join(description)) tags['description'] = self.bspace.sub('', " ".join(description))
if not tags['description']: #if not tags['description']:
tags['display'] = False # tags['display'] = False
tags['invalid'] = True # tags['invalid'] = True
if self.printable.match(tags['description']).group() != tags['description']: if self.printable.match(tags['description']).group() != tags['description']:
tags['invalid'] = True tags['invalid'] = True
......
...@@ -27,7 +27,6 @@ class Settings: ...@@ -27,7 +27,6 @@ class Settings:
# File names # File names
PLUGINS = "plugins" PLUGINS = "plugins"
PREFIX_FILE = "prefix.conf"
EXTRACT_FILE = "extract.conf" EXTRACT_FILE = "extract.conf"
BINWALK_MAGIC_FILE = "binwalk" BINWALK_MAGIC_FILE = "binwalk"
BINARCH_MAGIC_FILE = "binarch" BINARCH_MAGIC_FILE = "binarch"
...@@ -45,7 +44,7 @@ class Settings: ...@@ -45,7 +44,7 @@ class Settings:
# Build the paths to all user-specific files # Build the paths to all user-specific files
self.user = common.GenericContainer(binwalk=self._user_path(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE), self.user = common.GenericContainer(binwalk=self._user_path(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE),
binarch=self._user_path(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE), binarch=self._user_path(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE),
bincast=self._user_path(self.BINWALK_MAGIC_DIR, self.BINCAST_MAGIC_FILE), magic=self._magic_signature_files(user_only=True),
extract=self._user_path(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE), extract=self._user_path(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE),
plugins=self._user_path(self.BINWALK_PLUGINS_DIR)) plugins=self._user_path(self.BINWALK_PLUGINS_DIR))
...@@ -53,13 +52,14 @@ class Settings: ...@@ -53,13 +52,14 @@ class Settings:
# Build the paths to all system-wide files # Build the paths to all system-wide files
self.system = common.GenericContainer(binwalk=self._system_path(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE), self.system = common.GenericContainer(binwalk=self._system_path(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE),
binarch=self._system_path(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE), binarch=self._system_path(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE),
bincast=self._system_path(self.BINWALK_MAGIC_DIR, self.BINCAST_MAGIC_FILE), magic=self._magic_signature_files(system_only=True),
extract=self._system_path(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE), extract=self._system_path(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE),
prefix=self._system_path(self.BINWALK_CONFIG_DIR, self.PREFIX_FILE),
plugins=self._system_path(self.BINWALK_PLUGINS_DIR)) plugins=self._system_path(self.BINWALK_PLUGINS_DIR))
def magic_signature_files(self, system_only=False, user_only=False): def _magic_signature_files(self, system_only=False, user_only=False):
files = [] files = []
user_binarch = self._user_path(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE)
system_binarch = self._system_path(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE)
if not system_only: if not system_only:
user_dir = os.path.join(self.user_dir, self.BINWALK_USER_DIR, self.BINWALK_MAGIC_DIR) user_dir = os.path.join(self.user_dir, self.BINWALK_USER_DIR, self.BINWALK_MAGIC_DIR)
...@@ -67,8 +67,11 @@ class Settings: ...@@ -67,8 +67,11 @@ class Settings:
if not user_only: if not user_only:
system_dir = os.path.join(self.system_dir, self.BINWALK_MAGIC_DIR) system_dir = os.path.join(self.system_dir, self.BINWALK_MAGIC_DIR)
files += [os.path.join(system_dir, x) for x in os.listdir(system_dir)] files += [os.path.join(system_dir, x) for x in os.listdir(system_dir)]
if self.system.binarch in files:
files.remove(self.system.binarch) if user_binarch in files:
files.remove(user_binarch)
if system_binarch in files:
files.remove(system_binarch)
return files return files
......
...@@ -56,6 +56,10 @@ ...@@ -56,6 +56,10 @@
# PC bitmaps (OS/2, Windows BMP files) (Greg Roelofs, newt@uchicago.edu) # PC bitmaps (OS/2, Windows BMP files) (Greg Roelofs, newt@uchicago.edu)
0 string BM PC bitmap, 0 string BM PC bitmap,
>14 leshort !12
>>14 leshort !64
>>>14 leshort !40
>>>>14 leshort !128 {invalid}
>14 leshort 12 OS/2 1.x format, >14 leshort 12 OS/2 1.x format,
>>18 lelong <1 {invalid} >>18 lelong <1 {invalid}
>>18 lelong >1000000 {invalid} >>18 lelong >1000000 {invalid}
......
...@@ -25,10 +25,6 @@ class Signature(Module): ...@@ -25,10 +25,6 @@ class Signature(Module):
long='opcodes', long='opcodes',
kwargs={'enabled' : True, 'search_for_opcodes' : True}, kwargs={'enabled' : True, 'search_for_opcodes' : True},
description='Scan target file(s) for common executable opcode signatures'), description='Scan target file(s) for common executable opcode signatures'),
#Option(short='C',
# long='cast',
# kwargs={'enabled' : True, 'cast_data_types' : True},
# description='Cast offsets as a given data type (use -y to specify the data type / endianness)'),
Option(short='m', Option(short='m',
long='magic', long='magic',
kwargs={'enabled' : True, 'magic_files' : []}, kwargs={'enabled' : True, 'magic_files' : []},
...@@ -65,7 +61,6 @@ class Signature(Module): ...@@ -65,7 +61,6 @@ class Signature(Module):
Kwarg(name='raw_bytes', default=None), Kwarg(name='raw_bytes', default=None),
Kwarg(name='search_for_opcodes', default=False), Kwarg(name='search_for_opcodes', default=False),
Kwarg(name='explicit_signature_scan', default=False), Kwarg(name='explicit_signature_scan', default=False),
Kwarg(name='cast_data_types', default=False),
Kwarg(name='dumb_scan', default=False), Kwarg(name='dumb_scan', default=False),
Kwarg(name='magic_files', default=[]), Kwarg(name='magic_files', default=[]),
] ]
...@@ -85,16 +80,9 @@ class Signature(Module): ...@@ -85,16 +80,9 @@ class Signature(Module):
self.config.settings.system.binarch, self.config.settings.system.binarch,
] ]
elif self.cast_data_types:
self.keep_going = True
self.magic_files = [
self.config.settings.user.bincast,
self.config.settings.system.bincast,
]
# Use the system default magic file if no other was specified, or if -B was explicitly specified # Use the system default magic file if no other was specified, or if -B was explicitly specified
if (not self.magic_files) or (self.explicit_signature_scan and not self.cast_data_types): if (not self.magic_files) or self.explicit_signature_scan:
self.magic_files += self.config.settings.magic_signature_files() self.magic_files += self.config.settings.user.magic + self.config.settings.system.magic
# Initialize libmagic # Initialize libmagic
self.magic = binwalk.core.magic.Magic(include=self.include_filters, self.magic = binwalk.core.magic.Magic(include=self.include_filters,
...@@ -136,7 +124,7 @@ class Signature(Module): ...@@ -136,7 +124,7 @@ class Signature(Module):
block_start = fp.tell() - dlen block_start = fp.tell() - dlen
self.status.completed = block_start - fp.offset self.status.completed = block_start - fp.offset
# TODO: Make magic scan return a results object. # Scan this data block for magic signatures
for r in self.magic.scan(data, dlen): for r in self.magic.scan(data, dlen):
# current_block_offset is set when a jump-to-offset keyword is encountered while # current_block_offset is set when a jump-to-offset keyword is encountered while
...@@ -146,18 +134,15 @@ class Signature(Module): ...@@ -146,18 +134,15 @@ class Signature(Module):
if r.offset < current_block_offset: if r.offset < current_block_offset:
continue continue
# Keep a record of the relative offset of this signature inside the current data block
relative_offset = r.offset relative_offset = r.offset
# Set the absolute offset inside the target file # Set the absolute offset inside the target file
# TODO: Don't need the offset adjust stuff anymore, get rid of it r.offset = block_start + r.offset
r.offset = block_start + r.offset + r.adjust
# Provide an instance of the current file object # Provide an instance of the current file object
r.file = fp r.file = fp
# Check if this was marked as invalid
r.valid = (not r.invalid)
# Register the result for futher processing/display # Register the result for futher processing/display
# self.result automatically calls self.validate for result validation # self.result automatically calls self.validate for result validation
self.result(r=r) self.result(r=r)
......
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