GithubHelp home page GithubHelp logo

garzon / obfacros Goto Github PK

View Code? Open in Web Editor NEW
40.0 1.0 6.0 38 KB

obfacros - a set of C++ macros that can be used to obfuscate your c/c++ code, to make executables harder for reverse-engineering.

C++ 100.00%

obfacros's Introduction

obfacros

obfacros - a set of macros written in C++14 with g++5, that can be used to obfuscate your c/c++ code, to make it harder for reverse-engineering.

I use this to generate the CTF challenge of "Obfuscating Macros I/II" in DDCTF / *ctf 2019.

Demo

Please find the demo.cpp. To compile, just g++ demo.cpp -std=c++14 -o demo.out.

Features

  • easy to use: header-only, just include the provided obfacros.hpp and write your code in a way similar to plain c/c++, then compile with g++.
  • easy to disable: to disable the obfuscation, you just need to replace the macros by normal code like: #define FOR(init, cond, end, ...) for(init; cond; end) { __VA_ARGS__; }. Check demo_obfacros_disabled.cpp and the section A way to disable the obfuscation in the document.
  • much harder for reverse-engineering: by flattening the control flow and using dynamic JUMPs

If necessary, the macros may be modified into another form which do not require any features of C++14 or g++.

Usage

  1. #include "obfacros.hpp"
  2. write your code using the macros rather than the for/if/while c/c++ keywords
  3. compile and enjoy!

Basic rules and WARNINGS

  1. Using all macros(like FOR/IF/RETURN...) ONLY IN the obfacros scope(between FUNCTION_START(var_to_accept_return_value) and FUNCTION_END;)
  2. DO NOT declare variables inside the scope. Please declare all the variables outside in advance.
  3. Avoid using {} in the obfacros scope. If you want to use {} anyway, please do not use any obfacros inside the {}(before the bracket is closed).

Document

Basic features

FUNCTION_START(retVal) and FUNCTION_END;

Write this before using any other obfacros to create a scope of obfacros (or we call it obfacros scope or the scope).

retVal specifies the variable to be assigned when RETURN. If you do not use RETURN, just fill in a random variable.

FOR(init, cond, end, ...);

just like for (init; cond; end) { ... } in c/c++

WHILE(expr, ...);

just like while (expr) { ... } in c/c++

IF(expr, ...); and IF_ELSE(expr, ...)

just like if (expr) { ... } in c/c++, but with a difference that:

if (expr) { code; } should be written in the form of IF(expr, code);
if (expr) { code; } else { code2; } should be written in the form of IF_ELSE(expr, code) ELSE (code2);

In a word, before you use any ELIF or ELSE, please check the previous macro is with the suffix _ELSE. Likewise, we also have ELIF and ELIF_ELSE.

RETURN(val);

Jump to next line of FUNCTION_END(jump out of the scope of obfacros) and assign the val to retVal that specified in FUNCTION_START.

Advanced features

If you use any of advanced features, you may not easily disable the obfuscation because there is no corresponding features in the language of c/c++.

For demo, please visit the source code of one of my CTF reverse challenge: https://github.com/garzon/my_ctf_challenges_source_code/tree/master/starctf_2019/obfuscating_macros_II

BLOCK(...);

Manually create a code block. Just like { code }; in c/c++.

MAKE_BLOCK_WITH_NAME(name, ...);

Create a code block with a name. Just like if (false) { name: code }; in c/c++.

INCLUDE_BLOCK(name);

"include" a previously defined named block(by MAKE_BLOCK_WITH_NAME). Like a function call in c/c++ with variables shared.

A way to disable the obfuscation

  1. Comment out #include "obfacros.hpp"
  2. Using the code below to replace the obfacros:
#define FUNCTION_START(...)
#define FUNCTION_END
#define BLOCK(...) { __VA_ARGS__; }
#define IF(expr, ...) if (expr) { __VA_ARGS__; } else {}
#define FOR(init, cond, end, ...) for(init; cond; end) { __VA_ARGS__; }
#define WHILE(expr, ...) while(expr) { __VA_ARGS__; }
#define IF_ELSE(expr, ...) if (expr) { __VA_ARGS__; }
#define ELSE(...) else { __VA_ARGS__; }
#define ELIF(expr, ...) else { if (expr) { __VA_ARGS__; } }
#define ELIF_ELSE(expr, ...) else if (expr) { __VA_ARGS__; }
#define RETURN(...) return (__VA_ARGS__)

obfacros's People

Contributors

garzon avatar

Stargazers

 avatar  avatar  avatar Krittanut Siripornnoppakhun avatar Koray avatar 暮阔 avatar Esonhugh Skyworship avatar koalr avatar Trey Jenkins avatar  avatar Jesse Pledger avatar Snyzer avatar  avatar Vilari avatar  avatar  avatar avery avatar Ceramicskate0 avatar  avatar C. Tan avatar pivasicq avatar wdnmd avatar  avatar Wawan avatar aweNousaku avatar Tou avatar Kuldip Patel avatar  avatar  avatar r4b3rt-isc avatar _ avatar 0w3 avatar Infko avatar  avatar Junpeng Wan avatar driverxdw avatar  avatar 0xpoker avatar cow avatar Aekr1_         //akrasia avatar

Watchers

James Cloos avatar

obfacros's Issues

Love this!

You can mark as fixed. But I just want to congratulate you for making this.

I had a similar idea of writing C++ macros to create arithmetic identities using a combination of trig, algebriac geometry, discrete math, and linear algebra.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.