
Obfusk8: lightweight Obfuscation library based on C++17 / Header Only for windows binaries
Obfusk8 is a lightweight, header-only C++17 library designed to significantly enhance the obfuscation of your applications, making reverse engineering a substantially more challenging endeavor. It achieves this through a diverse set of compile-time and runtime techniques aimed at protecting your code's logic and data.

main Function Wrapping (_main Macro)The entry point of your application (main) is transformed into a complex, multi-layered obfuscation engine:
main_body code is executed, a mini-VM (simulated CPU) runs a sequence of "encrypted" instructions. This conceals the true entry point and initial operations. The VM's state (registers, program counter, dispatch key) is initialized with runtime-randomized values._main macro (both in the prologue and epilogue) are transformed into intricate state machines. Control flow is not direct but determined by heavily "encrypted" state variables. The encoding/decoding keys for these state variables are dynamic, derived from VM state, loop counters, compile-time randomness (like __COUNTER__, __LINE__, __TIME__), and a global opaque seed. This makes static analysis of the control flow exceptionally difficult.
obf_icff_ns_dcff and obf_icff_ns_epd) are used with different state transition logic and key generation, further complicating analysis.OBF_BOGUS_FLOW_* macros): Numerous misleading jump patterns and convoluted conditional structures are injected throughout _main. These use goto statements combined with opaque predicates (conditions that always evaluate to true or false but are computationally expensive or hard to determine statically). This creates a labyrinth of false paths for disassemblers and decompilers.
obf_vm_engine)A core component of the _main macro's obfuscation:
r0, r1, r2), a program counter (pc), and a dispatch_key. It executes custom "instructions" (handlers).reg_dispatch_idx).get_mem_dispatch_table).mixed_dispatch_idx).
The dispatch_key is constantly mutated, making the sequence of executed handlers highly unpredictable.vm_handler_table) is itself mutated at runtime within the prologue and epilogue, further obscuring the VM's behavior.OBFUSCATE_STRING from AES8.hpp)__FILE__, __LINE__), and build time (__DATE__, __TIME__).AES8.hpp).STEALTH_API_OBFSTR / STEALTH_API_OBF from Resolve8.hpp)GetModuleHandle and GetProcAddress for initial resolution if those themselves are not yet resolved by this mechanism.CT_HASH) of DLL and API names for lookups. This prevents plaintext DLL and API names from appearing in the binary's import-related data or string tables when using these macros.K8_SYSCALL)Obfusk8 now integrates a state-of-the-art Indirect Syscall mechanism to bypass User-Mode Hooks (EDRs/AVs) and static analysis checks.
K8_SYSCALL("ZwOpenProcess", ...) instead of NtOpenProcess.OBF_METHOD)Obfusk8 now provides granular control over your binary's security through Method-Based Obfuscation. Instead of obfuscating your entire project (which can impact performance), you can now selectively protect specific, high-value functions or class methods.
Include the Pass
Ensure you include the method obfuscation logic in your project:
#include "../transform/PASSES/obf_cmethods.cxx"
The Macro Syntax
Define your method using the OBF_METHOD macro:
OBF_METHOD(ret_type, func_name, params, method_body)
ret_type: The return type of your function (e.g., bool, int, void*).func_name: The name of the method.params: The function parameters (must be enclosed in parentheses).method_body: The actual logic of your function enclosed in { }.In this example, PrintStatus is a normal, readable function. Obfusk8_PrintStatus is protected by Obfusk8.
#include "../Instrumentation/materialization/state/Obfusk8Core.hpp"
#include "../Instrumentation/materialization/transform/K8_UTILS/k8_utils.hpp" // for the printf_, u can change the printf_ with anything else...
class Obfusk8_C
{
public:
// standard method which is visible to reverse engineers
void PrintStatus(void)
{
printf_("method\n");
}
// Obfuscated method protected by Obfusk8
OBF_METHOD_(void, Obfusk8_PrintStatus, (void),
{
printf_("same method but Obfuscated\n");
})
};
_main({
Obfusk8_C *pp = new Obfusk8_C;
pp->PrintStatus();
pp->Obfusk8_PrintStatus();
delete pp;
})
You can view the full example here: obfusk8_methods.cpp
Obfusk8 provides helper classes that encapsulate common sets of Windows APIs. These classes automatically use the stealthy API resolution mechanism (STEALTH_API_OBFSTR) during their construction, ensuring that the underlying Windows functions are resolved without leaving obvious static import traces.
K8_ProcessManipulationAPIs::ProcessAPI (k8_ProcessManipulationAPIs.hpp):
OpenProcess, TerminateProcess, CreateRemoteThread, VirtualAllocEx, WriteProcessMemory, ReadProcessMemory, GetProcAddress, GetModuleHandleA, NtQueryInformationProcess, SuspendThread, and GetCurrentProcessId.Obfusk8Core.hpp)These are the building blocks used extensively throughout the library, especially in the _main macro and VM engine:
OBF_MBA_ADD, OBF_MBA_XOR). These are designed to be very difficult for decompilers to simplify back to their original forms.OBF_OPAQUE_PREDICATE_TRUE_1) or always false (e.g., OBF_OPAQUE_PREDICATE_FALSE_1). These conditions are constructed from complex, hard-to-statically-evaluate expressions involving __COUNTER__, __LINE__, __TIME__, and the _obf_global_opaque_seed. They create misleading code paths and can be used to guard dead code or force specific execution flows.OBF_CALL_ANY_LOCAL_JUNK: Calls one of many small, randomized junk functions defined in obf_junk_ns. These functions perform trivial, volatile operations and are selected randomly at compile time. Their purpose is to increase code entropy, break up simple code patterns, and potentially mislead signature-based detection or analysis tools.The Obfusk8 library is modular. Core functionality relies on:
Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hpp: (This file) The central header that orchestrates and provides the main obfuscation macros and primitives.Obfusk8/Instrumentation/materialization/transform/AES8.hpp: Provides AES-based compile-time string encryption and optional PE section manipulation features.Obfusk8/Instrumentation/materialization/transform/Resolve8.hpp: Implements the PEB-based stealthy Windows API resolution.Obfusk8/Instrumentation/materialization/transform/k8_indsys.hpp: Orchestrates the Indirect Syscall Engine. It manages the lifecycle of transition stubs and provides the interface for executing system calls through lateral memory gadgets.Obfusk8/Instrumentation/materialization/transform/getpeb8.hpp: Facilitates the initial bootstrap and PEB Discovery. It contains the custom hashing logic, native structure definitions, and the "Sorting Hat" algorithm for SSN deduction. It serves as the low-level foundation for all module enumeration tasks.
Optional helper API classes are provided in separate headers, typically located in subdirectories:k8_ProcessManipulationAPIs/k8_ProcessManipulationAPIs.hpp: For stealthy process manipulation APIs.k8_CryptographyAPIs/k8_CryptographyAPIs.hpp: For stealthy cryptography APIs.k8_NetworkingAPIs/k8_NetworkingAPIs.hpp: For stealthy networking APIs.k8_RegistryAPIs/k8_RegistryAPIs.hpp: For stealthy registry APIs.ida graph:

