Store obfuscated getter in annotations

This commit is contained in:
Adam
2015-11-20 19:30:15 -05:00
parent bd63eeb684
commit 26b3aa46a5
5 changed files with 77 additions and 43 deletions

View File

@@ -9,6 +9,10 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.attributes.annotation.Annotation;
import net.runelite.deob.attributes.annotation.Element;
import net.runelite.deob.pool.PoolEntry;
import net.runelite.deob.signature.Type;
public class Attributes
{
@@ -123,4 +127,23 @@ public class Attributes
assert a.getAttributes() == this;
attributes.add(a);
}
public void addAnnotation(Type type, PoolEntry value)
{
Annotations an = (Annotations) findType(AttributeType.RUNTIMEVISIBLEANNOTATIONS);
if (an == null)
{
an = new Annotations(this);
this.addAttribute(an);
}
Annotation annotation = new Annotation(an);
annotation.setType(type);
an.addAnnotation(annotation);
Element element = new Element(annotation);
element.setType(new Type("value"));
element.setValue(value);
annotation.addElement(element);
}
}

View File

@@ -13,7 +13,7 @@ public class Annotation
{
private final Annotations annotations;
private Type type;
private List<Element> elements = new ArrayList<>();
private final List<Element> elements = new ArrayList<>();
public Annotation(Annotations annotations)
{

View File

@@ -4,13 +4,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ConstantPool;
import net.runelite.deob.pool.PoolEntry;
import net.runelite.deob.signature.Type;
public class Element
{
private final Annotation annotation;
private Type type;
private String value;
private PoolEntry value;
public Element(Annotation annotation)
{
@@ -32,12 +33,12 @@ public class Element
this.type = type;
}
public String getValue()
public PoolEntry getValue()
{
return value;
}
public void setValue(String value)
public void setValue(PoolEntry value)
{
this.value = value;
}
@@ -51,12 +52,12 @@ public class Element
byte type = is.readByte();
if (type != 's')
throw new RuntimeException("can't parse non string annotation element");
if (type != 's' && type != 'I' && type != 'J')
throw new RuntimeException("can't parse annotation element type " + type);
int index = is.readShort(); // pool index to String
value = pool.getUTF8(index);
value = pool.getEntry(index);
}
public void write(DataOutputStream out) throws IOException
@@ -64,7 +65,22 @@ public class Element
ConstantPool pool = annotation.getAnnotations().getAttributes().getClassFile().getPool();
out.writeShort(pool.makeUTF8(type.toString()));
out.write('s');
out.writeShort(pool.makeUTF8(value));
byte type;
switch (value.getType())
{
case UTF8:
type = 's';
break;
case INTEGER:
type = 'I';
break;
case LONG:
type = 'J';
break;
default:
throw new RuntimeException("can't write annotation type " + value);
}
out.write(type);
out.writeShort(pool.make(value));
}
}

View File

