Skip to content

Tonic-Box/YABR

Repository files navigation

YABR - Yet Another Bytecode Reader/Writer

YABR is a bidirectional Java (de)compiler, program-analysis, and transformation framework. It spans bytecode, SSA, a structured IR, execution, and source, so a program can be lifted, analyzed, transformed, executed, compiled, and decompiled across one ecosystem.

Projects using YABR

  • JStudio - A Java reverse engineering and analysis IDE.
  • J2CS - A Java to C# transpiler.
  • Dukes-8-Bit-Challenge - A game-jam submission using YABR in buildSrc/ for compile-time transformations.

Building

  • Java 11+
./gradlew build
./gradlew :all:shadowJar

Installation

The published artifact is the merged jar from the all module. Via JitPack:

repositories {
    mavenCentral()
    maven { url = uri("https://jitpack.io") }
}

dependencies {
    implementation("com.github.Tonic-Box.YABR:all:<version>")
}

Quick Start

// Load a class
ClassPool pool = ClassPool.getDefault();
ClassFile cf = pool.loadClass(inputStream);

// Create a new class with a default constructor
int access = new AccessBuilder().setPublic().build();
ClassFile newClass = ClassFactory.createClass(pool, "com/example/MyClass", access);

// Add a field with a getter and setter
FieldEntry field = newClass.createNewField(access, "value", "I", new ArrayList<>());
ClassFactory.generateGetter(newClass, field, false);
ClassFactory.generateSetter(newClass, field, false);

// Write the class
newClass.rebuild();
byte[] bytes = newClass.write();

Examples

Runnable examples are in examples/src/main/java/com/tonic/demo/, including class creation, SSA transformation, LLVM lowering, AST mutation, decompilation, call graphs, dependency analysis, type inference, and pattern search.

Documentation

Getting Started

Guide Description
Quick Start Load, create, and modify classes in five minutes
Architecture Module structure and design

Class Files & Bytecode

Guide Description
Class Files ClassPool, ClassFile, ConstPool
Bytecode API Low-level bytecode editing
Generation API Fluent class/method generation
Visitors Traversal and transformation patterns
Frame Computation StackMapTable generation

SSA & IR

Guide Description
SSA Guide SSA intermediate representation
SSA Transforms Optimization and analysis passes
LLVM Lowering Lower SSA IR to textual LLVM IR
LLVM Lifting Lift LLVM IR back to SSA

Source & Decompilation

Guide Description
AST Guide AST recovery, mutation, and emission
AST Editor ExprEditor-style AST transformation
Parser API Java source parser
Decompiler API Class -> Java source decompilation

Analysis

Guide Description
Analysis APIs Overview of the analysis suite
Call Graph API Call-graph construction
Data Flow API Data-flow analysis
Dependency API Dependency analysis
PDG API Program Dependence Graph with slicing
SDG API Interprocedural System Dependence Graph
CPG API Code Property Graph with taint analysis
Pattern Search API Structural bytecode pattern search
Similarity API Method similarity and fingerprinting
Type Inference API Type inference
Xref API Cross-references

Execution & Runtime

Guide Description
Execution API Concrete bytecode execution
Simulation API Abstract simulation
Abstract Execution API Operand-stack and local def-use
Instrumentation API Bytecode instrumentation and hooks
Verifier API Bytecode verification

Language & Query

Guide Description
Query API Bytecode query language
Renamer API Class, method, and field renaming

Project Layout

YABR is a Gradle multi-project. Production code is split into layered modules (core, bytecode, renamer, ssa, source, analyses, execution, query) whose dependencies are acyclic and build-enforced; the all module merges them into a single jar. See Architecture.

Acknowledgements

Inspired by classpooly.

License

MIT

About

A unified, bidirectional framework for Java compilation, analysis, and transformation.

Topics

Resources

License

Stars

22 stars

Watchers

1 watching

Forks

Contributors

Languages