From ba8b387fb48e24d4fe188273244f40cec099967f Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Thu, 2 Jan 2025 10:06:38 -0800 Subject: [PATCH 1/4] update dielib to 2b4d6e986b273fd20e3f6733bfe244d2fa85892a --- .gitignore | 3 +++ cmake/FindDieLibrary.cmake | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 933fef7..5a867ad 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ __pycache__ aqtinstall.log wheel wheelhouse +.vscode +.venv +6.* diff --git a/cmake/FindDieLibrary.cmake b/cmake/FindDieLibrary.cmake index 8a28955..223e0c4 100644 --- a/cmake/FindDieLibrary.cmake +++ b/cmake/FindDieLibrary.cmake @@ -7,13 +7,13 @@ set(ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/..") set(QT_BUILD_VERSION "6.6.2") if(WIN32) - # python -m aqt install-qt windows desktop ${QT_BUILD_VERSION} win64_msvc2019_64 + # python -m aqt install-qt windows desktop ${QT_BUILD_VERSION} win64_msvc2019_64 set(QT_BUILD_COMPILER "msvc2019_64") elseif(LINUX) - # python -m aqt install-qt linux desktop ${QT_BUILD_VERSION} gcc_64 + # python -m aqt install-qt linux desktop ${QT_BUILD_VERSION} gcc_64 set(QT_BUILD_COMPILER "gcc_64") elseif(APPLE) - # python -m aqt install-qt mac desktop ${QT_BUILD_VERSION} clang_64 + # python -m aqt install-qt mac desktop ${QT_BUILD_VERSION} clang_64 set(QT_BUILD_COMPILER "macos") else() message(FATAL "nope") @@ -27,10 +27,9 @@ find_package(Qt6 REQUIRED COMPONENTS Core Qml Concurrent) FetchContent_Declare( DieLibrary - # GIT_REPOSITORY "https://github.com/calladoum-elastic/die_library" - # GIT_TAG ff412022d34289115426ba1cb7b8663d728f7bb3 GIT_REPOSITORY "https://github.com/horsicq/die_library" - GIT_TAG 2b4d6e986b273fd20e3f6733bfe244d2fa85892a + # GIT_TAG 2b4d6e986b273fd20e3f6733bfe244d2fa85892a + GIT_TAG ebe34ba3b3a38d5f40c02064a116faec7376bad3 ) set(DIE_BUILD_AS_STATIC ON CACHE INTERNAL "") From c7b53dad3c5edae0fe139390f0dcf3e679eaded4 Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Thu, 2 Jan 2025 10:49:37 -0800 Subject: [PATCH 2/4] Fixed tests --- cmake/FindDieLibrary.cmake | 6 ++--- python/tests/test_die.py | 46 +++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/cmake/FindDieLibrary.cmake b/cmake/FindDieLibrary.cmake index 223e0c4..91fb909 100644 --- a/cmake/FindDieLibrary.cmake +++ b/cmake/FindDieLibrary.cmake @@ -7,13 +7,13 @@ set(ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/..") set(QT_BUILD_VERSION "6.6.2") if(WIN32) - # python -m aqt install-qt windows desktop ${QT_BUILD_VERSION} win64_msvc2019_64 + # python -m aqt install-qt -O build windows desktop ${QT_BUILD_VERSION} win64_msvc2019_64 set(QT_BUILD_COMPILER "msvc2019_64") elseif(LINUX) - # python -m aqt install-qt linux desktop ${QT_BUILD_VERSION} gcc_64 + # python -m aqt install-qt -O build linux desktop ${QT_BUILD_VERSION} gcc_64 set(QT_BUILD_COMPILER "gcc_64") elseif(APPLE) - # python -m aqt install-qt mac desktop ${QT_BUILD_VERSION} clang_64 + # python -m aqt install-qt -O build mac desktop ${QT_BUILD_VERSION} clang_64 set(QT_BUILD_COMPILER "macos") else() message(FATAL "nope") diff --git a/python/tests/test_die.py b/python/tests/test_die.py index e20983f..6a6f126 100644 --- a/python/tests/test_die.py +++ b/python/tests/test_die.py @@ -1,8 +1,8 @@ +import bs4 +import json import pathlib import platform -import json - -import bs4 +import pytest import die @@ -61,23 +61,28 @@ def test_scan_basic(): die.ScanFlags.DEEP_SCAN, ) assert res + assert isinstance(res, str) + + lines = res.splitlines() + assert len(lines) if platform.system() == "Windows": - assert res == "PE64" + assert lines[0] == "PE64" elif platform.system() == "Linux": - assert res == "ELF64" + assert lines[0] == "ELF64" -def test_scan_export_format(): - default_target = ( +@pytest.fixture +def target_binary(): + return ( pathlib.Path("c:/windows/system32/winver.exe") if platform.system() == "Windows" else pathlib.Path("/bin/ls") ) - # JS +def test_scan_export_format_json(target_binary: pathlib.Path): res = die.scan_file( - default_target, + target_binary, die.ScanFlags.DEEP_SCAN | die.ScanFlags.RESULT_AS_JSON, ) assert res @@ -85,37 +90,36 @@ def test_scan_export_format(): js = json.loads(res) assert len(js["detects"]) if platform.system() == "Windows": - assert js["detects"][0]["string"] == "PE64" + assert js["detects"][0]["filetype"] == "PE64" elif platform.system() == "Linux": - assert js["detects"][0]["string"] == "ELF64" + assert js["detects"][0]["filetype"] == "ELF64" - # XML +def test_scan_export_format_xml(target_binary: pathlib.Path) -> None: res = die.scan_file( - default_target, + target_binary, die.ScanFlags.DEEP_SCAN | die.ScanFlags.RESULT_AS_XML, ) assert res xml = bs4.BeautifulSoup(res, "xml") assert xml.Result if platform.system() == "Windows": - assert xml.Result.detect.text == "PE64" + assert hasattr(xml.Result, "PE64") + assert xml.Result.PE64["filetype"] == "PE64" elif platform.system() == "Linux": - assert xml.Result.detect.text == "ELF64" + assert hasattr(xml.Result, "ELF64") + assert xml.Result.ELF64["filetype"] == "ELF64" - # CSV +def test_scan_export_format_csv(target_binary: pathlib.Path): res = die.scan_file( - default_target, + target_binary, die.ScanFlags.DEEP_SCAN | die.ScanFlags.RESULT_AS_CSV, ) assert res assert len(res.splitlines()) == 1 parts = res.split(";") + print(parts) assert len(parts) == 5 - if platform.system() == "Windows": - assert parts[-1] == "PE64" - elif platform.system() == "Linux": - assert parts[-1] == "ELF64" def test_basic_databases(): From b1ff89b001a10038d1c2683f2361f1fd732087ee Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Thu, 2 Jan 2025 10:56:44 -0800 Subject: [PATCH 3/4] added test for tsv --- python/tests/test_die.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/python/tests/test_die.py b/python/tests/test_die.py index 6a6f126..cbec074 100644 --- a/python/tests/test_die.py +++ b/python/tests/test_die.py @@ -110,6 +110,7 @@ def test_scan_export_format_xml(target_binary: pathlib.Path) -> None: assert xml.Result.ELF64["filetype"] == "ELF64" def test_scan_export_format_csv(target_binary: pathlib.Path): + CSV_DELIMITER = ";" res = die.scan_file( target_binary, die.ScanFlags.DEEP_SCAN | die.ScanFlags.RESULT_AS_CSV, @@ -117,10 +118,22 @@ def test_scan_export_format_csv(target_binary: pathlib.Path): assert res assert len(res.splitlines()) == 1 - parts = res.split(";") - print(parts) - assert len(parts) == 5 + assert len(res.split(CSV_DELIMITER)) == 5 +def test_scan_export_format_tsv(target_binary: pathlib.Path): + res = die.scan_file( + target_binary, + die.ScanFlags.DEEP_SCAN | die.ScanFlags.RESULT_AS_TSV, + ) + assert res + + lines = res.splitlines() + assert len(lines) + + if platform.system() == "Windows": + assert lines[0] == "PE64" + elif platform.system() == "Linux": + assert lines[0] == "ELF64" def test_basic_databases(): for db in die.databases(): From 1d8d35a1b057f8785ce4ea3e504c48a224045a6b Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Thu, 2 Jan 2025 11:16:28 -0800 Subject: [PATCH 4/4] cleanup --- python/tests/test_die.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/python/tests/test_die.py b/python/tests/test_die.py index cbec074..f8ab4cd 100644 --- a/python/tests/test_die.py +++ b/python/tests/test_die.py @@ -48,16 +48,17 @@ def test_constants(): ] ) - -def test_scan_basic(): - default_target = ( +@pytest.fixture +def target_binary(): + return ( pathlib.Path("c:/windows/system32/winver.exe") if platform.system() == "Windows" else pathlib.Path("/bin/ls") ) +def test_scan_basic(target_binary: pathlib.Path): res = die.scan_file( - default_target, + target_binary, die.ScanFlags.DEEP_SCAN, ) assert res @@ -72,14 +73,6 @@ def test_scan_basic(): assert lines[0] == "ELF64" -@pytest.fixture -def target_binary(): - return ( - pathlib.Path("c:/windows/system32/winver.exe") - if platform.system() == "Windows" - else pathlib.Path("/bin/ls") - ) - def test_scan_export_format_json(target_binary: pathlib.Path): res = die.scan_file( target_binary, @@ -94,6 +87,7 @@ def test_scan_export_format_json(target_binary: pathlib.Path): elif platform.system() == "Linux": assert js["detects"][0]["filetype"] == "ELF64" + def test_scan_export_format_xml(target_binary: pathlib.Path) -> None: res = die.scan_file( target_binary, @@ -109,6 +103,7 @@ def test_scan_export_format_xml(target_binary: pathlib.Path) -> None: assert hasattr(xml.Result, "ELF64") assert xml.Result.ELF64["filetype"] == "ELF64" + def test_scan_export_format_csv(target_binary: pathlib.Path): CSV_DELIMITER = ";" res = die.scan_file( @@ -116,10 +111,10 @@ def test_scan_export_format_csv(target_binary: pathlib.Path): die.ScanFlags.DEEP_SCAN | die.ScanFlags.RESULT_AS_CSV, ) assert res - assert len(res.splitlines()) == 1 assert len(res.split(CSV_DELIMITER)) == 5 + def test_scan_export_format_tsv(target_binary: pathlib.Path): res = die.scan_file( target_binary, @@ -135,6 +130,7 @@ def test_scan_export_format_tsv(target_binary: pathlib.Path): elif platform.system() == "Linux": assert lines[0] == "ELF64" + def test_basic_databases(): for db in die.databases(): assert isinstance(db, pathlib.Path)