Rewrite rename unique to work much different. Seems to run ok.

This commit is contained in:
Adam
2015-10-18 18:41:04 -04:00
parent f43a926e61
commit 95c4c441d0
23 changed files with 386 additions and 255 deletions

View File

@@ -166,6 +166,11 @@ public class ClassFile
{
return fields.findField(name);
}
public Class getPoolClass()
{
return name;
}
public Field findFieldDeep(NameAndType nat)
{
@@ -201,7 +206,7 @@ public class ClassFile
ClassFile parent = getParent();
if (parent != null)
return parent.findMethodDeep(nat);
return parent.findMethodDeepStatic(nat);
return null;
}

View File

@@ -39,40 +39,40 @@ public class Deob
ClassGroup group = loadJar(args[0]);
//run(group, new RenameUnique());
run(group, new RenameUnique());
// remove except RuntimeException
run(group, new RuntimeExceptions());
// remove unused methods
run(group, new UnusedMethods());
run(group, new UnreachedCode());
// remove illegal state exceptions, frees up some parameters
run(group, new IllegalStateExceptions());
// remove constant logically dead parameters
run(group, new ConstantParameter());
// remove unhit blocks
run(group, new UnreachedCode());
// // remove except RuntimeException
// run(group, new RuntimeExceptions());
//
// // remove unused methods
// run(group, new UnusedMethods());
//
// run(group, new UnreachedCode());
//
// // remove illegal state exceptions, frees up some parameters
// run(group, new IllegalStateExceptions());
//
// // remove constant logically dead parameters
// run(group, new ConstantParameter());
//
// // remove unhit blocks
// run(group, new UnreachedCode());
//
// // remove unused parameters
// run(group, new UnusedParameters());
//
// // remove jump obfuscation
// //new Jumps().run(group);
//
// // remove unused fields
// run(group, new UnusedFields());
//
// // remove unused methods, again?
// run(group, new UnusedMethods());
// remove unused fields
run(group, new UnusedFields());
// remove unused methods, again?
run(group, new UnusedMethods());
//
// run(group, new MethodInliner());
//
// run(group, new MethodMover());
// //run(group, new MethodMover());
//
// run(group, new FieldInliner());
//
@@ -82,27 +82,27 @@ public class Deob
//
// run(group, new UnusedClass());
ModArith mod = new ModArith();
mod.run(group);
int last = -1, cur;
while ((cur = mod.runOnce()) > 0)
{
new MultiplicationDeobfuscator().run(group);
new MultiplyOneDeobfuscator().run(group);
new MultiplyZeroDeobfuscator().run(group);
if (last == cur)
{
System.out.println("break");
break;
}
last = cur;
//break;
}
// ModArith mod = new ModArith();
// mod.run(group);
//
// int last = -1, cur;
// while ((cur = mod.runOnce()) > 0)
// {
// new MultiplicationDeobfuscator().run(group);
//
// new MultiplyOneDeobfuscator().run(group);
//
// new MultiplyZeroDeobfuscator().run(group);
//
// if (last == cur)
// {
// System.out.println("break");
// break;
// }
//
// last = cur;
// //break;
// }
saveJar(group, args[1]);

View File

@@ -151,7 +151,15 @@ public class Method
{
return new net.runelite.deob.pool.Method(
new net.runelite.deob.pool.Class(this.getMethods().getClassFile().getName()),
new NameAndType(this.getName(), this.getDescriptor())
new NameAndType(this.getName(), new Signature(this.getDescriptor()))
);
}
public net.runelite.deob.pool.InterfaceMethod getPoolInterfaceMethod()
{
return new net.runelite.deob.pool.InterfaceMethod(
new net.runelite.deob.pool.Class(this.getMethods().getClassFile().getName()),
new NameAndType(this.getName(), new Signature(this.getDescriptor()))
);
}
}

View File

