Rename unique non overriden methods
This commit is contained in:
@@ -123,7 +123,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
||||
ClassFile cf = group.findClass(field.getClassEntry().getName());
|
||||
if (cf == null)
|
||||
return null;
|
||||
return cf.findField(field.getNameAndType());
|
||||
return cf.findFieldDeep(field.getNameAndType());
|
||||
}
|
||||
|
||||
private List<info.sigterm.deob.pool.Field> checkDown(InstructionContext context)
|
||||
@@ -261,7 +261,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
||||
|
||||
// get Field from pool Field
|
||||
info.sigterm.deob.pool.Field field = gf.getField();
|
||||
Field f = group.findClass(field.getClassEntry().getName()).findField(field.getNameAndType());
|
||||
Field f = group.findClass(field.getClassEntry().getName()).findFieldDeep(field.getNameAndType());
|
||||
|
||||
assert f != null;
|
||||
|
||||
@@ -296,7 +296,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
||||
|
||||
// get Field from pool Field
|
||||
info.sigterm.deob.pool.Field field = sf.getField();
|
||||
Field f = group.findClass(field.getClassEntry().getName()).findField(field.getNameAndType());
|
||||
Field f = group.findClass(field.getClassEntry().getName()).findFieldDeep(field.getNameAndType());
|
||||
|
||||
assert f != null;
|
||||
|
||||
@@ -424,7 +424,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
||||
|
||||
// get Field from pool Field
|
||||
info.sigterm.deob.pool.Field field = gf.getField();
|
||||
Field f = group.findClass(field.getClassEntry().getName()).findField(field.getNameAndType());
|
||||
Field f = group.findClass(field.getClassEntry().getName()).findFieldDeep(field.getNameAndType());
|
||||
|
||||
Magic magic = workMagics.getMagic(f);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.deobfuscators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
@@ -93,6 +94,70 @@ public class RenameUnique implements Deobfuscator
|
||||
|
||||
field.setName(name);
|
||||
}
|
||||
|
||||
private void findMethodDown(List<Method> list, ClassFile cf, Method method)
|
||||
{
|
||||
if (cf == null)
|
||||
return;
|
||||
|
||||
Method m = cf.findMethod(method.getNameAndType());
|
||||
if (m != null && !m.isStatic())
|
||||
list.add(m);
|
||||
|
||||
findMethodDown(list, cf.getParent(), method);
|
||||
|
||||
for (ClassFile inter : cf.getInterfaces().getMyInterfaces())
|
||||
findMethodDown(list, inter, method);
|
||||
}
|
||||
|
||||
private void findMethodUp(List<Method> list, ClassFile cf, Method method)
|
||||
{
|
||||
Method m = cf.findMethod(method.getNameAndType());
|
||||
if (m != null && !m.isStatic())
|
||||
list.add(m);
|
||||
|
||||
for (ClassFile child : cf.getChildren())
|
||||
findMethodUp(list, child, method);
|
||||
}
|
||||
|
||||
private List<Method> getVirutalMethods(Method method)
|
||||
{
|
||||
List<Method> list = new ArrayList<>();
|
||||
|
||||
list.add(method);
|
||||
|
||||
if (method.isStatic())
|
||||
return list;
|
||||
|
||||
ClassFile classOfMethod = method.getMethods().getClassFile();
|
||||
findMethodDown(list, classOfMethod.getParent(), method);
|
||||
|
||||
for (ClassFile inter : classOfMethod.getInterfaces().getMyInterfaces())
|
||||
findMethodDown(list, inter, method);
|
||||
|
||||
for (ClassFile child : classOfMethod.getChildren())
|
||||
findMethodUp(list, child, method);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void renameMethod(ClassGroup group, Method m, 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();
|
||||
instructions.renameMethod(m, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ClassGroup group)
|
||||
@@ -120,7 +185,23 @@ public class RenameUnique implements Deobfuscator
|
||||
++fields;
|
||||
}
|
||||
|
||||
group.buildClassGraph();
|
||||
|
||||
// rename methods
|
||||
for (ClassFile cf : group.getClasses())
|
||||
for (Method method : cf.getMethods().getMethods())
|
||||
{
|
||||
if (method.getName().length() > 2)
|
||||
continue;
|
||||
|
||||
List<Method> virtualMethods = getVirutalMethods(method);
|
||||
assert !virtualMethods.isEmpty();
|
||||
if (virtualMethods.size() != 1)
|
||||
continue; // do next
|
||||
|
||||
renameMethod(group, method, "method" + i++);
|
||||
++methods;
|
||||
}
|
||||
|
||||
System.out.println("Uniquely renamed " + classes + " classes, " + fields + " fields, and " + methods + " methods");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UnusedFields implements Deobfuscator
|
||||
if (clazz == null)
|
||||
continue;
|
||||
|
||||
Field f = clazz.findField(ff.getNameAndType());
|
||||
Field f = clazz.findFieldDeep(ff.getNameAndType());
|
||||
|
||||
if (field == f)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ public class UnusedParameters implements Deobfuscator
|
||||
|
||||
visited.add(cf);
|
||||
|
||||
Method method = cf.findMethod(nat); // XXX this searches down
|
||||
Method method = cf.findMethodDeep(nat); // XXX this searches down
|
||||
if (method != null && !method.isStatic())
|
||||
list.add(method);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user