From cb45b9bb04dbdef2c668ed5a21867ce616586669 Mon Sep 17 00:00:00 2001 From: orange Date: Tue, 24 Feb 2026 13:17:54 +0300 Subject: [PATCH] added files --- .idea/dictionaries/project.xml | 7 +++++++ CMakeLists.txt | 11 +++++++++++ CMakePresets.json | 2 +- examples/CMakeLists.txt | 2 +- examples/exmple_var_encryption/CMakeLists.txt | 10 ++++++++++ examples/exmple_var_encryption/main.cpp | 15 +++++++++++++++ include/omath/containers/encrypted_variable.hpp | 14 ++++++++++---- source/utility/elf_pattern_scan.cpp | 1 + vcpkg.json | 11 +++++++++-- 9 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .idea/dictionaries/project.xml create mode 100644 examples/exmple_var_encryption/CMakeLists.txt create mode 100644 examples/exmple_var_encryption/main.cpp diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..a577620 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + vmprotect + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 29a20e7..cc48cbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,10 @@ option(OMATH_SUPRESS_SAFETY_CHECKS option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF) option(OMATH_ENABLE_FORCE_INLINE "Will for compiler to make some functions to be force inlined no matter what" ON) +option(OMATH_VMPROTECT_INTEGRATION + "omath will use vmprotect sdk to protect sensitive parts of code from reverse engineering" + OFF) + if(VCPKG_MANIFEST_FEATURES) foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES) if(omath_feature STREQUAL "imgui") @@ -43,6 +47,8 @@ if(VCPKG_MANIFEST_FEATURES) set(OMATH_BUILD_BENCHMARK ON) elseif(omath_feature STREQUAL "examples") set(OMATH_BUILD_EXAMPLES ON) + elseif(omath_feature STREQUAL "vmprotect") + set(OMATH_VMPROTECT_INTEGRATION ON) endif() endforeach() @@ -107,6 +113,11 @@ if(OMATH_IMGUI_INTEGRATION) endif() +if(OMATH_VMPROTECT_INTEGRATION) + find_package(vmprotect_sdk CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} PUBLIC vmprotect_sdk::vmprotect_sdk) +endif() + if(OMATH_USE_AVX2) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_AVX2) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 5efed25..e1d96d8 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -145,7 +145,7 @@ "hidden": true, "inherits": ["linux-base", "vcpkg-base"], "cacheVariables": { - "VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2" + "VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;vmprotect;examples" } }, { diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 52dff0e..b073ecf 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,7 +2,7 @@ add_subdirectory(example_barycentric) add_subdirectory(example_glfw3) add_subdirectory(example_proj_mat_builder) add_subdirectory(example_signature_scan) - +add_subdirectory(exmple_var_encryption) if(OMATH_ENABLE_VALGRIND) omath_setup_valgrind(example_projection_matrix_builder) omath_setup_valgrind(example_signature_scan) diff --git a/examples/exmple_var_encryption/CMakeLists.txt b/examples/exmple_var_encryption/CMakeLists.txt new file mode 100644 index 0000000..5333c30 --- /dev/null +++ b/examples/exmple_var_encryption/CMakeLists.txt @@ -0,0 +1,10 @@ +project(example_var_encryption) + +add_executable(${PROJECT_NAME} main.cpp) +set_target_properties( + ${PROJECT_NAME} + PROPERTIES CXX_STANDARD 23 + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}") +target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath) diff --git a/examples/exmple_var_encryption/main.cpp b/examples/exmple_var_encryption/main.cpp new file mode 100644 index 0000000..77e9e35 --- /dev/null +++ b/examples/exmple_var_encryption/main.cpp @@ -0,0 +1,15 @@ +// +// Created by orange on 24.02.2026. +// +#include "omath/containers/encrypted_variable.hpp" +#include +#include +int main() +{ + OMATH_DEF_CRYPT_VAR(int, 64) var{5}; + var.encrypt(); + std::println("{}", var.value()); + var.decrypt(); + std::println("{}", var.value()); + return var.value(); +} \ No newline at end of file diff --git a/include/omath/containers/encrypted_variable.hpp b/include/omath/containers/encrypted_variable.hpp index b7c9a22..fe823a5 100644 --- a/include/omath/containers/encrypted_variable.hpp +++ b/include/omath/containers/encrypted_variable.hpp @@ -2,10 +2,14 @@ // Created by Vladislav on 04.01.2026. // #pragma once +#include #include #include #include #include +#include + + #ifdef OMATH_ENABLE_FORCE_INLINE #ifdef _MSC_VER #define OMATH_FORCE_INLINE __forceinline @@ -110,16 +114,18 @@ namespace omath bool m_is_encrypted{}; value_type m_data{}; - OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key() + OMATH_FORCE_INLINE void xor_contained_var_by_key() { + VMProtectBeginVirtualization(nullptr); // Safe, keeps const-correctness, and avoids reinterpret_cast issues auto bytes = std::as_writable_bytes(std::span{&m_data, 1}); for (std::size_t i = 0; i < bytes.size(); ++i) { - const std::uint8_t k = static_cast(key[i % key_size] + (i * key_size)); + const auto k = static_cast(key[i % key_size] + (i * key_size)); bytes[i] ^= static_cast(k); } + VMProtectEnd(); } public: @@ -134,7 +140,7 @@ namespace omath return m_is_encrypted; } - OMATH_FORCE_INLINE constexpr void decrypt() + OMATH_FORCE_INLINE void decrypt() { if (!m_is_encrypted) return; @@ -142,7 +148,7 @@ namespace omath m_is_encrypted = false; } - OMATH_FORCE_INLINE constexpr void encrypt() + OMATH_FORCE_INLINE void encrypt() { if (m_is_encrypted) return; diff --git a/source/utility/elf_pattern_scan.cpp b/source/utility/elf_pattern_scan.cpp index be5d3a0..dc7b4b3 100644 --- a/source/utility/elf_pattern_scan.cpp +++ b/source/utility/elf_pattern_scan.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #pragma pack(push, 1) diff --git a/vcpkg.json b/vcpkg.json index 7a99ddf..b53e9fd 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -17,9 +17,16 @@ ], "features": { "avx2": { - "description": "Omath will use AVX2 to boost performance", + "description": "omath will use AVX2 to boost performance", "supports": "!arm" }, + "vmprotect": { + "description": "omath will use vmprotect sdk to protect sensitive parts of code from reverse engineering", + "supports": "windows | linux | osx | android", + "dependencies": [ + "orange-vmprotect-sdk" + ] + }, "benchmark": { "description": "Build benchmarks", "dependencies": [ @@ -35,7 +42,7 @@ ] }, "imgui": { - "description": "Omath will define method to convert omath types to imgui types", + "description": "omath will define method to convert omath types to imgui types", "dependencies": [ "imgui" ]