@@ -1,10 +1,7 @@
package net.runelite.deob.attributes.code;
import java.io.DataInputStream;
import net.runelite.deob.ClassFile;
import net.runelite.deob.ConstantPool;
import net.runelite.deob.Field;
import net.runelite.deob.Method;
import net.runelite.deob.block.Block;
import net.runelite.deob.execution.Frame;
@@ -12,6 +9,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.util.NameMappings;
public abstract class Instruction
{
@@ -222,15 +220,12 @@ public abstract class Instruction
{
}
public void renameClass(ClassFile cf, String name)
// look up symbols from pool
public void lookup2()
{
}
public void renameField(Field f, net.runelite.deob.pool.Field name)
{
}
public void renameMethod(Method oldMethod, net.runelite.deob.pool.Method newMethod)
public void regeneratePool()
{
}

View File

@@ -14,6 +14,7 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.util.NameMappings;
public class Instructions
{
@@ -253,24 +254,18 @@ public class Instructions
return null;
}
public void renameClass(ClassFile cf, String name)
public void lookup()
{
for (Instruction i : instructions)
i.renameClass(cf, name);
i.lookup2();
}
public void renameField(Field f, net.runelite.deob.pool.Field newField)
public void regeneratePool()
{
for (Instruction i : instructions)
i.renameField(f, newField);
i.regeneratePool();
}
public void renameMethod(Method oldMethod, net.runelite.deob.pool.Method newMethod)
{
for (Instruction i : instructions)
i.renameMethod(oldMethod, newMethod);
}
public void replace(Instruction oldi, Instruction newi)
{
assert oldi != newi;

View File

@@ -14,10 +14,14 @@ import net.runelite.deob.pool.Class;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.util.NameMappings;
public class ANewArray extends Instruction
{
private Class clazz;
private ClassFile myClass;
private int dimensions;
public ANewArray(Instructions instructions, InstructionType type, int pc)
{
@@ -59,10 +63,27 @@ public class ANewArray extends Instruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
net.runelite.deob.signature.Type t = new net.runelite.deob.signature.Type(clazz.getName());
if (t.getType().equals("L" + cf.getName() + ";") || t.getType().equals(cf.getName()))
clazz = new Class(name, t.getArrayDims());
String name = t.getType();
if (name.startsWith("L") && name.endsWith(";"))
name = name.substring(1, name.length() - 1);
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
myClass = group.findClass(name);
dimensions = t.getArrayDims();
}
@Override
public void regeneratePool()
{
if (myClass != null)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < this.dimensions; ++i)
sb.append('[');
sb.append("L" + myClass.getName() + ";");
clazz = new Class(sb.toString());
}
}
}

View File

@@ -14,10 +14,13 @@ import net.runelite.deob.pool.Class;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.util.NameMappings;
public class CheckCast extends Instruction
{
private Class clazz;
private ClassFile myClass;
public CheckCast(Instructions instructions, InstructionType type, int pc)
{
@@ -57,9 +60,16 @@ public class CheckCast extends Instruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (clazz.getName().equals(cf.getName()))
clazz = new Class(name);
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
myClass = group.findClass(clazz.getName());
}
@Override
public void regeneratePool()
{
if (myClass != null)
clazz = myClass.getPoolClass();
}
}

View File

@@ -17,12 +17,15 @@ import net.runelite.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.deobfuscators.arithmetic.Encryption;
import net.runelite.deob.deobfuscators.arithmetic.Pair;
import net.runelite.deob.util.NameMappings;
public class GetField extends Instruction implements GetFieldInstruction
{
private Field field;
private net.runelite.deob.Field myField;
public GetField(Instructions instructions, InstructionType type, int pc)
{
@@ -81,21 +84,15 @@ public class GetField extends Instruction implements GetFieldInstruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (field.getClassEntry().getName().equals(cf.getName()))
field = new Field(new Class(name), field.getNameAndType());
if (field.getNameAndType().getDescriptorType().getType().equals("L" + cf.getName() + ";"))
field = new Field(field.getClassEntry(), new NameAndType(field.getNameAndType().getName(), new net.runelite.deob.signature.Type("L" + name + ";", field.getNameAndType().getDescriptorType().getArrayDims())));
myField = getMyField();
}
@Override
public void renameField(net.runelite.deob.Field f, Field newField)
public void regeneratePool()
{
net.runelite.deob.Field f2 = getMyField();
if (f2 == f)
field = newField;
if (myField != null)
field = myField.getPoolField();
}
}

View File

