I will need to actually perform method invocations during execution to

be able to pass/get the correct underlying types of variables for the
virtual method lookup.
This commit is contained in:
Adam
2015-06-26 13:19:51 -04:00
parent 0543950013
commit dfcc41b41c
7 changed files with 30 additions and 34 deletions

View File

@@ -185,11 +185,6 @@ public class ClassFile
methods.buildInstructionGraph(); methods.buildInstructionGraph();
} }
public void buildCallGraph()
{
methods.buildCallGraph();
}
public boolean instanceOf(ClassFile other) public boolean instanceOf(ClassFile other)
{ {
return this == other || interfaces.instanceOf(other) || (getParent() != null && getParent().instanceOf(other)); return this == other || interfaces.instanceOf(other) || (getParent() != null && getParent().instanceOf(other));

View File

@@ -222,14 +222,6 @@ public class Method
code.buildInstructionGraph(); code.buildInstructionGraph();
} }
public void buildCallGraph()
{
Code code = getCode();
if (code != null)
code.buildCallGraph();
}
public void clearCallGraph() public void clearCallGraph()
{ {
callsTo.clear(); callsTo.clear();

View File

@@ -79,10 +79,4 @@ public class Methods
for (Method m : methods) for (Method m : methods)
m.buildInstructionGraph(); m.buildInstructionGraph();
} }
public void buildCallGraph()
{
for (Method m : methods)
m.buildCallGraph();
}
} }

View File

@@ -68,9 +68,4 @@ public class Code extends Attribute
{ {
instructions.buildInstructionGraph(); instructions.buildInstructionGraph();
} }
public void buildCallGraph()
{
instructions.buildCallGraph();
}
} }

View File

@@ -195,10 +195,6 @@ public abstract class Instruction
{ {
} }
public void buildCallGraph()
{
}
public abstract void execute(Frame e); public abstract void execute(Frame e);
/* does this terminate a block? */ /* does this terminate a block? */

View File

@@ -184,12 +184,6 @@ public class Instructions
i.buildInstructionGraph(); i.buildInstructionGraph();
} }
public void buildCallGraph()
{
for (Instruction i : instructions)
i.buildCallGraph();
}
public Code getCode() public Code getCode()
{ {
return code; return code;

View File

@@ -1,6 +1,7 @@
package info.sigterm.deob.attributes.code.instructions; package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile; import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.attributes.code.Instruction; import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType; import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions; import info.sigterm.deob.attributes.code.Instructions;
@@ -74,6 +75,9 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
StackContext object = stack.pop(); StackContext object = stack.pop();
ins.pop(object); ins.pop(object);
// the method being invoked, looked up dynamically based on the type
//info.sigterm.deob.Method executedMethod = findVirtualMethod(object.getType());
handleExceptions(frame); handleExceptions(frame);
if (!method.getNameAndType().isVoid()) if (!method.getNameAndType().isVoid())
@@ -87,6 +91,31 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
frame.addInstructionContext(ins); frame.addInstructionContext(ins);
} }
private info.sigterm.deob.Method findVirtualMethod(Type type)
{
// 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);
if (otherClass == null)
return null; // not our class
// now find the method with the same signature as 'method' on this class, or subclass
return findMethodFromClass(otherClass);
}
private info.sigterm.deob.Method findMethodFromClass(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());
}
private void handleExceptions(Frame frame) private void handleExceptions(Frame frame)
{ {
// jump to instruction handlers that can catch exceptions here // jump to instruction handlers that can catch exceptions here
@@ -95,6 +124,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
Instruction start = e.getStart(), Instruction start = e.getStart(),
end = e.getEnd(); end = e.getEnd();
// XXX this relies on pc?
// [start, end) // [start, end)
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc()) if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
{ {