From 06c6c5d3b0e1a736ce976207f449367fefaac11f Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 10 Mar 2016 23:40:48 -0500 Subject: [PATCH] constant parameter: annotate methods with constant parameters are @obfuscatedsignature so we can find them later in inject. Remove deobbed 16 jar as it doesnt have up to date annotations anymore. --- .../runelite/deob/attributes/Attributes.java | 4 +- .../deob/deobfuscators/ConstantParameter.java | 37 ++++++++++++++++--- .../deob/deobfuscators/rename/MapperTest.java | 3 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/Attributes.java b/src/main/java/net/runelite/deob/attributes/Attributes.java index 1411fe5730..3aa6f0f0e8 100644 --- a/src/main/java/net/runelite/deob/attributes/Attributes.java +++ b/src/main/java/net/runelite/deob/attributes/Attributes.java @@ -128,7 +128,7 @@ public class Attributes attributes.add(a); } - public void addAnnotation(Type type, String etype, PoolEntry value) + public Annotation addAnnotation(Type type, String etype, PoolEntry value) { Annotations an = (Annotations) findType(AttributeType.RUNTIMEVISIBLEANNOTATIONS); if (an == null) @@ -145,6 +145,8 @@ public class Attributes element.setType(new Type(etype)); element.setValue(value); annotation.addElement(element); + + return annotation; } public Annotations getAnnotations() diff --git a/src/main/java/net/runelite/deob/deobfuscators/ConstantParameter.java b/src/main/java/net/runelite/deob/deobfuscators/ConstantParameter.java index 010a15c08f..4897e999b7 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/ConstantParameter.java +++ b/src/main/java/net/runelite/deob/deobfuscators/ConstantParameter.java @@ -26,6 +26,11 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import net.runelite.deob.attributes.Annotations; +import net.runelite.deob.attributes.Attributes; +import net.runelite.deob.attributes.annotation.Annotation; +import net.runelite.deob.attributes.annotation.Element; +import net.runelite.deob.signature.Type; import org.apache.commons.collections4.map.MultiValueMap; class ConstantMethodParameter @@ -71,8 +76,6 @@ class ConstantMethodParameter } return true; } - - } class MethodGroup @@ -342,12 +345,14 @@ public class ConstantParameter implements Deobfuscator Method method; int lvtIndex; int paramIndex; + Object value; // example value, used for @ObfuscatedSignature. Just one possible value. - public MethodLvtPair(Method method, int lvtIndex, int paramIndex) + public MethodLvtPair(Method method, int lvtIndex, int paramIndex, Object value) { this.method = method; this.lvtIndex = lvtIndex; this.paramIndex = paramIndex; + this.value = value; } @Override @@ -396,7 +401,7 @@ public class ConstantParameter implements Deobfuscator { for (Method method : cmp.methods) { - MethodLvtPair pair = new MethodLvtPair(method, cmp.lvtIndex, cmp.paramIndex); + MethodLvtPair pair = new MethodLvtPair(method, cmp.lvtIndex, cmp.paramIndex, cmp.value); if (invalidDeadops.contains(pair)) continue; @@ -440,8 +445,9 @@ public class ConstantParameter implements Deobfuscator int count = 0; for (MethodLvtPair mvp : deadops.keySet()) { - Method method = mvp.method; List ops = deadops.get(mvp); + + annotateObfuscatedSignature(mvp); for (LogicallyDeadOp op : ops) { @@ -510,6 +516,27 @@ public class ConstantParameter implements Deobfuscator return count; } + private static final Type OBFUSCATED_SIGNATURE = new Type("Lnet/runelite/mapping/ObfuscatedSignature;"); + + private void annotateObfuscatedSignature(MethodLvtPair mvp) + { + Method m = mvp.method; + Object value = mvp.value; + + Attributes attributes = m.getAttributes(); + Annotations annotations = attributes.getAnnotations(); + + if (annotations != null && annotations.find(OBFUSCATED_SIGNATURE) != null) + return; + + Annotation annotation = attributes.addAnnotation(OBFUSCATED_SIGNATURE, "signature", new net.runelite.deob.pool.UTF8(m.getDescriptor().toString())); + + Element element = new Element(annotation); + element.setType(new Type("garbageValue")); + element.setValue(new net.runelite.deob.pool.UTF8(value.toString())); + annotation.addElement(element); + } + @Override public void run(ClassGroup group) { diff --git a/src/test/java/net/runelite/deob/deobfuscators/rename/MapperTest.java b/src/test/java/net/runelite/deob/deobfuscators/rename/MapperTest.java index 295e253988..555f1090c1 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapperTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapperTest.java @@ -8,10 +8,11 @@ import static net.runelite.deob.deobfuscators.rename.MapStaticTest.summary; import net.runelite.deob.util.JarUtil; import org.junit.Test; +// Compares two deobfuscated versions of the client public class MapperTest { private static final String JAR1 = "C:\\Users\\Adam\\.m2\\repository\\net\\runelite\\rs\\rs-client\\1.0-SNAPSHOT\\rs-client-1.0-SNAPSHOT.jar",//"d:/rs/07/gamepack_v16_deobbed.jar", - JAR2 = "d:/rs/07/gamepack_v17_deobbed.jar"; + JAR2 = MapperTest.class.getResource("/gamepack_v16_deobbed.jar").getFile(); // private static final String JAR1 = MapStaticTest.class.getResource("/adamin1.jar").getFile(), // JAR2 = MapStaticTest.class.getResource("/adamin2.jar").getFile();