Add OriginalArg annotation

The dummy argument removal code is going to fiddle with the argument
lists (and so could manual refactoring).
master
Graham 5 years ago
parent 3978ee9ea0
commit cf650af5fa
  1. 9
      deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalArg.java
  2. 20
      deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java

@ -0,0 +1,9 @@
package dev.openrs2.deob.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ ElementType.PARAMETER })
public @interface OriginalArg {
int value();
}

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.openrs2.asm.Transformer; import dev.openrs2.asm.Transformer;
import dev.openrs2.deob.annotation.OriginalArg;
import dev.openrs2.deob.annotation.OriginalClass; import dev.openrs2.deob.annotation.OriginalClass;
import dev.openrs2.deob.annotation.OriginalMember; import dev.openrs2.deob.annotation.OriginalMember;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@ -29,6 +30,12 @@ public final class OriginalNameTransformer extends Transformer {
return annotation; return annotation;
} }
private static AnnotationNode createOriginalArgAnnotation(int index) {
var annotation = new AnnotationNode(Type.getDescriptor(OriginalArg.class));
annotation.values = List.of("value", index);
return annotation;
}
@Override @Override
public void transformClass(ClassNode clazz) { public void transformClass(ClassNode clazz) {
if (clazz.invisibleAnnotations == null) { if (clazz.invisibleAnnotations == null) {
@ -45,6 +52,7 @@ public final class OriginalNameTransformer extends Transformer {
field.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, field.name, field.desc)); field.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, field.name, field.desc));
} }
@SuppressWarnings("unchecked")
@Override @Override
public void transformMethod(ClassNode clazz, MethodNode method) { public void transformMethod(ClassNode clazz, MethodNode method) {
if (method.name.equals("<init>") || method.name.equals("<clinit>")) { if (method.name.equals("<init>") || method.name.equals("<clinit>")) {
@ -55,5 +63,17 @@ public final class OriginalNameTransformer extends Transformer {
method.invisibleAnnotations = new ArrayList<>(); method.invisibleAnnotations = new ArrayList<>();
} }
method.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, method.name, method.desc)); method.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, method.name, method.desc));
int args = Type.getArgumentTypes(method.desc).length;
if (method.invisibleParameterAnnotations == null) {
method.invisibleParameterAnnotations = (List<AnnotationNode>[]) new List<?>[args];
}
for (int i = 0; i < method.invisibleParameterAnnotations.length; i++) {
var annotations = method.invisibleParameterAnnotations[i];
if (annotations == null) {
annotations = method.invisibleParameterAnnotations[i] = new ArrayList<>();
}
annotations.add(createOriginalArgAnnotation(i));
}
} }
} }

Loading…
Cancel
Save