From 71b06f4b200d4c6c96abf878ec82a4ca8cd2b3c5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 11 Sep 2021 14:40:53 +0200 Subject: [PATCH] build: Only copy yara crypto wrapper if it changed --- external/yara/CMakeLists.txt | 6 ++-- tests/CMakeLists.txt | 0 tests/include/test_patterns/test_pattern.hpp | 8 +++++ .../test_patterns/test_pattern_example.hpp | 30 +++++++++++++++++++ .../test_patterns/test_pattern_placement.hpp | 26 ++++++++++++++++ tests/include/test_provider.hpp | 8 +++++ tests/source/main.cpp | 1 + 7 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/include/test_patterns/test_pattern.hpp create mode 100644 tests/include/test_patterns/test_pattern_example.hpp create mode 100644 tests/include/test_patterns/test_pattern_placement.hpp create mode 100644 tests/include/test_provider.hpp create mode 100644 tests/source/main.cpp diff --git a/external/yara/CMakeLists.txt b/external/yara/CMakeLists.txt index dd79c96c6..94e037924 100644 --- a/external/yara/CMakeLists.txt +++ b/external/yara/CMakeLists.txt @@ -94,8 +94,10 @@ set(LIBYARA_MODULES ${LIBYARA_SOURCE_PATH}/modules/magic/magic.c) # Add mbedtls crypto wrappers -file(READ crypto_mbedtls.h MBEDTLS_CRYPTO_H) -file(WRITE ${LIBYARA_SOURCE_PATH}/crypto.h "${MBEDTLS_CRYPTO_H}") +add_custom_command( + OUTPUT ${LIBYARA_SOURCE_PATH}/crypto.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/crypto_mbedtls.h ${LIBYARA_SOURCE_PATH}/crypto.h + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/crypto_mbedtls.h) add_compile_definitions("HAVE_MBEDTLS") add_compile_definitions("USE_NO_PROC") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/include/test_patterns/test_pattern.hpp b/tests/include/test_patterns/test_pattern.hpp new file mode 100644 index 000000000..99bae8e86 --- /dev/null +++ b/tests/include/test_patterns/test_pattern.hpp @@ -0,0 +1,8 @@ +// +// Created by werwo on 11/09/2021. +// + +#ifndef IMHEX_TEST_PATTERN_HPP +#define IMHEX_TEST_PATTERN_HPP + +#endif //IMHEX_TEST_PATTERN_HPP diff --git a/tests/include/test_patterns/test_pattern_example.hpp b/tests/include/test_patterns/test_pattern_example.hpp new file mode 100644 index 000000000..d8ef065e2 --- /dev/null +++ b/tests/include/test_patterns/test_pattern_example.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include + +namespace hex::test { + + class TestPattern { + public: + TestPattern() = default; + virtual TestPattern() { + for (auto &pattern : this->m_patterns) + delete pattern; + } + + virtual std::string getSourceCode() = 0; + + [[nodiscard]] + virtual const std::vector& getPatterns() const final { return this->m_patterns; } + virtual void addPattern(pl::PatternData *pattern) final { + this->m_patterns.push_back(pattern); + } + + private: + std::vector m_patterns; + }; + +} \ No newline at end of file diff --git a/tests/include/test_patterns/test_pattern_placement.hpp b/tests/include/test_patterns/test_pattern_placement.hpp new file mode 100644 index 000000000..4a413e109 --- /dev/null +++ b/tests/include/test_patterns/test_pattern_placement.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "test_pattern.hpp" + +namespace hex::test { + + class TestPatternExample : public TestPattern { + public: + TestPatternExample() { + auto placementTest = new pl::PatternDataSigned(0x00, sizeof(u32)); + placementTest->setTypeName("u32"); + placementTest->setVariableName("placementTest"); + addPattern(placementTest); + } + ~TestPatternExample() override = default; + + [[nodiscard]] + std::string getSourceCode() const override { + return R"( + u32 placementTest @ 0x00; + )"; + } + + }; + +} \ No newline at end of file diff --git a/tests/include/test_provider.hpp b/tests/include/test_provider.hpp new file mode 100644 index 000000000..ac255fc28 --- /dev/null +++ b/tests/include/test_provider.hpp @@ -0,0 +1,8 @@ +// +// Created by werwo on 11/09/2021. +// + +#ifndef IMHEX_TEST_PROVIDER_HPP +#define IMHEX_TEST_PROVIDER_HPP + +#endif //IMHEX_TEST_PROVIDER_HPP diff --git a/tests/source/main.cpp b/tests/source/main.cpp new file mode 100644 index 000000000..137fcc3ef --- /dev/null +++ b/tests/source/main.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file