mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-22 11:34:50 +01:00
fix: descriptor obfuscation now handled properly
This commit is contained in:
parent
dac2510de7
commit
d451cc3460
4 changed files with 29 additions and 13 deletions
|
@ -354,9 +354,9 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
.addMethod(constructorBuilder.build())
|
.addMethod(constructorBuilder.build())
|
||||||
.addMethod(buildStringReturnMethod("name", cl.getSimpleName().toString()))
|
.addMethod(buildStringReturnMethod("name", cl.getSimpleName().toString()))
|
||||||
.addMethod(buildStringReturnMethod("reason", toGenerate.get(injName).reason))
|
.addMethod(buildStringReturnMethod("reason", toGenerate.get(injName).reason))
|
||||||
.addMethod(buildStringReturnMethod("targetClass", targetClass.fqn))
|
.addMethod(buildStringReturnMethod("targetClass", targetClass.fqnObf))
|
||||||
.addMethod(buildStringReturnMethod("methodName", toGenerate.get(injName).target.name))
|
.addMethod(buildStringReturnMethod("methodName", toGenerate.get(injName).target.nameObf))
|
||||||
.addMethod(buildStringReturnMethod("methodDesc", toGenerate.get(injName).target.descriptor))
|
.addMethod(buildStringReturnMethod("methodDesc", toGenerate.get(injName).target.descriptorObf))
|
||||||
.addMethods(generateDummies(targets))
|
.addMethods(generateDummies(targets))
|
||||||
.addMethod(inject)
|
.addMethod(inject)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -127,19 +127,19 @@ public class JavaPoetUtils {
|
||||||
final boolean isMethod = type == ProxyType.METHOD;
|
final boolean isMethod = type == ProxyType.METHOD;
|
||||||
final String builderName = var.getSimpleName().toString() + "Builder";
|
final String builderName = var.getSimpleName().toString() + "Builder";
|
||||||
|
|
||||||
String descriptor, nameObf;
|
String descriptorObf, nameObf;
|
||||||
ClassContainer parent;
|
ClassContainer parent;
|
||||||
Element target;
|
Element target;
|
||||||
|
|
||||||
if(isMethod) {
|
if(isMethod) {
|
||||||
MethodContainer mc = MethodContainer.from(stub, t, f, env, mapper);
|
MethodContainer mc = MethodContainer.from(stub, t, f, env, mapper);
|
||||||
descriptor = mc.descriptor;
|
descriptorObf = mc.descriptorObf;
|
||||||
nameObf = mc.nameObf;
|
nameObf = mc.nameObf;
|
||||||
parent = mc.parent;
|
parent = mc.parent;
|
||||||
target = mc.elem;
|
target = mc.elem;
|
||||||
} else {
|
} else {
|
||||||
FieldContainer fc = FieldContainer.from(var, env, mapper);
|
FieldContainer fc = FieldContainer.from(var, env, mapper);
|
||||||
descriptor = fc.descriptor;
|
descriptorObf = fc.descriptorObf;
|
||||||
nameObf = fc.nameObf;
|
nameObf = fc.nameObf;
|
||||||
parent = fc.parent;
|
parent = fc.parent;
|
||||||
target = fc.elem;
|
target = fc.elem;
|
||||||
|
@ -172,7 +172,7 @@ public class JavaPoetUtils {
|
||||||
con.addStatement(
|
con.addStatement(
|
||||||
"$L.setDescriptor($S)",
|
"$L.setDescriptor($S)",
|
||||||
builderName,
|
builderName,
|
||||||
descriptor
|
descriptorObf
|
||||||
);
|
);
|
||||||
|
|
||||||
//build and set
|
//build and set
|
||||||
|
|
|
@ -4,6 +4,7 @@ import ftbsc.lll.exceptions.AmbiguousDefinitionException;
|
||||||
import ftbsc.lll.processor.annotations.Find;
|
import ftbsc.lll.processor.annotations.Find;
|
||||||
import ftbsc.lll.processor.annotations.Patch;
|
import ftbsc.lll.processor.annotations.Patch;
|
||||||
import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper;
|
import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
import javax.lang.model.element.VariableElement;
|
import javax.lang.model.element.VariableElement;
|
||||||
|
@ -11,6 +12,7 @@ import javax.lang.model.type.TypeKind;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
|
||||||
import static ftbsc.lll.processor.tools.ASTUtils.*;
|
import static ftbsc.lll.processor.tools.ASTUtils.*;
|
||||||
|
import static ftbsc.lll.processor.tools.JavaPoetUtils.descriptorFromExecutableElement;
|
||||||
import static ftbsc.lll.processor.tools.JavaPoetUtils.descriptorFromType;
|
import static ftbsc.lll.processor.tools.JavaPoetUtils.descriptorFromType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,6 +37,12 @@ public class FieldContainer {
|
||||||
*/
|
*/
|
||||||
public final String nameObf;
|
public final String nameObf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The obfuscated descriptor of the field.
|
||||||
|
* If the mapper passed is null, then this will be identical to {@link #descriptor}.
|
||||||
|
*/
|
||||||
|
public final String descriptorObf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link ClassContainer} representing the parent of this field.
|
* The {@link ClassContainer} representing the parent of this field.
|
||||||
* May be null if the parent is a class type that can not be checked
|
* May be null if the parent is a class type that can not be checked
|
||||||
|
@ -63,12 +71,13 @@ public class FieldContainer {
|
||||||
throw new AmbiguousDefinitionException("Cannot use name-based lookups for fields of unverifiable classes!");
|
throw new AmbiguousDefinitionException("Cannot use name-based lookups for fields of unverifiable classes!");
|
||||||
this.elem = null;
|
this.elem = null;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.descriptor = mapper == null ? descriptor : mapper.obfuscateMethodDescriptor(descriptor);
|
this.descriptor = descriptor;
|
||||||
|
this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateType(Type.getType(this.descriptor)).getDescriptor();
|
||||||
} else {
|
} else {
|
||||||
this.elem = (VariableElement) findMember(parent, name, descriptor, descriptor != null, true);
|
this.elem = (VariableElement) findMember(parent, name, descriptor, descriptor != null, true);
|
||||||
this.name = this.elem.getSimpleName().toString();
|
this.name = this.elem.getSimpleName().toString();
|
||||||
String validatedDescriptor = descriptorFromType(this.elem.asType());
|
this.descriptor = descriptorFromType(this.elem.asType());
|
||||||
this.descriptor = mapper == null ? descriptor : mapper.obfuscateMethodDescriptor(validatedDescriptor);
|
this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateType(Type.getType(this.descriptor)).getDescriptor();
|
||||||
}
|
}
|
||||||
this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper);
|
this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,12 @@ public class MethodContainer {
|
||||||
*/
|
*/
|
||||||
public final String nameObf;
|
public final String nameObf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The obfuscated descriptor of the field.
|
||||||
|
* If the mapper passed is null, then this will be identical to {@link #descriptor}.
|
||||||
|
*/
|
||||||
|
public final String descriptorObf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link ClassContainer} representing the parent of this method.
|
* The {@link ClassContainer} representing the parent of this method.
|
||||||
* May be null if the parent is a class type that can not be checked
|
* May be null if the parent is a class type that can not be checked
|
||||||
|
@ -67,12 +73,13 @@ public class MethodContainer {
|
||||||
throw new AmbiguousDefinitionException("Cannot use name-based lookups for methods of unverifiable classes!");
|
throw new AmbiguousDefinitionException("Cannot use name-based lookups for methods of unverifiable classes!");
|
||||||
this.elem = null;
|
this.elem = null;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.descriptor = mapper == null ? descriptor : mapper.obfuscateMethodDescriptor(descriptor);
|
this.descriptor = descriptor;
|
||||||
|
this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateMethodDescriptor(this.descriptor);
|
||||||
} else {
|
} else {
|
||||||
this.elem = (ExecutableElement) findMember(parent, name, descriptor, descriptor != null && strict, false);
|
this.elem = (ExecutableElement) findMember(parent, name, descriptor, descriptor != null && strict, false);
|
||||||
this.name = this.elem.getSimpleName().toString();
|
this.name = this.elem.getSimpleName().toString();
|
||||||
String validatedDescriptor = descriptorFromExecutableElement(this.elem);
|
this.descriptor = descriptorFromExecutableElement(this.elem);
|
||||||
this.descriptor = mapper == null ? descriptor : mapper.obfuscateMethodDescriptor(validatedDescriptor);
|
this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateMethodDescriptor(this.descriptor);
|
||||||
}
|
}
|
||||||
this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper);
|
this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue