Ebyte-Go-Morpher

command module
v0.0.0-...-8ab2f96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 3 Imported by: 0

README ยถ

๐Ÿฆพ 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

  1. ๐Ÿ” Scan Files: Recursively walks the project directory, skipping configured folders (vendor, tools, include by default).
  2. ๐Ÿง  Parse & Analyze: Parses each .go file into an AST.
  3. ๐Ÿฆพ Obfuscate: Applies string, number, identifier, type, field, and MBA obfuscation as configured.
  4. ๐Ÿญ Generate Code: Writes decryption/obfuscation logic to include/preproc.go.
  5. โœ๏ธ 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

  1. ๐Ÿ“‚ Place your Go project in the workspace.
  2. โ–ถ๏ธ Run the obfuscator:
    go generate 
    go run .
    
  3. ๐Ÿ“ฆ 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.

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Directories ยถ

Path Synopsis
* โ”‚ Author : Evilbytecode * โ”‚ Name : Ebyte-Go-Morpher * โ”‚ Contact : https://github.com/Evilbytecode * * This program is distributed for educational purposes only.
* โ”‚ Author : Evilbytecode * โ”‚ Name : Ebyte-Go-Morpher * โ”‚ Contact : https://github.com/Evilbytecode * * This program is distributed for educational purposes only.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL