Files in directory /examples from the latest check-in
- README.md
- target.c
- target.go
Examples
C tutorial
Throughout this walk-through, we'll use the target function
in target.c.
The CFG produced by this function (including GIMPLE IR) is as follows:
gcc -fplugin=../build/hellscape.so \
-fplugin-arg-hellscape-viz=. \
-c target.c -o /dev/null

The compiler plugin is easy to use; let's enable each pass one-by-one and look at the CFG, then at the end run all 3 passes together.
Instruction Substitution
For the first magic trick, instruction substitution. The command below,
- Sets the RNG seed to
0xdeadbeefas to ensure binaries are reproducable. Outside of testing, you probably want to omit that flag to produce diverse binaries, - Enables the subsitution pass (note you can enable "looping", i.e.: running the pass over itself multiple times with
-fplugin-arg-hellscape-subLoop=X.)
$ gcc -fPIC -fplugin=/path/to/hellscape.so -fplugin-arg-hellscape-seed=deadbeef -fplugin-arg-hellscape-sub target.c
Let's view the produced CFG with the Viz class:

Bogus Control Flow
Now for a smokescreen: bogus control flow. The command below,
- Sets the RNG seed (see above),
- Enables the bogus control flow pass which wraps every basic block in an opaque condition that always evaluates to
true.
$ gcc -fPIC -fplugin=/path/to/hellscape.so -fplugin-arg-hellscape-seed=deadbeef -fplugin-arg-hellscape-bcf target.c
Again, viewing the CFG:

Flattening
The last trick (for now) is flattening. The command below,
- Sets the RNG seed (see above),
- Enables the flattening pass.
$ gcc -fPIC -fplugin=/path/to/hellscape.so -fplugin-arg-hellscape-seed=deadbeef -fplugin-arg-hellscape-fla target.c
Then, viewing the CFG:

All at once
Simply rolling all the above commands together, we get the following CFG (view in a browser):
$ gcc -fPIC -fplugin=/path/to/hellscape.so -fplugin-arg-hellscape-seed=deadbeef -fplugin-arg-hellscape-fla -fplugin-arg-hellscape-bcf -fplugin-arg-hellscape-sub target.c

And of course in IDA it is even worse due to switch lowering:

gccgo
This example explains building a Go executable obfuscated with Hellscape.
For this guide, you will need gccgo installed. The standard Go executable will
NOT work with this example.
In the CMakeLists.txt, edit the execute_process command to use the gccgo
executable instead of the standard gcc executable. Then, build Hellscape as
normal.
It can then be used with the main.go provided here with the example command (to enable all passes):
$ gccgo -fplugin=/path/to/hellscape.so -fplugin-arg-hellscape-seed=deadbeef -fplugin-arg-hellscape-fla -fplugin-arg-hellscape-bcf -fplugin-arg-hellscape-sub main.go