Пример #1
0
def test_featureless_file_is_unpacked(scan_environment):
    fn = pathlib.Path("unpackers") / "ihex" / "example.txt"
    fn_abs = testdata_dir / fn
    # TODO: FileResult asks for relative path
    fileresult = FileResult(None, fn_abs, set())
    fileresult.set_filesize(fn_abs.stat().st_size)

    scanjob = ScanJob(fileresult)
    scanjob.set_scanenvironment(scan_environment)
    scanjob.initialize()
    unpacker = UnpackManager(scan_environment.unpackdirectory)
    scanjob.prepare_for_unpacking()
    scanjob.check_for_valid_extension(unpacker)
    assert fileresult.labels == set()
    scanjob.check_for_signatures(unpacker)
    assert fileresult.labels == set()
    assert fileresult.unpackedfiles == []
    scanjob.carve_file_data(unpacker)
    assert fileresult.unpackedfiles == []
    fileresult.labels.add('text')
    scanjob.check_entire_file(unpacker)
    assert len(fileresult.unpackedfiles) == 1
    j = scan_environment.scanfilequeue.get()
    expected_extracted_fn = pathlib.Path('.') / \
            ("%s-0x%08x-ihex-1" % (fn.name, 0)) / "unpacked-from-ihex"
    assert j.fileresult.filename == expected_extracted_fn
    assertUnpackedPathExists(scan_environment, j.fileresult.filename)
Пример #2
0
 def test_carved_padding_file_has_correct_labels(self):
     self._create_padding_file_in_directory()
     fileresult = self._create_fileresult_for_file(self.padding_file,
                                                   self.parent_dir, [])
     scanjob = ScanJob(fileresult)
     scanjob.set_scanenvironment(self.scan_environment)
     unpacker = Unpacker()
     scanjob.prepare_for_unpacking()
     scanjob.check_unscannable_file()
     unpacker.append_unpacked_range(0, 5)  # bytes [0:5) are unpacked
     scanjob.carve_file_data(unpacker)
     j = self.scanfile_queue.get()
     self.assertSetEqual(j.fileresult.labels,
                         set(['padding', 'synthesized']))
Пример #3
0
def test_carved_padding_file_has_correct_labels(scan_environment):
    padding_file = _create_padding_file_in_unpack_directory(scan_environment)
    fileresult = FileResult(None,
                            scan_environment.unpackdirectory / padding_file,
                            set())
    fileresult.set_filesize(
        (scan_environment.unpackdirectory / padding_file).stat().st_size)
    scanjob = ScanJob(fileresult)
    scanjob.set_scanenvironment(scan_environment)
    scanjob.initialize()
    unpacker = UnpackManager(scan_environment.unpackdirectory)
    scanjob.prepare_for_unpacking()
    scanjob.check_unscannable_file()
    unpacker.append_unpacked_range(0, 5)  # bytes [0:5) are unpacked
    scanjob.carve_file_data(unpacker)
    j = scan_environment.scanfilequeue.get()
    assert j.fileresult.labels == set(['padding', 'synthesized'])
Пример #4
0
def test_carved_data_is_extracted_from_file(scan_environment):
    fn = pathlib.Path("unpackers") / "gif" / "test-prepend-random-data.gif"
    fn_abs = testdata_dir / fn
    # TODO: FileResult asks for relative path
    fileresult = FileResult(None, fn_abs, set())
    fileresult.set_filesize(fn_abs.stat().st_size)

    scanjob = ScanJob(fileresult)
    scanjob.set_scanenvironment(scan_environment)
    scanjob.initialize()
    unpacker = UnpackManager(scan_environment.unpackdirectory)
    scanjob.prepare_for_unpacking()
    scanjob.check_for_valid_extension(unpacker)
    scanjob.check_for_signatures(unpacker)
    j = scan_environment.scanfilequeue.get()
    scanjob.carve_file_data(unpacker)
    j = scan_environment.scanfilequeue.get()
    synthesized_name = pathlib.Path('.') / \
            ("%s-0x%08x-synthesized-1" % (fn.name,0)) / \
            ("unpacked-0x%x-0x%x" % (0,127))
    assert j.fileresult.filename == synthesized_name
    assertUnpackedPathExists(scan_environment, j.fileresult.filename)