Beginning work of rename unique, now renames classes
This commit is contained in:
@@ -123,6 +123,21 @@ public class ClassFile
|
||||
{
|
||||
return name.getName();
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = new Class(name);
|
||||
}
|
||||
|
||||
public Class getParentClass()
|
||||
{
|
||||
return this.super_class;
|
||||
}
|
||||
|
||||
public void setParentClass(Class c)
|
||||
{
|
||||
super_class = c;
|
||||
}
|
||||
|
||||
public ClassFile getParent()
|
||||
{
|
||||
@@ -188,7 +203,7 @@ public class ClassFile
|
||||
parent.children.add(this);
|
||||
}
|
||||
|
||||
for (ClassFile i : interfaces.getInterfaces())
|
||||
for (ClassFile i : interfaces.getMyInterfaces())
|
||||
{
|
||||
i.children.add(this);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob;
|
||||
import info.sigterm.deob.deobfuscators.IllegalStateExceptions;
|
||||
import info.sigterm.deob.deobfuscators.Jumps;
|
||||
import info.sigterm.deob.deobfuscators.ModularArithmeticDeobfuscation;
|
||||
import info.sigterm.deob.deobfuscators.RenameUnique;
|
||||
import info.sigterm.deob.deobfuscators.RuntimeExceptions;
|
||||
import info.sigterm.deob.deobfuscators.UnusedBlocks;
|
||||
import info.sigterm.deob.deobfuscators.UnusedFields;
|
||||
@@ -42,6 +43,9 @@ public class Deob
|
||||
|
||||
ClassGroup group = loadJar(args[0]);
|
||||
|
||||
new RenameUnique().run(group);
|
||||
|
||||
/*
|
||||
// remove except RuntimeException
|
||||
new RuntimeExceptions().run(group);
|
||||
|
||||
@@ -60,9 +64,11 @@ public class Deob
|
||||
// remove jump obfuscation
|
||||
new Jumps().run(group);
|
||||
|
||||
// remove unused fields
|
||||
new UnusedFields().run(group);
|
||||
|
||||
//new ModularArithmeticDeobfuscation().run(group);
|
||||
*/
|
||||
|
||||
saveJar(group, args[1]);
|
||||
|
||||
|
||||
@@ -26,7 +26,17 @@ public class Interfaces
|
||||
interfaces.add(c.getPool().getClass(is.readUnsignedShort()));
|
||||
}
|
||||
|
||||
public List<ClassFile> getInterfaces()
|
||||
public List<Class> getInterfaces()
|
||||
{
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public void setInterfaces(List<Class> interfaces)
|
||||
{
|
||||
this.interfaces = interfaces;
|
||||
}
|
||||
|
||||
public List<ClassFile> getMyInterfaces()
|
||||
{
|
||||
List<ClassFile> l = new ArrayList<>();
|
||||
for (Class clazz : interfaces)
|
||||
|
||||
@@ -3,24 +3,17 @@ package info.sigterm.deob;
|
||||
import info.sigterm.deob.attributes.AttributeType;
|
||||
import info.sigterm.deob.attributes.Attributes;
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
import info.sigterm.deob.attributes.Exceptions;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.instruction.types.InvokeInstruction;
|
||||
import info.sigterm.deob.attributes.code.instruction.types.LVTInstruction;
|
||||
import info.sigterm.deob.callgraph.Node;
|
||||
import info.sigterm.deob.execution.Execution;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
import info.sigterm.deob.signature.Signature;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Method
|
||||
{
|
||||
@@ -55,11 +48,6 @@ public class Method
|
||||
out.writeShort(pool.makeUTF8(arguments.toString()));
|
||||
attributes.write(out);
|
||||
}
|
||||
|
||||
protected void remove()
|
||||
{
|
||||
//assert callsFrom.isEmpty();
|
||||
}
|
||||
|
||||
public Methods getMethods()
|
||||
{
|
||||
@@ -85,34 +73,16 @@ public class Method
|
||||
{
|
||||
return (accessFlags & ACC_STATIC) != 0;
|
||||
}
|
||||
|
||||
public Exceptions getExceptions()
|
||||
{
|
||||
return (Exceptions) attributes.findType(AttributeType.EXCEPTIONS);
|
||||
}
|
||||
|
||||
public Code getCode()
|
||||
{
|
||||
return (Code) attributes.findType(AttributeType.CODE);
|
||||
}
|
||||
|
||||
/*
|
||||
public List<Method> getOverriddenMethods()
|
||||
{
|
||||
List<Method> m = new ArrayList<Method>();
|
||||
|
||||
ClassFile parent = methods.getClassFile().getParent();
|
||||
if (parent != null)
|
||||
{
|
||||
Method other = parent.getMethods().findMethod(getName(), getDescriptor());
|
||||
if (other != null)
|
||||
m.add(other);
|
||||
}
|
||||
|
||||
for (ClassFile inter : methods.getClassFile().getInterfaces().getInterfaces())
|
||||
{
|
||||
Method other = inter.getMethods().findMethod(getName(), getDescriptor());
|
||||
if (other != null)
|
||||
m.add(other);
|
||||
}
|
||||
|
||||
return m;
|
||||
}*/
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
@@ -122,36 +92,6 @@ public class Method
|
||||
code.buildInstructionGraph();
|
||||
}
|
||||
|
||||
/*public void clearCallGraph()
|
||||
{
|
||||
callsTo.clear();
|
||||
callsFrom.clear();
|
||||
}*/
|
||||
|
||||
/*public boolean isUsed()
|
||||
{
|
||||
if (!callsFrom.isEmpty())
|
||||
return true;
|
||||
|
||||
for (Method sm : getOverriddenMethods())
|
||||
{
|
||||
if (sm.isUsed())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}*/
|
||||
|
||||
/*
|
||||
public void addCallTo(Instruction ins, Method method)
|
||||
{
|
||||
assert method != null;
|
||||
Node node = new Node(this, method, ins);
|
||||
callsTo.add(node);
|
||||
method.callsFrom.add(node);
|
||||
}
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Instruction & LVTInstruction> List<T> findLVTInstructionsForVariable(int index)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,6 @@ public class Methods
|
||||
|
||||
public void removeMethod(Method m)
|
||||
{
|
||||
m.remove();
|
||||
methods.remove(m);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -33,4 +34,17 @@ public class Exceptions extends Attribute
|
||||
for (Class c : classes)
|
||||
out.writeShort(this.getAttributes().getClassFile().getPool().make(c));
|
||||
}
|
||||
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
for (Class c : classes)
|
||||
{
|
||||
if (c.getName().equals(cf.getName()))
|
||||
{
|
||||
int idx = classes.indexOf(c);
|
||||
classes.remove(idx);
|
||||
classes.add(idx, new Class(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
@@ -93,4 +94,10 @@ public class Exception
|
||||
{
|
||||
return catchType;
|
||||
}
|
||||
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (catchType != null && cf.getName().equals(catchType.getName()))
|
||||
catchType = new Class(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -47,4 +48,10 @@ public class Exceptions
|
||||
{
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
for (Exception e : exceptions)
|
||||
e.renameClass(cf, name);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
@@ -206,4 +207,8 @@ public abstract class Instruction
|
||||
public void replace(Instruction oldi, Instruction newi)
|
||||
{
|
||||
}
|
||||
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
import info.sigterm.deob.attributes.code.instruction.types.JumpingInstruction;
|
||||
import info.sigterm.deob.attributes.code.instructions.LDC;
|
||||
@@ -196,4 +197,10 @@ public class Instructions
|
||||
return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
for (Instruction i : instructions)
|
||||
i.renameClass(cf, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -53,4 +54,11 @@ public class ANewArray extends Instruction
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (clazz.getName().equals(cf.getName()))
|
||||
clazz = new Class(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -11,6 +12,7 @@ import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.VariableContext;
|
||||
import info.sigterm.deob.execution.Variables;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -69,4 +70,11 @@ public class CheckCast extends Instruction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (clazz.getName().equals(cf.getName()))
|
||||
clazz = new Class(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -9,6 +10,7 @@ import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Field;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -57,4 +59,11 @@ public class GetField extends Instruction implements GetFieldInstruction
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||
field = new Field(new Class(name), field.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,4 +74,10 @@ public class GetStatic extends Instruction implements GetFieldInstruction
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||
field = new Field(new Class(name), field.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -49,4 +50,11 @@ public class InstanceOf extends Instruction
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (clazz.getName().equals(cf.getName()))
|
||||
clazz = new Class(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.InterfaceMethod;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
@@ -155,4 +156,11 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||
method = new InterfaceMethod(new Class(name), method.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
@@ -147,4 +148,11 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||
method = new Method(new Class(name), method.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
@@ -144,4 +145,11 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||
method = new Method(new Class(name), method.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
@@ -154,4 +155,11 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (method.getClassEntry().getName().equals(cf.getName()))
|
||||
method = new Method(new Class(name), method.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -57,4 +58,11 @@ public class MultiANewArray extends Instruction
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (clazz.getName().equals(cf.getName()))
|
||||
clazz = new Class(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -52,4 +53,11 @@ public class New extends Instruction
|
||||
{
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (clazz.getName().equals(cf.getName()))
|
||||
clazz = new Class(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -8,6 +9,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Field;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -53,4 +55,10 @@ public class PutField extends Instruction implements SetFieldInstruction
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||
field = new Field(new Class(name), field.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
@@ -8,6 +9,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Field;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -51,4 +53,11 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameClass(ClassFile cf, String name)
|
||||
{
|
||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||
field = new Field(new Class(name), field.getNameAndType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package info.sigterm.deob.deobfuscators;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.ClassGroup;
|
||||
import info.sigterm.deob.Interfaces;
|
||||
import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.attributes.code.Exceptions;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.signature.Signature;
|
||||
import info.sigterm.deob.signature.Type;
|
||||
|
||||
public class RenameUnique
|
||||
{
|
||||
private void renameClass(ClassFile on, ClassFile old, String name)
|
||||
{
|
||||
if (on.getParentClass().getName().equals(old.getName()))
|
||||
on.setParentClass(new Class(name));
|
||||
|
||||
Interfaces interfaces = on.getInterfaces();
|
||||
List<Class> interfaceList = interfaces.getInterfaces();
|
||||
for (Class inter : interfaceList)
|
||||
if (inter.getName().equals(old.getName()))
|
||||
{
|
||||
int idx = interfaceList.indexOf(inter);
|
||||
interfaceList.remove(idx);
|
||||
interfaceList.add(idx, new Class(name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void renameClass(ClassGroup group, ClassFile cf, String name)
|
||||
{
|
||||
for (ClassFile c : group.getClasses())
|
||||
{
|
||||
// rename on child interfaces and classes
|
||||
renameClass(c, cf, name);
|
||||
|
||||
for (Method method : c.getMethods().getMethods())
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// rename on parameters
|
||||
Signature signature = method.getDescriptor();
|
||||
for (int i = 0; i < signature.size(); ++i)
|
||||
{
|
||||
Type type = signature.getTypeOfArg(i);
|
||||
|
||||
if (type.getType().equals("L" + cf.getName() + ";"))
|
||||
signature.setTypeOfArg(i, new Type("L" + name + ";", type.getArrayDims()));
|
||||
}
|
||||
|
||||
// rename return type
|
||||
if (signature.getReturnValue().getType().equals("L" + cf.getName() + ";"))
|
||||
signature.setTypeOfReturnValue(new Type("L" + name + ";", signature.getReturnValue().getArrayDims()));
|
||||
|
||||
// rename on exceptions thrown
|
||||
if (method.getExceptions() != null)
|
||||
method.getExceptions().renameClass(cf, name);
|
||||
}
|
||||
}
|
||||
|
||||
cf.setName(name);
|
||||
}
|
||||
|
||||
public void run(ClassGroup group)
|
||||
{
|
||||
group.buildClassGraph();
|
||||
|
||||
int i = 0;
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
if (cf.getName().length() > 2)
|
||||
continue;
|
||||
|
||||
renameClass(group, cf, "class" + i++);
|
||||
|
||||
// rename method
|
||||
|
||||
// rename fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class UnusedParameters
|
||||
list.addAll(findDependentMethods(nat, visited, group, cf.getParent()));
|
||||
|
||||
// search interfaces
|
||||
for (ClassFile inter : cf.getInterfaces().getInterfaces())
|
||||
for (ClassFile inter : cf.getInterfaces().getMyInterfaces())
|
||||
list.addAll(findDependentMethods(nat, visited, group, inter));
|
||||
|
||||
// search children
|
||||
|
||||
@@ -20,6 +20,13 @@ public class Class extends PoolEntry
|
||||
index = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Class(java.lang.String name)
|
||||
{
|
||||
super(ConstantType.CLASS);
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve(ConstantPool pool)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,14 @@ public class Field extends PoolEntry
|
||||
natIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Field(Class clazz, NameAndType nat)
|
||||
{
|
||||
super(ConstantType.FIELDREF);
|
||||
|
||||
this.clazz = clazz;
|
||||
this.nat = nat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve(ConstantPool pool)
|
||||
{
|
||||
|
||||
@@ -74,8 +74,18 @@ public class Signature
|
||||
return arguments.get(i);
|
||||
}
|
||||
|
||||
public void setTypeOfArg(int i, Type type)
|
||||
{
|
||||
arguments.set(i, type);
|
||||
}
|
||||
|
||||
public Type getReturnValue()
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
public void setTypeOfReturnValue(Type type)
|
||||
{
|
||||
rv = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,26 @@ public class Type
|
||||
type = str;
|
||||
}
|
||||
|
||||
public Type(String type, int dimms)
|
||||
{
|
||||
this.type = type;
|
||||
this.arrayDimms = dimms;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getFullType()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < arrayDimms; ++i)
|
||||
sb.append('[');
|
||||
sb.append(type);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int getArrayDims()
|
||||
{
|
||||
return arrayDimms;
|
||||
@@ -49,10 +64,6 @@ public class Type
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < arrayDimms; ++i)
|
||||
sb.append('[');
|
||||
sb.append(type);
|
||||
return sb.toString();
|
||||
return getFullType();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user