Skip to content

Commit

Permalink
Merge pull request fkie-cad#118 from fkie-cad/sasquatch-lzma-bugfix
Browse files Browse the repository at this point in the history
sasquatch lzma bugfix
  • Loading branch information
dorpvom authored Mar 31, 2023
2 parents 8231a85 + ac58ed6 commit f17a4d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
18 changes: 10 additions & 8 deletions fact_extractor/plugins/unpacking/squashFS/code/squash_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@

from helperFunctions.file_system import get_fact_bin_dir


SASQUATCH = Path('/usr/local/bin/sasquatch')
UNSQUASHFS4_AVM_BE = Path(get_fact_bin_dir()) / 'unsquashfs4-avm-be'
UNSQUASHFS4_AVM_LE = Path(get_fact_bin_dir()) / 'unsquashfs4-avm-le'
UNSQUASHFS3_MULTI = Path(get_fact_bin_dir()) / 'unsquashfs3-multi'


NAME = 'SquashFS'
MIME_PATTERNS = ['filesystem/squashfs']
VERSION = '0.9'
SQUASH_UNPACKER = [SASQUATCH, UNSQUASHFS4_AVM_BE, UNSQUASHFS4_AVM_LE, UNSQUASHFS3_MULTI]
VERSION = '0.10'
SQUASH_UNPACKER = [
(SASQUATCH, '-c lzma-adaptive'),
(UNSQUASHFS4_AVM_BE, '-scan'),
(UNSQUASHFS4_AVM_LE, '-scan'),
(UNSQUASHFS3_MULTI, '-scan'),
]


def unpack_function(file_path, tmp_dir):
'''
file_path specifies the input file.
tmp_dir should be used to store the extracted files.
'''
unpack_result = dict()
for unpacker in SQUASH_UNPACKER:
scan_parameter = '-scan' if '-avm-' in unpacker.name else ''
output = execute_shell_command(f'fakeroot {unpacker} {scan_parameter} -d {tmp_dir}/fact_extracted {file_path}')
unpack_result = {}
for unpacker, parameter in SQUASH_UNPACKER:
output = execute_shell_command(f'fakeroot {unpacker} {parameter} -d {tmp_dir}/fact_extracted {file_path}')
if _unpack_success(tmp_dir):
unpack_result['unpacking_tool'] = unpacker.name
unpack_result['output'] = output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@

from ..code.squash_fs import _unpack_success, unpack_function, SQUASH_UNPACKER


TEST_DATA_DIR = Path(__file__).parent / 'data'


@pytest.mark.parametrize('unpack_path, expected', [
('/foo/bar/unpacker', False),
(TEST_DATA_DIR, True),
])
@pytest.mark.parametrize(
'unpack_path, expected',
[
('/foo/bar/unpacker', False),
(TEST_DATA_DIR, True),
],
)
def test_unpack_success(unpack_path, expected):
assert _unpack_success(unpack_path) == expected


def test_not_unpackable_file():
empty_test_file = TEST_DATA_DIR / 'empty'
unpack_dir = TemporaryDirectory(prefix='fact_test_')
result = unpack_function(empty_test_file, unpack_dir)
assert 'sasquatch - error' in result.keys()
assert 'unsquashfs4-avm-be - error' in result.keys()
with TemporaryDirectory(prefix='fact_test_') as unpack_dir:
result = unpack_function(empty_test_file, unpack_dir)
assert 'sasquatch - error' in result
assert 'unsquashfs4-avm-be - error' in result


def test_tool_pathes_set_correctly():
for unpacker in SQUASH_UNPACKER:
def test_tool_paths_set_correctly():
for unpacker, _ in SQUASH_UNPACKER:
assert unpacker.exists()


Expand All @@ -36,5 +38,6 @@ def test_unpacker_selection_generic(self):
self.check_unpacker_selection('filesystem/squashfs', 'SquashFS')

def test_extraction_sqfs(self):
self.check_unpacking_of_standard_unpack_set(TEST_DATA_DIR / 'sqfs.img',
additional_prefix_folder='fact_extracted')
self.check_unpacking_of_standard_unpack_set(
TEST_DATA_DIR / 'sqfs.img', additional_prefix_folder='fact_extracted'
)

0 comments on commit f17a4d7

Please sign in to comment.