├── .gitignore ├── LICENSE ├── README.md ├── include └── crycall.hpp └── src └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Android1337 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # crycall | Compile-Time Calls Obfuscator for C++14+ 2 | 3 | ## Description 4 | This repository provides a compile-time calls obfuscator based on lambdas, virtual calls and on how std::function works.\ 5 | Users can easily obfuscate their calls using the `crycall` and `crycall_virtual` macro provided in the header.\ 6 | The repository includes an example demonstrating the usage of `crycall`.\ 7 | `Needs optimization off (C/C++ -> Optimization -> "Optimization" and "Whole Program Optimization")` 8 | 9 | ## Key Aspects 10 | - The actual sub that's being called is hidden. 11 | - All the arguments passed in the call are hidden. 12 | - Memory is correctly managed, everything gets free'ed after usage. 13 | - Supports virtual functions (see crycall_virtual macro) 14 | - Works well with crystr ([see the repo](https://github.com/Android1337/crystr)) 15 | - Supports C++14 and higher versions. 16 | 17 | ## How it shows 18 | [Look here](https://imgur.com/a/WN23wmS) 19 | 20 | ## Repository Structure 21 | - **`include/`**: Contains the `crycall.hpp` header file providing the compile-time calls obfuscation mechanism. 22 | - **`src/`**: Holds the example `main.cpp` file showcasing the usage of the `crycall` macro. 23 | - **`LICENSE`**: Licensing information for the provided code. 24 | - **`README.md`**: Documentation explaining how to use the `crycall` macro and example usage. 25 | 26 | ## Usage 27 | ```cpp 28 | crycall(returntype, function, args...) 29 | ``` 30 | or 31 | ```cpp 32 | crycall_virtual(returntype, class_address, virtual_index, args...) 33 | ``` 34 | Note that the virtual_index must be the index and not the virtual offset. (index = offset / 0x8) 35 | 36 | ## Usage Example 37 | The repository includes an example demonstrating the usage of the `crycall` macro: 38 | 39 | ### `main.cpp` 40 | ```cpp 41 | #include 42 | #include "crycall.hpp" 43 | 44 | int sum(int a, int b) 45 | { 46 | return a + b; 47 | } 48 | 49 | int main() 50 | { 51 | printf("sum: %d", crycall(int, sum, 10, 5)); 52 | 53 | return 0; 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /include/crycall.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License https://github.com/Android1337/crycall/blob/main/LICENSE 3 | * 4 | * Copyright (c) 2023 Android1337 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef CRYCALL_HPP 26 | #define CRYCALL_HPP 27 | #include // std::unique_ptr 28 | 29 | namespace cryc 30 | { 31 | template 32 | class cryCall { 33 | public: 34 | template 35 | cryCall(func_type&& func) : storage(new cryHolder(std::forward(func))) {} 36 | 37 | ret_type operator()() const { 38 | return storage->invoke(); 39 | } 40 | 41 | private: 42 | struct cryBase { 43 | virtual ret_type invoke() const = 0; 44 | virtual ~cryBase() = default; 45 | }; 46 | 47 | template 48 | struct cryHolder : cryBase { 49 | func_type func; 50 | 51 | cryHolder(func_type&& f) : func(std::forward(f)) {} 52 | 53 | ret_type invoke() const override { 54 | return func(); 55 | } 56 | }; 57 | 58 | std::unique_ptr storage; 59 | }; 60 | } 61 | 62 | #define crycall(ret_type, func, ...) [&]() { \ 63 | cryc::cryCall f([&]() { \ 64 | return func(__VA_ARGS__); \ 65 | }); \ 66 | return f(); \ 67 | }() 68 | 69 | #define crycall_virtual(ret_type, _this, idx, ...) [&]() { \ 70 | ret_type (*func)(__int64, ...); \ 71 | func = decltype(func)(*(__int64*)(*(__int64*)__int64(_this) + (idx * sizeof(__int64)))); \ 72 | cryc::cryCall f([&]() { \ 73 | return func(__int64(_this), __VA_ARGS__); \ 74 | }); \ 75 | return f(); \ 76 | }() 77 | 78 | #endif // include guard 79 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "crycall.hpp" 3 | 4 | int sum(int a, int b) 5 | { 6 | return a + b; 7 | } 8 | 9 | int main() 10 | { 11 | printf("sum: %d", crycall(int, sum, 10, 5)); 12 | 13 | return 0; 14 | } 15 | --------------------------------------------------------------------------------