wip removal of unused methods based on execution from init.

This commit is contained in:
Adam
2015-06-27 23:47:43 -04:00
parent dfcc41b41c
commit d9f4d257a5
13 changed files with 161 additions and 107 deletions

View File

@@ -1,5 +1,7 @@
package info.sigterm.deob.attributes.code.instruction.types;
import java.util.List;
import info.sigterm.deob.Method;
import info.sigterm.deob.pool.PoolEntry;

View File

@@ -1,6 +1,7 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
@@ -11,7 +12,6 @@ import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.execution.Type;
import info.sigterm.deob.pool.InterfaceMethod;
import info.sigterm.deob.pool.Method;
import info.sigterm.deob.pool.NameAndType;
import info.sigterm.deob.pool.PoolEntry;
import info.sigterm.deob.signature.Signature;
@@ -19,6 +19,8 @@ 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.List;
public class InvokeInterface extends Instruction implements InvokeInstruction
{
@@ -45,20 +47,28 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
out.writeByte(0);
}
@Override
public void buildCallGraph()
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
private List<info.sigterm.deob.Method> getMethods()
{
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
ClassFile otherClass = group.findClass(method.getClassEntry().getName());
if (otherClass == null)
return;
info.sigterm.deob.Method other = otherClass.findMethod(nat);
return new ArrayList<>(); // not our class
thisMethod.addCallTo(this, other);
// look up this method in this class and anything that inherits from it
List<info.sigterm.deob.Method> list = new ArrayList<>();
findMethodFromClass(list, otherClass);
return list;
}
private void findMethodFromClass(List<info.sigterm.deob.Method> list, ClassFile clazz)
{
info.sigterm.deob.Method m = clazz.findMethod(method.getNameAndType());
if (m != null)
list.add(m);
for (ClassFile cf : clazz.getChildren())
findMethodFromClass(list, cf);
}
@Override
@@ -89,6 +99,12 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
}
frame.addInstructionContext(ins);
for (info.sigterm.deob.Method method : getMethods())
{
// add possible method call to execution
frame.getExecution().addMethod(method);
}
}
private void handleExceptions(Frame frame)

View File

@@ -1,6 +1,7 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
@@ -18,6 +19,8 @@ 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.List;
public class InvokeSpecial extends Instruction implements InvokeInstruction
{
@@ -39,21 +42,19 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
out.writeShort(this.getPool().make(method));
}
@Override
public void buildCallGraph()
private List<info.sigterm.deob.Method> getMethods()
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
ClassFile otherClass = group.findClass(method.getClassEntry().getName());
if (otherClass == null)
return;
return new ArrayList<>(); // not our class
info.sigterm.deob.Method other = otherClass.findMethod(nat);
info.sigterm.deob.Method other = otherClass.findMethod(method.getNameAndType());
thisMethod.addCallTo(this, other);
List<info.sigterm.deob.Method> list = new ArrayList<>();
list.add(other);
return list;
}
@Override
@@ -84,6 +85,12 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
}
frame.addInstructionContext(ins);
for (info.sigterm.deob.Method method : getMethods())
{
// add possible method call to execution
frame.getExecution().addMethod(method);
}
}
private void handleExceptions(Frame frame)

View File

@@ -1,6 +1,7 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
@@ -18,6 +19,8 @@ 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.List;
public class InvokeStatic extends Instruction implements InvokeInstruction
{
@@ -39,21 +42,19 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
out.writeShort(this.getPool().make(method));
}
@Override
public void buildCallGraph()
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
private List<info.sigterm.deob.Method> getMethods()
{
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
ClassFile otherClass = group.findClass(method.getClassEntry().getName());
if (otherClass == null)
return;
return new ArrayList<>(); // not our class
info.sigterm.deob.Method other = otherClass.findMethod(nat);
info.sigterm.deob.Method other = otherClass.findMethod(method.getNameAndType());
thisMethod.addCallTo(this, other);
List<info.sigterm.deob.Method> list = new ArrayList<>();
list.add(other);
return list;
}
@Override
@@ -81,6 +82,12 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
}
frame.addInstructionContext(ins);
for (info.sigterm.deob.Method method : getMethods())
{
// add possible method call to execution
frame.getExecution().addMethod(method);
}
}
private void handleExceptions(Frame frame)

View File

@@ -19,6 +19,8 @@ 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.List;
public class InvokeVirtual extends Instruction implements InvokeInstruction
{
@@ -39,24 +41,6 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
super.write(out);
out.writeShort(this.getPool().make(method));
}
@Override
public void buildCallGraph()
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
if (otherClass == null)
return;
info.sigterm.deob.Method other = otherClass.findMethod(nat);
if (other == null)
return;
thisMethod.addCallTo(this, other);
}
@Override
public void execute(Frame frame)
@@ -75,9 +59,6 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
StackContext object = stack.pop();
ins.pop(object);
// the method being invoked, looked up dynamically based on the type
//info.sigterm.deob.Method executedMethod = findVirtualMethod(object.getType());
handleExceptions(frame);
if (!method.getNameAndType().isVoid())
@@ -89,31 +70,39 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
}
frame.addInstructionContext(ins);
for (info.sigterm.deob.Method method : getMethods())
{
// add possible method call to execution
frame.getExecution().addMethod(method);
}
}
private info.sigterm.deob.Method findVirtualMethod(Type type)
// find the possible methods this instruction might be invoking. we can't know for sure
// which method is being invoked without tracking the types of objects in fields and when
// passed in parameters/return values.
private List<info.sigterm.deob.Method> getMethods()
{
// invokevirtual 'method' on 'type', see if we can find the actual method that would be invoked based on the type of the object
ClassGroup group = this.getInstructions().getCode().getAttributes().getClassFile().getGroup();
ClassFile otherClass = group.findClass(type.type);
ClassFile otherClass = group.findClass(method.getClassEntry().getName());
if (otherClass == null)
return null; // not our class
return new ArrayList<>(); // not our class
// now find the method with the same signature as 'method' on this class, or subclass
return findMethodFromClass(otherClass);
// look up this method in this class and anything that inherits from it
List<info.sigterm.deob.Method> list = new ArrayList<>();
findMethodFromClass(list, otherClass);
return list;
}
private info.sigterm.deob.Method findMethodFromClass(ClassFile clazz)
private void findMethodFromClass(List<info.sigterm.deob.Method> list, ClassFile clazz)
{
if (clazz == null)
return null;
info.sigterm.deob.Method m = clazz.findMethod(method.getNameAndType());
if (m != null)
return m;
return findMethodFromClass(clazz.getParent());
list.add(m);
for (ClassFile cf : clazz.getChildren())
findMethodFromClass(list, cf);
}
private void handleExceptions(Frame frame)