@@ -17,12 +17,15 @@ import net.runelite.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.deobfuscators.arithmetic.Encryption;
import net.runelite.deob.deobfuscators.arithmetic.Pair;
import net.runelite.deob.util.NameMappings;
public class GetStatic extends Instruction implements GetFieldInstruction
{
private Field field;
private net.runelite.deob.Field myField;
public GetStatic(Instructions instructions, InstructionType type, int pc)
{
@@ -83,25 +86,17 @@ public class GetStatic extends Instruction implements GetFieldInstruction
net.runelite.deob.Field f2 = cf.findFieldDeep(nat);
return f2;
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (field.getClassEntry().getName().equals(cf.getName()))
field = new Field(new Class(name), field.getNameAndType());
if (field.getNameAndType().getDescriptorType().getType().equals("L" + cf.getName() + ";"))
field = new Field(field.getClassEntry(), new NameAndType(field.getNameAndType().getName(), new net.runelite.deob.signature.Type("L" + name + ";", field.getNameAndType().getDescriptorType().getArrayDims())));
myField = this.getMyField();
}
@Override
public void renameField(net.runelite.deob.Field f, Field newField)
public void regeneratePool()
{
net.runelite.deob.Field f2 = getMyField();
if (f2 == f)
{
field = newField;
}
if (myField != null)
field = myField.getPoolField();
}
}

View File

@@ -13,10 +13,13 @@ import net.runelite.deob.pool.Class;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.util.NameMappings;
public class InstanceOf extends Instruction
{
private Class clazz;
private ClassFile myClass;
public InstanceOf(Instructions instructions, InstructionType type, int pc)
{
@@ -55,9 +58,16 @@ public class InstanceOf extends Instruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (clazz.getName().equals(cf.getName()))
clazz = new Class(name);
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
myClass = group.findClass(clazz.getName());
}
@Override
public void regeneratePool()
{
if (myClass != null)
clazz = myClass.getPoolClass();
}
}

View File

