๐ฆพ Ebyte-Go-Morpher
A technical overview of the Go source code obfuscator as implemented in tools/genobf.go.
๐ Description
Ebyte-Go-Morpher is a Go program that parses, analyzes, and rewrites Go source code to apply multiple layers of obfuscation. It operates directly on the Go Abstract Syntax Tree (AST) and generates both obfuscated source files and runtime decryption logic.
๐๏ธ Core Design
- Language: Go
- Entry Point:
main() in tools/genobf.go
- Primary Function: Obfuscates Go source code by traversing and rewriting the AST using Goโs standard library.
๐งฉ Key Components
๐ Obfuscator Types
- StringObfuscator: Encrypts string literals (XOR with random key), generates a unique function for each, and replaces calls to
OBF("...") with these functions.
- NumberObfuscator: Replaces integer literals with Mixed Boolean-Arithmetic (MBA) expressions, e.g.,
a = 42 โ a = (100 ^ 78).
- IdentifierObfuscator: Renames variables, functions, and local identifiers using FNV hash-based names (e.g.,
OBF_ABCDEF).
- TypeObfuscator: Renames struct types and tracks type references, including recursive types.
- FieldObfuscator: Renames struct fields, preserving field tags for reflection.
- FunctionObfuscator: Renames functions (except special ones like
main, init, etc.).
- MBAObfuscator: Applies De Morganโs laws and algebraic rewrites to boolean and arithmetic expressions.
๐ณ AST Processing
- ASTProcessor: Walks the AST, applies obfuscation logic, manages variable/function scope, and delegates to the appropriate obfuscator.
- Scope Tracking: Ensures local variable renaming is collision-free and context-aware.
๐ File Processing
- FileProcessor: Handles reading, parsing, and rewriting Go files. Applies obfuscation and writes changes back to disk.
๐ญ Code Generation
- CodeGenerator: Generates
include/preproc.go containing all runtime decryption and obfuscation logic for strings and numbers.
โ๏ธ Configuration
- Config struct: Controls which obfuscation features are enabled, which directories to skip, and output directory for generated code.
๐ Workflow
- ๐ Scan Files: Recursively walks the project directory, skipping configured folders (
vendor, tools, include by default).
- ๐ง Parse & Analyze: Parses each
.go file into an AST.
- ๐ฆพ Obfuscate: Applies string, number, identifier, type, field, and MBA obfuscation as configured.
- ๐ญ Generate Code: Writes decryption/obfuscation logic to
include/preproc.go.
- โ๏ธ Rewrite Source: Updates original source files to use obfuscated names and function calls.
๐ Supported Features
- ๐ String encryption for any string wrapped in
OBF()
- ๐ข Number obfuscation for all integer literals (except 0, 1, and constants)
- ๐ท๏ธ Identifier renaming for all local variables, functions, types, and struct fields (with scope awareness)
- ๐งฌ Type and field obfuscation for structs and their fields, with tag preservation
- ๐งฎ MBA transformations for boolean and arithmetic expressions
- ๐ ๏ธ Configurable: All features can be toggled in
NewConfig()
โ ๏ธ Limitations
- ๐ซ Does not obfuscate constants (Go
const values are skipped)
- ๐ก๏ธ Does not obfuscate exported identifiers by default (unless configured)
- ๐ช Reflection compatibility: Field tags are preserved, but heavy reflection use may need extra care
- ๐ Only processes
.go files; skips vendor, tools, and include by default
๐ ๏ธ Notable Implementation Details
- ๐ Uses Goโs standard library for AST manipulation (
go/ast, go/parser, go/token)
- ๐ท๏ธ Uses FNV hash for deterministic obfuscated names
- ๐ฒ Randomness for encryption and MBA expressions is sourced from
crypto/rand and math/rand
- ๐งน Generated code is formatted with
gofmt after writing
๐ Example (from code logic)
- main_test_input.go (for input, before)
- main_test_output.go (for output, after)
๐ Usage
- ๐ Place your Go project in the workspace.
- โถ๏ธ Run the obfuscator:
go generate
go run .
- ๐ฆ Obfuscated files and generated code will be written in-place and to the
include/ directory.
โ๏ธ Configuration
Edit the NewConfig() function in tools/genobf.go to customize:
- ๐ Directories to skip (
SkipDirs)
- ๐ท๏ธ Obfuscation tag for functions (
ObfuscateTag)
- ๐ฆ Output directory for generated code (
OutputDir)
- ๐ ๏ธ Toggle obfuscation for structs, variables, numbers, types, MBA, and fields
func NewConfig() *Config {
return &Config{
SkipDirs: []string{"vendor", "tools", "include"},
ObfuscateTag: "//obfuscate:function",
OutputDir: "include",
ObfuscateStructs: true,
ObfuscateVars: true,
ObfuscateNumbers: true,
ObfuscateTypes: true,
ObfuscateMBA: true,
ObfuscateFields: true,
}
}
๐ License
This project is licensed under the MIT License. See the LICENSE file for details.