Check mappings works now, add array load/store instruction types. Beginning of mapping importer.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package net.runelite.deob.attributes.code.instruction.types;
|
||||
|
||||
public interface ArrayLoad
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.runelite.deob.attributes.code.instruction.types;
|
||||
|
||||
public interface ArrayStore
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
|
||||
120
src/test/java/net/runelite/deob/runeloader/MappingImporter.java
Normal file
120
src/test/java/net/runelite/deob/runeloader/MappingImporter.java
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user