@@ -24,11 +24,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.execution.Execution;
import net.runelite.deob.util.NameMappings;
public class InvokeInterface extends Instruction implements InvokeInstruction
{
private InterfaceMethod method;
private int count;
private List<net.runelite.deob.Method> myMethods;
public InvokeInterface(Instructions instructions, InstructionType type, int pc)
{
@@ -142,30 +144,15 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (method.getClassEntry().getName().equals(cf.getName()))
method = new InterfaceMethod(new Class(name), method.getNameAndType());
Signature signature = method.getNameAndType().getDescriptor();
for (int i = 0; i < signature.size(); ++i)
{
net.runelite.deob.signature.Type type = signature.getTypeOfArg(i);
if (type.getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfArg(i, new net.runelite.deob.signature.Type("L" + name + ";", type.getArrayDims()));
}
// rename return type
if (signature.getReturnValue().getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfReturnValue(new net.runelite.deob.signature.Type("L" + name + ";", signature.getReturnValue().getArrayDims()));
myMethods = this.getMethods();
}
@Override
public void renameMethod(net.runelite.deob.Method m, Method newMethod)
public void regeneratePool()
{
for (net.runelite.deob.Method m2 : getMethods())
if (m2.equals(m))
method = new InterfaceMethod(newMethod.getClassEntry(), newMethod.getNameAndType());
if (!myMethods.isEmpty())
method = myMethods.get(0).getPoolInterfaceMethod(); // is this right?
}
}

View File

@@ -23,10 +23,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.execution.Execution;
import net.runelite.deob.pool.InterfaceMethod;
import net.runelite.deob.util.NameMappings;
public class InvokeSpecial extends Instruction implements InvokeInstruction
{
private Method method;
private List<net.runelite.deob.Method> myMethods;
public InvokeSpecial(Instructions instructions, InstructionType type, int pc)
{
@@ -134,30 +137,15 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (method.getClassEntry().getName().equals(cf.getName()))
method = new Method(new Class(name), method.getNameAndType());
Signature signature = method.getNameAndType().getDescriptor();
for (int i = 0; i < signature.size(); ++i)
{
net.runelite.deob.signature.Type type = signature.getTypeOfArg(i);
if (type.getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfArg(i, new net.runelite.deob.signature.Type("L" + name + ";", type.getArrayDims()));
}
// rename return type
if (signature.getReturnValue().getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfReturnValue(new net.runelite.deob.signature.Type("L" + name + ";", signature.getReturnValue().getArrayDims()));
myMethods = this.getMethods();
}
@Override
public void renameMethod(net.runelite.deob.Method m, Method newMethod)
public void regeneratePool()
{
for (net.runelite.deob.Method m2 : getMethods())
if (m2.equals(m))
method = newMethod;
if (!myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod();
}
}

View File

@@ -23,10 +23,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.execution.Execution;
import net.runelite.deob.util.NameMappings;
public class InvokeStatic extends Instruction implements InvokeInstruction
{
private Method method;
private List<net.runelite.deob.Method> myMethods;
public InvokeStatic(Instructions instructions, InstructionType type, int pc)
{
@@ -138,37 +140,15 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (method.getClassEntry().getName().equals(cf.getName()))
method = new Method(new Class(name), method.getNameAndType());
Signature signature = method.getNameAndType().getDescriptor();
for (int i = 0; i < signature.size(); ++i)
{
net.runelite.deob.signature.Type type = signature.getTypeOfArg(i);
if (type.getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfArg(i, new net.runelite.deob.signature.Type("L" + name + ";", type.getArrayDims()));
}
// rename return type
if (signature.getReturnValue().getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfReturnValue(new net.runelite.deob.signature.Type("L" + name + ";", signature.getReturnValue().getArrayDims()));
myMethods = this.getMethods();
}
@Override
public void renameMethod(net.runelite.deob.Method m, Method newMethod)
public void regeneratePool()
{
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
ClassFile otherClass = group.findClass(method.getClassEntry().getName());
if (otherClass == null)
return; // not our class
net.runelite.deob.Method other = otherClass.findMethodDeepStatic(method.getNameAndType());
assert other.isStatic();
if (other.equals(m))
method = newMethod;
if (!myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod();
}
}

View File

@@ -23,10 +23,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.runelite.deob.execution.Execution;
import net.runelite.deob.util.NameMappings;
public class InvokeVirtual extends Instruction implements InvokeInstruction
{
private Method method;
private List<net.runelite.deob.Method> myMethods;
public InvokeVirtual(Instructions instructions, InstructionType type, int pc)
{
@@ -139,30 +141,15 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (method.getClassEntry().getName().equals(cf.getName()))
method = new Method(new Class(name), method.getNameAndType());
Signature signature = method.getNameAndType().getDescriptor();
for (int i = 0; i < signature.size(); ++i)
{
net.runelite.deob.signature.Type type = signature.getTypeOfArg(i);
if (type.getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfArg(i, new net.runelite.deob.signature.Type("L" + name + ";", type.getArrayDims()));
}
// rename return type
if (signature.getReturnValue().getType().equals("L" + cf.getName() + ";"))
signature.setTypeOfReturnValue(new net.runelite.deob.signature.Type("L" + name + ";", signature.getReturnValue().getArrayDims()));
myMethods = this.getMethods();
}
@Override
public void renameMethod(net.runelite.deob.Method m, Method newMethod)
public void regeneratePool()
{
for (net.runelite.deob.Method m2 : getMethods())
if (m2.equals(m))
method = newMethod;
if (!myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod(); // is this right?
}
}

View File

@@ -14,11 +14,14 @@ import net.runelite.deob.pool.Class;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.util.NameMappings;
public class MultiANewArray extends Instruction
{
private Class clazz;
private int dimensions;
private ClassFile myClass;
public MultiANewArray(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -63,11 +66,26 @@ public class MultiANewArray extends Instruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
// class is an array type, ugh.
net.runelite.deob.signature.Type t = new net.runelite.deob.signature.Type(clazz.getName());
if (t.getType().equals("L" + cf.getName() + ";"))
clazz = new Class("L" + name + ";", t.getArrayDims());
String name = t.getType();
if (name.startsWith("L") && name.endsWith(";"))
name = name.substring(1, name.length() - 1);
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
myClass = group.findClass(name);
}
@Override
public void regeneratePool()
{
if (myClass != null)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < this.dimensions; ++i)
sb.append('[');
sb.append("L" + myClass.getName() + ";");
clazz = new Class(sb.toString());
}
}
}

View File

@@ -14,10 +14,13 @@ import net.runelite.deob.pool.Class;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.util.NameMappings;
public class New extends Instruction
{
private Class clazz;
private ClassFile myClass;
public New(Instructions instructions, InstructionType type, int pc)
{
@@ -58,9 +61,16 @@ public class New extends Instruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (clazz.getName().equals(cf.getName()))
clazz = new Class(name);
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
myClass = group.findClass(clazz.getName());
}
@Override
public void regeneratePool()
{
if (myClass != null)
clazz = myClass.getPoolClass();
}
}

View File

@@ -16,12 +16,15 @@ import net.runelite.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.deobfuscators.arithmetic.Encryption;
import net.runelite.deob.deobfuscators.arithmetic.Pair;
import net.runelite.deob.util.NameMappings;
public class PutField extends Instruction implements SetFieldInstruction
{
private Field field;
private net.runelite.deob.Field myField;
public PutField(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -74,32 +77,17 @@ public class PutField extends Instruction implements SetFieldInstruction
net.runelite.deob.Field f2 = cf.findFieldDeep(nat);
return f2;
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (field.getClassEntry().getName().equals(cf.getName()))
field = new Field(new Class(name), field.getNameAndType());
if (field.getNameAndType().getDescriptorType().getType().equals("L" + cf.getName() + ";"))
field = new Field(field.getClassEntry(), new NameAndType(field.getNameAndType().getName(), new net.runelite.deob.signature.Type("L" + name + ";", field.getNameAndType().getDescriptorType().getArrayDims())));
myField = getMyField();
}
@Override
public void renameField(net.runelite.deob.Field f, Field newField)
public void regeneratePool()
{
Class clazz = field.getClassEntry();
NameAndType nat = field.getNameAndType();
ClassFile cf = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
if (cf == null)
return;
net.runelite.deob.Field f2 = cf.findFieldDeep(nat);
if (f2 == f)
{
field = newField;
}
if (myField != null)
field = myField.getPoolField();
}
}

View File

@@ -16,10 +16,13 @@ import net.runelite.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.util.NameMappings;
public class PutStatic extends Instruction implements SetFieldInstruction
{
private Field field;
private net.runelite.deob.Field myField;
public PutStatic(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -73,30 +76,15 @@ public class PutStatic extends Instruction implements SetFieldInstruction
}
@Override
public void renameClass(ClassFile cf, String name)
public void lookup2()
{
if (field.getClassEntry().getName().equals(cf.getName()))
field = new Field(new Class(name), field.getNameAndType());
if (field.getNameAndType().getDescriptorType().getType().equals("L" + cf.getName() + ";"))
field = new Field(field.getClassEntry(), new NameAndType(field.getNameAndType().getName(), new net.runelite.deob.signature.Type("L" + name + ";", field.getNameAndType().getDescriptorType().getArrayDims())));
myField = getMyField();
}
@Override
public void renameField(net.runelite.deob.Field f, Field newField)
public void regeneratePool()
{
Class clazz = field.getClassEntry();
NameAndType nat = field.getNameAndType();
ClassFile cf = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
if (cf == null)
return;
net.runelite.deob.Field f2 = cf.findFieldDeep(nat);
if (f2 == f)
{
field = newField;
}
if (myField != null)
field = myField.getPoolField();
}
}

View File

@@ -17,6 +17,8 @@ import net.runelite.deob.signature.Signature;
import net.runelite.deob.signature.Type;
import java.util.HashSet;
import java.util.Set;
import net.runelite.deob.attributes.Code;
import net.runelite.deob.util.NameMappings;
public class RenameUnique implements Deobfuscator
{
@@ -49,8 +51,8 @@ public class RenameUnique implements Deobfuscator
// rename on instructions. this includes method calls and field accesses.
if (method.getCode() != null)
{
Instructions instructions = method.getCode().getInstructions();
instructions.renameClass(cf, name);
// Instructions instructions = method.getCode().getInstructions();
// instructions.renameClass(cf, name);
// rename on exception handlers
Exceptions exceptions = method.getCode().getExceptions();
@@ -99,7 +101,7 @@ public class RenameUnique implements Deobfuscator
new net.runelite.deob.pool.Class(field.getFields().getClassFile().getName()),
new NameAndType(name, field.getType())
);
instructions.renameField(field, newField);
//instructions.renameField(field, newField);
}
}
}
@@ -183,7 +185,7 @@ public class RenameUnique implements Deobfuscator
new net.runelite.deob.pool.Class(m.getMethods().getClassFile().getName()),
new NameAndType(name, m.getNameAndType().getDescriptor())
);
instructions.renameMethod(m, newMethod);
//instructions.renameMethod(m, newMethod);
}
}
}
@@ -192,36 +194,45 @@ public class RenameUnique implements Deobfuscator
for (Method m : methods)
m.setName(name);
}
@Override
public void run(ClassGroup group)
private NameMappings generateClassNames(ClassGroup group)
{
NameMappings map = new NameMappings();
int i = 0;
int classes = 0, fields = 0, methods = 0;
group.buildClassGraph();
for (ClassFile cf : group.getClasses())
{
if (cf.getName().length() > 2)
continue;
renameClass(group, cf, "class" + i++);
++classes;
map.map(cf.getPoolClass(), "class" + i++);
}
// rename fields
return map;
}
private NameMappings generatFieldNames(ClassGroup group)
{
NameMappings map = new NameMappings();
int i = 0;
for (ClassFile cf : group.getClasses())
for (Field field : cf.getFields().getFields())
{
if (field.getName().length() > 2)
continue;
renameField(group, field, "field" + i++);
++fields;
map.map(field.getPoolField(), "field" + i++);
}
// rename methods
return map;
}
private NameMappings generateMethodNames(ClassGroup group)
{
NameMappings map = new NameMappings();
int i = 0;
for (ClassFile cf : group.getClasses())
for (Method method : cf.getMethods().getMethods())
{
@@ -237,10 +248,99 @@ public class RenameUnique implements Deobfuscator
else
name = "vmethod" + i++;
renameMethod(group, virtualMethods, name);
for (Method m : virtualMethods)
map.map(m.getPoolMethod(), name);
}
return map;
}
private void lookup(ClassGroup group)
{
for (ClassFile cf : group.getClasses())
for (Method m : cf.getMethods().getMethods())
{
Code c = m.getCode();
if (c == null)
continue;
c.getInstructions().lookup();
}
}
private void regeneratePool(ClassGroup group)
{
for (ClassFile cf : group.getClasses())
for (Method m : cf.getMethods().getMethods())
{
Code c = m.getCode();
if (c == null)
continue;
c.getInstructions().regeneratePool();
}
}
@Override
public void run(ClassGroup group)
{
group.buildClassGraph();
lookup(group);
NameMappings mappings = this.generateClassNames(group);
//renameIns(group, mappings);
int i = 0;
int classes = 0, fields = 0, methods = 0;
for (ClassFile cf : group.getClasses())
{
String newName = mappings.get(cf.getPoolClass());
if (newName == null)
continue;
renameClass(group, cf, newName);
++classes;
}
mappings = this.generatFieldNames(group);
//renameIns(group, mappings);
// rename fields
for (ClassFile cf : group.getClasses())
for (Field field : cf.getFields().getFields())
{
String newName = mappings.get(field.getPoolField());
if (newName == null)
continue;
renameField(group, field, newName);
++fields;
}
mappings = this.generateMethodNames(group);
//renameIns(group, mappings);
// rename methods
for (ClassFile cf : group.getClasses())
for (Method method : cf.getMethods().getMethods())
{
String newName = mappings.get(method.getPoolMethod());
if (newName == null)
continue;
List<Method> virtualMethods = getVirutalMethods(method);
assert !virtualMethods.isEmpty();
renameMethod(group, virtualMethods, newName);
methods += virtualMethods.size();
}
this.regeneratePool(group);
System.out.println("Uniquely renamed " + classes + " classes, " + fields + " fields, and " + methods + " methods");
}
}

