Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
Add Go example
Browse files Browse the repository at this point in the history
  • Loading branch information
meme committed Jun 2, 2020
1 parent 3e92835 commit 7fbe3d0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ If you ever get stuck, reference one of the existing passes, they're well docume
4) Register it under the `PassManager` by adding a new option, `register_pass_info` and `register_callback`, as necessary,
5) Submit the pass for review.
Note that for as pass to be accepted upstream, it must compile for a `gcc` build that has `--enable-checking=yes,rtl,tree` added. (You will need to re-build `gcc` for your target architecture with `--enable-checking`.)
Additionally: If you experience crashes when developing your plug-in, you can debug them by passing `-wrapper gdb,--args` to `gcc`. (Run `gcc` in `gdb`, effectively.)
### License
Hellscape is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Expand Down
1 change: 1 addition & 0 deletions examples/gccgo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a.out
17 changes: 17 additions & 0 deletions examples/gccgo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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):

```sh
$ 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
```
24 changes: 24 additions & 0 deletions examples/gccgo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import "fmt"

func target(n uint32) uint32 {
var mod uint32 = n % 4
var result uint32 = 0

if mod == 0 {
result = (n | 0xbaaad0bf) * (2 ^ n)
} else if mod == 1 {
result = (n & 0xbaaad0bf) * (3 + n)
} else if mod == 2 {
result = (n ^ 0xbaaad0bf) * (4 | n)
} else {
result = (n + 0xbaaad0bf) * (5 & n)
}

return result
}

func main() {
fmt.Printf("%d\n", target(10))
}

0 comments on commit 7fbe3d0

Please sign in to comment.