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..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") @@ -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 "") diff --git a/python/tests/test_die.py b/python/tests/test_die.py index e20983f..f8ab4cd 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 @@ -48,36 +48,34 @@ 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 + 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 = ( - 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 +83,52 @@ 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): + CSV_DELIMITER = ";" 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(";") - 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 parts[-1] == "PE64" + assert lines[0] == "PE64" elif platform.system() == "Linux": - assert parts[-1] == "ELF64" + assert lines[0] == "ELF64" def test_basic_databases():