From 7a1441ec6902b7e4a276a6a4fc9b1846d886f88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Fri, 7 Apr 2023 10:06:27 +0200 Subject: [PATCH] Removed deb unpacker (#117) Patool can already extract debian archives. --- .../plugins/unpacking/deb/__init__.py | 0 .../plugins/unpacking/deb/code/__init__.py | 0 .../plugins/unpacking/deb/code/deb.py | 18 ------- .../plugins/unpacking/deb/test/__init__.py | 0 .../plugins/unpacking/deb/test/test_deb.py | 17 ------- .../plugins/unpacking/patool/code/patool.py | 48 ++++++++++++++---- .../{deb => patool}/test/data/test.deb | Bin .../patool/test/test_plugin_patool.py | 6 +++ 8 files changed, 44 insertions(+), 45 deletions(-) delete mode 100644 fact_extractor/plugins/unpacking/deb/__init__.py delete mode 100644 fact_extractor/plugins/unpacking/deb/code/__init__.py delete mode 100644 fact_extractor/plugins/unpacking/deb/code/deb.py delete mode 100644 fact_extractor/plugins/unpacking/deb/test/__init__.py delete mode 100644 fact_extractor/plugins/unpacking/deb/test/test_deb.py rename fact_extractor/plugins/unpacking/{deb => patool}/test/data/test.deb (100%) diff --git a/fact_extractor/plugins/unpacking/deb/__init__.py b/fact_extractor/plugins/unpacking/deb/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/fact_extractor/plugins/unpacking/deb/code/__init__.py b/fact_extractor/plugins/unpacking/deb/code/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/fact_extractor/plugins/unpacking/deb/code/deb.py b/fact_extractor/plugins/unpacking/deb/code/deb.py deleted file mode 100644 index f76600e9..00000000 --- a/fact_extractor/plugins/unpacking/deb/code/deb.py +++ /dev/null @@ -1,18 +0,0 @@ -''' -This plugin unpacks debian packages -''' -from common_helper_process import execute_shell_command - -NAME = 'Deb' -MIME_PATTERNS = ['application/vnd.debian.binary-package'] -VERSION = '0.1' - - -def unpack_function(file_path, tmp_dir): - return {'output': execute_shell_command('fakeroot dpkg-deb -v -x {} {}'.format(file_path, tmp_dir))} - - -# ----> Do not edit below this line <---- -def setup(unpack_tool): - for item in MIME_PATTERNS: - unpack_tool.register_plugin(item, (unpack_function, NAME, VERSION)) diff --git a/fact_extractor/plugins/unpacking/deb/test/__init__.py b/fact_extractor/plugins/unpacking/deb/test/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/fact_extractor/plugins/unpacking/deb/test/test_deb.py b/fact_extractor/plugins/unpacking/deb/test/test_deb.py deleted file mode 100644 index c1fc4fa7..00000000 --- a/fact_extractor/plugins/unpacking/deb/test/test_deb.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -from test.unit.unpacker.test_unpacker import TestUnpackerBase - - -TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') - - -class TestDebUnpacker(TestUnpackerBase): - - def test_unpacker_selection_generic(self): - self.check_unpacker_selection('application/vnd.debian.binary-package', 'Deb') - - def test_extraction(self): - files, meta_data = self.unpacker.extract_files_from_file(os.path.join(TEST_DATA_DIR, 'test.deb'), self.tmp_dir.name) - - assert len(files) == 3, 'file number incorrect' - assert './usr/bin/test_elf_sfx' in meta_data['output'] diff --git a/fact_extractor/plugins/unpacking/patool/code/patool.py b/fact_extractor/plugins/unpacking/patool/code/patool.py index 90f8e337..530378b0 100644 --- a/fact_extractor/plugins/unpacking/patool/code/patool.py +++ b/fact_extractor/plugins/unpacking/patool/code/patool.py @@ -5,16 +5,42 @@ NAME = 'PaTool' MIME_PATTERNS = [ - 'application/x-lrzip', 'application/x-cpio', 'application/x-archive', 'application/x-adf', - 'application/x-redhat-package-manager', 'application/x-rpm', 'application/x-lzop', 'application/x-lzh', - 'application/x-lha', 'application/x-cab', 'application/vnd.ms-cab-compressed', 'application/zpaq', - 'application/x-chm', 'application/x-gzip', 'application/gzip', 'application/x-bzip2', 'application/x-dms', - 'application/x-debian-package', 'application/x-rzip', 'application/x-tar', 'application/x-shar', - 'application/x-lzip', 'application/x-alzip', 'application/x-rar', 'application/rar', - 'application/java-archive', 'application/x-iso9660-image', 'application/x-compress', 'application/x-arc', - 'audio/flac', 'application/x-ace', 'application/x-zoo', 'application/x-xz' + 'application/gzip', + 'application/java-archive', + 'application/rar', + 'application/vnd.debian.binary-package', + 'application/vnd.ms-cab-compressed', + 'application/x-ace', + 'application/x-adf', + 'application/x-alzip', + 'application/x-arc', + 'application/x-archive', + 'application/x-bzip2', + 'application/x-cab', + 'application/x-chm', + 'application/x-compress', + 'application/x-cpio', + 'application/x-debian-package', + 'application/x-dms', + 'application/x-gzip', + 'application/x-iso9660-image', + 'application/x-lha', + 'application/x-lrzip', + 'application/x-lzh', + 'application/x-lzip', + 'application/x-lzop', + 'application/x-rar', + 'application/x-redhat-package-manager', + 'application/x-rpm', + 'application/x-rzip', + 'application/x-shar', + 'application/x-tar', + 'application/x-xz', + 'application/x-zoo', + 'application/zpaq', + 'audio/flac', ] -VERSION = '0.5.2' +VERSION = '0.5.3' TOOL_PATH = execute_shell_command('which patool').strip() @@ -25,7 +51,9 @@ def unpack_function(file_path, tmp_dir): tmp_dir should be used to store the extracted files. """ return { - 'output': execute_shell_command('fakeroot python3 {} extract --outdir {} {}'.format(TOOL_PATH, tmp_dir, file_path), timeout=600) + 'output': execute_shell_command( + f'fakeroot python3 {TOOL_PATH} extract --outdir {tmp_dir} {file_path}', timeout=600 + ) } diff --git a/fact_extractor/plugins/unpacking/deb/test/data/test.deb b/fact_extractor/plugins/unpacking/patool/test/data/test.deb similarity index 100% rename from fact_extractor/plugins/unpacking/deb/test/data/test.deb rename to fact_extractor/plugins/unpacking/patool/test/data/test.deb diff --git a/fact_extractor/plugins/unpacking/patool/test/test_plugin_patool.py b/fact_extractor/plugins/unpacking/patool/test/test_plugin_patool.py index 47030600..65812388 100644 --- a/fact_extractor/plugins/unpacking/patool/test/test_plugin_patool.py +++ b/fact_extractor/plugins/unpacking/patool/test/test_plugin_patool.py @@ -26,3 +26,9 @@ def test_extraction(self, in_file, ignore): output=False, ignore=ignore, ) + + def test_extract_deb(self): + in_file = os.path.join(TEST_DATA_DIR, 'test.deb') + files, meta_data = self.unpacker.extract_files_from_file(in_file, self.tmp_dir.name) + assert len(files) == 3, f'file number incorrect: {meta_data}' + assert 'extracted to' in meta_data['output']