Skip to content

Commit

Permalink
Arguments format changed
Browse files Browse the repository at this point in the history
  • Loading branch information
DosX-dev committed May 12, 2024
1 parent 7f41cd6 commit 456e574
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ This will automatically obfuscate your code during compilation, ensuring protect

> Available options for protection configuring:
> ```c
> // Additional options
> #define cflow_v2 1 // More powerful Control Flow obfuscation (slowly!)
> #define antidebug_v2 1 // Use better dynamic anti-debugging protection
> #define fake_signs 1 // Adds fake signatures of various protectors or packers
>
> // Advanced code protection (see the "Virtualization" part of the documentation!)
> #define virt 1 // Allows you to use the functions of a math VM
> #define VIRT 1 // Allows you to use the functions of a math VM
>
> // Additional options
> #define CFLOW_V2 1 // More powerful Control Flow obfuscation (slowly!)
> #define ANTIDEBUG_V2 1 // Use better dynamic anti-debugging protection
> #define FAKE_SIGNS 1 // Adds fake signatures of various protectors or packers
>
> // Disabling default features
> #define no_cflow 1 // Don't use Control-Flow obfuscation
> #define no_antidebug 1 // Don't build in debugging protection
> #define NO_CFLOW 1 // Don't use Control-Flow obfuscation
> #define NO_ANTIDEBUG 1 // Don't build in debugging protection
> ```
> or use it with compiler args:
>
> ```
> tcc "app.c" -w -D no_cflow -D antidebug_v2 -D fake_signs
> tcc "app.c" -w -D NO_CFLOW -D ANTIDEBUG_V2 -D FAKE_SIGNS
> ```
⚠️ When compiling an application with obfuscation, use the `-w` argument to suppress warnings. Otherwise, the console will display numerous intimidating logs that have no impact on the final result. There's no need to be alarmed by them.
Expand All @@ -51,7 +51,7 @@ if (!licenseExpired()) {
```
## 👺 Virtualization
This is a protection technique in which certain calculations are performed through an embedded virtual machine upon command. Makes analysis of mathematical operations **very difficult**! It will work with the `virt` option enabled (and only!). Otherwise, all virtual machine commands will be replaced by ordinary mathematical operators.
This is a protection technique in which certain calculations are performed through an embedded virtual machine upon command. Makes analysis of mathematical operations **very difficult**! It will work with the `VIRT` option enabled (and only!). Otherwise, all virtual machine commands will be replaced by ordinary mathematical operators.
⚠️ Virtualization in critical locations can impact optimization. Use with caution only in areas where it is really needed
Expand Down Expand Up @@ -81,7 +81,7 @@ This is a protection technique in which certain calculations are performed throu
A simple example of using virtualization::
```c
// ...
#define virt 1
#define VIRT 1
// ...
if (VM_EQU(VM_ADD(2, 2), 4)) {
Expand All @@ -93,20 +93,20 @@ if (VM_EQU(VM_ADD(2, 2), 4)) {
You can find examples of using all the functions of a virtual machine in the file [tests/virtualmachine.c](tests/virtualmachine.c)
## ❓ Example of using
If you need advanced protection against skilled reversers, use `cflow_v2` and `antidebug_v2` options.
If you need advanced protection against skilled reversers, use `CFLOW_V2` and `ANTIDEBUG_V2` options.
```c
// Let's obfuscate your code!
#include <stdio.h>
#define virt 1 // [+] Use math virtual machine
#define VIRT 1 // [+] Use math virtual machine
#define cflow_v2 1 // [+] ControlFlow v2
#define fake_signs 1 // [+] Fake signatures
#define antidebug_v2 1 // [+] AntiDebug v2
#define CFLOW_V2 1 // [+] ControlFlow v2
#define FAKE_SIGNS 1 // [+] Fake signatures
#define ANTIDEBUG_V2 1 // [+] AntiDebug v2
#define no_cflow 0 // [-] Disable ControlFlow
#define no_antidebug 0 // [-] Disable AntiDebug
#define NO_CFLOW 0 // [-] Disable ControlFlow
#define NO_ANTIDEBUG 0 // [-] Disable AntiDebug
#include "obfus.h"
Expand All @@ -122,6 +122,7 @@ void main() {
printf("Error!\n");
}
free(out);
int result = VM_ADD(5, 7); // 5 + 7
Expand Down
45 changes: 27 additions & 18 deletions include/obfus.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,35 @@
Coded by (C) DosX, 2024
[Additional options]
~ cflow_v2 = more powerful Control Flow obfuscation (slowly!)
~ antidebug_v2 = use better dynamic anti-debugging protection
~ fake_signs = adds fake signatures of various protectors or packers
~ CFLOW_V2 = more powerful Control Flow obfuscation (slowly!)
~ ANTIDEBUG_V2 = use better dynamic anti-debugging protection
~ FAKE_SIGNS = adds fake signatures of various protectors or packers
[Advanced code protection]
~ virt = allows you to use the functions of a math VM
~ VIRT = allows you to use the functions of a math VM
[Disabling default features]
~ no_cflow = disable control flow obfuscation
~ no_antidebug = disable antidebug protection
~ NO_CFLOW = disable control flow obfuscation
~ NO_ANTIDEBUG = disable antidebug protection
~ no_obf = disable obfuscation
~ NO_OBF = disable obfuscation
GitHub:
-> https://github.com/DosX-dev/obfus.h
*/

// legacy args support
#define ANTIDEBUG_V2 antidebug_v2
#define NO_ANTIDEBUG no_antidebug
#define FAKE_SIGNS fake_signs
#define CFLOW_V2 cflow_v2
#define NO_CFLOW no_cflow
#define NO_OBF no_obf
#define VIRT virt

// if virtualization disabled
#if no_obf == 1 || virt != 1
#if NO_OBF == 1 || VIRT != 1
#define VM_ADD(num1, num2) num1 + num2
#define VM_SUB(num1, num2) num1 - num2
#define VM_MUL(num1, num2) num1 *num2
Expand All @@ -49,7 +58,7 @@
#define VM_GTR_DBL(num1, num2) num1 > num2
#endif

#if !no_obf
#if !NO_OBF

#include <conio.h>
#include <stdio.h>
Expand All @@ -69,7 +78,7 @@
#define SECTION_ATTRIBUTE(NAME) __attribute__((section(NAME)))

// Fake signatures ;)
#if defined(fake_signs) && (fake_signs != 0) && SUPPORTED
#if defined(FAKE_SIGNS) && (FAKE_SIGNS != 0) && SUPPORTED

static const char FAKE_ENIGMAVM_1[] SECTION_ATTRIBUTE(".enigma1") = {0};
static const char FAKE_ENIGMAVM_2[] SECTION_ATTRIBUTE(".enigma2") = {0};
Expand Down Expand Up @@ -353,7 +362,7 @@ int condition_Proxy(int junk, int condition) {

// =============================================================
// Anti-Tamper for Control-Flow obfuscation (beta!)
#if antitamper == 1 && no_cflow != 1
#if antitamper == 1 && NO_CFLOW != 1
int obfhIsBlockValidated = 0;
int validateBlock() { // returns false
obfhIsBlockValidated = 1;
Expand All @@ -374,9 +383,9 @@ int isBlockValidated() { // returns true if validateBlock() executed

// =============================================================
// Control Flow (global)
#if no_cflow != 1
#if NO_CFLOW != 1

#if cflow_v2 == 1 // Control flow obfuscation for 'if' & 'for', V2 (strong!)
#if CFLOW_V2 == 1 // Control flow obfuscation for 'if' & 'for', V2 (strong!)

// if (V2)
#define if(condition) \
Expand Down Expand Up @@ -433,7 +442,7 @@ int isBlockValidated() { // returns true if validateBlock() executed

// =============================================================
// Virtualization (global)
#if virt == 1
#if VIRT == 1
typedef enum {
OP__ADD = RND(0, 900) * __COUNTER__ * 5,
OP__SUB = RND(1000, 1900) * __COUNTER__ * 5,
Expand Down Expand Up @@ -781,9 +790,9 @@ char *LoadLibraryA_Proxy(LPCSTR lpLibFileName) {

// =============================================================
// Anti-Debug (global)
#if no_antidebug != 1
#if NO_ANTIDEBUG != 1

#if antidebug_v2 == 1 // for antidebug_v2
#if ANTIDEBUG_V2 == 1 // for ANTIDEBUG_V2
void ad_ZeroDRs(PCONTEXT pCtx) {
BREAK_STACK_1;
pCtx->Dr0 = _0;
Expand Down Expand Up @@ -841,7 +850,7 @@ int IsDebuggerPresent_Proxy() {
BREAK_STACK_1;
NOP_FLOOD;
BREAK_STACK_2;
#if antidebug_v2 == 1
#if ANTIDEBUG_V2 == 1

// Registers validation
HANDLE hMainThread;
Expand Down Expand Up @@ -929,7 +938,7 @@ void loop() {
__asm__ __volatile("ret"); \
crash(); \
} else { \
0.0 / !IsDebuggerPresent(); \
0.0 / !IsDebuggerPresent(); \
};

#else
Expand Down
2 changes: 1 addition & 1 deletion tests/virtualmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string.h>
#include <windows.h>

#define virt 1
#define VIRT 1
#include "../include/obfus.h"

void main() {
Expand Down

0 comments on commit 456e574

Please sign in to comment.