@@ -10,20 +10,18 @@ import net.runelite.deob.Deobfuscator;
import net.runelite.deob.Field;
import net.runelite.deob.Interfaces;
import net.runelite.deob.Method;
import net.runelite.deob.attributes.Annotations;
import net.runelite.deob.attributes.AttributeType;
import net.runelite.deob.attributes.Attributes;
import net.runelite.deob.attributes.Code;
import net.runelite.deob.attributes.annotation.Annotation;
import net.runelite.deob.attributes.annotation.Element;
import net.runelite.deob.attributes.code.Exceptions;
import net.runelite.deob.pool.NameAndType;
import net.runelite.deob.pool.UTF8;
import net.runelite.deob.signature.Signature;
import net.runelite.deob.signature.Type;
import net.runelite.deob.util.NameMappings;
public class Renamer implements Deobfuscator
{
private static final Type OBFUSCATED_NAME_TYPE = new Type("Lnet/runelite/mapping/ObfuscatedName;");
private final NameMappings mappings;
public Renamer(NameMappings mappings)
@@ -90,7 +88,7 @@ public class Renamer implements Deobfuscator
field.setType(new Type("L" + name + ";", field.getType().getArrayDims()));
}
createOriginalNameAnnotation(cf.getAttributes(), cf.getName());
cf.getAttributes().addAnnotation(OBFUSCATED_NAME_TYPE, new UTF8(cf.getName()));
cf.setName(name);
}
@@ -166,27 +164,6 @@ public class Renamer implements Deobfuscator
c.getInstructions().regeneratePool();
}
}
private static final Type OBFUSCATED_NAME_TYPE = new Type("Lnet/runelite/mapping/ObfuscatedName");
private void createOriginalNameAnnotation(Attributes attr, String name)
{
Annotations an = (Annotations) attr.findType(AttributeType.RUNTIMEVISIBLEANNOTATIONS);
if (an == null)
{
an = new Annotations(attr);
attr.addAttribute(an);
}
Annotation annotation = new Annotation(an);
annotation.setType(OBFUSCATED_NAME_TYPE);
an.addAnnotation(annotation);
Element element = new Element(annotation);
element.setType(new Type("value"));
element.setValue(name);
annotation.addElement(element);
}
@Override
public void run(ClassGroup group)
@@ -204,7 +181,7 @@ public class Renamer implements Deobfuscator
if (newName == null)
continue;
createOriginalNameAnnotation(field.getAttributes(), field.getName());
field.getAttributes().addAnnotation(OBFUSCATED_NAME_TYPE, new UTF8(field.getName()));
field.setName(newName);
++fields;
}
@@ -222,7 +199,7 @@ public class Renamer implements Deobfuscator
for (Method m : virtualMethods)
{
createOriginalNameAnnotation(m.getAttributes(), m.getName());
m.getAttributes().addAnnotation(OBFUSCATED_NAME_TYPE, new UTF8(m.getName()));
m.setName(newName);
}
methods += virtualMethods.size();

View File

@@ -32,6 +32,8 @@ import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Frame;
import net.runelite.deob.execution.InstructionContext;
import net.runelite.deob.execution.StackContext;
import net.runelite.deob.pool.PoolEntry;
import net.runelite.deob.signature.Type;
import org.apache.commons.collections4.map.MultiValueMap;
public class ModArith implements Deobfuscator
@@ -41,7 +43,6 @@ public class ModArith implements Deobfuscator
private MultiValueMap<Field, Number> constantGetters = new MultiValueMap<>(),
constantSetters = new MultiValueMap<>();
private List<Pair> pairs = new ArrayList<>();
private Encryption encryption = new Encryption();
private List<InstructionContext> getInsInExpr(InstructionContext ctx, Set<Instruction> set)
{
@@ -650,6 +651,8 @@ public class ModArith implements Deobfuscator
execution.populateInitialMethods();
execution.run();
Encryption encryption = new Encryption();
findUses();
findUses2();
reduce2();
@@ -668,7 +671,7 @@ public class ModArith implements Deobfuscator
System.out.println("Changed " + ++i);
}
System.out.println(pairs);
annotateEncryption(encryption);
try
{
@@ -681,9 +684,24 @@ public class ModArith implements Deobfuscator
return i;
}
public Encryption getEncryption()
private static final Type OBFUSCATED_GETTER = new Type("Lnet/runelite/mapping/ObfuscatedGetter;");
private void annotateEncryption(Encryption encryption)
{
return encryption;
for (ClassFile cf : group.getClasses())
{
for (Field f : cf.getFields().getFields())
{
Pair pair = encryption.getField(f.getPoolField());
if (pair == null)
continue;
PoolEntry value = pair.getType() == Long.class ?
new net.runelite.deob.pool.Long((long) pair.getter) :
new net.runelite.deob.pool.Integer((int) pair.getter);
f.getAttributes().addAnnotation(OBFUSCATED_GETTER, value);
}
}
}
}