mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 00:39:34 +00:00
Refactor AP to support different mapping environments, closes #141
This commit is contained in:
1 parent
6a8f127ed5
commit
8d87440faf
48 files changed
+2988
-1003
No files matched your search
@@ -194,6 +194,16 @@ public abstract class MirrorUtils {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getDescriptor(Element elem) {
|
||||
if (elem instanceof ExecutableElement) {
|
||||
return MirrorUtils.generateSignature((ExecutableElement)elem);
|
||||
} else if (elem instanceof VariableElement) {
|
||||
return MirrorUtils.getInternalName((VariableElement)elem);
|
||||
}
|
||||
|
||||
return MirrorUtils.getInternalName(elem.asType());
|
||||
}
|
||||
|
||||
public static String getTypeName(TypeMirror type) {
|
||||
switch (type.getKind()) {
|
||||
|
||||
@@ -27,11 +27,7 @@ package org.spongepowered.tools.obfuscation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
@@ -46,9 +42,13 @@ import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinInjectorHandler.AnnotatedElementInjectionPoint;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinInjectorHandler.AnnotatedElementInjector;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinOverwriteHandler.AnnotatedElementOverwrite;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator.ValidationPass;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.ITypeHandleProvider;
|
||||
import org.spongepowered.tools.obfuscation.struct.Message;
|
||||
@@ -78,6 +78,11 @@ class AnnotatedMixin {
|
||||
*/
|
||||
private final IObfuscationManager obf;
|
||||
|
||||
/**
|
||||
* Generated mappings
|
||||
*/
|
||||
private final IMappingConsumer mappings;
|
||||
|
||||
/**
|
||||
* Mixin class
|
||||
*/
|
||||
@@ -112,17 +117,7 @@ class AnnotatedMixin {
|
||||
* True if we will actually process remappings for this mixin
|
||||
*/
|
||||
private final boolean remap;
|
||||
|
||||
/**
|
||||
* Stored (ordered) field mappings
|
||||
*/
|
||||
private final Map<ObfuscationType, Set<String>> fieldMappings = new HashMap<ObfuscationType, Set<String>>();
|
||||
|
||||
/**
|
||||
* Stored (ordered) method mappings
|
||||
*/
|
||||
private final Map<ObfuscationType, Set<String>> methodMappings = new HashMap<ObfuscationType, Set<String>>();
|
||||
|
||||
|
||||
/**
|
||||
* Overwrite handler
|
||||
*/
|
||||
@@ -142,6 +137,7 @@ class AnnotatedMixin {
|
||||
this.annotation = MirrorUtils.getAnnotation(type, Mixin.class);
|
||||
this.typeProvider = ap.getTypeProvider();
|
||||
this.obf = ap.getObfuscationManager();
|
||||
this.mappings = this.obf.createMappingConsumer();
|
||||
this.messager = ap;
|
||||
this.mixin = type;
|
||||
this.handle = new TypeHandle(type);
|
||||
@@ -158,11 +154,6 @@ class AnnotatedMixin {
|
||||
|
||||
this.remap = AnnotatedMixins.getRemapValue(this.annotation) && this.targets.size() > 0;
|
||||
|
||||
for (ObfuscationType obfType : ObfuscationType.values()) {
|
||||
this.fieldMappings.put(obfType, new LinkedHashSet<String>());
|
||||
this.methodMappings.put(obfType, new LinkedHashSet<String>());
|
||||
}
|
||||
|
||||
this.overwrites = new AnnotatedMixinOverwriteHandler(ap, this);
|
||||
this.shadows = new AnnotatedMixinShadowHandler(ap, this);
|
||||
this.injectors = new AnnotatedMixinInjectorHandler(ap, this);
|
||||
@@ -239,9 +230,9 @@ class AnnotatedMixin {
|
||||
}
|
||||
|
||||
private void addSoftTarget(TypeHandle type, String reference) {
|
||||
ObfuscationData<String> obfClassData = this.obf.getObfClass(type);
|
||||
ObfuscationData<String> obfClassData = this.obf.getDataProvider().getObfClass(type);
|
||||
if (!obfClassData.isEmpty()) {
|
||||
this.obf.addClassMapping(this.classRef, reference, obfClassData);
|
||||
this.obf.getReferenceManager().addClassMapping(this.classRef, reference, obfClassData);
|
||||
}
|
||||
|
||||
this.addTarget(type);
|
||||
@@ -316,54 +307,28 @@ class AnnotatedMixin {
|
||||
return this.remap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored field mappings
|
||||
*/
|
||||
public Set<String> getFieldMappings(ObfuscationType type) {
|
||||
return this.fieldMappings.get(type);
|
||||
public IMappingConsumer getMappings() {
|
||||
return this.mappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored method mappings
|
||||
*/
|
||||
public Set<String> getMethodMappings(ObfuscationType type) {
|
||||
return this.methodMappings.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all stored mappings
|
||||
*/
|
||||
public void clear() {
|
||||
this.fieldMappings.clear();
|
||||
this.methodMappings.clear();
|
||||
}
|
||||
|
||||
public void registerOverwrite(ExecutableElement method, AnnotationMirror overwrite) {
|
||||
this.overwrites.registerOverwrite(method, overwrite);
|
||||
this.overwrites.registerOverwrite(new AnnotatedElementOverwrite(method, overwrite));
|
||||
}
|
||||
|
||||
public void registerShadow(VariableElement field, AnnotationMirror shadow, boolean shouldRemap) {
|
||||
this.shadows.registerShadow(field, shadow, shouldRemap);
|
||||
this.shadows.registerShadow(this.shadows.new AnnotatedElementShadowField(field, shadow, shouldRemap));
|
||||
}
|
||||
|
||||
public void registerShadow(ExecutableElement method, AnnotationMirror shadow, boolean shouldRemap) {
|
||||
this.shadows.registerShadow(method, shadow, shouldRemap);
|
||||
this.shadows.registerShadow(this.shadows.new AnnotatedElementShadowMethod(method, shadow, shouldRemap));
|
||||
}
|
||||
|
||||
public Message registerInjector(ExecutableElement method, AnnotationMirror inject, boolean remap) {
|
||||
return this.injectors.registerInjector(method, inject, remap);
|
||||
public Message registerInjector(ExecutableElement method, AnnotationMirror inject, boolean shouldRemap) {
|
||||
return this.injectors.registerInjector(new AnnotatedElementInjector(method, inject, shouldRemap));
|
||||
}
|
||||
|
||||
public int registerInjectionPoint(ExecutableElement element, AnnotationMirror inject, AnnotationMirror at) {
|
||||
return this.injectors.registerInjectionPoint(element, inject, at);
|
||||
}
|
||||
|
||||
void addFieldMapping(ObfuscationType type, String mapping) {
|
||||
this.fieldMappings.get(type).add(mapping);
|
||||
}
|
||||
|
||||
void addMethodMapping(ObfuscationType type, String mapping) {
|
||||
this.methodMappings.get(type).add(mapping);
|
||||
return this.injectors.registerInjectionPoint(new AnnotatedElementInjectionPoint(element, inject, at));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,9 @@ import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.ConstraintParser;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
import org.spongepowered.asm.util.throwables.ConstraintViolationException;
|
||||
@@ -50,6 +52,32 @@ import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
|
||||
*/
|
||||
abstract class AnnotatedMixinElementHandler {
|
||||
|
||||
/**
|
||||
* An annotated element to be processed by this element handler
|
||||
*
|
||||
* @param <E> type of inner element
|
||||
*/
|
||||
abstract static class AnnotatedElement<E extends Element> {
|
||||
|
||||
private final E element;
|
||||
|
||||
private final AnnotationMirror annotation;
|
||||
|
||||
public AnnotatedElement(E element, AnnotationMirror annotation) {
|
||||
this.element = element;
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
public E getElement() {
|
||||
return this.element;
|
||||
}
|
||||
|
||||
public AnnotationMirror getAnnotation() {
|
||||
return this.annotation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A name of an element which may have aliases
|
||||
*/
|
||||
@@ -153,6 +181,17 @@ abstract class AnnotatedMixinElementHandler {
|
||||
public String baseName() {
|
||||
return this.baseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the obfuscated name for this element
|
||||
*
|
||||
* @param name Mapping containing new name
|
||||
* @return fluent interface
|
||||
*/
|
||||
public ShadowElementName setObfuscatedName(IMapping<?> name) {
|
||||
this.obfuscated = name.getName();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the obfuscated name for this element
|
||||
@@ -161,7 +200,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
* @return fluent interface
|
||||
*/
|
||||
public ShadowElementName setObfuscatedName(String name) {
|
||||
this.obfuscated = name.substring(name.lastIndexOf('/') + 1);
|
||||
this.obfuscated = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -241,20 +280,20 @@ abstract class AnnotatedMixinElementHandler {
|
||||
}
|
||||
|
||||
if (targetMember.isField()) {
|
||||
ObfuscationData<String> obfFieldData = this.obf.getObfFieldRecursive(targetMember);
|
||||
ObfuscationData<MappingField> obfFieldData = this.obf.getDataProvider().getObfFieldRecursive(targetMember);
|
||||
if (obfFieldData.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for @At(" + key + ") '" + target + "'", element, inject);
|
||||
return false;
|
||||
}
|
||||
this.obf.addFieldMapping(this.classRef, target, targetMember, obfFieldData);
|
||||
this.obf.getReferenceManager().addFieldMapping(this.classRef, target, targetMember, obfFieldData);
|
||||
} else {
|
||||
ObfuscationData<SrgMethod> obfMethodData = this.obf.getObfMethodRecursive(targetMember);
|
||||
ObfuscationData<MappingMethod> obfMethodData = this.obf.getDataProvider().getObfMethodRecursive(targetMember);
|
||||
if (obfMethodData.isEmpty()) {
|
||||
if (targetMember.owner == null || !targetMember.owner.startsWith("java/lang/")) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find method mapping for @At(" + key + ") '" + target + "'", element, inject);
|
||||
}
|
||||
}
|
||||
this.obf.addMethodMapping(this.classRef, target, targetMember, obfMethodData);
|
||||
this.obf.getReferenceManager().addMethodMapping(this.classRef, target, targetMember, obfMethodData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -262,9 +301,17 @@ abstract class AnnotatedMixinElementHandler {
|
||||
/**
|
||||
* Add a field mapping to the local table
|
||||
*/
|
||||
protected final void addFieldMapping(ObfuscationType type, ShadowElementName name) {
|
||||
String mapping = String.format("FD: %s %s", this.classRef + "/" + name.name(), this.classRef + "/" + name.obfuscated());
|
||||
this.mixin.addFieldMapping(type, mapping);
|
||||
protected final void addFieldMapping(ObfuscationType type, ShadowElementName name, String mcpSignature, String obfSignature) {
|
||||
this.addFieldMapping(type, name.name(), name.obfuscated(), mcpSignature, obfSignature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a field mapping to the local table
|
||||
*/
|
||||
protected final void addFieldMapping(ObfuscationType type, String mcpName, String obfName, String mcpSignature, String obfSignature) {
|
||||
MappingField from = new MappingField(this.classRef, mcpName, mcpSignature);
|
||||
MappingField to = new MappingField(this.classRef, obfName, obfSignature);
|
||||
this.mixin.getMappings().addFieldMapping(type, from, to);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,8 +325,9 @@ abstract class AnnotatedMixinElementHandler {
|
||||
* Add a method mapping to the local table
|
||||
*/
|
||||
protected final void addMethodMapping(ObfuscationType type, String mcpName, String obfName, String mcpSignature, String obfSignature) {
|
||||
String mapping = String.format("MD: %s %s %s %s", this.classRef + "/" + mcpName, mcpSignature, this.classRef + "/" + obfName, obfSignature);
|
||||
this.mixin.addMethodMapping(type, mapping);
|
||||
MappingMethod from = new MappingMethod(this.classRef, mcpName, mcpSignature);
|
||||
MappingMethod to = new MappingMethod(this.classRef, obfName, obfSignature);
|
||||
this.mixin.getMappings().addMethodMapping(type, from, to);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,6 +365,14 @@ abstract class AnnotatedMixinElementHandler {
|
||||
}
|
||||
}
|
||||
|
||||
protected final void validateTarget(Element element, AnnotationMirror annotation, AliasedElementName name, String type) {
|
||||
if (element instanceof ExecutableElement) {
|
||||
this.validateTargetMethod((ExecutableElement)element, annotation, name, type);
|
||||
} else if (element instanceof VariableElement) {
|
||||
this.validateTargetField((VariableElement)element, annotation, name, type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the specified method exists in all targets and raises
|
||||
* warnings where appropriate
|
||||
|
||||
+58
-29
@@ -30,13 +30,12 @@ import java.util.Map;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
@@ -47,24 +46,52 @@ import org.spongepowered.tools.obfuscation.struct.Message;
|
||||
*/
|
||||
class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
/**
|
||||
* Injector element
|
||||
*/
|
||||
static class AnnotatedElementInjector extends AnnotatedElement<ExecutableElement> {
|
||||
|
||||
private final boolean shouldRemap;
|
||||
|
||||
public AnnotatedElementInjector(ExecutableElement element, AnnotationMirror annotation, boolean shouldRemap) {
|
||||
super(element, annotation);
|
||||
this.shouldRemap = shouldRemap;
|
||||
}
|
||||
|
||||
public boolean shouldRemap() {
|
||||
return this.shouldRemap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection point element
|
||||
*/
|
||||
static class AnnotatedElementInjectionPoint extends AnnotatedElement<ExecutableElement> {
|
||||
|
||||
private final AnnotationMirror at;
|
||||
|
||||
public AnnotatedElementInjectionPoint(ExecutableElement element, AnnotationMirror inject, AnnotationMirror at) {
|
||||
super(element, inject);
|
||||
this.at = at;
|
||||
}
|
||||
|
||||
public AnnotationMirror getAt() {
|
||||
return this.at;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AnnotatedMixinInjectorHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
super(ap, mixin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link org.spongepowered.asm.mixin.injection.Inject} method
|
||||
*
|
||||
* @param method Callback method
|
||||
* @param inject Inject annotation
|
||||
* @param remap
|
||||
* @return pending error message or null if no error condition
|
||||
*/
|
||||
public Message registerInjector(ExecutableElement method, AnnotationMirror inject, boolean remap) {
|
||||
public Message registerInjector(AnnotatedElementInjector elem) {
|
||||
if (this.mixin.isInterface()) {
|
||||
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", method);
|
||||
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", elem.getElement());
|
||||
}
|
||||
|
||||
String originalReference = MirrorUtils.<String>getAnnotationValue(inject, "method");
|
||||
String originalReference = MirrorUtils.<String>getAnnotationValue(elem.getAnnotation(), "method");
|
||||
MemberInfo targetMember = MemberInfo.parse(originalReference);
|
||||
if (targetMember.name == null) {
|
||||
return null;
|
||||
@@ -73,15 +100,15 @@ class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
|
||||
try {
|
||||
targetMember.validate();
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), method, inject);
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), elem.getAnnotation());
|
||||
}
|
||||
|
||||
String type = "@" + inject.getAnnotationType().asElement().getSimpleName() + "";
|
||||
String type = "@" + elem.getAnnotation().getAnnotationType().asElement().getSimpleName() + "";
|
||||
if (targetMember.desc != null) {
|
||||
this.validateReferencedTarget(method, inject, targetMember, type);
|
||||
this.validateReferencedTarget(elem.getElement(), elem.getAnnotation(), targetMember, type);
|
||||
}
|
||||
|
||||
if (!remap || !this.validateSingleTarget(type, method)) {
|
||||
if (!elem.shouldRemap() || !this.validateSingleTarget(type, elem.getElement())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -89,20 +116,22 @@ class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
|
||||
if (desc == null) {
|
||||
if (this.mixin.getPrimaryTarget().isImaginary()) {
|
||||
this.ap.printMessage(Kind.WARNING, type + " target requires method signature because enclosing type information is unavailable",
|
||||
method, inject);
|
||||
elem.getElement(), elem.getAnnotation());
|
||||
} else if (!Constants.CTOR.equals(targetMember.name)) {
|
||||
this.ap.printMessage(Kind.WARNING, "Unable to determine signature for " + type + " target method", method, inject);
|
||||
this.ap.printMessage(Kind.WARNING, "Unable to determine signature for " + type + " target method",
|
||||
elem.getElement(), elem.getAnnotation());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ObfuscationData<SrgMethod> obfData = this.obf.getObfMethod(new SrgMethod(this.mixin.getPrimaryTargetRef() + "/" + targetMember.name, desc));
|
||||
MappingMethod targetMethod = new MappingMethod(this.mixin.getPrimaryTargetRef(), targetMember.name, desc);
|
||||
ObfuscationData<MappingMethod> obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
|
||||
if (obfData.isEmpty()) {
|
||||
Kind error = Constants.CTOR.equals(targetMember.name) ? Kind.WARNING : Kind.ERROR;
|
||||
return new Message(error, "No obfuscation mapping for " + type + " target " + targetMember.name, method, inject);
|
||||
return new Message(error, "No obfuscation mapping for " + type + " target " + targetMember.name, elem.getElement(), elem.getAnnotation());
|
||||
}
|
||||
|
||||
this.obf.addMethodMapping(this.classRef, originalReference, obfData);
|
||||
this.obf.getReferenceManager().addMethodMapping(this.classRef, originalReference, obfData);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -110,22 +139,22 @@ class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
|
||||
* Register a {@link org.spongepowered.asm.mixin.injection.At} annotation
|
||||
* and process the references
|
||||
*/
|
||||
public int registerInjectionPoint(Element element, AnnotationMirror inject, AnnotationMirror at) {
|
||||
public int registerInjectionPoint(AnnotatedElementInjectionPoint elem) {
|
||||
if (this.mixin.isInterface()) {
|
||||
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", element);
|
||||
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", elem.getElement());
|
||||
}
|
||||
|
||||
if (!AnnotatedMixins.getRemapValue(at)) {
|
||||
if (!AnnotatedMixins.getRemapValue(elem.getAt())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String type = MirrorUtils.<String>getAnnotationValue(at, "value");
|
||||
String target = MirrorUtils.<String>getAnnotationValue(at, "target");
|
||||
int remapped = this.remapReference(type + ".<target>", target, element, inject, at) ? 1 : 0;
|
||||
String type = MirrorUtils.<String>getAnnotationValue(elem.getAt(), "value");
|
||||
String target = MirrorUtils.<String>getAnnotationValue(elem.getAt(), "target");
|
||||
int remapped = this.remapReference(type + ".<target>", target, elem.getElement(), elem.getAnnotation(), elem.getAt()) ? 1 : 0;
|
||||
|
||||
// Pattern for replacing references in args, not used yet
|
||||
// if ("SOMETYPE".equals(type)) {
|
||||
// Map<String, String> args = InjectorHandler.getAtArgs(at);
|
||||
// Map<String, String> args = InjectorHandler.getAtArgs(e.getAt());
|
||||
// this.remapReference(type + ".args[target]", args.get("target"));
|
||||
// }
|
||||
|
||||
|
||||
+30
-18
@@ -30,7 +30,7 @@ import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
@@ -39,42 +39,54 @@ import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
*/
|
||||
class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
/**
|
||||
* Overwrite element
|
||||
*/
|
||||
static class AnnotatedElementOverwrite extends AnnotatedElement<ExecutableElement> {
|
||||
|
||||
public AnnotatedElementOverwrite(ExecutableElement element, AnnotationMirror annotation) {
|
||||
super(element, annotation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AnnotatedMixinOverwriteHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
super(ap, mixin);
|
||||
}
|
||||
|
||||
void registerOverwrite(ExecutableElement method, AnnotationMirror overwrite) {
|
||||
AliasedElementName name = new AliasedElementName(method, overwrite);
|
||||
this.validateTargetMethod(method, overwrite, name, "@Overwrite");
|
||||
this.checkConstraints(method, overwrite);
|
||||
public void registerOverwrite(AnnotatedElementOverwrite elem) {
|
||||
AliasedElementName name = new AliasedElementName(elem.getElement(), elem.getAnnotation());
|
||||
this.validateTargetMethod(elem.getElement(), elem.getAnnotation(), name, "@Overwrite");
|
||||
this.checkConstraints(elem.getElement(), elem.getAnnotation());
|
||||
|
||||
if (!this.mixin.remap() || !this.validateSingleTarget("@Overwrite", method)) {
|
||||
if (!this.mixin.remap() || !this.validateSingleTarget("@Overwrite", elem.getElement())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String mcpName = method.getSimpleName().toString();
|
||||
String mcpSignature = MirrorUtils.generateSignature(method);
|
||||
ObfuscationData<SrgMethod> obfData = this.obf.getObfMethod(new SrgMethod(this.mixin.getPrimaryTargetRef() + "/" + mcpName, mcpSignature));
|
||||
String mcpName = elem.getElement().getSimpleName().toString();
|
||||
String mcpSignature = MirrorUtils.generateSignature(elem.getElement());
|
||||
MappingMethod targetMethod = new MappingMethod(this.mixin.getPrimaryTargetRef(), mcpName, mcpSignature);
|
||||
ObfuscationData<MappingMethod> obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
|
||||
|
||||
if (obfData.isEmpty()) {
|
||||
Kind error = Kind.ERROR;
|
||||
|
||||
try {
|
||||
// Try to access isStatic from com.sun.tools.javac.code.Symbol
|
||||
Method md = method.getClass().getMethod("isStatic");
|
||||
if (((Boolean)md.invoke(method)).booleanValue()) {
|
||||
Method md = elem.getElement().getClass().getMethod("isStatic");
|
||||
if (((Boolean)md.invoke(elem.getElement())).booleanValue()) {
|
||||
error = Kind.WARNING;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// well, we tried
|
||||
}
|
||||
|
||||
this.ap.printMessage(error, "No obfuscation mapping for @Overwrite method", method);
|
||||
this.ap.printMessage(error, "No obfuscation mapping for @Overwrite method", elem.getElement());
|
||||
return;
|
||||
}
|
||||
|
||||
for (ObfuscationType type : obfData) {
|
||||
SrgMethod obfMethod = obfData.get(type);
|
||||
MappingMethod obfMethod = obfData.get(type);
|
||||
this.addMethodMapping(type, mcpName, obfMethod.getSimpleName(), mcpSignature, obfMethod.getDesc());
|
||||
}
|
||||
|
||||
@@ -82,20 +94,20 @@ class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
|
||||
Kind overwriteErrorKind = "error".equalsIgnoreCase(this.ap.getOption(SupportedOptions.OVERWRITE_ERROR_LEVEL))
|
||||
? Kind.ERROR : Kind.WARNING;
|
||||
|
||||
String javadoc = this.ap.getJavadocProvider().getJavadoc(method);
|
||||
String javadoc = this.ap.getJavadocProvider().getJavadoc(elem.getElement());
|
||||
if (javadoc == null) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", method);
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", elem.getElement());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!javadoc.toLowerCase().contains("@author")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", method);
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", elem.getElement());
|
||||
}
|
||||
|
||||
if (!javadoc.toLowerCase().contains("@reason")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", method);
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", elem.getElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -25,18 +25,127 @@
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping.Type;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
|
||||
|
||||
/**
|
||||
* A module for {@link AnnotatedMixin} which handles shadowed fields and methods
|
||||
*/
|
||||
class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
/**
|
||||
* A shadow element to be processed
|
||||
*
|
||||
* @param <E> Type of inner element
|
||||
* @param <M> Mapping type of mapping used by this element
|
||||
*/
|
||||
abstract static class AnnotatedElementShadow<E extends Element, M extends IMapping<M>> extends AnnotatedElement<E> {
|
||||
|
||||
private final boolean shouldRemap;
|
||||
|
||||
private final ShadowElementName name;
|
||||
|
||||
private final String desc;
|
||||
|
||||
private final Type type;
|
||||
|
||||
protected AnnotatedElementShadow(E element, AnnotationMirror annotation, boolean shouldRemap, Type type) {
|
||||
super(element, annotation);
|
||||
this.shouldRemap = shouldRemap;
|
||||
this.name = new ShadowElementName(element, annotation);
|
||||
this.desc = MirrorUtils.getDescriptor(element);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean shouldRemap() {
|
||||
return this.shouldRemap;
|
||||
}
|
||||
|
||||
public ShadowElementName getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public Type getElementType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getElementType().name().toLowerCase();
|
||||
}
|
||||
|
||||
public ShadowElementName setObfuscatedName(IMapping<?> name) {
|
||||
return this.setObfuscatedName(name.getName());
|
||||
}
|
||||
|
||||
public ShadowElementName setObfuscatedName(String name) {
|
||||
return this.getName().setObfuscatedName(name);
|
||||
}
|
||||
|
||||
public ObfuscationData<M> getObfuscationData(IObfuscationDataProvider provider, String owner) {
|
||||
return provider.getObfEntry(this.getMapping(owner, this.getName().toString(), this.getDesc()));
|
||||
}
|
||||
|
||||
public abstract M getMapping(String owner, String name, String desc);
|
||||
|
||||
public abstract void addMapping(ObfuscationType type, IMapping<?> remapped);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shadow field element
|
||||
*/
|
||||
class AnnotatedElementShadowField extends AnnotatedElementShadow<VariableElement, MappingField> {
|
||||
|
||||
public AnnotatedElementShadowField(VariableElement element, AnnotationMirror annotation, boolean shouldRemap) {
|
||||
super(element, annotation, shouldRemap, Type.FIELD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField getMapping(String owner, String name, String desc) {
|
||||
return new MappingField(owner, name, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMapping(ObfuscationType type, IMapping<?> remapped) {
|
||||
AnnotatedMixinShadowHandler.this.addFieldMapping(type, this.setObfuscatedName(remapped), this.getDesc(), remapped.getDesc());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shadow method element
|
||||
*/
|
||||
class AnnotatedElementShadowMethod extends AnnotatedElementShadow<ExecutableElement, MappingMethod> {
|
||||
|
||||
public AnnotatedElementShadowMethod(ExecutableElement element, AnnotationMirror annotation, boolean shouldRemap) {
|
||||
super(element, annotation, shouldRemap, Type.METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod getMapping(String owner, String name, String desc) {
|
||||
return new MappingMethod(owner, name, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMapping(ObfuscationType type, IMapping<?> remapped) {
|
||||
AnnotatedMixinShadowHandler.this.addMethodMapping(type, this.setObfuscatedName(remapped), this.getDesc(), remapped.getDesc());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AnnotatedMixinShadowHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
super(ap, mixin);
|
||||
@@ -45,49 +154,22 @@ class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
|
||||
/**
|
||||
* Register a {@link org.spongepowered.asm.mixin.Shadow} field
|
||||
*/
|
||||
public void registerShadow(VariableElement field, AnnotationMirror shadow, boolean remap) {
|
||||
ShadowElementName name = new ShadowElementName(field, shadow);
|
||||
this.validateTargetField(field, shadow, name, "@Shadow");
|
||||
public void registerShadow(AnnotatedElementShadow<?, ?> elem) {
|
||||
this.validateTarget(elem.getElement(), elem.getAnnotation(), elem.getName(), "@Shadow");
|
||||
|
||||
if (!remap || !this.validateSingleTarget("@Shadow", field)) {
|
||||
if (!elem.shouldRemap() || !this.validateSingleTarget("@Shadow", elem.getElement())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ObfuscationData<String> obfFieldData = this.obf.getObfField(this.mixin.getPrimaryTargetRef() + "/" + name);
|
||||
|
||||
if (obfFieldData.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Unable to locate obfuscation mapping for @Shadow field", field, shadow);
|
||||
return;
|
||||
}
|
||||
|
||||
for (ObfuscationType type : obfFieldData) {
|
||||
String fieldName = obfFieldData.get(type);
|
||||
this.addFieldMapping(type, name.setObfuscatedName(fieldName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link org.spongepowered.asm.mixin.Shadow} method
|
||||
*/
|
||||
public void registerShadow(ExecutableElement method, AnnotationMirror shadow, boolean remap) {
|
||||
ShadowElementName name = new ShadowElementName(method, shadow);
|
||||
this.validateTargetMethod(method, shadow, name, "@Shadow");
|
||||
|
||||
if (!remap || !this.validateSingleTarget("@Shadow", method)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String mcpSignature = MirrorUtils.generateSignature(method);
|
||||
ObfuscationData<SrgMethod> obfData = this.obf.getObfMethod(new SrgMethod(this.mixin.getPrimaryTargetRef() + "/" + name, mcpSignature));
|
||||
ObfuscationData<? extends IMapping<?>> obfData = elem.getObfuscationData(this.obf.getDataProvider(), this.mixin.getPrimaryTargetRef());
|
||||
|
||||
if (obfData.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Unable to locate obfuscation mapping for @Shadow method", method, shadow);
|
||||
this.ap.printMessage(Kind.WARNING, "Unable to locate obfuscation mapping for @Shadow " + elem, elem.getElement(), elem.getAnnotation());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (ObfuscationType type : obfData) {
|
||||
SrgMethod obfMethod = obfData.get(type);
|
||||
this.addMethodMapping(type, name.setObfuscatedName(obfMethod.getName()), mcpSignature, obfMethod.getDesc());
|
||||
elem.addMapping(type, obfData.get(type));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Mixin info manager, stores all of the mixin info during processing and also
|
||||
* manages access to the srgs
|
||||
* manages access to the mappings
|
||||
*/
|
||||
class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITypeHandleProvider, IJavadocProvider {
|
||||
|
||||
@@ -118,7 +118,7 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp
|
||||
/**
|
||||
* Obfuscation manager
|
||||
*/
|
||||
private final ObfuscationManager obf;
|
||||
private final IObfuscationManager obf;
|
||||
|
||||
/**
|
||||
* Rule validators
|
||||
@@ -145,12 +145,13 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp
|
||||
* Private constructor, get instances using {@link #getMixinsForEnvironment}
|
||||
*/
|
||||
private AnnotatedMixins(ProcessingEnvironment processingEnv) {
|
||||
this.printMessage(Kind.NOTE, "SpongePowered Mixin Annotation Processor v" + MixinBootstrap.VERSION);
|
||||
|
||||
this.env = this.detectEnvironment(processingEnv);
|
||||
this.processingEnv = processingEnv;
|
||||
this.targets = this.initTargetMap();
|
||||
this.obf = new ObfuscationManager(this);
|
||||
|
||||
this.printMessage(Kind.NOTE, "SpongePowered Mixin Annotation Processor v" + MixinBootstrap.VERSION);
|
||||
this.obf.init();
|
||||
|
||||
this.validators = ImmutableList.<IMixinValidator>of(
|
||||
new ParentValidator(this),
|
||||
@@ -233,6 +234,10 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp
|
||||
|
||||
@Override
|
||||
public String getOption(String option) {
|
||||
if (option == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String value = this.processingEnv.getOptions().get(option);
|
||||
if (value != null) {
|
||||
return value;
|
||||
@@ -270,17 +275,17 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out generated srgs
|
||||
* Write out generated mappings
|
||||
*/
|
||||
public void writeSrgs() {
|
||||
this.obf.writeSrgs(this.mixins);
|
||||
public void writeMappings() {
|
||||
this.obf.writeMappings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out stored mappings
|
||||
* Write out stored references
|
||||
*/
|
||||
public void writeRefs() {
|
||||
this.obf.writeRefs();
|
||||
public void writeReferences() {
|
||||
this.obf.writeReferences();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.spongepowered.tools.MirrorUtils;
|
||||
|
||||
/**
|
||||
* Annotation processor which finds {@link Inject} and {@link At} annotations in
|
||||
* mixin classes and generates SRG mappings
|
||||
* mixin classes and generates obfuscation mappings
|
||||
*/
|
||||
@SupportedAnnotationTypes({
|
||||
"org.spongepowered.asm.mixin.injection.Inject",
|
||||
@@ -83,7 +83,7 @@ public class InjectionObfuscationProcessor extends MixinProcessor {
|
||||
super.postProcess(roundEnv);
|
||||
|
||||
try {
|
||||
this.mixins.writeRefs();
|
||||
this.mixins.writeReferences();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet.Pair;
|
||||
|
||||
/**
|
||||
* Reference implementation of mapping consumer
|
||||
*/
|
||||
class Mappings implements IMappingConsumer {
|
||||
|
||||
/**
|
||||
* Stored (ordered) field mappings
|
||||
*/
|
||||
private final Map<ObfuscationType, MappingSet<MappingField>> fieldMappings =
|
||||
new HashMap<ObfuscationType, MappingSet<MappingField>>();
|
||||
|
||||
/**
|
||||
* Stored (ordered) method mappings
|
||||
*/
|
||||
private final Map<ObfuscationType, MappingSet<MappingMethod>> methodMappings =
|
||||
new HashMap<ObfuscationType, MappingSet<MappingMethod>>();
|
||||
|
||||
|
||||
public Mappings() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
for (ObfuscationType obfType : ObfuscationType.types()) {
|
||||
this.fieldMappings.put(obfType, new MappingSet<MappingField>());
|
||||
this.methodMappings.put(obfType, new MappingSet<MappingMethod>());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored field mappings
|
||||
*/
|
||||
@Override
|
||||
public MappingSet<MappingField> getFieldMappings(ObfuscationType type) {
|
||||
MappingSet<MappingField> mappings = this.fieldMappings.get(type);
|
||||
return mappings != null ? mappings : new MappingSet<MappingField>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored method mappings
|
||||
*/
|
||||
@Override
|
||||
public MappingSet<MappingMethod> getMethodMappings(ObfuscationType type) {
|
||||
MappingSet<MappingMethod> mappings = this.methodMappings.get(type);
|
||||
return mappings != null ? mappings : new MappingSet<MappingMethod>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all stored mappings
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
this.fieldMappings.clear();
|
||||
this.methodMappings.clear();
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFieldMapping(ObfuscationType type, MappingField from, MappingField to) {
|
||||
MappingSet<MappingField> mappings = this.fieldMappings.get(type);
|
||||
if (mappings == null) {
|
||||
mappings = new MappingSet<MappingField>();
|
||||
this.fieldMappings.put(type, mappings);
|
||||
}
|
||||
mappings.add(new Pair<MappingField>(from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMethodMapping(ObfuscationType type, MappingMethod from, MappingMethod to) {
|
||||
MappingSet<MappingMethod> mappings = this.methodMappings.get(type);
|
||||
if (mappings == null) {
|
||||
mappings = new MappingSet<MappingMethod>();
|
||||
this.methodMappings.put(type, mappings);
|
||||
}
|
||||
mappings.add(new Pair<MappingMethod>(from, to));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public abstract class MixinProcessor extends AbstractProcessor {
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedOptions() {
|
||||
return SupportedOptions.all;
|
||||
return SupportedOptions.getAllOptions();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
|
||||
/**
|
||||
* Return value struct for various obfuscation queries performed by the mixin
|
||||
@@ -43,7 +43,7 @@ import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
* {@link #get} to retrieve the remapped entries for each key.</p>
|
||||
*
|
||||
* @param <T> Contained type of the data, usually {@link String} for field
|
||||
* and type obfuscations, and {@link SrgMethod} for methods.
|
||||
* and type obfuscations, and {@link MappingMethod} for methods.
|
||||
*/
|
||||
public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
private String listValues() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (ObfuscationType type : this.data.keySet()) {
|
||||
sb.append(type.name()).append('=').append(this.data.get(type)).append(',');
|
||||
sb.append(type.getKey()).append('=').append(this.data.get(type)).append(',');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping.Type;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
|
||||
|
||||
/**
|
||||
* Implementation of obfuscation provider which queries all obfuscation
|
||||
* environments to return mappings for each source member
|
||||
*/
|
||||
public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
|
||||
/**
|
||||
* Annotation processor
|
||||
*/
|
||||
private final IMixinAnnotationProcessor ap;
|
||||
|
||||
/**
|
||||
* Available obfuscation environments
|
||||
*/
|
||||
private final List<ObfuscationEnvironment> environments;
|
||||
|
||||
public ObfuscationDataProvider(IMixinAnnotationProcessor ap, List<ObfuscationEnvironment> environments) {
|
||||
this.ap = ap;
|
||||
this.environments = environments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfEntryRecursive(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ObfuscationData<T> getObfEntryRecursive(final MemberInfo targetMember) {
|
||||
MemberInfo currentTarget = targetMember;
|
||||
ObfuscationData<String> obfTargetNames = this.getObfClass(currentTarget.owner);
|
||||
ObfuscationData<T> obfData = this.getObfEntry(currentTarget);
|
||||
try {
|
||||
while (obfData.isEmpty()) {
|
||||
TypeHandle targetType = this.ap.getTypeProvider().getTypeHandle(currentTarget.owner);
|
||||
if (targetType == null) {
|
||||
return obfData;
|
||||
}
|
||||
TypeHandle superClass = targetType.getSuperclass();
|
||||
if (superClass == null) {
|
||||
return obfData;
|
||||
}
|
||||
currentTarget = currentTarget.move(superClass.getName());
|
||||
obfData = this.getObfEntry(currentTarget);
|
||||
if (!obfData.isEmpty()) {
|
||||
for (ObfuscationType type : obfData) {
|
||||
String obfClass = obfTargetNames.get(type);
|
||||
T obfMember = obfData.get(type);
|
||||
obfData.add(type, (T)MemberInfo.fromMapping((IMapping<?>)obfMember).move(obfClass).asMapping());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return this.getObfEntry(targetMember);
|
||||
}
|
||||
return obfData;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfEntry(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember) {
|
||||
if (targetMember.isField()) {
|
||||
return (ObfuscationData<T>)this.getObfField(targetMember);
|
||||
}
|
||||
return (ObfuscationData<T>)this.getObfMethod(targetMember.asMethodMapping());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> ObfuscationData<T> getObfEntry(IMapping<T> mapping) {
|
||||
if (mapping != null) {
|
||||
if (mapping.getType() == Type.FIELD) {
|
||||
return (ObfuscationData<T>) this.getObfField((MappingField)mapping);
|
||||
} else if (mapping.getType() == Type.METHOD) {
|
||||
return (ObfuscationData<T>) this.getObfMethod((MappingMethod)mapping);
|
||||
}
|
||||
}
|
||||
|
||||
return new ObfuscationData<T>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfMethodRecursive(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingMethod> getObfMethodRecursive(MemberInfo targetMember) {
|
||||
return this.<MappingMethod>getObfEntryRecursive(targetMember);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfMethod(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingMethod> getObfMethod(MemberInfo method) {
|
||||
ObfuscationData<MappingMethod> data = new ObfuscationData<MappingMethod>();
|
||||
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingMethod obfMethod = env.getObfMethod(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(env.getType(), obfMethod);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.isEmpty() || !Constants.CTOR.equals(method.name)) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return this.remapDescriptor(data, method);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationProvider
|
||||
* #getObfMethod(
|
||||
* org.spongepowered.asm.obfuscation.mapping.common.MappingMethod)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingMethod> getObfMethod(MappingMethod method) {
|
||||
ObfuscationData<MappingMethod> data = new ObfuscationData<MappingMethod>();
|
||||
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingMethod obfMethod = env.getObfMethod(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(env.getType(), obfMethod);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.isEmpty() || !Constants.CTOR.equals(method.getSimpleName())) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return this.remapDescriptor(data, new MemberInfo(method));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap a method owner and descriptor only, used for remapping ctors
|
||||
*
|
||||
* @param data Output method data collection
|
||||
* @param method Method to remap
|
||||
* @return data
|
||||
*/
|
||||
public ObfuscationData<MappingMethod> remapDescriptor(ObfuscationData<MappingMethod> data, MemberInfo method) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MemberInfo obfMethod = env.remapDescriptor(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(env.getType(), obfMethod.asMethodMapping());
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfFieldRecursive(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingField> getObfFieldRecursive(MemberInfo targetMember) {
|
||||
return this.<MappingField>getObfEntryRecursive(targetMember);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfField(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingField> getObfField(MemberInfo field) {
|
||||
return this.getObfField(field.asFieldMapping());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfField(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingField> getObfField(MappingField field) {
|
||||
ObfuscationData<MappingField> data = new ObfuscationData<MappingField>();
|
||||
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingField obfField = env.getObfField(field);
|
||||
if (obfField != null) {
|
||||
if (obfField.getDesc() == null && field.getDesc() != null) {
|
||||
obfField = obfField.transform(env.remapDescriptor(field.getDesc()));
|
||||
}
|
||||
data.add(env.getType(), obfField);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfClass(org.spongepowered.tools.obfuscation.TypeHandle)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<String> getObfClass(TypeHandle type) {
|
||||
return this.getObfClass(type.getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfClass(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<String> getObfClass(String className) {
|
||||
ObfuscationData<String> data = new ObfuscationData<String>(className);
|
||||
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
String obfClass = env.getObfClass(className);
|
||||
if (obfClass != null) {
|
||||
data.add(env.getType(), obfClass);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
+109
-144
@@ -25,39 +25,36 @@
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.SrgContainer;
|
||||
import org.spongepowered.asm.obfuscation.SrgField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.ObfuscationUtil;
|
||||
import org.spongepowered.asm.util.ObfuscationUtil.IClassRemapper;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
/**
|
||||
* Stores information relevant to a particular target obfuscation environment.
|
||||
* Stores information relevant to a particular obfuscation environment.
|
||||
*
|
||||
* <p>We classify different types of possible obfuscation (eg. "searge", "notch"
|
||||
* ) as <em>obfuscation environments</em> and store related information such as
|
||||
* the input SRG mappings, generated refmap, generated SRGs, here.</p>
|
||||
* <p>We classify different types of possible obfuscation (eg. "searge",
|
||||
* "notch") as <em>obfuscation environments</em> and store related information
|
||||
* such as the input mappings, generated refmap and generated mappings here.</p>
|
||||
*/
|
||||
class TargetObfuscationEnvironment {
|
||||
public abstract class ObfuscationEnvironment {
|
||||
|
||||
/**
|
||||
* Remapping proxy for remapping descriptors
|
||||
@@ -66,88 +63,95 @@ class TargetObfuscationEnvironment {
|
||||
|
||||
@Override
|
||||
public String map(String typeName) {
|
||||
if (TargetObfuscationEnvironment.this.srgs == null) {
|
||||
if (ObfuscationEnvironment.this.mappingProvider == null) {
|
||||
return null;
|
||||
}
|
||||
return TargetObfuscationEnvironment.this.srgs.getClassMapping(typeName);
|
||||
return ObfuscationEnvironment.this.mappingProvider.getClassMapping(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmap(String typeName) {
|
||||
if (TargetObfuscationEnvironment.this.srgs == null) {
|
||||
if (ObfuscationEnvironment.this.mappingProvider == null) {
|
||||
return null;
|
||||
}
|
||||
return TargetObfuscationEnvironment.this.srgs.getClassMapping(typeName);
|
||||
return ObfuscationEnvironment.this.mappingProvider.getClassMapping(typeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SRG container for mcp->? mappings
|
||||
*/
|
||||
protected SrgContainer srgs;
|
||||
|
||||
private final RemapperProxy remapper = new RemapperProxy();
|
||||
|
||||
/**
|
||||
* Type
|
||||
*/
|
||||
private final ObfuscationType type;
|
||||
protected final ObfuscationType type;
|
||||
|
||||
/**
|
||||
* Mapping provider
|
||||
*/
|
||||
protected final IMappingProvider mappingProvider;
|
||||
|
||||
protected final IMappingWriter mappingWriter;
|
||||
|
||||
protected final RemapperProxy remapper = new RemapperProxy();
|
||||
|
||||
/**
|
||||
* Annotation processor
|
||||
*/
|
||||
private final IMixinAnnotationProcessor ap;
|
||||
protected final IMixinAnnotationProcessor ap;
|
||||
|
||||
/**
|
||||
* Name of the resource to write generated srgs to
|
||||
* Name of the resource to write generated mappings to
|
||||
*/
|
||||
private final String outSrgFileName;
|
||||
protected final String outFileName;
|
||||
|
||||
/**
|
||||
* File containing the reobfd srgs
|
||||
* File containing the source mappings
|
||||
*/
|
||||
private final List<String> reobfSrgFileNames;
|
||||
protected final List<String> inFileNames;
|
||||
|
||||
/**
|
||||
* Reference mapper for reference mapping
|
||||
*/
|
||||
private final ReferenceMapper refMapper;
|
||||
|
||||
/**
|
||||
* True once we've tried to initialise the srgs, initially false so that we
|
||||
* can do srg init lazily
|
||||
* True once we've tried to initialise the mappings, initially false so that
|
||||
* we can do mapping init lazily
|
||||
*/
|
||||
private boolean initDone;
|
||||
|
||||
public TargetObfuscationEnvironment(IMixinAnnotationProcessor ap, ObfuscationType type, ReferenceMapper refMapper) {
|
||||
this.ap = ap;
|
||||
protected ObfuscationEnvironment(ObfuscationType type) {
|
||||
this.type = type;
|
||||
this.refMapper = refMapper;
|
||||
this.ap = type.getAnnotationProcessor();
|
||||
|
||||
this.reobfSrgFileNames = type.getSrgFileNames(ap);
|
||||
this.outSrgFileName = type.getOutputSrgFileName(ap);
|
||||
this.inFileNames = type.getInputFileNames();
|
||||
this.outFileName = type.getOutputFileName();
|
||||
|
||||
this.mappingProvider = this.getMappingProvider(this.ap, this.ap.getProcessingEnvironment().getFiler());
|
||||
this.mappingWriter = this.getMappingWriter(this.ap, this.ap.getProcessingEnvironment().getFiler());
|
||||
}
|
||||
|
||||
private boolean initSrgs() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.type.toString();
|
||||
}
|
||||
|
||||
protected abstract IMappingProvider getMappingProvider(Messager messager, Filer filer);
|
||||
|
||||
protected abstract IMappingWriter getMappingWriter(Messager messager, Filer filer);
|
||||
|
||||
private boolean initMappings() {
|
||||
if (!this.initDone) {
|
||||
this.initDone = true;
|
||||
|
||||
if (this.reobfSrgFileNames == null) {
|
||||
this.ap.printMessage(Kind.ERROR, "The " + this.type.getSrgFileOption()
|
||||
if (this.inFileNames == null) {
|
||||
this.ap.printMessage(Kind.ERROR, "The " + this.type.getConfig().getInputFileOption()
|
||||
+ " argument was not supplied, obfuscation processing will not occur");
|
||||
return false;
|
||||
}
|
||||
|
||||
int successCount = 0;
|
||||
this.srgs = new SrgContainer();
|
||||
|
||||
for (String srgFileName : this.reobfSrgFileNames) {
|
||||
File reobfSrgFile = new File(srgFileName);
|
||||
for (String inputFileName : this.inFileNames) {
|
||||
File inputFile = new File(inputFileName);
|
||||
try {
|
||||
if (reobfSrgFile.isFile()) {
|
||||
this.ap.printMessage(Kind.NOTE, "Loading " + this.type + " mappings from " + reobfSrgFile.getAbsolutePath());
|
||||
this.srgs.readSrg(reobfSrgFile);
|
||||
if (inputFile.isFile()) {
|
||||
this.ap.printMessage(Kind.NOTE, "Loading " + this.type + " mappings from " + inputFile.getAbsolutePath());
|
||||
this.mappingProvider.read(inputFile);
|
||||
successCount++;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@@ -156,12 +160,12 @@ class TargetObfuscationEnvironment {
|
||||
}
|
||||
|
||||
if (successCount < 1) {
|
||||
this.ap.printMessage(Kind.ERROR, "No valid SRG files for " + this.type + " could be read, processing may not be sucessful.");
|
||||
this.srgs = null;
|
||||
this.ap.printMessage(Kind.ERROR, "No valid input files for " + this.type + " could be read, processing may not be sucessful.");
|
||||
this.mappingProvider.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return this.srgs != null;
|
||||
return !this.mappingProvider.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,18 +175,11 @@ class TargetObfuscationEnvironment {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void addMapping(String className, String reference, String newReference) {
|
||||
this.refMapper.addMapping(this.type.getKey(), className, reference, newReference);
|
||||
if (this.type.isDefault(this.ap)) {
|
||||
this.refMapper.addMapping(null, className, reference, newReference);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*/
|
||||
public SrgMethod getObfMethod(MemberInfo method) {
|
||||
SrgMethod obfd = this.getObfMethod(method.asSrgMethod());
|
||||
public MappingMethod getObfMethod(MemberInfo method) {
|
||||
MappingMethod obfd = this.getObfMethod(method.asMethodMapping());
|
||||
if (obfd != null || !method.isFullyQualified()) {
|
||||
return obfd;
|
||||
}
|
||||
@@ -207,21 +204,21 @@ class TargetObfuscationEnvironment {
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*/
|
||||
public SrgMethod getObfMethod(SrgMethod method) {
|
||||
public MappingMethod getObfMethod(MappingMethod method) {
|
||||
return this.getObfMethod(method, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*/
|
||||
public SrgMethod getObfMethod(SrgMethod method, boolean srgOnly) {
|
||||
if (this.initSrgs()) {
|
||||
public MappingMethod getObfMethod(MappingMethod method, boolean lazyRemap) {
|
||||
if (this.initMappings()) {
|
||||
boolean remapped = true;
|
||||
SrgMethod originalMethod = method.copy();
|
||||
SrgMethod methodMapping = this.srgs.getMethodMapping(method);
|
||||
MappingMethod originalMethod = method.copy();
|
||||
MappingMethod methodMapping = this.mappingProvider.getMethodMapping(method);
|
||||
// If no obf mapping, we can attempt to remap the owner class
|
||||
if (methodMapping == null) {
|
||||
if (srgOnly) {
|
||||
if (lazyRemap) {
|
||||
return null;
|
||||
}
|
||||
methodMapping = originalMethod;
|
||||
@@ -234,7 +231,8 @@ class TargetObfuscationEnvironment {
|
||||
if (remapped) {
|
||||
return methodMapping.move(remappedOwner);
|
||||
}
|
||||
return new SrgMethod(remappedOwner, methodMapping.getSimpleName(), ObfuscationUtil.mapDescriptor(methodMapping.getDesc(), this.remapper));
|
||||
String desc = ObfuscationUtil.mapDescriptor(methodMapping.getDesc(), this.remapper);
|
||||
return new MappingMethod(remappedOwner, methodMapping.getSimpleName(), desc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -283,96 +281,63 @@ class TargetObfuscationEnvironment {
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public SrgField getObfField(String field) {
|
||||
public MappingField getObfField(MemberInfo field) {
|
||||
return this.getObfField(field.asFieldMapping(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public MappingField getObfField(MappingField field) {
|
||||
return this.getObfField(field, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public SrgField getObfField(String field, boolean srgOnly) {
|
||||
if (this.initSrgs()) {
|
||||
SrgField originalField = new SrgField(field);
|
||||
SrgField fieldMapping = this.srgs.getFieldMapping(originalField);
|
||||
// If no obf mapping, we can attempt to remap the owner class
|
||||
if (fieldMapping == null) {
|
||||
if (srgOnly) {
|
||||
return null;
|
||||
}
|
||||
fieldMapping = originalField;
|
||||
}
|
||||
String remappedOwner = this.getObfClass(fieldMapping.getOwner());
|
||||
if (remappedOwner == null || remappedOwner.equals(originalField.getOwner()) || remappedOwner.equals(fieldMapping.getOwner())) {
|
||||
return fieldMapping != originalField ? fieldMapping : null;
|
||||
}
|
||||
return fieldMapping.move(remappedOwner);
|
||||
public MappingField getObfField(MappingField field, boolean lazyRemap) {
|
||||
if (!this.initMappings()) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
MappingField fieldMapping = this.mappingProvider.getFieldMapping(field);
|
||||
// If no obf mapping, we can attempt to remap the owner class
|
||||
if (fieldMapping == null) {
|
||||
if (lazyRemap) {
|
||||
return null;
|
||||
}
|
||||
fieldMapping = field;
|
||||
}
|
||||
String remappedOwner = this.getObfClass(fieldMapping.getOwner());
|
||||
if (remappedOwner == null || remappedOwner.equals(field.getOwner()) || remappedOwner.equals(fieldMapping.getOwner())) {
|
||||
return fieldMapping != field ? fieldMapping : null;
|
||||
}
|
||||
return fieldMapping.move(remappedOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public String getObfClass(String className) {
|
||||
if (this.initSrgs()) {
|
||||
return this.srgs.getClassMapping(className);
|
||||
if (!this.initMappings()) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return this.mappingProvider.getClassMapping(className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out generated srgs
|
||||
* Write out generated mappings
|
||||
*/
|
||||
public void writeSrgs(Filer filer, Map<String, AnnotatedMixin> mixins) {
|
||||
if (this.outSrgFileName == null) {
|
||||
return;
|
||||
public void writeMappings(Collection<IMappingConsumer> consumers) {
|
||||
MappingSet<MappingField> fields = new MappingSet<MappingField>();
|
||||
MappingSet<MappingMethod> methods = new MappingSet<MappingMethod>();
|
||||
|
||||
for (IMappingConsumer mappings : consumers) {
|
||||
fields.addAll(mappings.getFieldMappings(this.type));
|
||||
methods.addAll(mappings.getMethodMappings(this.type));
|
||||
}
|
||||
|
||||
Set<String> fieldMappings = new LinkedHashSet<String>();
|
||||
Set<String> methodMappings = new LinkedHashSet<String>();
|
||||
|
||||
for (AnnotatedMixin mixin : mixins.values()) {
|
||||
fieldMappings.addAll(mixin.getFieldMappings(this.type));
|
||||
methodMappings.addAll(mixin.getMethodMappings(this.type));
|
||||
}
|
||||
|
||||
PrintWriter writer = null;
|
||||
|
||||
try {
|
||||
writer = this.openFileWriter(filer, this.outSrgFileName, this.type + " output SRGs");
|
||||
for (String fieldMapping : fieldMappings) {
|
||||
writer.println(fieldMapping);
|
||||
}
|
||||
for (String methodMapping : methodMappings) {
|
||||
writer.println(methodMapping);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (Exception ex) {
|
||||
// oh well
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a writer for an output file
|
||||
*/
|
||||
private PrintWriter openFileWriter(Filer filer, String fileName, String description) throws IOException {
|
||||
if (fileName.matches("^.*[\\\\/:].*$")) {
|
||||
File outSrgFile = new File(fileName);
|
||||
outSrgFile.getParentFile().mkdirs();
|
||||
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + outSrgFile.getAbsolutePath());
|
||||
return new PrintWriter(outSrgFile);
|
||||
}
|
||||
|
||||
FileObject outSrg = filer.createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
|
||||
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + new File(outSrg.toUri()).getAbsolutePath());
|
||||
return new PrintWriter(outSrg.openWriter());
|
||||
|
||||
this.mappingWriter.write(this.outFileName, this.type, fields, methods);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,24 +24,15 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.SrgField;
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationServices;
|
||||
|
||||
/**
|
||||
* Obfuscation Manager for mixin Annotation Processor
|
||||
@@ -54,336 +45,85 @@ public class ObfuscationManager implements IObfuscationManager {
|
||||
private final IMixinAnnotationProcessor ap;
|
||||
|
||||
/**
|
||||
* Name of the resource to write remapped refs to
|
||||
* Available obfuscation environments
|
||||
*/
|
||||
private final String outRefMapFileName;
|
||||
private final List<ObfuscationEnvironment> environments = new ArrayList<ObfuscationEnvironment>();
|
||||
|
||||
/**
|
||||
* Target obfuscation environments
|
||||
* Obfuscation provider
|
||||
*/
|
||||
private final List<TargetObfuscationEnvironment> targetEnvironments = new ArrayList<TargetObfuscationEnvironment>();
|
||||
private final IObfuscationDataProvider obfs;
|
||||
|
||||
/**
|
||||
* Reference mapper for reference mapping
|
||||
* Refmap manager
|
||||
*/
|
||||
private final ReferenceMapper refMapper = new ReferenceMapper();
|
||||
private final IReferenceManager refs;
|
||||
|
||||
/**
|
||||
* Mapping consumers
|
||||
*/
|
||||
private final List<IMappingConsumer> consumers = new ArrayList<IMappingConsumer>();
|
||||
|
||||
private boolean initDone;
|
||||
|
||||
public ObfuscationManager(IMixinAnnotationProcessor ap) {
|
||||
this.ap = ap;
|
||||
this.outRefMapFileName = this.ap.getOption(SupportedOptions.OUT_REFMAP_FILE);
|
||||
for (ObfuscationType obfType : ObfuscationType.values()) {
|
||||
if (obfType.isSupported(this.ap)) {
|
||||
this.targetEnvironments.add(new TargetObfuscationEnvironment(ap, obfType, this.refMapper));
|
||||
this.obfs = new ObfuscationDataProvider(ap, this.environments);
|
||||
this.refs = new ReferenceManager(ap, this.environments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (this.initDone) {
|
||||
return;
|
||||
}
|
||||
this.initDone = true;
|
||||
ObfuscationServices.getInstance().initProviders(this.ap);
|
||||
for (ObfuscationType obfType : ObfuscationType.types()) {
|
||||
if (obfType.isSupported()) {
|
||||
this.environments.add(obfType.createEnvironment());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getReferenceMapper()
|
||||
*/
|
||||
@Override
|
||||
public ReferenceMapper getReferenceMapper() {
|
||||
return this.refMapper;
|
||||
public IObfuscationDataProvider getDataProvider() {
|
||||
return this.obfs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IReferenceManager getReferenceManager() {
|
||||
return this.refs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMappingConsumer createMappingConsumer() {
|
||||
Mappings mappings = new Mappings();
|
||||
this.consumers.add(mappings);
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObfuscationEnvironment> getEnvironments() {
|
||||
return this.environments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out generated srgs
|
||||
* Write out generated mappings
|
||||
*/
|
||||
public void writeSrgs(Map<String, AnnotatedMixin> mixins) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
targetEnv.writeSrgs(this.ap.getProcessingEnvironment().getFiler(), mixins);
|
||||
@Override
|
||||
public void writeMappings() {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
env.writeMappings(this.consumers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out stored mappings
|
||||
*/
|
||||
public void writeRefs() {
|
||||
if (this.outRefMapFileName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PrintWriter writer = null;
|
||||
|
||||
try {
|
||||
writer = this.newWriter(this.outRefMapFileName, "refmap");
|
||||
this.refMapper.write(writer);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (Exception ex) {
|
||||
// oh well
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a writer for an output file
|
||||
*/
|
||||
private PrintWriter newWriter(String fileName, String description) throws IOException {
|
||||
if (fileName.matches("^.*[\\\\/:].*$")) {
|
||||
File outSrgFile = new File(fileName);
|
||||
outSrgFile.getParentFile().mkdirs();
|
||||
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + outSrgFile.getAbsolutePath());
|
||||
return new PrintWriter(outSrgFile);
|
||||
}
|
||||
|
||||
FileObject outSrg = this.ap.getProcessingEnvironment().getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
|
||||
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + new File(outSrg.toUri()).getAbsolutePath());
|
||||
return new PrintWriter(outSrg.openWriter());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfEntryRecursive(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ObfuscationData<T> getObfEntryRecursive(final MemberInfo targetMember) {
|
||||
MemberInfo currentTarget = targetMember;
|
||||
ObfuscationData<String> obfTargetNames = this.getObfClass(currentTarget.owner);
|
||||
ObfuscationData<T> obfData = this.getObfEntry(currentTarget);
|
||||
try {
|
||||
while (obfData.isEmpty()) {
|
||||
TypeHandle targetType = this.ap.getTypeProvider().getTypeHandle(currentTarget.owner);
|
||||
if (targetType == null) {
|
||||
return obfData;
|
||||
}
|
||||
TypeHandle superClass = targetType.getSuperclass();
|
||||
if (superClass == null) {
|
||||
return obfData;
|
||||
}
|
||||
currentTarget = currentTarget.move(superClass.getName());
|
||||
obfData = this.getObfEntry(currentTarget);
|
||||
if (!obfData.isEmpty()) {
|
||||
for (ObfuscationType type : obfData) {
|
||||
String obfClass = obfTargetNames.get(type);
|
||||
T obfMember = obfData.get(type);
|
||||
if (currentTarget.isField()) {
|
||||
obfData.add(type, (T)MemberInfo.fromSrgField(obfMember.toString(), "").move(obfClass).toSrg());
|
||||
} else {
|
||||
obfData.add(type, (T)MemberInfo.fromSrgMethod((SrgMethod)obfMember).move(obfClass).asSrgMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return this.getObfEntry(targetMember);
|
||||
}
|
||||
return obfData;
|
||||
public void writeReferences() {
|
||||
this.refs.write();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfEntry(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember) {
|
||||
if (targetMember.isField()) {
|
||||
return (ObfuscationData<T>)this.getObfField(targetMember.toSrg());
|
||||
}
|
||||
return (ObfuscationData<T>)this.getObfMethod(targetMember.asSrgMethod());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfMethodRecursive(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<SrgMethod> getObfMethodRecursive(MemberInfo targetMember) {
|
||||
return this.<SrgMethod>getObfEntryRecursive(targetMember);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfMethod(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<SrgMethod> getObfMethod(MemberInfo method) {
|
||||
ObfuscationData<SrgMethod> data = new ObfuscationData<SrgMethod>();
|
||||
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
SrgMethod obfMethod = targetEnv.getObfMethod(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(targetEnv.getType(), obfMethod);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.isEmpty() || !Constants.CTOR.equals(method.name)) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return this.remapDescriptor(data, method);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #getObfMethod(org.spongepowered.asm.obfuscation.SrgMethod)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<SrgMethod> getObfMethod(SrgMethod method) {
|
||||
ObfuscationData<SrgMethod> data = new ObfuscationData<SrgMethod>();
|
||||
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
SrgMethod obfMethod = targetEnv.getObfMethod(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(targetEnv.getType(), obfMethod);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.isEmpty() || !Constants.CTOR.equals(method.getSimpleName())) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return this.remapDescriptor(data, new MemberInfo(method));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap a method owner and descriptor only, used for remapping ctors
|
||||
*
|
||||
* @param data Output method data collection
|
||||
* @param method Method to remap
|
||||
* @return data
|
||||
*/
|
||||
public ObfuscationData<SrgMethod> remapDescriptor(ObfuscationData<SrgMethod> data, MemberInfo method) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
MemberInfo obfMethod = targetEnv.remapDescriptor(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(targetEnv.getType(), obfMethod.asSrgMethod());
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfFieldRecursive(
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<String> getObfFieldRecursive(MemberInfo targetMember) {
|
||||
return this.<String>getObfEntryRecursive(targetMember);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfField(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<String> getObfField(String field) {
|
||||
ObfuscationData<String> data = new ObfuscationData<String>();
|
||||
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
SrgField obfField = targetEnv.getObfField(field);
|
||||
if (obfField != null) {
|
||||
data.add(targetEnv.getType(), obfField.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfClass(org.spongepowered.tools.obfuscation.TypeHandle)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<String> getObfClass(TypeHandle type) {
|
||||
return this.getObfClass(type.getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getObfClass(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<String> getObfClass(String className) {
|
||||
ObfuscationData<String> data = new ObfuscationData<String>(className);
|
||||
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
String obfClass = targetEnv.getObfClass(className);
|
||||
if (obfClass != null) {
|
||||
data.add(targetEnv.getType(), obfClass);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addMethodMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addMethodMapping(String className, String reference, ObfuscationData<SrgMethod> obfMethodData) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
SrgMethod obfMethod = obfMethodData.get(targetEnv.getType());
|
||||
if (obfMethod != null) {
|
||||
MemberInfo remappedReference = new MemberInfo(obfMethod);
|
||||
targetEnv.addMapping(className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addMethodMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addMethodMapping(String className, String reference, MemberInfo context, ObfuscationData<SrgMethod> obfMethodData) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
SrgMethod obfMethod = obfMethodData.get(targetEnv.getType());
|
||||
if (obfMethod != null) {
|
||||
MemberInfo remappedReference = context.remapUsing(obfMethod, true);
|
||||
targetEnv.addMapping(className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addFieldMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addFieldMapping(String className, String reference, MemberInfo context, ObfuscationData<String> obfFieldData) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
String obfField = obfFieldData.get(targetEnv.getType());
|
||||
if (obfField != null) {
|
||||
MemberInfo remappedReference = MemberInfo.fromSrgField(obfField, targetEnv.remapDescriptor(context.desc));
|
||||
targetEnv.addMapping(className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addClassMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addClassMapping(String className, String reference, ObfuscationData<String> obfClassData) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
String remapped = obfClassData.get(targetEnv.getType());
|
||||
if (remapped != null) {
|
||||
targetEnv.addMapping(className, reference, remapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,15 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IOptionProvider;
|
||||
import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP;
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
@@ -34,47 +40,34 @@ import com.google.common.collect.ImmutableList.Builder;
|
||||
/**
|
||||
* Obfuscation types supported by the annotation processor
|
||||
*/
|
||||
enum ObfuscationType {
|
||||
public final class ObfuscationType {
|
||||
|
||||
/**
|
||||
* "SEARGE" mappings, these are unique mappings used by MCP and derived
|
||||
* projects
|
||||
*/
|
||||
SRG("searge", SupportedOptions.REOBF_SRG_FILE, SupportedOptions.REOBF_EXTRA_SRG_FILES, SupportedOptions.OUT_SRG_SRG_FILE),
|
||||
private static final Map<String, ObfuscationType> types = new LinkedHashMap<String, ObfuscationType>();
|
||||
|
||||
/**
|
||||
* "NOTCH" mappings, internal to minecraft only
|
||||
*/
|
||||
NOTCH("notch", SupportedOptions.REOBF_NOTCH_FILE, SupportedOptions.REOBF_EXTRA_NOTCH_FILES, SupportedOptions.OUT_NOTCH_SRG_FILE);
|
||||
|
||||
/**
|
||||
* Refmap key for this mapping type
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
private final ObfuscationTypeDescriptor descriptor;
|
||||
|
||||
/**
|
||||
* The name of the Annotation Processor argument which contains the file
|
||||
* name to read the SRGs for this obfuscation type from
|
||||
*/
|
||||
private final String srgFileArgName;
|
||||
private final IMixinAnnotationProcessor ap;
|
||||
|
||||
/**
|
||||
* The name of the Annotation Processor argument which contains the file
|
||||
* name to read the extra SRGs for this obfuscation type from
|
||||
*/
|
||||
private final String extraSrgFilesArgName;
|
||||
private final IOptionProvider options;
|
||||
|
||||
/**
|
||||
* The name of the Annotation Processor argument which contains the file
|
||||
* name to write generated SRG mappings to
|
||||
*/
|
||||
private final String outSrgFileArgName;
|
||||
private ObfuscationType(ObfuscationTypeDescriptor descriptor, IMixinAnnotationProcessor ap) {
|
||||
this.key = descriptor.getKey();
|
||||
this.descriptor = descriptor;
|
||||
this.ap = ap;
|
||||
this.options = ap;
|
||||
}
|
||||
|
||||
private ObfuscationType(String displayName, String srgFileArgName, String extraSrgFilesArgName, String outSrgFileArgName) {
|
||||
this.key = displayName;
|
||||
this.srgFileArgName = srgFileArgName;
|
||||
this.extraSrgFilesArgName = extraSrgFilesArgName;
|
||||
this.outSrgFileArgName = outSrgFileArgName;
|
||||
public final ObfuscationEnvironment createEnvironment() {
|
||||
try {
|
||||
Class<? extends ObfuscationEnvironment> cls = this.descriptor.getEnvironmentType();
|
||||
Constructor<? extends ObfuscationEnvironment> ctor = cls.getDeclaredConstructor(ObfuscationType.class);
|
||||
ctor.setAccessible(true);
|
||||
return ctor.newInstance(this);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,51 +75,70 @@ enum ObfuscationType {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getSrgFileOption() {
|
||||
return this.srgFileArgName;
|
||||
|
||||
public ObfuscationTypeDescriptor getConfig() {
|
||||
return this.descriptor;
|
||||
}
|
||||
|
||||
public String getExtraSrgFilesOption() {
|
||||
return this.extraSrgFilesArgName;
|
||||
public IMixinAnnotationProcessor getAnnotationProcessor() {
|
||||
return this.ap;
|
||||
}
|
||||
|
||||
public String getOutputSrgFileOption() {
|
||||
return this.outSrgFileArgName;
|
||||
public boolean isDefault() {
|
||||
String defaultEnv = this.options.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV);
|
||||
return (defaultEnv == null && this.key.equals(ObfuscationServiceMCP.SEARGE))
|
||||
|| (defaultEnv != null && this.key.equals(defaultEnv.toLowerCase()));
|
||||
}
|
||||
|
||||
public boolean isDefault(IOptionProvider options) {
|
||||
String defaultEnv = options.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV);
|
||||
return (defaultEnv == null && this == ObfuscationType.SRG) || (defaultEnv != null && this.key.equals(defaultEnv.toLowerCase()));
|
||||
public boolean isSupported() {
|
||||
return this.getInputFileNames().size() > 0;
|
||||
}
|
||||
|
||||
public boolean isSupported(IOptionProvider options) {
|
||||
return this.getSrgFileNames(options).size() > 0;
|
||||
}
|
||||
|
||||
public List<String> getSrgFileNames(IOptionProvider options) {
|
||||
public List<String> getInputFileNames() {
|
||||
Builder<String> builder = ImmutableList.<String>builder();
|
||||
|
||||
String srgFile = options.getOption(this.srgFileArgName);
|
||||
if (srgFile != null) {
|
||||
builder.add(srgFile);
|
||||
String inputFile = this.options.getOption(this.descriptor.getInputFileOption());
|
||||
if (inputFile != null) {
|
||||
builder.add(inputFile);
|
||||
}
|
||||
|
||||
String extraSrgFiles = options.getOption(this.extraSrgFilesArgName);
|
||||
if (extraSrgFiles != null) {
|
||||
for (String extraSrgFile : extraSrgFiles.split(";")) {
|
||||
builder.add(extraSrgFile.trim());
|
||||
String extraInputFiles = this.options.getOption(this.descriptor.getExtraInputFilesOption());
|
||||
if (extraInputFiles != null) {
|
||||
for (String extraInputFile : extraInputFiles.split(";")) {
|
||||
builder.add(extraInputFile.trim());
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public String getOutputSrgFileName(IOptionProvider options) {
|
||||
return options.getOption(this.outSrgFileArgName);
|
||||
public String getOutputFileName() {
|
||||
return this.options.getOption(this.descriptor.getOutputFileOption());
|
||||
}
|
||||
|
||||
public static Iterable<ObfuscationType> types() {
|
||||
return ObfuscationType.types.values();
|
||||
}
|
||||
|
||||
public static ObfuscationType create(ObfuscationTypeDescriptor config, IMixinAnnotationProcessor ap) {
|
||||
String key = config.getKey();
|
||||
if (ObfuscationType.types.containsKey(key)) {
|
||||
throw new IllegalArgumentException("Obfuscation type with key " + key + " was already registered");
|
||||
}
|
||||
ObfuscationType type = new ObfuscationType(config, ap);
|
||||
ObfuscationType.types.put(key, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
public static ObfuscationType get(String key) {
|
||||
ObfuscationType type = ObfuscationType.types.get(key);
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Obfuscation type with key " + key + " was not registered");
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
|
||||
|
||||
/**
|
||||
* Implementation of the reference manager
|
||||
*/
|
||||
public class ReferenceManager implements IReferenceManager {
|
||||
|
||||
/**
|
||||
* Annotation processor
|
||||
*/
|
||||
private final IMixinAnnotationProcessor ap;
|
||||
|
||||
/**
|
||||
* Name of the resource to write remapped refs to
|
||||
*/
|
||||
private final String outRefMapFileName;
|
||||
|
||||
/**
|
||||
* Available obfuscation environments
|
||||
*/
|
||||
private final List<ObfuscationEnvironment> environments;
|
||||
|
||||
/**
|
||||
* Reference mapper for reference mapping
|
||||
*/
|
||||
private final ReferenceMapper refMapper = new ReferenceMapper();
|
||||
|
||||
public ReferenceManager(IMixinAnnotationProcessor ap, List<ObfuscationEnvironment> environments) {
|
||||
this.ap = ap;
|
||||
this.environments = environments;
|
||||
this.outRefMapFileName = this.ap.getOption(SupportedOptions.OUT_REFMAP_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out stored mappings
|
||||
*/
|
||||
@Override
|
||||
public void write() {
|
||||
if (this.outRefMapFileName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PrintWriter writer = null;
|
||||
|
||||
try {
|
||||
writer = this.newWriter(this.outRefMapFileName, "refmap");
|
||||
this.refMapper.write(writer);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (Exception ex) {
|
||||
// oh well
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a writer for an output file
|
||||
*/
|
||||
private PrintWriter newWriter(String fileName, String description) throws IOException {
|
||||
if (fileName.matches("^.*[\\\\/:].*$")) {
|
||||
File outFile = new File(fileName);
|
||||
outFile.getParentFile().mkdirs();
|
||||
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + outFile.getAbsolutePath());
|
||||
return new PrintWriter(outFile);
|
||||
}
|
||||
|
||||
FileObject outResource = this.ap.getProcessingEnvironment().getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
|
||||
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
|
||||
return new PrintWriter(outResource.openWriter());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
|
||||
* #getReferenceMapper()
|
||||
*/
|
||||
@Override
|
||||
public ReferenceMapper getMapper() {
|
||||
return this.refMapper;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addMethodMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addMethodMapping(String className, String reference, ObfuscationData<MappingMethod> obfMethodData) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingMethod obfMethod = obfMethodData.get(env.getType());
|
||||
if (obfMethod != null) {
|
||||
MemberInfo remappedReference = new MemberInfo(obfMethod);
|
||||
this.addMapping(env.getType(), className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addMethodMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addMethodMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingMethod> obfMethodData) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingMethod obfMethod = obfMethodData.get(env.getType());
|
||||
if (obfMethod != null) {
|
||||
MemberInfo remappedReference = context.remapUsing(obfMethod, true);
|
||||
this.addMapping(env.getType(), className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addFieldMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addFieldMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingField> obfFieldData) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingField obfField = obfFieldData.get(env.getType());
|
||||
if (obfField != null) {
|
||||
MemberInfo remappedReference = MemberInfo.fromMapping(obfField.transform(env.remapDescriptor(context.desc)));
|
||||
this.addMapping(env.getType(), className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager
|
||||
* #addClassMapping(java.lang.String, java.lang.String,
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addClassMapping(String className, String reference, ObfuscationData<String> obfClassData) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
String remapped = obfClassData.get(env.getType());
|
||||
if (remapped != null) {
|
||||
this.addMapping(env.getType(), className, reference, remapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addMapping(ObfuscationType type, String className, String reference, String newReference) {
|
||||
this.refMapper.addMapping(type.getKey(), className, reference, newReference);
|
||||
if (type.isDefault()) {
|
||||
this.refMapper.addMapping(null, className, reference, newReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,10 @@ package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationServices;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
/**
|
||||
* Supported options for the annotation processor. Not an enum mainly so that
|
||||
@@ -35,12 +38,6 @@ import com.google.common.collect.ImmutableSet;
|
||||
public final class SupportedOptions {
|
||||
|
||||
public static final String TOKENS = "tokens";
|
||||
public static final String REOBF_SRG_FILE = "reobfSrgFile";
|
||||
public static final String REOBF_EXTRA_SRG_FILES = "reobfSrgFiles";
|
||||
public static final String REOBF_NOTCH_FILE = "reobfNotchSrgFile";
|
||||
public static final String REOBF_EXTRA_NOTCH_FILES = "reobfNotchSrgFiles";
|
||||
public static final String OUT_SRG_SRG_FILE = "outSrgFile";
|
||||
public static final String OUT_NOTCH_SRG_FILE = "outNotchSrgFile";
|
||||
public static final String OUT_REFMAP_FILE = "outRefMapFile";
|
||||
public static final String DISABLE_TARGET_VALIDATOR = "disableTargetValidator";
|
||||
public static final String DISABLE_TARGET_EXPORT = "disableTargetExport";
|
||||
@@ -48,24 +45,24 @@ public final class SupportedOptions {
|
||||
public static final String OVERWRITE_ERROR_LEVEL = "overwriteErrorLevel";
|
||||
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";
|
||||
public static final String DEPENDENCY_TARGETS_FILE = "dependencyTargetsFile";
|
||||
|
||||
public static final Set<String> all = ImmutableSet.<String>of(
|
||||
SupportedOptions.TOKENS,
|
||||
SupportedOptions.REOBF_SRG_FILE,
|
||||
SupportedOptions.REOBF_EXTRA_SRG_FILES,
|
||||
SupportedOptions.REOBF_NOTCH_FILE,
|
||||
SupportedOptions.REOBF_EXTRA_NOTCH_FILES,
|
||||
SupportedOptions.OUT_SRG_SRG_FILE,
|
||||
SupportedOptions.OUT_NOTCH_SRG_FILE,
|
||||
SupportedOptions.OUT_REFMAP_FILE,
|
||||
SupportedOptions.DISABLE_TARGET_VALIDATOR,
|
||||
SupportedOptions.DISABLE_TARGET_EXPORT,
|
||||
SupportedOptions.DISABLE_OVERWRITE_CHECKER,
|
||||
SupportedOptions.OVERWRITE_ERROR_LEVEL,
|
||||
SupportedOptions.DEFAULT_OBFUSCATION_ENV,
|
||||
SupportedOptions.DEPENDENCY_TARGETS_FILE
|
||||
);
|
||||
|
||||
private SupportedOptions() {}
|
||||
|
||||
public static Set<String> getAllOptions() {
|
||||
Builder<String> options = ImmutableSet.<String>builder();
|
||||
options.add(
|
||||
SupportedOptions.TOKENS,
|
||||
SupportedOptions.OUT_REFMAP_FILE,
|
||||
SupportedOptions.DISABLE_TARGET_VALIDATOR,
|
||||
SupportedOptions.DISABLE_TARGET_EXPORT,
|
||||
SupportedOptions.DISABLE_OVERWRITE_CHECKER,
|
||||
SupportedOptions.OVERWRITE_ERROR_LEVEL,
|
||||
SupportedOptions.DEFAULT_OBFUSCATION_ENV,
|
||||
SupportedOptions.DEPENDENCY_TARGETS_FILE
|
||||
);
|
||||
options.addAll(
|
||||
ObfuscationServices.getInstance().getSupportedOptions()
|
||||
);
|
||||
return options.build();
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import org.spongepowered.tools.MirrorUtils;
|
||||
|
||||
/**
|
||||
* Annotation processor which finds {@link Shadow} and {@link Overwrite}
|
||||
* annotations in mixin classes and generates SRG mappings
|
||||
* annotations in mixin classes and generates new obfuscation mappings
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "org.spongepowered.asm.mixin.Mixin", "org.spongepowered.asm.mixin.Shadow", "org.spongepowered.asm.mixin.Overwrite" })
|
||||
public class TargetObfuscationProcessor extends MixinProcessor {
|
||||
@@ -71,7 +71,7 @@ public class TargetObfuscationProcessor extends MixinProcessor {
|
||||
super.postProcess(roundEnv);
|
||||
|
||||
try {
|
||||
this.mixins.writeSrgs();
|
||||
this.mixins.writeMappings();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationData;
|
||||
import org.spongepowered.tools.obfuscation.TypeHandle;
|
||||
|
||||
/**
|
||||
* Provides obfuscation data to the annotation processor
|
||||
*/
|
||||
public interface IObfuscationDataProvider {
|
||||
|
||||
/**
|
||||
* Attempts to resolve an obfuscation entry by recursively enumerating
|
||||
* superclasses of the target member until a match is found. If a match is
|
||||
* found in a superclass then the reference is remapped to the original
|
||||
* owner class.
|
||||
*
|
||||
* @param targetMember Member to search for
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntryRecursive(MemberInfo targetMember);
|
||||
|
||||
/**
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
*
|
||||
* @param targetMember member to search for
|
||||
* @return obfuscation data (by type) for the supplied member
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember);
|
||||
|
||||
/**
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
*
|
||||
* @param mapping member to search for
|
||||
* @return obfuscation data (by type) for the supplied member
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(IMapping<T> mapping);
|
||||
|
||||
/**
|
||||
* Attempts to resolve an obfuscated method by recursively enumerating
|
||||
* superclasses of the target method until a match is found. If a match is
|
||||
* found in a superclass then the method owner is remapped to the obfuscated
|
||||
* name of the original owner class.
|
||||
*
|
||||
* @param method Method to search for
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethodRecursive(MemberInfo method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethod(MemberInfo method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethod(MappingMethod method);
|
||||
|
||||
/**
|
||||
* Attempts to resolve an obfuscated field by recursively enumerating
|
||||
* superclasses of the target field until a match is found. If a match is
|
||||
* found in a superclass then the field owner is remapped to the obfuscated
|
||||
* name of the original owner class.
|
||||
*
|
||||
* @param field Field to search for
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfFieldRecursive(MemberInfo field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfField(MemberInfo field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfField(MappingField field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfClass(TypeHandle type);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfClass(String className);
|
||||
|
||||
}
|
||||
+22
-104
@@ -24,11 +24,10 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationData;
|
||||
import org.spongepowered.tools.obfuscation.TypeHandle;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
|
||||
/**
|
||||
* Manages obfuscation things
|
||||
@@ -36,119 +35,38 @@ import org.spongepowered.tools.obfuscation.TypeHandle;
|
||||
public interface IObfuscationManager {
|
||||
|
||||
/**
|
||||
* Get the underlying reference mapper
|
||||
* Initialise the obfuscation environments
|
||||
*/
|
||||
public abstract ReferenceMapper getReferenceMapper();
|
||||
public abstract void init();
|
||||
|
||||
/**
|
||||
* Attempts to resolve an obfuscation entry by recursively enumerating
|
||||
* superclasses of the target member until a match is found. If a match is
|
||||
* found in a superclass then the reference is remapped to the original
|
||||
* owner class.
|
||||
*
|
||||
* @param targetMember Member to search for
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
* Get the obfuscation mapping source
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntryRecursive(MemberInfo targetMember);
|
||||
public abstract IObfuscationDataProvider getDataProvider();
|
||||
|
||||
/**
|
||||
* Get the reference manager
|
||||
*/
|
||||
public abstract IReferenceManager getReferenceManager();
|
||||
|
||||
/**
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
*
|
||||
* @param targetMember member to search for
|
||||
* @return obfuscation data (by type) for the supplied member
|
||||
* Create a new mapping consumer
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember);
|
||||
public abstract IMappingConsumer createMappingConsumer();
|
||||
|
||||
/**
|
||||
* Attempts to resolve an obfuscated method by recursively enumerating
|
||||
* superclasses of the target method until a match is found. If a match is
|
||||
* found in a superclass then the method owner is remapped to the obfuscated
|
||||
* name of the original owner class.
|
||||
*
|
||||
* @param method Method to search for
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
* Get available obfuscation environments within this manager
|
||||
*/
|
||||
public abstract ObfuscationData<SrgMethod> getObfMethodRecursive(MemberInfo method);
|
||||
public abstract List<ObfuscationEnvironment> getEnvironments();
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
* Write out generated mappings to the target environments
|
||||
*/
|
||||
public abstract ObfuscationData<SrgMethod> getObfMethod(MemberInfo method);
|
||||
public abstract void writeMappings();
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
* Write out generated refmap
|
||||
*/
|
||||
public abstract ObfuscationData<SrgMethod> getObfMethod(SrgMethod method);
|
||||
|
||||
/**
|
||||
* Attempts to resolve an obfuscated field by recursively enumerating
|
||||
* superclasses of the target field until a match is found. If a match is
|
||||
* found in a superclass then the field owner is remapped to the obfuscated
|
||||
* name of the original owner class.
|
||||
*
|
||||
* @param field Field to search for
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfFieldRecursive(MemberInfo field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfField(String field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfClass(TypeHandle type);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfClass(String className);
|
||||
|
||||
/**
|
||||
* Adds a method mapping to the internal refmap
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param obfMethodData Method data to add for this mapping
|
||||
*/
|
||||
public abstract void addMethodMapping(String className, String reference, ObfuscationData<SrgMethod> obfMethodData);
|
||||
|
||||
/**
|
||||
* Adds a method mapping to the internal refmap, generates refmap entries
|
||||
* using the supplied parsed memberinfo as context
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param context The context for this mapping entry, remapped using the
|
||||
* supplied obfuscation data
|
||||
* @param obfMethodData Method data to add for this mapping
|
||||
*/
|
||||
public abstract void addMethodMapping(String className, String reference, MemberInfo context, ObfuscationData<SrgMethod> obfMethodData);
|
||||
|
||||
/**
|
||||
* Adds a field mapping to the internal refmap, generates refmap entries
|
||||
* using the supplied parsed memberinfo as context
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param context The context for this mapping entry, remapped using the
|
||||
* supplied obfuscation data
|
||||
* @param obfFieldData Field data to add for this mapping
|
||||
*/
|
||||
public abstract void addFieldMapping(String className, String reference, MemberInfo context, ObfuscationData<String> obfFieldData);
|
||||
|
||||
/**
|
||||
* Adds a class mapping to the internal refmap
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param obfClassData Class obf names
|
||||
*/
|
||||
public abstract void addClassMapping(String className, String reference, ObfuscationData<String> obfClassData);
|
||||
|
||||
void writeReferences();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationData;
|
||||
|
||||
/**
|
||||
* Consumer for generated references, builds the refmap during an AP pass and
|
||||
* supports writing the generated refmap to file once the AP run is complete
|
||||
*/
|
||||
public interface IReferenceManager {
|
||||
|
||||
/**
|
||||
* Write the generated refmap to file
|
||||
*/
|
||||
public abstract void write();
|
||||
|
||||
/**
|
||||
* Get the underlying reference mapper
|
||||
*/
|
||||
public abstract ReferenceMapper getMapper();
|
||||
|
||||
/**
|
||||
* Adds a method mapping to the internal refmap
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param obfMethodData Method data to add for this mapping
|
||||
*/
|
||||
public abstract void addMethodMapping(String className, String reference, ObfuscationData<MappingMethod> obfMethodData);
|
||||
|
||||
/**
|
||||
* Adds a method mapping to the internal refmap, generates refmap entries
|
||||
* using the supplied parsed memberinfo as context
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param context The context for this mapping entry, remapped using the
|
||||
* supplied obfuscation data
|
||||
* @param obfMethodData Method data to add for this mapping
|
||||
*/
|
||||
public abstract void addMethodMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingMethod> obfMethodData);
|
||||
|
||||
/**
|
||||
* Adds a field mapping to the internal refmap, generates refmap entries
|
||||
* using the supplied parsed memberinfo as context
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param context The context for this mapping entry, remapped using the
|
||||
* supplied obfuscation data
|
||||
* @param obfFieldData Field data to add for this mapping
|
||||
*/
|
||||
public abstract void addFieldMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingField> obfFieldData);
|
||||
|
||||
/**
|
||||
* Adds a class mapping to the internal refmap
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
* @param obfClassData Class obf names
|
||||
*/
|
||||
public abstract void addClassMapping(String className, String reference, ObfuscationData<String> obfClassData);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* Mapping consumers collect the mappings generated by an AP pass ready for them
|
||||
* to be written to the output files
|
||||
*/
|
||||
public interface IMappingConsumer {
|
||||
|
||||
/**
|
||||
* A set of mapping pairs
|
||||
*
|
||||
* @param <TMapping> type of mappings in the set
|
||||
*/
|
||||
public class MappingSet<TMapping extends IMapping<TMapping>> extends LinkedHashSet<MappingSet.Pair<TMapping>> {
|
||||
|
||||
/**
|
||||
* A pair of mappings
|
||||
*
|
||||
* @param <TMapping> The type of mappings being mapped
|
||||
*/
|
||||
public static class Pair<TMapping extends IMapping<TMapping>> {
|
||||
|
||||
/**
|
||||
* Source mapping
|
||||
*/
|
||||
public final TMapping from;
|
||||
|
||||
/**
|
||||
* Destination mapping
|
||||
*/
|
||||
public final TMapping to;
|
||||
|
||||
public Pair(TMapping from, TMapping to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Pair)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<TMapping> other = (Pair<TMapping>) obj;
|
||||
return Objects.equal(this.from, other.from) && Objects.equal(this.to, other.to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.from, this.to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s -> %s", this.from, this.to);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all collections in the consumer
|
||||
*/
|
||||
public abstract void clear();
|
||||
|
||||
/**
|
||||
* Add a field mapping to this consumer.
|
||||
*
|
||||
* @param type obfuscation type for this entry
|
||||
* @param from source mapping
|
||||
* @param to destination mapping
|
||||
*/
|
||||
public abstract void addFieldMapping(ObfuscationType type, MappingField from, MappingField to);
|
||||
|
||||
/**
|
||||
* Add a method mapping to this consumer.
|
||||
*
|
||||
* @param type obfuscation type for this entry
|
||||
* @param from source mapping
|
||||
* @param to destination mapping
|
||||
*/
|
||||
public abstract void addMethodMapping(ObfuscationType type, MappingMethod from, MappingMethod to);
|
||||
|
||||
/**
|
||||
* Get the stored field mappings for the specified obfuscation type
|
||||
*
|
||||
* @param type obfuscation type
|
||||
* @return stored field mappings
|
||||
*/
|
||||
public abstract MappingSet<MappingField> getFieldMappings(ObfuscationType type);
|
||||
|
||||
/**
|
||||
* Get the stored method mappings for the specified obfuscation type
|
||||
*
|
||||
* @param type obfuscation type
|
||||
* @return stored method mappings
|
||||
*/
|
||||
public abstract MappingSet<MappingMethod> getMethodMappings(ObfuscationType type);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
|
||||
/**
|
||||
* A mapping provider supplies mapping information to the AP
|
||||
*/
|
||||
public interface IMappingProvider {
|
||||
|
||||
/**
|
||||
* Clear this mapping provider, used to ensure the internal data is cleared
|
||||
* before beginning a {@link #read}
|
||||
*/
|
||||
public abstract void clear();
|
||||
|
||||
/**
|
||||
* Returns true if this mapping provider contains no mappings
|
||||
*/
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Called multiple times by the environment. This method will be called for
|
||||
* each input file specified by the user.
|
||||
*
|
||||
* @param input
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract void read(File input) throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieve a method mapping from this provider. This method should return
|
||||
* <tt>null</tt> if no mapping is found
|
||||
*
|
||||
* @param method method to find a mapping for
|
||||
* @return mapped method or <tt>null</tt> if not found
|
||||
*/
|
||||
public abstract MappingMethod getMethodMapping(MappingMethod method);
|
||||
|
||||
/**
|
||||
* Retrieve a field mapping from this provider. This method should return
|
||||
* <tt>null</tt> if no mapping is found
|
||||
*
|
||||
* @param field field to find a mapping for
|
||||
* @return mapped field or <tt>null</tt> if not found
|
||||
*/
|
||||
public abstract MappingField getFieldMapping(MappingField field);
|
||||
|
||||
/**
|
||||
* Retrieve a class mapping from this provider. This method should return
|
||||
* <tt>null</tt> if no mapping is found
|
||||
*
|
||||
* @param className name of the class to find a mapping for
|
||||
* @return mapped class name or <tt>null</tt> if not found
|
||||
*/
|
||||
public abstract String getClassMapping(String className);
|
||||
|
||||
/**
|
||||
* Retrieve a package mapping from this provider. This method should return
|
||||
* <tt>null</tt> if no mapping is found
|
||||
*
|
||||
* @param packageName name of the package to find a mapping for
|
||||
* @return mapped package name or <tt>null</tt> if not found
|
||||
*/
|
||||
public abstract String getPackageMapping(String packageName);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet;
|
||||
|
||||
/**
|
||||
* Mapping writer
|
||||
*/
|
||||
public interface IMappingWriter {
|
||||
|
||||
/**
|
||||
* Receives
|
||||
*
|
||||
* @param output
|
||||
* @param type
|
||||
* @param fields
|
||||
* @param methods
|
||||
*/
|
||||
public abstract void write(String output, ObfuscationType type, MappingSet<MappingField> fields, MappingSet<MappingMethod> methods);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping.common;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
/**
|
||||
* Base class for mapping providers
|
||||
*/
|
||||
public abstract class MappingProvider implements IMappingProvider {
|
||||
|
||||
protected final Messager messager;
|
||||
protected final Filer filer;
|
||||
|
||||
protected final BiMap<String, String> packageMap = HashBiMap.create();
|
||||
protected final BiMap<String, String> classMap = HashBiMap.create();
|
||||
protected final BiMap<MappingField, MappingField> fieldMap = HashBiMap.create();
|
||||
protected final BiMap<MappingMethod, MappingMethod> methodMap = HashBiMap.create();
|
||||
|
||||
public MappingProvider(Messager messager, Filer filer) {
|
||||
this.messager = messager;
|
||||
this.filer = filer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.packageMap.clear();
|
||||
this.classMap.clear();
|
||||
this.fieldMap.clear();
|
||||
this.methodMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.packageMap.isEmpty() && this.classMap.isEmpty() && this.fieldMap.isEmpty() && this.methodMap.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod getMethodMapping(MappingMethod method) {
|
||||
return this.methodMap.get(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField getFieldMapping(MappingField field) {
|
||||
return this.fieldMap.get(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassMapping(String className) {
|
||||
return this.classMap.get(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageMapping(String packageName) {
|
||||
return this.packageMap.get(packageName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
|
||||
|
||||
/**
|
||||
* Writer for mappings
|
||||
*/
|
||||
public abstract class MappingWriter implements IMappingWriter {
|
||||
|
||||
private final Messager messager;
|
||||
|
||||
private final Filer filer;
|
||||
|
||||
public MappingWriter(Messager messager, Filer filer) {
|
||||
this.messager = messager;
|
||||
this.filer = filer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a writer for an output file
|
||||
*/
|
||||
protected PrintWriter openFileWriter(String fileName, String description) throws IOException {
|
||||
if (fileName.matches("^.*[\\\\/:].*$")) {
|
||||
File outFile = new File(fileName);
|
||||
outFile.getParentFile().mkdirs();
|
||||
this.messager.printMessage(Kind.NOTE, "Writing " + description + " to " + outFile.getAbsolutePath());
|
||||
return new PrintWriter(outFile);
|
||||
}
|
||||
|
||||
FileObject outResource = this.filer.createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
|
||||
this.messager.printMessage(Kind.NOTE, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
|
||||
return new PrintWriter(outResource.openWriter());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping.mcp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.mcp.MappingFieldSrg;
|
||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingProvider;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.io.LineProcessor;
|
||||
|
||||
/**
|
||||
* Ported from <strong>Srg2Source</strong> (
|
||||
* <a href=\"https://github.com/MinecraftForge/Srg2Source\">
|
||||
* github.com/MinecraftForge/Srg2Source</a>).
|
||||
*/
|
||||
public class MappingProviderSrg extends MappingProvider {
|
||||
|
||||
public MappingProviderSrg(Messager messager, Filer filer) {
|
||||
super(messager, filer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(final File input) throws IOException {
|
||||
// Locally scoped to avoid synthetic accessor
|
||||
final BiMap<String, String> packageMap = this.packageMap;
|
||||
final BiMap<String, String> classMap = this.classMap;
|
||||
final BiMap<MappingField, MappingField> fieldMap = this.fieldMap;
|
||||
final BiMap<MappingMethod, MappingMethod> methodMap = this.methodMap;
|
||||
|
||||
Files.readLines(input, Charset.defaultCharset(), new LineProcessor<String>() {
|
||||
@Override
|
||||
public String getResult() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processLine(String line) throws IOException {
|
||||
if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String type = line.substring(0, 2);
|
||||
String[] args = line.substring(4).split(" ");
|
||||
|
||||
if (type.equals("PK")) {
|
||||
packageMap.forcePut(args[0], args[1]);
|
||||
} else if (type.equals("CL")) {
|
||||
classMap.forcePut(args[0], args[1]);
|
||||
} else if (type.equals("FD")) {
|
||||
fieldMap.forcePut(new MappingFieldSrg(args[0]).copy(), new MappingFieldSrg(args[1]).copy());
|
||||
} else if (type.equals("MD")) {
|
||||
methodMap.forcePut(new MappingMethod(args[0], args[1]), new MappingMethod(args[2], args[3]));
|
||||
} else {
|
||||
throw new MixinException("Invalid SRG file: " + input);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField getFieldMapping(MappingField field) {
|
||||
// SRG fields do not have descriptors so strip the field descriptor before looking up
|
||||
if (field.getDesc() != null) {
|
||||
field = new MappingFieldSrg(field);
|
||||
}
|
||||
return this.fieldMap.get(field);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mapping.mcp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet.Pair;
|
||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingWriter;
|
||||
|
||||
/**
|
||||
* Writer for SRG mappings
|
||||
*/
|
||||
public class MappingWriterSrg extends MappingWriter {
|
||||
|
||||
public MappingWriterSrg(Messager messager, Filer filer) {
|
||||
super(messager, filer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final String output, ObfuscationType type, MappingSet<MappingField> fields, MappingSet<MappingMethod> methods) {
|
||||
if (output == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PrintWriter writer = null;
|
||||
|
||||
try {
|
||||
writer = this.openFileWriter(output, type + " output SRGs");
|
||||
this.writeFieldMappings(writer, fields);
|
||||
this.writeMethodMappings(writer, methods);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (Exception ex) {
|
||||
// oh well
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeFieldMappings(PrintWriter writer, MappingSet<MappingField> fields) {
|
||||
for (Pair<MappingField> field : fields) {
|
||||
writer.println(this.formatFieldMapping(field));
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeMethodMappings(PrintWriter writer, MappingSet<MappingMethod> methods) {
|
||||
for (Pair<MappingMethod> method : methods) {
|
||||
writer.println(this.formatMethodMapping(method));
|
||||
}
|
||||
}
|
||||
|
||||
protected String formatFieldMapping(Pair<MappingField> mapping) {
|
||||
return String.format("FD: %s/%s %s/%s", mapping.from.getOwner(), mapping.from.getName(), mapping.to.getOwner(), mapping.to.getName());
|
||||
}
|
||||
|
||||
protected String formatMethodMapping(Pair<MappingMethod> mapping) {
|
||||
return String.format("MD: %s %s %s %s", mapping.from.getName(), mapping.from.getDesc(), mapping.to.getName(), mapping.to.getDesc());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mcp;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
|
||||
import org.spongepowered.tools.obfuscation.mapping.mcp.MappingProviderSrg;
|
||||
import org.spongepowered.tools.obfuscation.mapping.mcp.MappingWriterSrg;
|
||||
|
||||
/**
|
||||
* An MCP obfuscation environment (eg. SEARGE or NOTCH)
|
||||
*/
|
||||
public class ObfuscationEnvironmentMCP extends ObfuscationEnvironment {
|
||||
|
||||
protected ObfuscationEnvironmentMCP(ObfuscationType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMappingProvider getMappingProvider(Messager messager, Filer filer) {
|
||||
return new MappingProviderSrg(messager, filer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMappingWriter getMappingWriter(Messager messager, Filer filer) {
|
||||
return new MappingWriterSrg(messager, filer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.mcp;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.service.IObfuscationService;
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Default obfuscation service, provides MCP
|
||||
*/
|
||||
public class ObfuscationServiceMCP implements IObfuscationService {
|
||||
|
||||
public static final String SEARGE = "searge";
|
||||
public static final String NOTCH = "notch";
|
||||
|
||||
public static final String REOBF_SRG_FILE = "reobfSrgFile";
|
||||
public static final String REOBF_EXTRA_SRG_FILES = "reobfSrgFiles";
|
||||
public static final String REOBF_NOTCH_FILE = "reobfNotchSrgFile";
|
||||
public static final String REOBF_EXTRA_NOTCH_FILES = "reobfNotchSrgFiles";
|
||||
public static final String OUT_SRG_SRG_FILE = "outSrgFile";
|
||||
public static final String OUT_NOTCH_SRG_FILE = "outNotchSrgFile";
|
||||
public static final String OUT_REFMAP_FILE = "outRefMapFile";
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedOptions() {
|
||||
return ImmutableSet.<String>of(
|
||||
ObfuscationServiceMCP.REOBF_SRG_FILE,
|
||||
ObfuscationServiceMCP.REOBF_EXTRA_SRG_FILES,
|
||||
ObfuscationServiceMCP.REOBF_NOTCH_FILE,
|
||||
ObfuscationServiceMCP.REOBF_EXTRA_NOTCH_FILES,
|
||||
ObfuscationServiceMCP.OUT_SRG_SRG_FILE,
|
||||
ObfuscationServiceMCP.OUT_NOTCH_SRG_FILE,
|
||||
ObfuscationServiceMCP.OUT_REFMAP_FILE
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() {
|
||||
return ImmutableList.<ObfuscationTypeDescriptor>of(
|
||||
new ObfuscationTypeDescriptor(
|
||||
ObfuscationServiceMCP.SEARGE,
|
||||
ObfuscationServiceMCP.REOBF_SRG_FILE,
|
||||
ObfuscationServiceMCP.REOBF_EXTRA_SRG_FILES,
|
||||
ObfuscationServiceMCP.OUT_SRG_SRG_FILE,
|
||||
ObfuscationEnvironmentMCP.class
|
||||
),
|
||||
new ObfuscationTypeDescriptor(
|
||||
ObfuscationServiceMCP.NOTCH,
|
||||
ObfuscationServiceMCP.REOBF_NOTCH_FILE,
|
||||
ObfuscationServiceMCP.REOBF_EXTRA_NOTCH_FILES,
|
||||
ObfuscationServiceMCP.OUT_NOTCH_SRG_FILE,
|
||||
ObfuscationEnvironmentMCP.class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service interface for obfuscation services
|
||||
*/
|
||||
public interface IObfuscationService {
|
||||
|
||||
/**
|
||||
* Get all options supported by this service
|
||||
*
|
||||
* @return supported options as a Set
|
||||
*/
|
||||
public abstract Set<String> getSupportedOptions();
|
||||
|
||||
/**
|
||||
* This method should return a collection of available obfuscation types
|
||||
* supported by this service
|
||||
*
|
||||
* @return available obfuscation types or null
|
||||
*/
|
||||
public abstract Collection<ObfuscationTypeDescriptor> getObfuscationTypes();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
/**
|
||||
* Obfuscation service manager
|
||||
*/
|
||||
public class ObfuscationServices {
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*/
|
||||
private static ObfuscationServices instance;
|
||||
|
||||
/**
|
||||
* Service loader
|
||||
*/
|
||||
private final ServiceLoader<IObfuscationService> serviceLoader;
|
||||
|
||||
/**
|
||||
* Initialised services
|
||||
*/
|
||||
private final Set<IObfuscationService> services = new HashSet<IObfuscationService>();
|
||||
|
||||
/**
|
||||
* Singleton pattern
|
||||
*/
|
||||
private ObfuscationServices() {
|
||||
this.serviceLoader = ServiceLoader.<IObfuscationService>load(IObfuscationService.class, this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton pattern, get or create the instance
|
||||
*/
|
||||
public static ObfuscationServices getInstance() {
|
||||
if (ObfuscationServices.instance == null) {
|
||||
ObfuscationServices.instance = new ObfuscationServices();
|
||||
}
|
||||
return ObfuscationServices.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise services
|
||||
*/
|
||||
public void initProviders(IMixinAnnotationProcessor ap) {
|
||||
try {
|
||||
for (IObfuscationService service : this.serviceLoader) {
|
||||
if (!this.services.contains(service)) {
|
||||
this.services.add(service);
|
||||
|
||||
String serviceName = service.getClass().getSimpleName();
|
||||
// ap.printMessage(Kind.NOTE, "Preparing service " + serviceName);
|
||||
Collection<ObfuscationTypeDescriptor> obfTypes = service.getObfuscationTypes();
|
||||
if (obfTypes != null) {
|
||||
for (ObfuscationTypeDescriptor obfType : obfTypes) {
|
||||
try {
|
||||
ObfuscationType type = ObfuscationType.create(obfType, ap);
|
||||
ap.printMessage(Kind.NOTE, serviceName + " supports type: \"" + type + "\"");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ServiceConfigurationError serviceError) {
|
||||
ap.printMessage(Kind.ERROR, serviceError.getClass().getSimpleName() + ": " + serviceError.getMessage());
|
||||
serviceError.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getSupportedOptions() {
|
||||
Set<String> supportedOptions = new HashSet<String>();
|
||||
for (IObfuscationService provider : this.serviceLoader) {
|
||||
Set<String> options = provider.getSupportedOptions();
|
||||
if (options != null) {
|
||||
supportedOptions.addAll(options);
|
||||
}
|
||||
}
|
||||
return supportedOptions;
|
||||
}
|
||||
|
||||
public IObfuscationService getService(Class<? extends IObfuscationService> serviceClass) {
|
||||
for (IObfuscationService service : this.serviceLoader) {
|
||||
if (serviceClass.getName().equals(service.getClass().getName())) {
|
||||
return service;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.service;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
|
||||
/**
|
||||
* Describes the arguments for a particular obfuscation type, used as an args
|
||||
* object for creating {@link ObfuscationType}s
|
||||
*/
|
||||
public class ObfuscationTypeDescriptor {
|
||||
|
||||
/**
|
||||
* Refmap key for this mapping type
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The name of the Annotation Processor argument which contains the file
|
||||
* name to read the mappings for this obfuscation type from
|
||||
*/
|
||||
private final String inputFileArgName;
|
||||
|
||||
/**
|
||||
* The name of the Annotation Processor argument which contains the file
|
||||
* name to read the extra mappings for this obfuscation type from
|
||||
*/
|
||||
private final String extraInputFilesArgName;
|
||||
|
||||
/**
|
||||
* The name of the Annotation Processor argument which contains the file
|
||||
* name to write generated mappings to
|
||||
*/
|
||||
private final String outFileArgName;
|
||||
|
||||
private final Class<? extends ObfuscationEnvironment> environmentType;
|
||||
|
||||
public ObfuscationTypeDescriptor(String key, String inputFileArgName, String outFileArgName,
|
||||
Class<? extends ObfuscationEnvironment> environmentType) {
|
||||
this(key, inputFileArgName, null, outFileArgName, environmentType);
|
||||
}
|
||||
|
||||
public ObfuscationTypeDescriptor(String key, String inputFileArgName, String extraInputFilesArgName, String outFileArgName,
|
||||
Class<? extends ObfuscationEnvironment> environmentType) {
|
||||
this.key = key;
|
||||
this.inputFileArgName = inputFileArgName;
|
||||
this.extraInputFilesArgName = extraInputFilesArgName;
|
||||
this.outFileArgName = outFileArgName;
|
||||
this.environmentType = environmentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key for this type, must be unique
|
||||
*/
|
||||
public final String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the AP argument used to specify the input file
|
||||
*/
|
||||
public String getInputFileOption() {
|
||||
return this.inputFileArgName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the AP argument used to specify extra input files
|
||||
*/
|
||||
public String getExtraInputFilesOption() {
|
||||
return this.extraInputFilesArgName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the AP argument used to specify the output file
|
||||
*/
|
||||
public String getOutputFileOption() {
|
||||
return this.outFileArgName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the environment class
|
||||
*/
|
||||
public Class<? extends ObfuscationEnvironment> getEnvironmentType() {
|
||||
return this.environmentType;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user