some chunks from ida pro:

detect it easy signatures results:

Crowdsourced YARA rules from virustotal:

memory map (from die):

sections:

bounded files:

Obfusk8 is designed to prioritize the bypass of static signature-based detection engines. Testing against industry-standard vendors shows that the core obfuscation logic remains undetected by major security products, including:
While static signatures are bypassed, certain Next-Gen AVs and EDRs (such as CrowdStrike or Symantec) may generate heuristic flags labeled as "suspicious" or "high Confidence Malicious." These detections are typically triggered by the high architectural complexity and the presence of custom PE sections rather than identifiable malicious code.
.themida, .vmp0, .enigma2) to mimic known commercial protectors.
.data_01, .rdata_aux). Standardizing section names often lowers the heuristic "uniqueness" score, making the binary appear more like a conventional compiled application.mov r10, rcx; mov eax, ssnnumber; syscall; ret) to execute system calls indirectly.Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hpp in your main project file (e.g., main.cpp).
#include "Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hpp" // Adjust path as needed
main function's body with the _main:
_main({
// Your application's original main code here
// Example:
// OBFUSCATE_STRING("Hello, Obfuscated World!").c_str();
// Using an API wrapper class
k8_NetworkingAPIs::NetworkingAPI* netAPI = new k8_NetworkingAPIs::NetworkingAPI;
if (netAPI->IsInitialized() && netAPI->pInternetOpenA) {
HINTERNET hInternet = netAPI->pInternetOpenA(OBFUSCATE_STRING("MyAgent").c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hInternet) {
// ... use hInternet ...
netAPI->pInternetCloseHandle(hInternet);
}
}
delete netAPI;
})
OBFUSCATE_STRING("your string") for all important string literals. Access the decrypted string via its method if needed for API calls, or use its other methods like if provided by .Compiler Requirement: This library is designed for C++17. The Microsoft C++ Compiler (cl.exe) is primarily targeted, especially for PE section features and SEH usage.
Getting cl.exe (MSVC Compiler) on Windows:
cl.exe is by installing Visual Studio. You can download the Visual Studio Community edition for free from the Visual Studio website.cl.exe.Include Paths:
Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hpp is in your compiler's include path.Obfusk8/Instrumentation/materialization/transform/AES8.hpp, Obfusk8/Instrumentation/materialization/transform/Resolve8.hpp, and the API wrapper directories (e.g., ) are not in the same directory as , ensure their paths are also correctly configured. uses relative paths like for some of its internal includes of the API wrappers, so the directory structure matters. If is at the root of your include directory for this library, then API wrappers should be in subdirectories like relative to where expects them or adjust the include paths within itself.git clone https://github.com/x86byte/Obfusk8.git and join to the dir cd Obfusk8cmake CMakeLists.txtcmake --build .after opening x64 Native Tools Command Prompt for VS 2022:

