A Go AST-based transpilation and code analysis tool designed to optimize performance, reduce binary size, and increase code security through bitwise transformations and obfuscation.
- About the Project
- Features
- Installation
- CLI Usage
- Transpilation and Optimization
- Contributing
- License
- Contact
Gastype (part of the Kubex project) is a powerful and flexible command-line tool for Go software engineers. It excels in static source code analysis (AST) to identify optimization opportunities and transform code automatically. The primary goal is to improve the performance, security, and efficiency of Go binaries, especially for production environments.
The tool offers a suite of transpilation "passes" that convert common, less-efficient code patterns into ultra-optimized bitwise operations.
- Parallel Type Checking: Execute type checks on multiple Go files simultaneously to ensure code quality in large projects.
- Optimization Analysis: Analyzes code and suggests optimizations, such as converting
boolfields instructsto bitwiseflags. - Automatic Transpilation: Automatically transforms source code, applying optimization passes to generate a high-performance binary.
- Code Obfuscation: Obfuscates variable names, function names, and string literals to enhance security and make reverse engineering more difficult.
- Control Structure Optimization: Converts long
if/elsechains into "jump tables" for faster execution. - Staged Pipeline: Provides a multi-stage workflow (
staged-transpilation) that includes transpilation, validation, obfuscation, and a final build.
Requirements: Go version 1.19 or later.
# Clone the repository
git clone https://github.com/kubex-ecosystem/gastype.git
cd gastype
# Build and install the binary
make installThe gastype CLI is the central point for all operations.
gastype check: Initiates type checking on Go files in a specific directory.gastype watch: Monitors a directory for file changes and automatically triggers type checking.
Examples:
# Runs type checking on the current directory with 4 workers
gastype check -d ./ -w 4 -o results.json
# Watches a project and sends email notifications in case of an error
gastype watch --dir ./my-project --email user@example.com --notifygastype transpile: The main command for transforming code. It supports various modes of operation.
Examples:
# Analyzes a project and displays optimization opportunities
gastype transpile --input ./src --mode analyze --format text
# Transpiles a single file, converting bool fields to bitwise flags
gastype transpile --input ./config.go --output ./config_optimized.go --mode transpile --passes bool-to-flags
# Transpiles an entire project with maximum obfuscation
gastype transpile --input ./my-app --output ./my-app-optimized --mode full-project --security 3gastype provides a four-stage optimization pipeline to ensure code robustness.
gastype transpile --no-obfuscate(Stage 1: Clean Transpilation)- Creates an optimized version of the code without obfuscation, ideal for debugging and testing.
gastype validate(Stage 2: Validation)- Ensures the optimized code behaves identically to the original by running tests and verifying the build.
gastype obfuscate(Stage 3: Selective Obfuscation)- Applies obfuscation only to the parts of the code that passed validation.
gastype build(Stage 4: Final Build)- Compiles the final binary, applying Go compiler optimizations, stripping debug symbols, and optionally compressing the binary with UPX.
The heart of gastype lies in its transpilation "passes". Each pass is a modular AST transformation that can be enabled independently.
Optimization Examples:
bool-to-flags: Converts structs with multipleboolfields into a singleuint64field with bitwise flags, reducing memory consumption and improving cache locality.jump-table: Transforms chainedif/elsestatements that compare the same variable into a map of functions, resulting in faster execution.string-obfuscate: Replaces string literals with byte arrays, making static analysis of the binary more difficult.
We appreciate your interest in contributing to gastype. Feel free to open issues or submit pull requests. Please refer to the Contributing Guide for more details.
This project is licensed under the MIT License.
- Developer: Rafael Mori (faelmori@gmail.com)
- GitHub: https://github.com/faelmori
