Skip to content

Commit

Permalink
Fixed cpio jump offset error; updated testing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed Sep 14, 2017
1 parent 896a395 commit 40ae0ae
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 14,078 deletions.
2 changes: 1 addition & 1 deletion src/binwalk/plugins/cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
cpio utility since no output directory can be provided to it directly.
'''
CPIO_OUT_DIR = "cpio-root"
CPIO_HEADER_SIZE = 76
CPIO_HEADER_SIZE = 110

MODULES = ['Signature']

Expand Down
12 changes: 8 additions & 4 deletions testing/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import binwalk

test_script_template = """
import os
import binwalk
from os.path import dirname
from nose.tools import eq_, ok_
def test_%s():
Expand All @@ -21,7 +21,11 @@ def test_%s():
%s
]
scan_result = binwalk.scan(dirname(__file__) + '/input-vectors/%s',
input_vector_file = os.path.join(os.path.dirname(__file__),
"input-vectors",
"%s")
scan_result = binwalk.scan(input_vector_file,
signature=True,
quiet=True)
Expand All @@ -44,10 +48,10 @@ def test_%s():
sys.exit(1)

target_file_basename = os.path.basename(target_file)
scan_function_name = target_file_basename.replace('.', '_')
scan_function_name = target_file_basename.replace('.', '_').replace('-', '_')
expected_results = ""

signature = binwalk.scan(target_file, signature=True)[0]
signature = binwalk.scan(target_file, signature=True, term=True)[0]
for result in signature.results:
expected_results += "\t[%d, '%s'],\n" % (result.offset, result.description)

Expand Down
Binary file modified testing/tests/input-vectors/firmware.gzip
Binary file not shown.
Binary file modified testing/tests/input-vectors/firmware.jffs2
Binary file not shown.
Binary file modified testing/tests/input-vectors/firmware.squashfs
Binary file not shown.
844 changes: 13 additions & 831 deletions testing/tests/test_firmware_cpio.py

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions testing/tests/test_firmware_gzip.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@

import os
import binwalk
from os.path import dirname
from nose.tools import eq_, ok_

def test_firmware_gzip():
'''
Test: Open firmware.gzip, scan for signatures
verify that all (and only) expected signatures are detected
'''
expected_results = [
[0, 'uImage header, header size: 64 bytes, header CRC: 0x29953343, created: 2011-06-27 07:33:02, image size: 6395843 bytes, Data Address: 0x40100000, Entry Point: 0x408A6270, data CRC: 0x3D73C1BC, OS: Linux, image type: OS Kernel Image, compression type: gzip, image name: "Unknown - IP7160_DIR855_F_Board"'],
[64, 'gzip compressed data, maximum compression, from Unix, last modified: 2011-06-27 07:33:00'],
input_vector_file = os.path.join(os.path.dirname(__file__),
"input-vectors",
"firmware.gzip")

]

scan_result = binwalk.scan(dirname(__file__) + '/input-vectors/firmware.gzip',
scan_result = binwalk.scan(input_vector_file,
signature=True,
quiet=True)

# Test number of modules used
eq_(len(scan_result), 1)

# Test number of results for that module
eq_(len(scan_result[0].results), len(expected_results))
# There should be only one result
eq_(len(scan_result[0].results), 1)

# That result should be at offset 0
eq_(scan_result[0].results[0].offset, 0)

# Test result-description
for i in range(0, len(scan_result[0].results)):
eq_(scan_result[0].results[i].offset, expected_results[i][0])
eq_(scan_result[0].results[i].description, expected_results[i][1])
# That result should be a gzip file
ok_(scan_result[0].results[0].description.startswith("gzip compressed data"))
Loading

0 comments on commit 40ae0ae

Please sign in to comment.