From dad328de120e817f5cf23d78f83016c169d16818 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 19 Nov 2015 21:23:28 -0500 Subject: [PATCH] Cleanup rename unique --- .../code/instructions/InvokeInterface.java | 2 +- .../code/instructions/InvokeSpecial.java | 2 +- .../code/instructions/InvokeStatic.java | 2 +- .../code/instructions/InvokeVirtual.java | 2 +- .../deob/deobfuscators/RenameUnique.java | 69 ++----------------- 5 files changed, 10 insertions(+), 67 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java index ebc32972f9..d2be2ed68f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java @@ -150,7 +150,7 @@ public class InvokeInterface extends Instruction implements InvokeInstruction @Override public void regeneratePool() { - if (!myMethods.isEmpty()) + if (myMethods != null && !myMethods.isEmpty()) method = myMethods.get(0).getPoolInterfaceMethod(); // is this right? } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java index a7ca94662e..c03fba5138 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java @@ -143,7 +143,7 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction @Override public void regeneratePool() { - if (!myMethods.isEmpty()) + if (myMethods != null && !myMethods.isEmpty()) method = myMethods.get(0).getPoolMethod(); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index a322707740..629e737e7d 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -147,7 +147,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction @Override public void regeneratePool() { - if (!myMethods.isEmpty()) + if (myMethods != null && !myMethods.isEmpty()) method = myMethods.get(0).getPoolMethod(); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java index bff79bc400..d2c1ca1bf1 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java @@ -148,7 +148,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction @Override public void regeneratePool() { - if (!myMethods.isEmpty()) + if (myMethods != null && !myMethods.isEmpty()) method = myMethods.get(0).getPoolMethod(); // is this right? } } diff --git a/src/main/java/net/runelite/deob/deobfuscators/RenameUnique.java b/src/main/java/net/runelite/deob/deobfuscators/RenameUnique.java index eef14dcddf..a2f9bacc64 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/RenameUnique.java +++ b/src/main/java/net/runelite/deob/deobfuscators/RenameUnique.java @@ -10,7 +10,6 @@ import net.runelite.deob.Field; import net.runelite.deob.Interfaces; import net.runelite.deob.Method; 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.NameAndType; 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. if (method.getCode() != null) { -// Instructions instructions = method.getCode().getInstructions(); -// instructions.renameClass(cf, name); - // rename on exception handlers Exceptions exceptions = method.getCode().getExceptions(); exceptions.renameClass(cf, name); @@ -87,28 +83,6 @@ public class RenameUnique implements Deobfuscator 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 // different methods can be invoked with the same instruction. private List findBaseMethods(List methods, ClassFile cf, NameAndType method) @@ -131,7 +105,7 @@ public class RenameUnique implements Deobfuscator private List findBaseMethods(Method method) { - return findBaseMethods(new ArrayList(), method.getMethods().getClassFile(), method.getNameAndType()); + return findBaseMethods(new ArrayList<>(), method.getMethods().getClassFile(), method.getNameAndType()); } private void findMethodUp(List methods, Set visited, ClassFile cf, NameAndType method) @@ -164,37 +138,11 @@ public class RenameUnique implements Deobfuscator // now search up from bases, appending to list. for (Method m : bases) - findMethodUp(list, new HashSet(), m.getMethods().getClassFile(), m.getNameAndType()); + findMethodUp(list, new HashSet<>(), m.getMethods().getClassFile(), m.getNameAndType()); return list; } - private void renameMethod(ClassGroup group, List 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) { NameMappings map = new NameMappings(); @@ -272,12 +220,10 @@ public class RenameUnique implements Deobfuscator public void run(ClassGroup group) { group.buildClassGraph(); + group.lookup(); NameMappings mappings = this.generateClassNames(group); - //renameIns(group, mappings); - - int i = 0; int classes = 0, fields = 0, methods = 0; for (ClassFile cf : group.getClasses()) @@ -292,8 +238,6 @@ public class RenameUnique implements Deobfuscator mappings = this.generatFieldNames(group); - //renameIns(group, mappings); - // rename fields for (ClassFile cf : group.getClasses()) for (Field field : cf.getFields().getFields()) @@ -302,14 +246,12 @@ public class RenameUnique implements Deobfuscator if (newName == null) continue; - renameField(group, field, newName); + field.setName(newName); ++fields; } mappings = this.generateMethodNames(group); - //renameIns(group, mappings); - // rename methods for (ClassFile cf : group.getClasses()) for (Method method : cf.getMethods().getMethods()) @@ -321,7 +263,8 @@ public class RenameUnique implements Deobfuscator List virtualMethods = getVirutalMethods(method); assert !virtualMethods.isEmpty(); - renameMethod(group, virtualMethods, newName); + for (Method m : virtualMethods) + m.setName(newName); methods += virtualMethods.size(); }