From e2b0c90e7ad4af5a4d8c19d45cd513d449652eb9 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 22 Nov 2015 19:45:20 -0600 Subject: [PATCH] Check mappings works now, add array load/store instruction types. Beginning of mapping importer. --- .../code/instruction/types/ArrayLoad.java | 6 + .../code/instruction/types/ArrayStore.java | 6 + .../deob/runeloader/CheckMappings.java | 2 - .../deob/runeloader/MappingImporter.java | 120 ++++++++++++++++++ 4 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayLoad.java create mode 100644 src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayStore.java create mode 100644 src/test/java/net/runelite/deob/runeloader/MappingImporter.java diff --git a/src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayLoad.java b/src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayLoad.java new file mode 100644 index 0000000000..d7336a8f0a --- /dev/null +++ b/src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayLoad.java @@ -0,0 +1,6 @@ +package net.runelite.deob.attributes.code.instruction.types; + +public interface ArrayLoad +{ + +} diff --git a/src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayStore.java b/src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayStore.java new file mode 100644 index 0000000000..d6d6e9725c --- /dev/null +++ b/src/main/java/net/runelite/deob/attributes/code/instruction/types/ArrayStore.java @@ -0,0 +1,6 @@ +package net.runelite.deob.attributes.code.instruction.types; + +public interface ArrayStore +{ + +} diff --git a/src/test/java/net/runelite/deob/runeloader/CheckMappings.java b/src/test/java/net/runelite/deob/runeloader/CheckMappings.java index ef7b8ffe2b..883ab4a2b7 100644 --- a/src/test/java/net/runelite/deob/runeloader/CheckMappings.java +++ b/src/test/java/net/runelite/deob/runeloader/CheckMappings.java @@ -21,8 +21,6 @@ import org.slf4j.LoggerFactory; public class CheckMappings { - private static final Logger logger = LoggerFactory.getLogger(CheckMappings.class); - private static final File CLIENT = new File("/Users/adam/w/rs/07/rs-client-1.0-SNAPSHOT.jar"); private static final File RL_INJECTION = new File("/Users/adam/w/rs/07/rl/injection.json"); diff --git a/src/test/java/net/runelite/deob/runeloader/MappingImporter.java b/src/test/java/net/runelite/deob/runeloader/MappingImporter.java new file mode 100644 index 0000000000..9ffdaef8d2 --- /dev/null +++ b/src/test/java/net/runelite/deob/runeloader/MappingImporter.java @@ -0,0 +1,120 @@ +package net.runelite.deob.runeloader; + +import java.io.File; +import java.io.IOException; +import net.runelite.deob.ClassFile; +import net.runelite.deob.ClassGroup; +import net.runelite.deob.Field; +import net.runelite.deob.attributes.Annotations; +import net.runelite.deob.attributes.AttributeType; +import net.runelite.deob.attributes.annotation.Annotation; +import net.runelite.deob.attributes.annotation.Element; +import net.runelite.deob.pool.UTF8; +import net.runelite.deob.runeloader.inject.GetterInjectInstruction; +import net.runelite.deob.runeloader.inject.InjectionModscript; +import net.runelite.deob.signature.Type; +import net.runelite.deob.util.JarUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class MappingImporter +{ + private static final File IN = new File("/Users/adam/w/rs/07/adamin.jar"); + private static final File OUT = new File("/Users/adam/w/rs/07/adamout.jar"); + private static final File RL_INJECTION = new File("/Users/adam/w/rs/07/rl/injection.json"); + + private static final Type OBFUSCATED_NAME = new Type("Lnet/runelite/mapping/ObfuscatedName;"); + private static final Type EXPORT = new Type("Lnet/runelite/mapping/Export;"); + + private ClassGroup group; + + @Before + public void before() throws IOException + { + group = JarUtil.loadJar(IN); + } + + @After + public void after() throws IOException + { + JarUtil.saveJar(group, OUT); + } + + private boolean hasObfuscatedName(Annotations an, String name) + { + if (an == null) + { + return false; + } + + for (Annotation a : an.getAnnotations()) + { + if (a.getType().equals(OBFUSCATED_NAME)) + { + for (Element e : a.getElements()) + { + String str = (String) e.getValue().getObject(); + if (str.equals(name)) + { + return true; + } + } + } + } + + return false; + } + + private ClassFile findClassWithObfuscatedName(String name) + { + for (ClassFile c : group.getClasses()) + { + if (c.getName().equals(name)) + return c; + + Annotations an = (Annotations) c.getAttributes().findType(AttributeType.RUNTIMEVISIBLEANNOTATIONS); + if (this.hasObfuscatedName(an, name)) + return c; + } + return null; + } + + private Field findFieldWithObfuscatedName(ClassFile c, String name) + { + for (Field f : c.getFields().getFields()) + { + Annotations an = (Annotations) f.getAttributes().findType(AttributeType.RUNTIMEVISIBLEANNOTATIONS); + if (this.hasObfuscatedName(an, name)) + return f; + } + return null; + } + + @Test + public void makeMappings() throws IOException + { + InjectionModscript mod = InjectionModscript.load(RL_INJECTION); + + for (int i = 0; i < mod.getGetterInjects().size(); ++i) + { + GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i); + + ClassFile cf = this.findClassWithObfuscatedName(gii.getGetterClassName()); + Assert.assertNotNull(cf); + + Field f = this.findFieldWithObfuscatedName(cf, gii.getGetterFieldName()); + Assert.assertNotNull(f); + + String attrName = gii.getGetterName(); + if (attrName.startsWith("get")) + { + attrName = attrName.substring(3); + attrName = Character.toLowerCase(attrName.charAt(0)) + attrName.substring(1); + } + + f.getAttributes().addAnnotation(EXPORT, "value", new UTF8(attrName)); + } + } +}