Cleanup rename unique

This commit is contained in:
Adam
2015-11-19 21:23:28 -05:00
parent 9752e5529f
commit dad328de12
5 changed files with 10 additions and 67 deletions

View File

@@ -150,7 +150,7 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
@Override @Override
public void regeneratePool() public void regeneratePool()
{ {
if (!myMethods.isEmpty()) if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolInterfaceMethod(); // is this right? method = myMethods.get(0).getPoolInterfaceMethod(); // is this right?
} }
} }

View File

@@ -143,7 +143,7 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
@Override @Override
public void regeneratePool() public void regeneratePool()
{ {
if (!myMethods.isEmpty()) if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod(); method = myMethods.get(0).getPoolMethod();
} }
} }

View File

@@ -147,7 +147,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
@Override @Override
public void regeneratePool() public void regeneratePool()
{ {
if (!myMethods.isEmpty()) if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod(); method = myMethods.get(0).getPoolMethod();
} }
} }

View File

@@ -148,7 +148,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
@Override @Override
public void regeneratePool() public void regeneratePool()
{ {
if (!myMethods.isEmpty()) if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod(); // is this right? method = myMethods.get(0).getPoolMethod(); // is this right?
} }
} }

View File

@@ -10,7 +10,6 @@ import net.runelite.deob.Field;
import net.runelite.deob.Interfaces; import net.runelite.deob.Interfaces;
import net.runelite.deob.Method; import net.runelite.deob.Method;
import net.runelite.deob.attributes.code.Exceptions; import net.runelite.deob.attributes.code.Exceptions;
import net.runelite.deob.attributes.code.Instructions;
import net.runelite.deob.pool.Class; import net.runelite.deob.pool.Class;
import net.runelite.deob.pool.NameAndType; import net.runelite.deob.pool.NameAndType;
import net.runelite.deob.signature.Signature; import net.runelite.deob.signature.Signature;
@@ -51,9 +50,6 @@ public class RenameUnique implements Deobfuscator
// rename on instructions. this includes method calls and field accesses. // rename on instructions. this includes method calls and field accesses.
if (method.getCode() != null) if (method.getCode() != null)
{ {
// Instructions instructions = method.getCode().getInstructions();
// instructions.renameClass(cf, name);
// rename on exception handlers // rename on exception handlers
Exceptions exceptions = method.getCode().getExceptions(); Exceptions exceptions = method.getCode().getExceptions();
exceptions.renameClass(cf, name); exceptions.renameClass(cf, name);
@@ -87,28 +83,6 @@ public class RenameUnique implements Deobfuscator
cf.setName(name); cf.setName(name);
} }
private void renameField(ClassGroup group, Field field, String name)
{
for (ClassFile c : group.getClasses())
{
for (Method method : c.getMethods().getMethods())
{
// rename on instructions
if (method.getCode() != null)
{
Instructions instructions = method.getCode().getInstructions();
net.runelite.deob.pool.Field newField = new net.runelite.deob.pool.Field(
new net.runelite.deob.pool.Class(field.getFields().getClassFile().getName()),
new NameAndType(name, field.getType())
);
//instructions.renameField(field, newField);
}
}
}
field.setName(name);
}
// find the base methods for a method. search goes up from there to see if two // find the base methods for a method. search goes up from there to see if two
// different methods can be invoked with the same instruction. // different methods can be invoked with the same instruction.
private List<Method> findBaseMethods(List<Method> methods, ClassFile cf, NameAndType method) private List<Method> findBaseMethods(List<Method> methods, ClassFile cf, NameAndType method)
@@ -131,7 +105,7 @@ public class RenameUnique implements Deobfuscator
private List<Method> findBaseMethods(Method method) private List<Method> findBaseMethods(Method method)
{ {
return findBaseMethods(new ArrayList<Method>(), method.getMethods().getClassFile(), method.getNameAndType()); return findBaseMethods(new ArrayList<>(), method.getMethods().getClassFile(), method.getNameAndType());
} }
private void findMethodUp(List<Method> methods, Set<ClassFile> visited, ClassFile cf, NameAndType method) private void findMethodUp(List<Method> methods, Set<ClassFile> visited, ClassFile cf, NameAndType method)
@@ -164,37 +138,11 @@ public class RenameUnique implements Deobfuscator
// now search up from bases, appending to list. // now search up from bases, appending to list.
for (Method m : bases) for (Method m : bases)
findMethodUp(list, new HashSet<ClassFile>(), m.getMethods().getClassFile(), m.getNameAndType()); findMethodUp(list, new HashSet<>(), m.getMethods().getClassFile(), m.getNameAndType());
return list; return list;
} }
private void renameMethod(ClassGroup group, List<Method> methods, String name)
{
for (ClassFile c : group.getClasses())
{
for (Method method : c.getMethods().getMethods())
{
// rename on instructions
if (method.getCode() != null)
{
Instructions instructions = method.getCode().getInstructions();
for (Method m : methods)
{
net.runelite.deob.pool.Method newMethod = new net.runelite.deob.pool.Method(
new net.runelite.deob.pool.Class(m.getMethods().getClassFile().getName()),
new NameAndType(name, m.getNameAndType().getDescriptor())
);
//instructions.renameMethod(m, newMethod);
}
}
}
}
for (Method m : methods)
m.setName(name);
}
private NameMappings generateClassNames(ClassGroup group) private NameMappings generateClassNames(ClassGroup group)
{ {
NameMappings map = new NameMappings(); NameMappings map = new NameMappings();
@@ -272,12 +220,10 @@ public class RenameUnique implements Deobfuscator
public void run(ClassGroup group) public void run(ClassGroup group)
{ {
group.buildClassGraph(); group.buildClassGraph();
group.lookup();
NameMappings mappings = this.generateClassNames(group); NameMappings mappings = this.generateClassNames(group);
//renameIns(group, mappings);
int i = 0;
int classes = 0, fields = 0, methods = 0; int classes = 0, fields = 0, methods = 0;
for (ClassFile cf : group.getClasses()) for (ClassFile cf : group.getClasses())
@@ -292,8 +238,6 @@ public class RenameUnique implements Deobfuscator
mappings = this.generatFieldNames(group); mappings = this.generatFieldNames(group);
//renameIns(group, mappings);
// rename fields // rename fields
for (ClassFile cf : group.getClasses()) for (ClassFile cf : group.getClasses())
for (Field field : cf.getFields().getFields()) for (Field field : cf.getFields().getFields())
@@ -302,14 +246,12 @@ public class RenameUnique implements Deobfuscator
if (newName == null) if (newName == null)
continue; continue;
renameField(group, field, newName); field.setName(newName);
++fields; ++fields;
} }
mappings = this.generateMethodNames(group); mappings = this.generateMethodNames(group);
//renameIns(group, mappings);
// rename methods // rename methods
for (ClassFile cf : group.getClasses()) for (ClassFile cf : group.getClasses())
for (Method method : cf.getMethods().getMethods()) for (Method method : cf.getMethods().getMethods())
@@ -321,7 +263,8 @@ public class RenameUnique implements Deobfuscator
List<Method> virtualMethods = getVirutalMethods(method); List<Method> virtualMethods = getVirutalMethods(method);
assert !virtualMethods.isEmpty(); assert !virtualMethods.isEmpty();
renameMethod(group, virtualMethods, newName); for (Method m : virtualMethods)
m.setName(newName);
methods += virtualMethods.size(); methods += virtualMethods.size();
} }