Skip to content

Commit

Permalink
Update DiE Library (#22)
Browse files Browse the repository at this point in the history
# Description

Update die library to the latest to date :
horsicq/die_library@2b4d6e9

This fixes #20
  • Loading branch information
calladoum-elastic authored Jan 2, 2025
1 parent 45a22c5 commit 6006955
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ __pycache__
aqtinstall.log
wheel
wheelhouse
.vscode
.venv
6.*
11 changes: 5 additions & 6 deletions cmake/FindDieLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 "")
Expand Down
75 changes: 44 additions & 31 deletions python/tests/test_die.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import bs4
import json
import pathlib
import platform
import json

import bs4
import pytest

import die

Expand Down Expand Up @@ -48,74 +48,87 @@ 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

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():
Expand Down

0 comments on commit 6006955

Please sign in to comment.