View File

@@ -5,6 +5,7 @@ import net.runelite.deob.ConstantPool;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Objects;
public class Method extends PoolEntry
{
@@ -51,6 +52,15 @@ public class Method extends PoolEntry
Method m = (Method) other;
return clazz.equals(m.clazz) && nat.equals(m.nat);
}
@Override
public int hashCode()
{
int hash = 7;
hash = 67 * hash + Objects.hashCode(this.clazz);
hash = 67 * hash + Objects.hashCode(this.nat);
return hash;
}
public Class getClassEntry()
{

View File

@@ -33,8 +33,9 @@ public class Signature
public Signature(Signature other)
{
rv = other.rv;
arguments.addAll(other.arguments);
rv = new Type(other.rv);
for (Type t : other.arguments)
arguments.add(new Type(t));
}
@Override

View File

@@ -22,6 +22,12 @@ public class Type
this.arrayDimms = dimms;
}
public Type(Type other)
{
type = other.type;
arrayDimms = other.arrayDimms;
}
public String getType()
{
return type;

View File

@@ -0,0 +1,32 @@
package net.runelite.deob.util;
import java.util.HashMap;
import java.util.Map;
import net.runelite.deob.pool.Class;
import net.runelite.deob.pool.Field;
import net.runelite.deob.pool.Method;
public class NameMappings
{
private final Map<Object, String> map = new HashMap<>();
public void map(Class cf, String name)
{
map.put(cf, name);
}
public void map(Field field, String name)
{
map.put(field, name);
}
public void map(Method method, String name)
{
map.put(method, name);
}
public String get(Object object)
{
return map.get(object);
}
}