CMAKE && Microsoft Visual Studio:
microsoft visual studio, click on Ctrl + B to compile the project:
Considerations on Binary Size & Future Enhancements:
OBF_CALL_ANY_LOCAL_JUNK or the complexity of _main's loops) if binary size is a critical constraint.Obfusk8 includes a post-build script to further harden the compiled binary by removing forensic artifacts.
Obfusk8/SCRIPTS/obfuscate_pe.ps1PowerShell -NoProfile -ExecutionPolicy Bypass -File Obfusk8/SCRIPTS/obfuscate_pe.ps1 -Path "path\to\Obfusk8.exe"
[Obfusk8: C++17-Based Obfuscation Library - IDA pro Graph View] ~Video Demo
This project, Obfusk8, is an ongoing exploration into advanced C++ obfuscation techniques. The current version lays a strong foundation with a multitude of interwoven strategies.
Disclaimer Obfuscation is a layer of defense, not a foolproof solution. Determined attackers with sufficient skill and time can often reverse engineer obfuscated code. Obfusk8 aims to significantly raise the bar for such efforts. Use in conjunction with other security measures.
Get in Touch If you’d like to share feedback, discuss obfuscation techniques, report reverse engineering attempts, or just have a technical discussion, feel free to reach out directly. I’m always open to constructive conversations and collaboration (i would be happy to collab in obfuscation related projects or anything else).
OBF_BOGUS_FLOW_LABYRINTH, OBF_BOGUS_FLOW_GRID, OBF_BOGUS_FLOW_SCRAMBLE, OBF_BOGUS_FLOW_WEAVER, OBF_BOGUS_FLOW_CASCADE, and OBF_BOGUS_FLOW_CYCLONE to generate diverse and complex bogus flows.Runtime macro, SEH):
__except blocks can alter program state, making it hard to follow if the debugger skips exceptions.Runtime macro contains conditions that, if met (due to specific VM states or timing), could trigger __debugbreak() or throw exceptions, designed to disrupt debugging sessions._mainkernel32.dllntdll.dllPROCESSINFOCLASS enum for use with NtQueryInformationProcess.k8_CryptographyAPIs::CryptographyAPI (k8_CryptographyAPIs.hpp):
CryptAcquireContextA, CryptCreateHash, etc.)advapi32.dll (and kernel32.dll for core functions) stealthily.k8_NetworkingAPIs::NetworkingAPI (k8_NetworkingAPIs.hpp):
wininet.dll (e.g., InternetOpenA, HttpOpenRequestA, FtpPutFileA), urlmon.dll (e.g., URLDownloadToFileA), ws2_32.dll (e.g., socket, connect, WSAStartup), shell32.dll (e.g., ShellExecuteA), dnsapi.dll (e.g., DnsQuery_A), and mpr.dll (e.g., WNetOpenEnumA).STEALTH_API_OBFSTR and OBFUSCATE_STRING to resolve all required functions from their respective DLLs (and kernel32.dll for LoadLibraryA/GetLastError) without leaving obvious import traces.RegistryAPIs::RegistryAPI (k8_RegistryAPIs.hpp):
RegSetValueExA, RegCreateKeyExA, RegOpenKeyExA, RegQueryValueExA, RegCloseKey, etc.advapi32.dll (and kernel32.dll) stealthily during construction.NOP(): A macro that inserts volatile operations designed to prevent easy removal by optimizers and to subtly modify a global seed.OBF_JUMP_* macros): Creates goto statements whose conditions or targets are obfuscated, often relying on opaque predicates or MBA.OBF_SET_NEXT_STATE_* macros): Used in ICFF, these macros set the next state variable for the flattened control flow dispatcher using similar obfuscation techniques as the obfuscated jumps.OBF_STACK_ALLOC_MANIP, OBF_FAKE_PROLOGUE_MANIP): Allocates variable-sized chunks on the stack and performs bogus manipulations on them. Fake prologues attempt to confuse stack analysis.OBF_CALL_VIA_OBF_PTR): Function pointers are XORed with a dynamic key before and after being used, obscuring the true call target.K8_ASSUME(0): Used in dead code paths to hint to the MSVC compiler that these paths are unreachable, potentially allowing for different optimizations or code generation that might further confuse analysis if the assumption is violated by a patch..c_str().print_to_console()Obfusk8/Instrumentation/materialization/transform/AES8.hppSTEALTH_API_OBFSTR("dll_name.dll", "FunctionNameA") for direct stealthy API calls, or preferably use the API wrapper classes (e.g., K8_ProcessManipulationAPIs::ProcessAPI, k8_NetworkingAPIs::NetworkingAPI) for convenience and built-in stealth.OBF_BOGUS_FLOW_*, OBF_CALL_ANY_LOCAL_JUNK, NOP(), and other primitives in performance-insensitive critical sections of your code for added obfuscation layers.k8_NetworkingAPIs/Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hppObfusk8/Instrumentation/materialization/state/Obfusk8Core.hpp../Obfusk8Core.hppObfusk8/Instrumentation/materialization/state/Obfusk8Core.hppk8_NetworkingAPIs/Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hppObfusk8/Instrumentation/materialization/state/Obfusk8Core.hppCompilation Example (using Developer Command Prompt):
Assuming your main.cpp and the Obfusk8 headers are structured correctly, you can compile using a command similar to:
cl /std:c++17 /EHsc main.cpp
after opening x64 Native Tools Command Prompt for VS 2022:

/std:c++17: Specifies C++17 standard.
/EHsc: Specifies the C++ exception handling model.
main.cpp: Your main source file.
/I"path/to/your/obfusk8_includes": (Optional, if headers are not in default paths) Add the directory where Obfusk8/Instrumentation/materialization/state/Obfusk8Core.hpp and its dependencies are located. If they are in subdirectories, ensure the relative paths within Obfusk8Core.hpp match your layout.
Note on Libraries: While the stealth API resolution aims to avoid static linking for the obfuscated functions, the Windows SDK headers themselves might require certain .lib files to be available to the linker for resolving any non-obfuscated SDK usage or internal types (e.g., Ws2_32.lib, Wininet.lib, Advapi32.lib, etc.). For a simple project like cl /std:c++17 /EHsc main.cpp, the linker often resolves these automatically if they are standard Windows libraries.
CMAKE: you can Build Obfusk8 using cmake too.