From a2f74669de2e5988c54ad17d5633efa65a37f05a Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 30 Jul 2019 09:29:52 +0100 Subject: [PATCH] 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. --- .../{OriginalName.java => OriginalClass.java} | 4 ++-- .../deob/annotation/OriginalMember.java | 11 +++++++++ .../transform/OriginalNameTransformer.java | 23 ++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) rename deob-annotations/src/main/java/dev/openrs2/deob/annotation/{OriginalName.java => OriginalClass.java} (56%) create mode 100644 deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalMember.java diff --git a/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalName.java b/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalClass.java similarity index 56% rename from deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalName.java rename to deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalClass.java index da5724bd..b91a8b3b 100644 --- a/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalName.java +++ b/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalClass.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(); } diff --git a/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalMember.java b/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalMember.java new file mode 100644 index 00000000..8d392d70 --- /dev/null +++ b/deob-annotations/src/main/java/dev/openrs2/deob/annotation/OriginalMember.java @@ -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(); +} diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java index faabecba..96c7e9ba 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java @@ -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)); } }