Rename unique non overriden methods
This commit is contained in:
@@ -149,7 +149,7 @@ public class ClassFile
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Field findField(NameAndType nat)
|
public Field findFieldDeep(NameAndType nat)
|
||||||
{
|
{
|
||||||
Field f = fields.findField(nat);
|
Field f = fields.findField(nat);
|
||||||
if (f != null)
|
if (f != null)
|
||||||
@@ -157,12 +157,12 @@ public class ClassFile
|
|||||||
|
|
||||||
ClassFile parent = getParent();
|
ClassFile parent = getParent();
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
return parent.findField(nat);
|
return parent.findFieldDeep(nat);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method findMethod(NameAndType nat)
|
public Method findMethodDeep(NameAndType nat)
|
||||||
{
|
{
|
||||||
Method m = methods.findMethod(nat);
|
Method m = methods.findMethod(nat);
|
||||||
if (m != null)
|
if (m != null)
|
||||||
@@ -170,12 +170,17 @@ public class ClassFile
|
|||||||
|
|
||||||
ClassFile parent = getParent();
|
ClassFile parent = getParent();
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
return parent.findMethod(nat);
|
return parent.findMethodDeep(nat);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method findMethod(String name)
|
public Method findMethod(NameAndType nat)
|
||||||
|
{
|
||||||
|
return methods.findMethod(nat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method findMethodDeep(String name)
|
||||||
{
|
{
|
||||||
Method m = methods.findMethod(name);
|
Method m = methods.findMethod(name);
|
||||||
if (m != null)
|
if (m != null)
|
||||||
@@ -183,7 +188,7 @@ public class ClassFile
|
|||||||
|
|
||||||
ClassFile parent = getParent();
|
ClassFile parent = getParent();
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
return parent.findMethod(name);
|
return parent.findMethodDeep(name);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ public class Method
|
|||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public Signature getDescriptor()
|
public Signature getDescriptor()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code;
|
|||||||
import info.sigterm.deob.ClassFile;
|
import info.sigterm.deob.ClassFile;
|
||||||
import info.sigterm.deob.ConstantPool;
|
import info.sigterm.deob.ConstantPool;
|
||||||
import info.sigterm.deob.Field;
|
import info.sigterm.deob.Field;
|
||||||
|
import info.sigterm.deob.Method;
|
||||||
import info.sigterm.deob.execution.Frame;
|
import info.sigterm.deob.execution.Frame;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -216,4 +217,8 @@ public abstract class Instruction
|
|||||||
public void renameField(Field f, String name)
|
public void renameField(Field f, String name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void renameMethod(Method m, String name)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package info.sigterm.deob.attributes.code;
|
|||||||
|
|
||||||
import info.sigterm.deob.ClassFile;
|
import info.sigterm.deob.ClassFile;
|
||||||
import info.sigterm.deob.Field;
|
import info.sigterm.deob.Field;
|
||||||
|
import info.sigterm.deob.Method;
|
||||||
import info.sigterm.deob.attributes.Code;
|
import info.sigterm.deob.attributes.Code;
|
||||||
import info.sigterm.deob.attributes.code.instruction.types.JumpingInstruction;
|
import info.sigterm.deob.attributes.code.instruction.types.JumpingInstruction;
|
||||||
|
|
||||||
@@ -209,4 +210,10 @@ public class Instructions
|
|||||||
for (Instruction i : instructions)
|
for (Instruction i : instructions)
|
||||||
i.renameField(f, name);
|
i.renameField(f, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void renameMethod(Method m, String name)
|
||||||
|
{
|
||||||
|
for (Instruction i : instructions)
|
||||||
|
i.renameMethod(m, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class GetStatic extends Instruction implements GetFieldInstruction
|
|||||||
if (cf == null)
|
if (cf == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
info.sigterm.deob.Field f = cf.findField(nat);
|
info.sigterm.deob.Field f = cf.findFieldDeep(nat);
|
||||||
assert f != null;
|
assert f != null;
|
||||||
|
|
||||||
f.addReference(this);
|
f.addReference(this);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
|
|||||||
|
|
||||||
private void findMethodFromClass(List<info.sigterm.deob.Method> list, ClassFile clazz)
|
private void findMethodFromClass(List<info.sigterm.deob.Method> list, ClassFile clazz)
|
||||||
{
|
{
|
||||||
info.sigterm.deob.Method m = clazz.findMethod(method.getNameAndType());
|
info.sigterm.deob.Method m = clazz.findMethodDeep(method.getNameAndType());
|
||||||
if (m != null)
|
if (m != null)
|
||||||
list.add(m);
|
list.add(m);
|
||||||
|
|
||||||
@@ -163,4 +163,11 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
|
|||||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||||
method = new InterfaceMethod(new Class(name), method.getNameAndType());
|
method = new InterfaceMethod(new Class(name), method.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameMethod(info.sigterm.deob.Method m, String name)
|
||||||
|
{
|
||||||
|
if (method.getNameAndType().equals(m.getNameAndType()) && method.getClassEntry().getName().equals(m.getMethods().getClassFile().getName()))
|
||||||
|
method = new InterfaceMethod(method.getClassEntry(), new NameAndType(name, method.getNameAndType().getDescriptor()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
|
|||||||
if (otherClass == null)
|
if (otherClass == null)
|
||||||
return new ArrayList<>(); // not our class
|
return new ArrayList<>(); // not our class
|
||||||
|
|
||||||
info.sigterm.deob.Method other = otherClass.findMethod(method.getNameAndType());
|
info.sigterm.deob.Method other = otherClass.findMethodDeep(method.getNameAndType());
|
||||||
|
|
||||||
List<info.sigterm.deob.Method> list = new ArrayList<>();
|
List<info.sigterm.deob.Method> list = new ArrayList<>();
|
||||||
list.add(other);
|
list.add(other);
|
||||||
@@ -155,4 +155,11 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
|
|||||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||||
method = new Method(new Class(name), method.getNameAndType());
|
method = new Method(new Class(name), method.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameMethod(info.sigterm.deob.Method m, String name)
|
||||||
|
{
|
||||||
|
if (method.getNameAndType().equals(m.getNameAndType()) && method.getClassEntry().getName().equals(m.getMethods().getClassFile().getName()))
|
||||||
|
method = new Method(method.getClassEntry(), new NameAndType(name, method.getNameAndType().getDescriptor()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
|
|||||||
if (otherClass == null)
|
if (otherClass == null)
|
||||||
return new ArrayList<>(); // not our class
|
return new ArrayList<>(); // not our class
|
||||||
|
|
||||||
info.sigterm.deob.Method other = otherClass.findMethod(method.getNameAndType());
|
info.sigterm.deob.Method other = otherClass.findMethodDeep(method.getNameAndType());
|
||||||
|
|
||||||
List<info.sigterm.deob.Method> list = new ArrayList<>();
|
List<info.sigterm.deob.Method> list = new ArrayList<>();
|
||||||
list.add(other);
|
list.add(other);
|
||||||
@@ -152,4 +152,11 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
|
|||||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||||
method = new Method(new Class(name), method.getNameAndType());
|
method = new Method(new Class(name), method.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameMethod(info.sigterm.deob.Method m, String name)
|
||||||
|
{
|
||||||
|
if (method.getNameAndType().equals(m.getNameAndType()) && method.getClassEntry().getName().equals(m.getMethods().getClassFile().getName()))
|
||||||
|
method = new Method(method.getClassEntry(), new NameAndType(name, method.getNameAndType().getDescriptor()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
|
|||||||
|
|
||||||
private void findMethodFromClass(List<info.sigterm.deob.Method> list, ClassFile clazz)
|
private void findMethodFromClass(List<info.sigterm.deob.Method> list, ClassFile clazz)
|
||||||
{
|
{
|
||||||
info.sigterm.deob.Method m = clazz.findMethod(method.getNameAndType());
|
info.sigterm.deob.Method m = clazz.findMethodDeep(method.getNameAndType());
|
||||||
if (m != null)
|
if (m != null)
|
||||||
list.add(m);
|
list.add(m);
|
||||||
|
|
||||||
@@ -162,4 +162,11 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
|
|||||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||||
method = new Method(new Class(name), method.getNameAndType());
|
method = new Method(new Class(name), method.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameMethod(info.sigterm.deob.Method m, String name)
|
||||||
|
{
|
||||||
|
if (method.getNameAndType().equals(m.getNameAndType()) && method.getClassEntry().getName().equals(m.getMethods().getClassFile().getName()))
|
||||||
|
method = new Method(method.getClassEntry(), new NameAndType(name, method.getNameAndType().getDescriptor()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
|||||||
ClassFile cf = group.findClass(field.getClassEntry().getName());
|
ClassFile cf = group.findClass(field.getClassEntry().getName());
|
||||||
if (cf == null)
|
if (cf == null)
|
||||||
return null;
|
return null;
|
||||||
return cf.findField(field.getNameAndType());
|
return cf.findFieldDeep(field.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<info.sigterm.deob.pool.Field> checkDown(InstructionContext context)
|
private List<info.sigterm.deob.pool.Field> checkDown(InstructionContext context)
|
||||||
@@ -261,7 +261,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
|||||||
|
|
||||||
// get Field from pool Field
|
// get Field from pool Field
|
||||||
info.sigterm.deob.pool.Field field = gf.getField();
|
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;
|
assert f != null;
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
|||||||
|
|
||||||
// get Field from pool Field
|
// get Field from pool Field
|
||||||
info.sigterm.deob.pool.Field field = sf.getField();
|
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;
|
assert f != null;
|
||||||
|
|
||||||
@@ -424,7 +424,7 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
|||||||
|
|
||||||
// get Field from pool Field
|
// get Field from pool Field
|
||||||
info.sigterm.deob.pool.Field field = gf.getField();
|
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);
|
Magic magic = workMagics.getMagic(f);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package info.sigterm.deob.deobfuscators;
|
package info.sigterm.deob.deobfuscators;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.sigterm.deob.ClassFile;
|
import info.sigterm.deob.ClassFile;
|
||||||
@@ -93,6 +94,70 @@ public class RenameUnique implements Deobfuscator
|
|||||||
|
|
||||||
field.setName(name);
|
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
|
@Override
|
||||||
public void run(ClassGroup group)
|
public void run(ClassGroup group)
|
||||||
@@ -120,7 +185,23 @@ public class RenameUnique implements Deobfuscator
|
|||||||
++fields;
|
++fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.buildClassGraph();
|
||||||
|
|
||||||
// rename methods
|
// 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");
|
System.out.println("Uniquely renamed " + classes + " classes, " + fields + " fields, and " + methods + " methods");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class UnusedFields implements Deobfuscator
|
|||||||
if (clazz == null)
|
if (clazz == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Field f = clazz.findField(ff.getNameAndType());
|
Field f = clazz.findFieldDeep(ff.getNameAndType());
|
||||||
|
|
||||||
if (field == f)
|
if (field == f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class UnusedParameters implements Deobfuscator
|
|||||||
|
|
||||||
visited.add(cf);
|
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())
|
if (method != null && !method.isStatic())
|
||||||
list.add(method);
|
list.add(method);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user