MCPcopy Index your code
hub / github.com/Lenni0451/ClassTransform

github.com/Lenni0451/ClassTransform @v1.15.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.15.0 ↗ · + Follow
981 symbols 3,431 edges 208 files 293 documented · 30%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ClassTransform

A lightweight injection library using ASM. It abstracts away the complexity of ASM and makes it more user-friendly.\ ClassTransform is inspired by the SpongePowered/Mixin library. If you have used Mixins before, you will feel right at home with ClassTransform.

Because ClassTransform offers similar functionality to Mixins, you can use the MixinsTranslator to use Mixins code without any changes.\ It also supports some annotations from the popular LlamaLad7/MixinExtras extension library.

ClassTransform was mainly designed for use with Java agents which is the recommended and most stable way to use it.\ However, it can also be used manually by invoking the TransformerManager directly or by using the InjectionClassLoader.

Usage

For usage examples and a detailed explanation of the library, please check out the wiki. All commonly used classes and methods are documented there and in the Javadocs.

If you want to quickly get started and figure the rest out yourself, check out the Quick Start section.

Gradle/Maven

To use ClassTransform with Gradle/Maven you can get it from maven central.\ You can also find instructions on how to implement it into your build script there.

Gradle

You need to replace `x.x.x with the latest version number.\ You can find it on the maven central page or in the GitHub releases.

repositories {
    mavenCentral()
}

dependencies {
    include "net.lenni0451.classtransform:core:x.x.x"
}

Maven

You need to replace `x.x.x with the latest version number.\ You can find it on the maven central page or in the GitHub releases.

<dependency>
  <groupId>net.lenni0451.classtransform</groupId>
  <artifactId>core</artifactId>
  <version>x.x.x</version>
</dependency>

Jar File

If you just want the latest jar file you can download it from my Jenkins.

Quick Start

This is a simple example of how to use ClassTransform together with a Java agent.

Creating a TransformerManager, adding a transformer and hooking it into the instrumentation.

public static void agentmain(final String args, final Instrumentation instrumentation) {
    TransformerManager transformerManager = new TransformerManager(new BasicClassProvider());
    transformerManager.addTransformer("org.example.MyTransformer");
    transformerManager.hookInstrumentation(instrumentation);
}

A simple transformer could look like this:

import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CInject;

@CTransformer(OtherClass.class)
public class MyTransformer {

    @CInject(method = "<init>", target = @CTarget("RETURN"))
    public void inject() {
        System.out.println("Hello from the constructor!");
    }

}

This transformer injects into the constructor of OtherClass and prints a message.

Extension points exported contracts — how you extend this code

IClassProvider (Interface)
A provider for class bytecode. [14 implementers]
src/main/java/net/lenni0451/classtransform/utils/tree/IClassProvider.java
AnnotationTranslator (Interface)
(no doc) [9 implementers]
MixinsTranslator/src/main/java/net/lenni0451/classtransform/mixinstranslator/impl/AnnotationTranslator.java
IInjectionTarget (Interface)
The interface which is used to define a target for an injection. [10 implementers]
src/main/java/net/lenni0451/classtransform/targets/IInjectionTarget.java
IBytecodeTransformer (Interface)
A bytecode transformer like ClassFileTransformer. [24 implementers]
src/main/java/net/lenni0451/classtransform/transformer/IBytecodeTransformer.java
IRawTransformer (Interface)
A transformer which has access to the parsed class node of the transformed class. [24 implementers]
src/main/java/net/lenni0451/classtransform/transformer/IRawTransformer.java
IAnnotationCoprocessor (Interface)
Coprocessor for annotation handlers. The instance of this class will only be used once. Used to add support for spec [4 …
src/main/java/net/lenni0451/classtransform/transformer/IAnnotationCoprocessor.java

Core symbols most depended-on inside this repo

equals
called by 292
src/main/java/net/lenni0451/classtransform/utils/ASMComparator.java
add
called by 270
src/main/java/net/lenni0451/classtransform/transformer/HandlerPosition.java
add
called by 169
src/main/java/net/lenni0451/classtransform/transformer/coprocessor/AnnotationCoprocessorList.java
get
called by 139
src/main/java/net/lenni0451/classtransform/utils/IOSupplier.java
getOpcode
called by 129
src/main/java/net/lenni0451/classtransform/targets/impl/OpcodeTarget.java
equals
called by 70
src/main/java/net/lenni0451/classtransform/utils/tree/ClassTree.java
getType
called by 65
src/main/java/net/lenni0451/classtransform/utils/CoprocessorUtils.java
methodDescriptor
called by 59
src/main/java/net/lenni0451/classtransform/utils/Types.java

Shape

Method 757
Class 194
Interface 16
Enum 14

Languages

Java100%

Modules by API surface

src/main/java/net/lenni0451/classtransform/utils/ASMUtils.java38 symbols
src/main/java/net/lenni0451/classtransform/TransformerManager.java30 symbols
src/test/java/net/lenni0451/classtransform/transformer/impl/CRedirectAnnotationHandlerTest.java28 symbols
src/main/java/net/lenni0451/classtransform/utils/annotations/AnnotationParser.java24 symbols
src/main/java/net/lenni0451/classtransform/utils/loader/InjectionClassLoader.java21 symbols
src/main/java/net/lenni0451/classtransform/utils/annotations/AnnotationUtils.java20 symbols
src/main/java/net/lenni0451/classtransform/mappings/impl/special/MetaTinyV2Mapper.java18 symbols
src/main/java/net/lenni0451/classtransform/utils/mappings/MapRemapper.java17 symbols
src/test/java/net/lenni0451/classtransform/transformer/impl/CModifyConstantAnnotationHandlerTest.java16 symbols
src/main/java/net/lenni0451/classtransform/mappings/AMapper.java16 symbols
src/main/java/net/lenni0451/classtransform/utils/attributes/SharedVariableAttribute.java15 symbols
src/main/java/net/lenni0451/classtransform/utils/Codifier.java15 symbols

For agents

$ claude mcp add ClassTransform \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page