Commit 40ae0ae4 by Craig Heffner

Fixed cpio jump offset error; updated testing scripts

parent 896a3958
......@@ -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']
......
......@@ -8,8 +8,8 @@ import sys
import binwalk
test_script_template = """
import os
import binwalk
from os.path import dirname
from nose.tools import eq_, ok_
def test_%s():
......@@ -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)
......@@ -44,10 +48,10 @@ except IndexError:
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)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
import os
import binwalk
from os.path import dirname
from nose.tools import eq_, ok_
def test_firmware_gzip():
......@@ -8,23 +8,22 @@ 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"))
This source diff could not be displayed because it is too large. You can view the blob instead.
from os.path import dirname
import os
import binwalk
from nose.tools import eq_, ok_
def test_firmware_squashfs():
'''
Test: Open hello-world.srec, scan for signatures
verify that only one signature is returned
verify that the only signature returned is Motorola S-rec data-signature
Test: Open firmware.squashfs, scan for signatures
verify that all (and only) expected signatures are detected
'''
expected_results = [
[0, 'DLOB firmware header, boot partition: "dev=/dev/mtdblock/2"'],
[112, 'LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 3466208 bytes'],
[1179760, 'PackImg section delimiter tag, little endian size: 11548416 bytes; big endian size: 3649536 bytes'],
[1179792, 'Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 3647665 bytes, 1811 inodes, blocksize: 524288 bytes, created: 2013-09-17 06:43:22'],
]
input_vector_file = os.path.join(os.path.dirname(__file__),
"input-vectors",
"firmware.squashfs")
scan_result = binwalk.scan(input_vector_file,
signature=True,
quiet=True)
scan_result = binwalk.scan(
dirname(__file__) + '/input-vectors/firmware.squashfs',
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))
# 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])
# There should be only one result
eq_(len(scan_result[0].results), 1)
# That result should be at offset zero
eq_(scan_result[0].results[0].offset, 0)
# That result should be a squashfs file system
ok_(scan_result[0].results[0].description.startswith("Squashfs filesystem"))
import os
import binwalk
from os.path import dirname
from nose.tools import eq_, ok_
def test_firmware_zip():
......@@ -8,13 +9,18 @@ def test_firmware_zip():
verify that all (and only) expected signatures are detected
'''
expected_results = [
[0, 'Zip archive data, at least v1.0 to extract, name: dir655_revB_FW_203NA/'],
[51, 'Zip archive data, at least v2.0 to extract, compressed size: 6395868, uncompressed size: 6422554, name: dir655_revB_FW_203NA/DIR655B1_FW203NAB02.bin'],
[6395993, 'Zip archive data, at least v2.0 to extract, compressed size: 14243, uncompressed size: 61440, name: dir655_revB_FW_203NA/dir655_revB_release_notes_203NA.doc'],
[6410581, 'End of Zip archive, footer length: 22'],
[0, 'Zip archive data, at least v1.0 to extract, name: dir655_revB_FW_203NA/'],
[51, 'Zip archive data, at least v2.0 to extract, compressed size: 6395868, uncompressed size: 6422554, name: dir655_revB_FW_203NA/DIR655B1_FW203NAB02.bin'],
[6395993, 'Zip archive data, at least v2.0 to extract, compressed size: 14243, uncompressed size: 61440, name: dir655_revB_FW_203NA/dir655_revB_release_notes_203NA.doc'],
[6410581, 'End of Zip archive, footer length: 22'],
]
scan_result = binwalk.scan(dirname(__file__) + '/input-vectors/firmware.zip',
input_vector_file = os.path.join(os.path.dirname(__file__),
"input-vectors",
"firmware.zip")
scan_result = binwalk.scan(input_vector_file,
signature=True,
quiet=True)
......
from os.path import dirname
import binwalk
from nose.tools import eq_, ok_
def test_hello_world_simple_scan():
'''
Test: Open hello-world.ihex, scan for signatures
verify that only one signature is returned
verify that the only signature returned is Intel HEX data-signature
'''
scan_result = binwalk.scan(
dirname(__file__) + '/input-vectors/hello-world.ihex',
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), 1)
# Test result-description
eq_(scan_result[0].results[0].description,
'Intel HEX data, record type: data')
from os.path import dirname
import binwalk
from nose.tools import eq_, ok_
def test_hello_world_simple_scan():
'''
Test: Open hello-world.srec, scan for signatures
verify that only one signature is returned
verify that the only signature returned is Motorola S-rec data-signature
'''
scan_result = binwalk.scan(
dirname(__file__) + '/input-vectors/hello-world.srec',
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), 1)
# Test result-description
eq_(scan_result[0].results[0].description,
'Motorola S-Record; binary data in text format, record type: data (32-bit)')
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