Add owner and descriptor to original field/method annotations

This will make it easier to map original names to refactored names. It
also means we can keep tracking static methods even if they get moved
around.
bzip2
Graham 5 years ago
parent 9a27264d97
commit a2f74669de
  1. 4
      deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalClass.java
  2. 11
      deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalMember.java
  3. 23
      deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java

@ -3,7 +3,7 @@ package dev.openrs2.deob.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
public @interface OriginalName {
@Target({ ElementType.TYPE })
public @interface OriginalClass {
String value();
}

@ -0,0 +1,11 @@
package dev.openrs2.deob.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ ElementType.FIELD, ElementType.METHOD })
public @interface OriginalMember {
String owner();
String name();
String descriptor();
}

@ -4,7 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import dev.openrs2.asm.Transformer;
import dev.openrs2.deob.annotation.OriginalName;
import dev.openrs2.deob.annotation.OriginalClass;
import dev.openrs2.deob.annotation.OriginalMember;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.AnnotationNode;
@ -13,12 +14,22 @@ import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
public final class OriginalNameTransformer extends Transformer {
private static AnnotationNode createOriginalNameAnnotation(String name) {
var annotation = new AnnotationNode(Type.getDescriptor(OriginalName.class));
private static AnnotationNode createOriginalClassAnnotation(String name) {
var annotation = new AnnotationNode(Type.getDescriptor(OriginalClass.class));
annotation.values = List.of("value", name);
return annotation;
}
private static AnnotationNode createOriginalMemberAnnotation(String owner, String name, String desc) {
var annotation = new AnnotationNode(Type.getDescriptor(OriginalMember.class));
annotation.values = List.of(
"owner", owner,
"name", name,
"descriptor", desc
);
return annotation;
}
private final Remapper remapper;
public OriginalNameTransformer(Remapper remapper) {
@ -34,7 +45,7 @@ public final class OriginalNameTransformer extends Transformer {
if (clazz.invisibleAnnotations == null) {
clazz.invisibleAnnotations = new ArrayList<>();
}
clazz.invisibleAnnotations.add(createOriginalNameAnnotation(clazz.name));
clazz.invisibleAnnotations.add(createOriginalClassAnnotation(clazz.name));
}
@Override
@ -46,7 +57,7 @@ public final class OriginalNameTransformer extends Transformer {
if (field.invisibleAnnotations == null) {
field.invisibleAnnotations = new ArrayList<>();
}
field.invisibleAnnotations.add(createOriginalNameAnnotation(field.name));
field.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, field.name, field.desc));
}
@Override
@ -58,6 +69,6 @@ public final class OriginalNameTransformer extends Transformer {
if (method.invisibleAnnotations == null) {
method.invisibleAnnotations = new ArrayList<>();
}
method.invisibleAnnotations.add(createOriginalNameAnnotation(method.name));
method.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, method.name, method.desc));
}
}

Loading…
Cancel
Save