Skip to content

Commit

Permalink
Fixed lzmamod.py bug; updated extractor module to include information…
Browse files Browse the repository at this point in the history
… about which extraction utility was used.
  • Loading branch information
devttys0 committed Jun 16, 2017
1 parent 4e6c306 commit 53a1253
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
27 changes: 17 additions & 10 deletions src/binwalk/modules/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
from binwalk.core.common import file_size, file_md5, unique_file_name, BlockFile


class ExtractInfo(object):
class ExtractDetails(object):
def __init__(self, **kwargs):
for (k, v) in kwargs.iteritems():
setattr(self, k, v)

class ExtractInfo(object):
def __init__(self):
self.carved = {}
self.extracted = {}
Expand Down Expand Up @@ -204,10 +208,14 @@ def callback(self, r):
self.output[r.file.path] = ExtractInfo()

# Attempt extraction
binwalk.core.common.debug(
"Extractor callback for %s @%d [%s]" % (r.file.name, r.offset, r.description))
(extraction_directory, dd_file, scan_extracted_files) = self.extract(
r.offset, r.description, r.file.path, size, r.name)
binwalk.core.common.debug("Extractor callback for %s @%d [%s]" % (r.file.name,
r.offset,
r.description))
(extraction_directory, dd_file, scan_extracted_files, extraction_utility) = self.extract(r.offset,
r.description,
r.file.path,
size,
r.name)

# If the extraction was successful, self.extract will have returned
# the output directory and name of the dd'd file
Expand All @@ -219,7 +227,7 @@ def callback(self, r):
# info for this file
dd_file_path = os.path.join(extraction_directory, dd_file)
self.output[r.file.path].carved[r.offset] = dd_file_path
self.output[r.file.path].extracted[r.offset] = []
self.output[r.file.path].extracted[r.offset] = ExtractDetails(files=[], command=extraction_utility)

# Do a directory listing of the output directory
directory_listing = set(os.listdir(extraction_directory))
Expand All @@ -242,8 +250,7 @@ def callback(self, r):
# Also keep a list of files created by the extraction
# utility
if real_file_path != dd_file_path:
self.output[r.file.path].extracted[
r.offset].append(real_file_path)
self.output[r.file.path].extracted[r.offset].files.append(real_file_path)

# If recursion was specified, and the file is not the same
# one we just dd'd
Expand Down Expand Up @@ -564,7 +571,7 @@ def extract(self, offset, description, file_name, size, name=None):

# No extraction rules for this file
if not rules:
return (None, None, False)
return (None, None, False, str(None))
else:
binwalk.core.common.debug("Found %d matching extraction rules" % len(rules))

Expand Down Expand Up @@ -643,7 +650,7 @@ def extract(self, offset, description, file_name, size, name=None):

os.chdir(original_dir)

return (output_directory, fname, recurse)
return (output_directory, fname, recurse, str(rule['cmd']))

def _entry_offset(self, index, entries, description):
'''
Expand Down
13 changes: 7 additions & 6 deletions src/binwalk/plugins/lzmamod.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
SIGNATURE = "lzma compressed data"

def init(self):
self.original_cmd = ''

self.module.extractor.add_rule(txtrule=None,
regex="^%s" % self.SIGNATURE,
extension="7z",
cmd=self.lzma_cable_extractor, prepend=True)
if self.module.extractor.enabled:
self.module.extractor.add_rule(txtrule=None,
regex="^%s" % self.SIGNATURE,
extension="7z",
cmd=self.lzma_cable_extractor, prepend=True)

def lzma_cable_extractor(self, fname):
result = False

out_name = os.path.splitext(fname)[0] + '-patched' + os.path.splitext(fname)[1]
fp_out = BlockFile(out_name, 'w')
# Use self.module.config.open_file here to ensure that other config
Expand Down

0 comments on commit 53a1253

Please sign in to comment.