Skip to content

Commit

Permalink
Fixed some ROM signature and extraction bugs; added debug info during…
Browse files Browse the repository at this point in the history
… file open failures; updated plugins to use file.path instead of file.name
  • Loading branch information
devttys0 committed Mar 6, 2019
1 parent 720f770 commit ec47069
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/binwalk/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class StringFile(object):
'''

def __init__(self, fname, mode='r'):
self.string = fname
self.string = fname #bytes2str(fname)
self.name = "String"
self.args.size = len(self.string)

Expand Down
4 changes: 2 additions & 2 deletions src/binwalk/magic/filesystems
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,10 @@
>>0 string !Rom\x2E {invalid} unknown endianness
>0 string \x2EmoR little endian,
>>8 lelong x size: <= %d
>>8 lelong-0x20 x {jump:%d}
#>>8 lelong-0x20 x {jump:%d}
>0 string Rom\x2E big endian,
>>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
0 string owowowowowowowowowowowowowowow Wind River management filesystem,{overlap}
Expand Down
1 change: 1 addition & 0 deletions src/binwalk/modules/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def callback(self, r):
# 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.
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)

# If recursion was specified, and the file is not the same
Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/modules/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,4 @@ def _open_target_files(self):
except KeyboardInterrupt as e:
raise 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)))
4 changes: 2 additions & 2 deletions src/binwalk/plugins/cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def scan(self, result):
result.jump = self.CPIO_HEADER_SIZE + file_size + file_name_length
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
# scan to continue normally.
self.found_archive_in_file = result.file.name
self.found_archive_in_file = result.file.path
self.found_archive = True
result.extract = True
elif 'TRAILER!!!' in result.description:
Expand Down
8 changes: 7 additions & 1 deletion src/binwalk/plugins/dlromfsextract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import zlib
import struct
import binwalk.core.plugin
import binwalk.core.common
Expand Down Expand Up @@ -132,7 +133,12 @@ def get_data(self, uid):
except KeyboardInterrupt as e:
raise e
except Exception as e:
pass
try:
data = zlib.decompress(data)
except KeyboardInterrupt as e:
raise e
except Exception as e:
pass

return data

Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/plugins/gzipvalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def scan(self, result):
# If this result is a gzip signature match, try to decompress the data
if result.file and result.description.lower().startswith('gzip'):
# 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)
fd.close()

Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/plugins/hilink.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def scan(self, result):
if result.description.lower().startswith(self.SIGNATURE_DESCRIPTION) is True:
# Read in the first 64 bytes of the suspected encrypted
# 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))
fd.close()

Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/plugins/jffs2valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def scan(self, result):
if result.file and result.description.lower().startswith('jffs2 filesystem'):

# 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
# data from disk speeds up repeated disk access and decreases performance
# hits (disk caching?).
Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/plugins/lzmavalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def scan(self, result):
if result.valid and result.file and result.description.lower().startswith('lzma compressed 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)
fd.close()

Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/plugins/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def scan(self, result):
if result.description.lower().startswith('posix tar archive'):
is_tar = True
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:
# read in the tar header struct
Expand Down
6 changes: 3 additions & 3 deletions src/binwalk/plugins/ubivalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _check_crc(self, ec_header):
return header_crc == calculated_header_crc

def _process_result(self, result):
if self.current_file == result.file.name:
if self.current_file == result.file.path:
result.display = False
else:
# Reset everything in case new file is encountered
Expand All @@ -38,7 +38,7 @@ def _process_result(self, result):
# Display result and trigger extraction
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:
# Calculate PEB size by subtracting last EC block offset
Expand All @@ -56,7 +56,7 @@ def _process_result(self, result):
def scan(self, result):
if result.file and result.description.lower().startswith('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))
fd.close()
Expand Down
2 changes: 1 addition & 1 deletion src/binwalk/plugins/zlibvalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def scan(self, result):
offset = result.offset - adjust

# 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)
data = fd.read(self.MAX_DATA_SIZE)[adjust:]
fd.close()
Expand Down

0 comments on commit ec47069

Please sign in to comment.