From c697324cefd1f8af533cddd451a12fa5f8d2c55f Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Wed, 18 Feb 2026 13:36:00 -0800 Subject: [PATCH 1/7] Move DieLibrary git tag in separate file --- .dielib_commit | 1 + cmake/FindDieLibrary.cmake | 4 +++- python/CMakeLists.txt | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .dielib_commit diff --git a/.dielib_commit b/.dielib_commit new file mode 100644 index 0000000..9f0f455 --- /dev/null +++ b/.dielib_commit @@ -0,0 +1 @@ +09df9ccafe48a0531987ad1e605402ed79d4c3f6 \ No newline at end of file diff --git a/cmake/FindDieLibrary.cmake b/cmake/FindDieLibrary.cmake index b4783e5..5b8d359 100644 --- a/cmake/FindDieLibrary.cmake +++ b/cmake/FindDieLibrary.cmake @@ -65,10 +65,12 @@ list(INSERT CMAKE_MODULE_PATH 0 find_package(Qt6 REQUIRED COMPONENTS Core Qml Concurrent) +file (STRINGS "${ROOT_DIR}/.dielib_commit" DIE_LIBRARY_GIT_TAG) +message(STATUS "Using tag ${DIE_LIBRARY_GIT_TAG} for DieLibrary") FetchContent_Declare( DieLibrary GIT_REPOSITORY "https://github.com/horsicq/die_library" - GIT_TAG 09df9ccafe48a0531987ad1e605402ed79d4c3f6 + GIT_TAG "${DIE_LIBRARY_GIT_TAG}" ) set(DIE_BUILD_AS_STATIC ON CACHE INTERNAL "") diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index f5f4eb6..f65aa8e 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -60,6 +60,7 @@ target_compile_definitions(_die PRIVATE DIE_VERSION="${DIE_VERSION}" DIELIB_VERSION="${DIELIB_VERSION}" + DIELIB_TAG="${DIE_LIBRARY_GIT_TAG}" ) target_link_libraries(_die PRIVATE $ $) From 66f1baa544b5cf13314e3cb5e6a2d232dc9377c6 Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Wed, 18 Feb 2026 13:36:21 -0800 Subject: [PATCH 2/7] Expose dielib tag to Python --- python/die/__init__.py | 4 ++-- python/inc/die.hpp | 4 ++++ python/src/die.cpp | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/python/die/__init__.py b/python/die/__init__.py index 73ab8b2..ba46dda 100644 --- a/python/die/__init__.py +++ b/python/die/__init__.py @@ -13,9 +13,9 @@ ScanMemoryExA as _ScanMemoryExA, LoadDatabaseA as _LoadDatabaseA, ) -from ._die import die_version, dielib_version # ty:ignore[unresolved-import] +from ._die import die_version, dielib_version, dielib_tag # ty:ignore[unresolved-import] -__all__ = ["die_version", "dielib_version"] +__all__ = ["die_version", "dielib_version", "dielib_tag"] version_major, version_minor, version_patch = map(int, __version__.split(".")) diff --git a/python/inc/die.hpp b/python/inc/die.hpp index db62ca9..2ab3acf 100644 --- a/python/inc/die.hpp +++ b/python/inc/die.hpp @@ -14,6 +14,10 @@ #define DIE_VERSION "" #endif // DIE_VERSION +#ifndef DIELIB_TAG +#define DIELIB_TAG "" +#endif // DIELIB_TAG + #ifdef __cplusplus namespace DIE { diff --git a/python/src/die.cpp b/python/src/die.cpp index 312590b..9c713ac 100644 --- a/python/src/die.cpp +++ b/python/src/die.cpp @@ -126,6 +126,7 @@ NB_MODULE(_die, m) m.attr("__version__") = "0.5.0"; m.attr("die_version") = DIE_VERSION; m.attr("dielib_version") = DIELIB_VERSION; + m.attr("dielib_tag") = DIELIB_TAG; m.def("ScanFileA", DIE::ScanFileA, "filename"_a, "flags"_a, "database"_a, "Scan a file against known signatures"); From 7122e9db7a77f6a044e878e609955c75cfc08444 Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Wed, 18 Feb 2026 13:39:29 -0800 Subject: [PATCH 3/7] Enhance tests for die library: validate dielib_tag and improve path assertions --- python/tests/test_die.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/python/tests/test_die.py b/python/tests/test_die.py index 8d8b9cc..2f9499d 100644 --- a/python/tests/test_die.py +++ b/python/tests/test_die.py @@ -17,6 +17,8 @@ def test_constants(): assert die.die_version assert isinstance(die.dielib_version, str) assert die.dielib_version + assert isinstance(die.dielib_tag, str) + assert die.dielib_tag # validate die database assert isinstance(die.database_path, die._DatabasePath) @@ -117,9 +119,11 @@ def test_scan_export_format_xml(target_binary: pathlib.Path) -> None: assert xml.Result if platform.system() == "Windows": assert hasattr(xml.Result, "PE64") + assert xml.Result.PE64 assert xml.Result.PE64["filetype"] == "PE64" elif platform.system() == "Linux": assert hasattr(xml.Result, "ELF64") + assert xml.Result.ELF64 assert xml.Result.ELF64["filetype"] == "ELF64" @@ -170,16 +174,18 @@ def test_database_path_backward_compatibility(): # Test 2: database_path should resolve to a valid location with PE/ directory db_path = pathlib.Path(path_new) assert db_path.exists(), f"Database path does not exist: {db_path}" - assert (db_path / 'PE').exists(), f"PE directory not found at {db_path}" + assert (db_path / "PE").exists(), f"PE directory not found at {db_path}" # Test 3: Old usage with /'db' should work through smart path resolution # The smart path should detect the version and handle accordingly with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - path_old = str(die.database_path / 'db') + path_old = str(die.database_path / "db") # The path should exist in both old and new versions - assert pathlib.Path(path_old).exists(), f"Old usage path doesn't exist: {path_old}" + assert pathlib.Path(path_old).exists(), ( + f"Old usage path doesn't exist: {path_old}" + ) if len(w) > 0: # New fixed version: got deprecation warning @@ -200,13 +206,14 @@ def test_database_path_resolves_correctly(): db_path = pathlib.Path(str(die.database_path)) # Check for PE directory (main signature database) - assert (db_path / 'PE').exists(), f"PE directory not found at {db_path}" + assert (db_path / "PE").exists(), f"PE directory not found at {db_path}" # Check for other expected directories - expected_dirs = ['PE', 'ELF', 'MACH'] + expected_dirs = ["PE", "ELF", "MACH"] for dir_name in expected_dirs: - assert (db_path / dir_name).exists(), \ + assert (db_path / dir_name).exists(), ( f"Expected directory {dir_name} not found at {db_path}" + ) def test_scan_with_explicit_database_path(target_binary: pathlib.Path): @@ -230,7 +237,7 @@ def test_scan_with_explicit_database_path(target_binary: pathlib.Path): res = die.scan_file( target_binary, die.ScanFlags.DEEP_SCAN, - database=str(die.database_path / 'db'), + database=str(die.database_path / "db"), ) assert res assert isinstance(res, str) From a4375f44838e9884c8506b7d3a4081e83b9e2521 Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Wed, 18 Feb 2026 13:43:43 -0800 Subject: [PATCH 4/7] Use Py3.11 type hints --- python/die/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/python/die/__init__.py b/python/die/__init__.py index ba46dda..2f5fbc4 100644 --- a/python/die/__init__.py +++ b/python/die/__init__.py @@ -2,7 +2,7 @@ import pathlib import warnings -from typing import Generator, Optional, Union +from typing import Generator from ._die import __version__ # ty:ignore[unresolved-import] from ._die import DieFlags as _DieFlags # ty:ignore[unresolved-import] @@ -138,8 +138,8 @@ class ScanFlags(enum.IntFlag): def scan_file( - filepath: Union[pathlib.Path, str], flags: ScanFlags, database: Optional[str] = None -) -> Optional[str]: + filepath: pathlib.Path | str, flags: ScanFlags, database: str | None = None +) -> str | None: """ Scan the given file against the signature database, if specified @@ -192,8 +192,8 @@ def __enum_db(root: pathlib.Path) -> Generator[pathlib.Path, None, None]: def scan_memory( - memory: Union[bytes, bytearray], flags: ScanFlags, database: Optional[str] = None -) -> Optional[str]: + memory: bytes | bytearray, flags: ScanFlags, database: str | None = None +) -> str | None: """ Scan the given sequence of bytes against the signature database, if specified @@ -220,11 +220,14 @@ def scan_memory( return res.strip() -def load_database(database: str) -> int: +def load_database(database: str | pathlib.Path) -> int: """ Load a database """ - if not isinstance(database, str): + if isinstance(database, pathlib.Path): + database = str(database) + + elif not isinstance(database, str): raise TypeError return _LoadDatabaseA(database) From a008ce523dc203a1f83eda712a324cc667411471 Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Wed, 18 Feb 2026 14:29:08 -0800 Subject: [PATCH 5/7] Updated DieLib tag to recent version --- .dielib_commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dielib_commit b/.dielib_commit index 9f0f455..bc4aed4 100644 --- a/.dielib_commit +++ b/.dielib_commit @@ -1 +1 @@ -09df9ccafe48a0531987ad1e605402ed79d4c3f6 \ No newline at end of file +44513ff0c329a42c3efef00dd0c27b4f55a1cb28 \ No newline at end of file From d2a5e5e57184af268f275bab63962f44e150e184 Mon Sep 17 00:00:00 2001 From: Christophe Alladoum <85187342+calladoum-elastic@users.noreply.github.com> Date: Wed, 18 Feb 2026 14:44:00 -0800 Subject: [PATCH 6/7] Update cmake/FindDieLibrary.cmake Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmake/FindDieLibrary.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindDieLibrary.cmake b/cmake/FindDieLibrary.cmake index 5b8d359..47ba0b2 100644 --- a/cmake/FindDieLibrary.cmake +++ b/cmake/FindDieLibrary.cmake @@ -65,7 +65,7 @@ list(INSERT CMAKE_MODULE_PATH 0 find_package(Qt6 REQUIRED COMPONENTS Core Qml Concurrent) -file (STRINGS "${ROOT_DIR}/.dielib_commit" DIE_LIBRARY_GIT_TAG) +file(STRINGS "${ROOT_DIR}/.dielib_commit" DIE_LIBRARY_GIT_TAG) message(STATUS "Using tag ${DIE_LIBRARY_GIT_TAG} for DieLibrary") FetchContent_Declare( DieLibrary From 2a81b696bfbf7c849639705f5eb627203191f43e Mon Sep 17 00:00:00 2001 From: Christophe Alladoum Date: Wed, 18 Feb 2026 14:59:36 -0800 Subject: [PATCH 7/7] restored tag 09df9ccafe48a0531987ad1e605402ed79d4c3f6 for release --- .dielib_commit | 2 +- python/die/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.dielib_commit b/.dielib_commit index bc4aed4..9f0f455 100644 --- a/.dielib_commit +++ b/.dielib_commit @@ -1 +1 @@ -44513ff0c329a42c3efef00dd0c27b4f55a1cb28 \ No newline at end of file +09df9ccafe48a0531987ad1e605402ed79d4c3f6 \ No newline at end of file diff --git a/python/die/__init__.py b/python/die/__init__.py index 2f5fbc4..cc13191 100644 --- a/python/die/__init__.py +++ b/python/die/__init__.py @@ -108,7 +108,7 @@ def iterdir(self): # Initialize database path with smart handling -database_path = _DatabasePath(__path__[0]) / "db" +database_path: pathlib.Path = _DatabasePath(__path__[0]) / "db" """Path to the DIE signature database This path automatically points to the correct database location,