Commit ec47069b by devttys0

Fixed some ROM signature and extraction bugs; added debug info during file open…

Fixed some ROM signature and extraction bugs; added debug info during file open failures; updated plugins to use file.path instead of file.name
parent 720f770e
...@@ -258,7 +258,7 @@ class StringFile(object): ...@@ -258,7 +258,7 @@ class StringFile(object):
''' '''
def __init__(self, fname, mode='r'): def __init__(self, fname, mode='r'):
self.string = fname self.string = fname #bytes2str(fname)
self.name = "String" self.name = "String"
self.args.size = len(self.string) self.args.size = len(self.string)
......
...@@ -561,10 +561,10 @@ ...@@ -561,10 +561,10 @@
>>0 string !Rom\x2E {invalid} unknown endianness >>0 string !Rom\x2E {invalid} unknown endianness
>0 string \x2EmoR little endian, >0 string \x2EmoR little endian,
>>8 lelong x size: <= %d >>8 lelong x size: <= %d
>>8 lelong-0x20 x {jump:%d} #>>8 lelong-0x20 x {jump:%d}
>0 string Rom\x2E big endian, >0 string Rom\x2E big endian,
>>8 belong x size: <= %d >>8 belong x size: <= %d
>>8 belong-0x20 x {jump:%d} #>>8 belong-0x20 x {jump:%d}
# Wind River MemFS file system, found in some VxWorks devices # Wind River MemFS file system, found in some VxWorks devices
0 string owowowowowowowowowowowowowowow Wind River management filesystem,{overlap} 0 string owowowowowowowowowowowowowowow Wind River management filesystem,{overlap}
......
...@@ -254,6 +254,7 @@ class Extractor(Module): ...@@ -254,6 +254,7 @@ class Extractor(Module):
# Report the file_path, not the real_file_path, otherwise symlinks will be resolved and # Report the file_path, not the real_file_path, otherwise symlinks will be resolved and
# the same file can end up being listed multiple times if there are symlinks to it. # the same file can end up being listed multiple times if there are symlinks to it.
if real_file_path != dd_file_path: if real_file_path != dd_file_path:
binwalk.core.common.debug("Adding %s (%s) (%s) to file list" % (file_path, f, real_file_path))
self.output[r.file.path].extracted[r.offset].files.append(file_path) self.output[r.file.path].extracted[r.offset].files.append(file_path)
# If recursion was specified, and the file is not the same # If recursion was specified, and the file is not the same
......
...@@ -219,4 +219,4 @@ class General(Module): ...@@ -219,4 +219,4 @@ class General(Module):
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as e: except Exception as e:
self.error(description="Cannot open file : %s" % str(e)) self.error(description="Cannot open file %s (CWD: %s) : %s" % (tfile, os.getcwd(), str(e)))
...@@ -116,10 +116,10 @@ class CPIOPlugin(binwalk.core.plugin.Plugin): ...@@ -116,10 +116,10 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
result.jump = self.CPIO_HEADER_SIZE + file_size + file_name_length result.jump = self.CPIO_HEADER_SIZE + file_size + file_name_length
self.consecutive_hits += 1 self.consecutive_hits += 1
if not self.found_archive or self.found_archive_in_file != result.file.name: if not self.found_archive or self.found_archive_in_file != result.file.path:
# This is the first entry. Set found_archive and allow the # This is the first entry. Set found_archive and allow the
# scan to continue normally. # scan to continue normally.
self.found_archive_in_file = result.file.name self.found_archive_in_file = result.file.path
self.found_archive = True self.found_archive = True
result.extract = True result.extract = True
elif 'TRAILER!!!' in result.description: elif 'TRAILER!!!' in result.description:
......
import os import os
import zlib
import struct import struct
import binwalk.core.plugin import binwalk.core.plugin
import binwalk.core.common import binwalk.core.common
...@@ -132,7 +133,12 @@ class RomFS(object): ...@@ -132,7 +133,12 @@ class RomFS(object):
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as e: except Exception as e:
pass try:
data = zlib.decompress(data)
except KeyboardInterrupt as e:
raise e
except Exception as e:
pass
return data return data
......
...@@ -17,7 +17,7 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin): ...@@ -17,7 +17,7 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
# If this result is a gzip signature match, try to decompress the data # If this result is a gzip signature match, try to decompress the data
if result.file and result.description.lower().startswith('gzip'): if result.file and result.description.lower().startswith('gzip'):
# Seek to and read the suspected gzip data # Seek to and read the suspected gzip data
fd = self.module.config.open_file(result.file.name, offset=result.offset, length=self.MAX_DATA_SIZE) fd = self.module.config.open_file(result.file.path, offset=result.offset, length=self.MAX_DATA_SIZE)
data = fd.read(self.MAX_DATA_SIZE) data = fd.read(self.MAX_DATA_SIZE)
fd.close() fd.close()
......
...@@ -71,7 +71,7 @@ class HilinkDecryptor(binwalk.core.plugin.Plugin): ...@@ -71,7 +71,7 @@ class HilinkDecryptor(binwalk.core.plugin.Plugin):
if result.description.lower().startswith(self.SIGNATURE_DESCRIPTION) is True: if result.description.lower().startswith(self.SIGNATURE_DESCRIPTION) is True:
# Read in the first 64 bytes of the suspected encrypted # Read in the first 64 bytes of the suspected encrypted
# uImage header # uImage header
fd = self.module.config.open_file(result.file.name, offset=result.offset) fd = self.module.config.open_file(result.file.path, offset=result.offset)
encrypted_header_data = binwalk.core.compat.str2bytes(fd.read(64)) encrypted_header_data = binwalk.core.compat.str2bytes(fd.read(64))
fd.close() fd.close()
......
...@@ -34,7 +34,7 @@ class JFFS2ValidPlugin(binwalk.core.plugin.Plugin): ...@@ -34,7 +34,7 @@ class JFFS2ValidPlugin(binwalk.core.plugin.Plugin):
if result.file and result.description.lower().startswith('jffs2 filesystem'): if result.file and result.description.lower().startswith('jffs2 filesystem'):
# Seek to and read the suspected JFFS2 node header # Seek to and read the suspected JFFS2 node header
fd = self.module.config.open_file(result.file.name, offset=result.offset) fd = self.module.config.open_file(result.file.path, offset=result.offset)
# JFFS2 headers are only 12 bytes in size, but reading larger amounts of # JFFS2 headers are only 12 bytes in size, but reading larger amounts of
# data from disk speeds up repeated disk access and decreases performance # data from disk speeds up repeated disk access and decreases performance
# hits (disk caching?). # hits (disk caching?).
......
...@@ -52,7 +52,7 @@ class LZMAPlugin(binwalk.core.plugin.Plugin): ...@@ -52,7 +52,7 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
if result.valid and result.file and result.description.lower().startswith('lzma compressed data'): if result.valid and result.file and result.description.lower().startswith('lzma compressed data'):
# Seek to and read the suspected lzma data # Seek to and read the suspected lzma data
fd = self.module.config.open_file(result.file.name, offset=result.offset, length=self.MAX_DATA_SIZE) fd = self.module.config.open_file(result.file.path, offset=result.offset, length=self.MAX_DATA_SIZE)
data = fd.read(self.MAX_DATA_SIZE) data = fd.read(self.MAX_DATA_SIZE)
fd.close() fd.close()
......
...@@ -42,7 +42,7 @@ class TarPlugin(binwalk.core.plugin.Plugin): ...@@ -42,7 +42,7 @@ class TarPlugin(binwalk.core.plugin.Plugin):
if result.description.lower().startswith('posix tar archive'): if result.description.lower().startswith('posix tar archive'):
is_tar = True is_tar = True
file_offset = result.offset file_offset = result.offset
fd = self.module.config.open_file(result.file.name, offset=result.offset) fd = self.module.config.open_file(result.file.path, offset=result.offset)
while is_tar: while is_tar:
# read in the tar header struct # read in the tar header struct
......
...@@ -27,7 +27,7 @@ class UBIValidPlugin(binwalk.core.plugin.Plugin): ...@@ -27,7 +27,7 @@ class UBIValidPlugin(binwalk.core.plugin.Plugin):
return header_crc == calculated_header_crc return header_crc == calculated_header_crc
def _process_result(self, result): def _process_result(self, result):
if self.current_file == result.file.name: if self.current_file == result.file.path:
result.display = False result.display = False
else: else:
# Reset everything in case new file is encountered # Reset everything in case new file is encountered
...@@ -38,7 +38,7 @@ class UBIValidPlugin(binwalk.core.plugin.Plugin): ...@@ -38,7 +38,7 @@ class UBIValidPlugin(binwalk.core.plugin.Plugin):
# Display result and trigger extraction # Display result and trigger extraction
result.display = True result.display = True
self.current_file = result.file.name self.current_file = result.file.path
if not self.peb_size and self.last_ec_hdr_offset: if not self.peb_size and self.last_ec_hdr_offset:
# Calculate PEB size by subtracting last EC block offset # Calculate PEB size by subtracting last EC block offset
...@@ -56,7 +56,7 @@ class UBIValidPlugin(binwalk.core.plugin.Plugin): ...@@ -56,7 +56,7 @@ class UBIValidPlugin(binwalk.core.plugin.Plugin):
def scan(self, result): def scan(self, result):
if result.file and result.description.lower().startswith('ubi erase count header'): if result.file and result.description.lower().startswith('ubi erase count header'):
# Seek to and read the suspected UBI erase count header # Seek to and read the suspected UBI erase count header
fd = self.module.config.open_file(result.file.name, offset=result.offset) fd = self.module.config.open_file(result.file.path, offset=result.offset)
ec_header = binwalk.core.compat.str2bytes(fd.read(1024)) ec_header = binwalk.core.compat.str2bytes(fd.read(1024))
fd.close() fd.close()
......
...@@ -27,7 +27,7 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin): ...@@ -27,7 +27,7 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
offset = result.offset - adjust offset = result.offset - adjust
# Seek to and read the suspected zlib data # Seek to and read the suspected zlib data
fd = self.module.config.open_file(result.file.name) fd = self.module.config.open_file(result.file.path)
fd.seek(offset) fd.seek(offset)
data = fd.read(self.MAX_DATA_SIZE)[adjust:] data = fd.read(self.MAX_DATA_SIZE)[adjust:]
fd.close() fd.close()
......
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