mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-19 03:43:27 +00:00
Compare commits
7 Commits
v5.1.0.rc1
...
cb45b9bb04
| Author | SHA1 | Date | |
|---|---|---|---|
| cb45b9bb04 | |||
| f3656f9d2c | |||
| 7ebbed6763 | |||
| e271bccaf5 | |||
| 50765f69c5 | |||
| 1169534133 | |||
| 783501aab9 |
4
.github/FUNDING.yml
vendored
Normal file
4
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
open_collective: libomathorg
|
||||
github: orange-cpp
|
||||
7
.idea/dictionaries/project.xml
generated
Normal file
7
.idea/dictionaries/project.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="project">
|
||||
<words>
|
||||
<w>vmprotect</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
37
CODEOWNERS
Normal file
37
CODEOWNERS
Normal file
@@ -0,0 +1,37 @@
|
||||
## List of maintainers for the omath library
|
||||
|
||||
## This file purpose is to give newcomers to the project the responsible
|
||||
## developers when submitting a pull request on GitHub, or opening a bug
|
||||
## report in issues.
|
||||
|
||||
## This file will notably establish who is responsible for a specific
|
||||
## area of omath. Being a maintainer means the following:
|
||||
## - that person has good knownledge in the area
|
||||
## - that person is able to enforce consistency in the area
|
||||
## - that person may be available for giving help in the area
|
||||
## - that person has push access on the repository
|
||||
## Being a maintainer does not mean the following:
|
||||
## - that person is dedicated to the area
|
||||
## - that person is working full-time on the area/on omath
|
||||
## - that person is paid
|
||||
## - that person is always available
|
||||
|
||||
|
||||
# omath core source code
|
||||
/source @orange-cpp
|
||||
/include @orange-cpp
|
||||
|
||||
# Tests and becnchmarks
|
||||
/benchmark @orange-cpp
|
||||
/tests @orange-cpp @luadebug
|
||||
|
||||
# Examples and documentation
|
||||
/examples @luadebug @orange-cpp
|
||||
/docs @orange-cpp
|
||||
|
||||
# Misc like formating
|
||||
/scripts @luadebug
|
||||
/pixi @luadebug
|
||||
|
||||
# CI/CD
|
||||
/.github/workflows @luadbg @orange-cpp
|
||||
42
INSTALL.md
42
INSTALL.md
@@ -1,6 +1,6 @@
|
||||
# 📥Installation Guide
|
||||
|
||||
## <img width="28px" src="https://vcpkg.io/assets/mark/mark.svg" /> Using vcpkg
|
||||
## <img width="28px" src="https://vcpkg.io/assets/mark/mark.svg" /> Using vcpkg (recomended)
|
||||
**Note**: Support vcpkg for package management
|
||||
1. Install [vcpkg](https://github.com/microsoft/vcpkg)
|
||||
2. Run the following command to install the orange-math package:
|
||||
@@ -28,6 +28,46 @@ target("...")
|
||||
add_packages("omath")
|
||||
```
|
||||
|
||||
## <img width="28px" src="https://github.githubassets.com/favicons/favicon.svg" /> Using prebuilt binaries (GitHub Releases)
|
||||
|
||||
**Note**: This is the fastest option if you don’t want to build from source.
|
||||
|
||||
1. **Go to the Releases page**
|
||||
- Open the project’s GitHub **Releases** page and choose the latest version.
|
||||
|
||||
2. **Download the correct asset for your platform**
|
||||
- Pick the archive that matches your OS and architecture (for example: Windows x64 / Linux x64 / macOS arm64).
|
||||
|
||||
3. **Extract the archive**
|
||||
- You should end up with something like:
|
||||
- `include/` (headers)
|
||||
- `lib/` or `bin/` (library files / DLLs)
|
||||
- sometimes `cmake/` (CMake package config)
|
||||
|
||||
4. **Use it in your project**
|
||||
|
||||
### Option A: CMake package (recommended if the release includes CMake config files)
|
||||
If the extracted folder contains something like `lib/cmake/omath` or `cmake/omath`, you can point CMake to it:
|
||||
|
||||
```cmake
|
||||
# Example: set this to the extracted prebuilt folder
|
||||
list(APPEND CMAKE_PREFIX_PATH "path/to/omath-prebuilt")
|
||||
|
||||
find_package(omath CONFIG REQUIRED)
|
||||
target_link_libraries(main PRIVATE omath::omath)
|
||||
```
|
||||
### Option B: Manual include + link (works with any layout)
|
||||
If there’s no CMake package config, link it manually:
|
||||
```cmake
|
||||
target_include_directories(main PRIVATE "path/to/omath-prebuilt/include")
|
||||
|
||||
# Choose ONE depending on what you downloaded:
|
||||
# - Static library: .lib / .a
|
||||
# - Shared library: .dll + .lib import (Windows), .so (Linux), .dylib (macOS)
|
||||
|
||||
target_link_directories(main PRIVATE "path/to/omath-prebuilt/lib")
|
||||
target_link_libraries(main PRIVATE omath) # or the actual library filename
|
||||
```
|
||||
## <img width="28px" src="https://upload.wikimedia.org/wikipedia/commons/e/ef/CMake_logo.svg?" /> Build from source using CMake
|
||||
1. **Preparation**
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
10
examples/exmple_var_encryption/CMakeLists.txt
Normal file
10
examples/exmple_var_encryption/CMakeLists.txt
Normal file
@@ -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)
|
||||
15
examples/exmple_var_encryption/main.cpp
Normal file
15
examples/exmple_var_encryption/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by orange on 24.02.2026.
|
||||
//
|
||||
#include "omath/containers/encrypted_variable.hpp"
|
||||
#include <omath/omath.hpp>
|
||||
#include <print>
|
||||
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();
|
||||
}
|
||||
@@ -2,10 +2,14 @@
|
||||
// Created by Vladislav on 04.01.2026.
|
||||
//
|
||||
#pragma once
|
||||
#include <VMProtectSDK.h>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <source_location>
|
||||
|
||||
|
||||
#ifdef OMATH_ENABLE_FORCE_INLINE
|
||||
#ifdef _MSC_VER
|
||||
#define OMATH_FORCE_INLINE __forceinline
|
||||
@@ -62,20 +66,13 @@ namespace omath::detail
|
||||
return splitmix64(base_seed() + 0xD1B54A32D192ED03ull * (Stream + 1));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t bounded_u64(const std::uint64_t x, const std::uint64_t bound)
|
||||
{
|
||||
return (x * bound) >> 64;
|
||||
}
|
||||
|
||||
template<std::int64_t Lo, std::int64_t Hi, std::uint64_t Stream>
|
||||
[[nodiscard]]
|
||||
consteval std::int64_t rand_uint8_t()
|
||||
{
|
||||
static_assert(Lo <= Hi);
|
||||
const std::uint64_t span = static_cast<std::uint64_t>(Hi - Lo) + 1ull;
|
||||
const std::uint64_t r = rand_u64<Stream>();
|
||||
return static_cast<std::int64_t>(bounded_u64(r, span)) + Lo;
|
||||
return static_cast<std::int64_t>(r) + Lo;
|
||||
}
|
||||
[[nodiscard]]
|
||||
consteval std::uint64_t rand_u64(const std::uint64_t seed, const std::uint64_t i)
|
||||
@@ -117,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<value_type, 1>{&m_data, 1});
|
||||
|
||||
for (std::size_t i = 0; i < bytes.size(); ++i)
|
||||
{
|
||||
const std::uint8_t k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
||||
const auto k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
||||
bytes[i] ^= static_cast<std::byte>(k);
|
||||
}
|
||||
VMProtectEnd();
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -141,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;
|
||||
@@ -149,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;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <VMProtectSDK.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default-registry": {
|
||||
"kind": "git",
|
||||
"baseline": "b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01",
|
||||
"baseline": "05442024c3fda64320bd25d2251cc9807b84fb6f",
|
||||
"repository": "https://github.com/microsoft/vcpkg"
|
||||
},
|
||||
"registries": [
|
||||
|
||||
11
vcpkg.json
11
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"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user