Skip to content

Mappings

Lenni0451 edited this page Dec 16, 2023 · 3 revisions

ClassTransform supports using mappings when injecting into obfuscated code.
The mappings can be used to remap the class names and method/field names to their obfuscated names or to remap the entire transformer.

Implemented mapper

The following mapper implementations are available:

Name Description
VoidMapper Only used internally. Does not remap anything.
RawMapper Just takes a MapRemapper instance and uses it for remapping.
ProguardMapper Takes a Proguard mappings file and loads it.
SrgMapper Takes a SRG mappings file and loads it.
TinyV2Mapper Takes a TinyV2 mappings file and loads it.

Mapper config

There are a few options that can be used to change the behavior of the mapper.
The following options are available:

Option Name Description
fillSuperMappings When enabled, the mapper will automatically add mappings for super classes and interfaces.
superMappingsFailStrategy Defines how the mapper should handle missing super mappings.
remapTransformer When enabled, transformers will be remapped before they are applied.

The options can be set by passing a MapperConfig instance to the mapper constructor:

MapperConfig config = MapperConfig
        .create()
        .fillSuperMappings(true/*, FailStrategy.CANCEL*/)
        .remapTransformer(true);

AMapper mapper = new ProguardMapper(config, new File(...));

Creating a mapper

A remapper extends the AMapper class and implements the void init() method.
The init method is called by the TransformerManager when the mappings are loaded.

Inside the init method, you need to add all mappings into the remapper instance which is directly accessible (this.remapper).
You can look at the implemented mappers in the net.lenni0451.classtransform.mappings.impl package here for examples of how to load and add mappings.

Example:

public class ExampleMapper extends AMapper {

    protected void init() throws Throwable {
        this.remapper.addClassMapping("net/lenni0451/example/ExampleClass", "net/lenni0451/example/ExampleClassObf");
        this.remapper.addMethodMapping("net/lenni0451/example/ExampleClass", "exampleMethod", "()V", "exampleMethodObf");
        this.remapper.addFieldMapping("net/lenni0451/example/ExampleClass", "exampleField", "Ljava/lang/String;", "exampleFieldObf");
    }

}