forked from ReFirmLabs/binwalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new tests and a signature test script generator.
- Loading branch information
Showing
14 changed files
with
978 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# Automatically generates a binwalk signature test script for | ||
# a given input vector file. The test script will be written | ||
# to the tests directory, and will expect the input vector file | ||
# to be located in the tests/input-vectors/ directory. | ||
import os | ||
import sys | ||
import binwalk | ||
|
||
test_script_template = """ | ||
import binwalk | ||
from os.path import dirname | ||
from nose.tools import eq_, ok_ | ||
def test_%s(): | ||
''' | ||
Test: Open %s, scan for signatures | ||
verify that all (and only) expected signatures are detected | ||
''' | ||
expected_results = [ | ||
%s | ||
] | ||
scan_result = binwalk.scan(dirname(__file__) + '/input-vectors/%s', | ||
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]) | ||
""" | ||
|
||
try: | ||
target_file = sys.argv[1] | ||
except IndexError: | ||
sys.stderr.write("Usage: %s <input vector file>\n" % sys.argv[0]) | ||
sys.exit(1) | ||
|
||
target_file_basename = os.path.basename(target_file) | ||
scan_function_name = target_file_basename.replace('.', '_') | ||
expected_results = "" | ||
|
||
signature = binwalk.scan(target_file, signature=True)[0] | ||
for result in signature.results: | ||
expected_results += "\t[%d, '%s'],\n" % (result.offset, result.description) | ||
|
||
test_script = test_script_template % (scan_function_name, | ||
target_file_basename, | ||
expected_results, | ||
target_file_basename) | ||
|
||
test_script_path = os.path.join("tests", "test_%s.py" % scan_function_name) | ||
|
||
with open(test_script_path, "w") as fp: | ||
fp.write(test_script) | ||
|
||
sys.stdout.write("Generated test script for '%s' and saved it to '%s'\n" % (target_file, test_script_path)) | ||
sys.exit(0) | ||
|
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
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'], | ||
|
||
] | ||
|
||
scan_result = binwalk.scan(dirname(__file__) + '/input-vectors/firmware.gzip', | ||
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import binwalk | ||
from os.path import dirname | ||
from nose.tools import eq_, ok_ | ||
|
||
def test_firmware_zip(): | ||
''' | ||
Test: Open firmware.zip, scan for signatures | ||
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'], | ||
] | ||
|
||
scan_result = binwalk.scan(dirname(__file__) + '/input-vectors/firmware.zip', | ||
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters