aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-29 12:15:36 +0200
committer zaaarf <zaaarf@proton.me>2023-03-29 12:15:36 +0200
commitd451cc3460fc162295874f0b8ddb2f058dadfa66 (patch)
treebeb0688822876bfc9667010a63a516400439a298
parentdac2510de75839c7617c2fb648905541496494e0 (diff)
fix: descriptor obfuscation now handled properly
-rw-r--r--src/main/java/ftbsc/lll/processor/LilleroProcessor.java6
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java8
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java15
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java13
4 files changed, 29 insertions, 13 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
index 768fed0..4677a50 100644
--- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
+++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java
@@ -354,9 +354,9 @@ public class LilleroProcessor extends AbstractProcessor {
.addMethod(constructorBuilder.build())
.addMethod(buildStringReturnMethod("name", cl.getSimpleName().toString()))
.addMethod(buildStringReturnMethod("reason", toGenerate.get(injName).reason))
- .addMethod(buildStringReturnMethod("targetClass", targetClass.fqn))
- .addMethod(buildStringReturnMethod("methodName", toGenerate.get(injName).target.name))
- .addMethod(buildStringReturnMethod("methodDesc", toGenerate.get(injName).target.descriptor))
+ .addMethod(buildStringReturnMethod("targetClass", targetClass.fqnObf))
+ .addMethod(buildStringReturnMethod("methodName", toGenerate.get(injName).target.nameObf))
+ .addMethod(buildStringReturnMethod("methodDesc", toGenerate.get(injName).target.descriptorObf))
.addMethods(generateDummies(targets))
.addMethod(inject)
.build();
diff --git a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
index e2c8f2e..b698e74 100644
--- a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
+++ b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java
@@ -127,19 +127,19 @@ public class JavaPoetUtils {
final boolean isMethod = type == ProxyType.METHOD;
final String builderName = var.getSimpleName().toString() + "Builder";
- String descriptor, nameObf;
+ String descriptorObf, nameObf;
ClassContainer parent;
Element target;
if(isMethod) {
MethodContainer mc = MethodContainer.from(stub, t, f, env, mapper);
- descriptor = mc.descriptor;
+ descriptorObf = mc.descriptorObf;
nameObf = mc.nameObf;
parent = mc.parent;
target = mc.elem;
} else {
FieldContainer fc = FieldContainer.from(var, env, mapper);
- descriptor = fc.descriptor;
+ descriptorObf = fc.descriptorObf;
nameObf = fc.nameObf;
parent = fc.parent;
target = fc.elem;
@@ -172,7 +172,7 @@ public class JavaPoetUtils {
con.addStatement(
"$L.setDescriptor($S)",
builderName,
- descriptor
+ descriptorObf
);
//build and set
diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java
index 0b39a1c..b6a98bd 100644
--- a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java
+++ b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java
@@ -4,6 +4,7 @@ import ftbsc.lll.exceptions.AmbiguousDefinitionException;
import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper;
+import org.objectweb.asm.Type;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.VariableElement;
@@ -11,6 +12,7 @@ import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import static ftbsc.lll.processor.tools.ASTUtils.*;
+import static ftbsc.lll.processor.tools.JavaPoetUtils.descriptorFromExecutableElement;
import static ftbsc.lll.processor.tools.JavaPoetUtils.descriptorFromType;
/**
@@ -36,6 +38,12 @@ public class FieldContainer {
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.
* May be null if the parent is a class type that can not be checked
* at processing time (such as an anonymous class)
@@ -63,12 +71,13 @@ public class FieldContainer {
throw new AmbiguousDefinitionException("Cannot use name-based lookups for fields of unverifiable classes!");
this.elem = null;
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 {
this.elem = (VariableElement) findMember(parent, name, descriptor, descriptor != null, true);
this.name = this.elem.getSimpleName().toString();
- String validatedDescriptor = descriptorFromType(this.elem.asType());
- this.descriptor = mapper == null ? descriptor : mapper.obfuscateMethodDescriptor(validatedDescriptor);
+ this.descriptor = descriptorFromType(this.elem.asType());
+ this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateType(Type.getType(this.descriptor)).getDescriptor();
}
this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper);
}
diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java
index d8ab04f..7f328d6 100644
--- a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java
+++ b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java
@@ -39,6 +39,12 @@ public class MethodContainer {
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.
* May be null if the parent is a class type that can not be checked
* at processing time (such as an anonymous class)
@@ -67,12 +73,13 @@ public class MethodContainer {
throw new AmbiguousDefinitionException("Cannot use name-based lookups for methods of unverifiable classes!");
this.elem = null;
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 {
this.elem = (ExecutableElement) findMember(parent, name, descriptor, descriptor != null && strict, false);
this.name = this.elem.getSimpleName().toString();
- String validatedDescriptor = descriptorFromExecutableElement(this.elem);
- this.descriptor = mapper == null ? descriptor : mapper.obfuscateMethodDescriptor(validatedDescriptor);
+ this.descriptor = descriptorFromExecutableElement(this.elem);
+ this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateMethodDescriptor(this.descriptor);
}
this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper);
}