fixes for ir generation

This commit is contained in:
Julian Dolby 2014-10-10 17:48:37 -04:00
parent 0e55cd2eec
commit e3dfc5afe5
8 changed files with 85 additions and 26 deletions

View File

@ -0,0 +1,22 @@
package com.ibm.wala.dalvik.drivers;
import java.io.IOException;
import com.ibm.wala.dalvik.test.callGraph.DalvikCallGraphTestBase;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.util.CancelException;
public class APKCallGraphDriver {
public static void main(String[] args) throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {
CallGraph CG = DalvikCallGraphTestBase.makeAPKCallGraph(args[0]).fst;
System.err.println(CG);
for(CGNode n : CG) {
System.err.println(n);
System.err.println(n.getIR());
}
}
}

View File

@ -33,7 +33,6 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.properties.WalaProperties;
import com.ibm.wala.shrikeCT.InvalidClassFileException; import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.MethodReference; import com.ibm.wala.types.MethodReference;

View File

@ -14,8 +14,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
import junit.framework.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil; import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
@ -28,6 +27,7 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util; import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder; import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.cha.ClassHierarchy;
@ -36,6 +36,7 @@ import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Pair; import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.OrdinalSet;
public class JVMLDalvikComparison extends DalvikCallGraphTestBase { public class JVMLDalvikComparison extends DalvikCallGraphTestBase {
@ -83,17 +84,32 @@ public class JVMLDalvikComparison extends DalvikCallGraphTestBase {
Set<MethodReference> androidMethods = applicationMethods(android.fst); Set<MethodReference> androidMethods = applicationMethods(android.fst);
Set<MethodReference> javaMethods = applicationMethods(java.fst); Set<MethodReference> javaMethods = applicationMethods(java.fst);
Set<MethodReference> androidExtra = HashSetFactory.make(androidMethods); if (!androidMethods.containsAll(javaMethods)) {
androidExtra.removeAll(javaMethods); Set<MethodReference> androidExtra = HashSetFactory.make(androidMethods);
System.err.println(androidExtra); androidExtra.removeAll(javaMethods);
Set<MethodReference> javaExtra = HashSetFactory.make(javaMethods);
Set<MethodReference> javaExtra = HashSetFactory.make(javaMethods); javaExtra.removeAll(androidMethods);
javaExtra.removeAll(androidMethods);
System.err.println(javaExtra); System.err.println(edgeDiff(java.fst, android.fst));
System.err.println(javaExtra);
System.err.println(edgeDiff(android.fst, java.fst));
System.err.println(android.fst);
System.err.println(edgeDiff(java.fst, android.fst));
for(CGNode n : android.fst) {
System.err.println("### " + n);
if (n.getIR() != null) {
System.err.println(n.getIR());
for(int i = 1; i < n.getIR().getSymbolTable().getMaxValueNumber(); i++) {
LocalPointerKey x = new LocalPointerKey(n, i);
OrdinalSet<InstanceKey> s = android.snd.getPointsToSet(x);
if (s != null && !s.isEmpty()) {
System.err.println(i + ": " + s);
}
}
}
}
}
Assert.assertTrue(androidMethods.containsAll(javaMethods)); Assert.assertTrue(androidMethods.containsAll(javaMethods));
} }

View File

@ -984,7 +984,7 @@ public class DexIMethod implements IBytecodeMethod {
break; break;
case MOVE_EXCEPTION: case MOVE_EXCEPTION:
instructions.add(new UnaryOperation(instLoc, instructions.add(new UnaryOperation(instLoc,
UnaryOperation.OpID.MOVE, ((Instruction11x)inst).getRegisterA(), UnaryOperation.OpID.MOVE_EXCEPTION, ((Instruction11x)inst).getRegisterA(),
getExceptionReg(), inst.opcode, this)); getExceptionReg(), inst.opcode, this));
break; break;
case RETURN_VOID: case RETURN_VOID:

View File

@ -57,7 +57,7 @@ import com.ibm.wala.shrikeBT.IUnaryOpInstruction.IOperator;
public class UnaryOperation extends Instruction { public class UnaryOperation extends Instruction {
public static enum OpID {MOVE, MOVE_WIDE, NOT, NEGINT, NOTINT, NEGLONG, NOTLONG, NEGFLOAT, NEGDOUBLE, DOUBLETOLONG, DOUBLETOFLOAT, INTTOBYTE, INTTOCHAR, INTTOSHORT, DOUBLETOINT, FLOATTODOUBLE, FLOATTOLONG, FLOATTOINT, LONGTODOUBLE, LONGTOFLOAT, LONGTOINT, INTTODOUBLE, INTTOFLOAT, INTTOLONG}; public static enum OpID {MOVE, MOVE_WIDE, MOVE_EXCEPTION, NOT, NEGINT, NOTINT, NEGLONG, NOTLONG, NEGFLOAT, NEGDOUBLE, DOUBLETOLONG, DOUBLETOFLOAT, INTTOBYTE, INTTOCHAR, INTTOSHORT, DOUBLETOINT, FLOATTODOUBLE, FLOATTOLONG, FLOATTOINT, LONGTODOUBLE, LONGTOFLOAT, LONGTOINT, INTTODOUBLE, INTTOFLOAT, INTTOLONG};
public final OpID op; public final OpID op;
public final int source; public final int source;

View File

@ -289,7 +289,7 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
@Override @Override
public boolean isUnaryNoOp() { public boolean isUnaryNoOp() {
return true; return false;
} }
@Override @Override
@ -299,9 +299,14 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
// Exception e = new Exception("evaluating a MeetOperator"); // Exception e = new Exception("evaluating a MeetOperator");
// e.printStackTrace(); // e.printStackTrace();
// return NOT_CHANGED; // return NOT_CHANGED;
if (cfg.getDexMethod().getReference().toString().equals("< Application, Lcom/google/android/gms/tagmanager/v$a, onOpen(Landroid/database/sqlite/SQLiteDatabase;)V >")) {
System.err.println("got here");
}
if (!bb.isCatchBlock()) { if (!bb.isCatchBlock()) {
return meet(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED; return meet(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
} else { } else {
return meetForCatchBlock(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED; return meetForCatchBlock(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
} }
} }
@ -418,6 +423,7 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
// not already allocated. // not already allocated.
if (L.locals == null) { if (L.locals == null) {
L.allocateLocals(); L.allocateLocals();
changed = true;
} }
DexIMethod dMethod = (DexIMethod)L.getBasicBlock().getMethod(); DexIMethod dMethod = (DexIMethod)L.getBasicBlock().getMethod();
@ -428,10 +434,8 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
int meet = meeter.meetStackAtCatchBlock(bb); int meet = meeter.meetStackAtCatchBlock(bb);
if (L.locals[dMethod.getExceptionReg()] == TOP) { if (L.locals[dMethod.getExceptionReg()] == TOP) {
if (meet != TOP) { changed = true;
changed = true; L.locals[dMethod.getExceptionReg()] = meet;
L.locals[dMethod.getExceptionReg()] = meet;
}
} else if (meet != L.locals[dMethod.getExceptionReg()]) { } else if (meet != L.locals[dMethod.getExceptionReg()]) {
changed = true; changed = true;
L.locals[dMethod.getExceptionReg()] = meet; L.locals[dMethod.getExceptionReg()] = meet;
@ -543,6 +547,7 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
int nLocals = computeMeetNLocals(rhs); int nLocals = computeMeetNLocals(rhs);
if (nLocals > -1 && L.locals == null) { if (nLocals > -1 && L.locals == null) {
L.allocateLocals(); L.allocateLocals();
changed = true;
} }
// evaluate the element-wise meet over the locals. // evaluate the element-wise meet over the locals.

View File

@ -71,6 +71,7 @@ import com.ibm.wala.ssa.ISSABasicBlock;
import com.ibm.wala.ssa.PhiValue; import com.ibm.wala.ssa.PhiValue;
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
import com.ibm.wala.ssa.SSACFG; import com.ibm.wala.ssa.SSACFG;
import com.ibm.wala.ssa.SSACFG.ExceptionHandlerBasicBlock;
import com.ibm.wala.ssa.SSAConditionalBranchInstruction; import com.ibm.wala.ssa.SSAConditionalBranchInstruction;
import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction; import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction;
import com.ibm.wala.ssa.SSAInstruction; import com.ibm.wala.ssa.SSAInstruction;
@ -271,8 +272,11 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) cfg.getNode(bbNumber); SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) cfg.getNode(bbNumber);
SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction();
int exceptionValue; int exceptionValue;
if (cfg.getMethod().getReference().toString().equals("< Application, Lcom/google/android/gms/tagmanager/v$a, onOpen(Landroid/database/sqlite/SQLiteDatabase;)V >")) {
System.err.println("got here");
}
if (s == null) { if (s == null) {
exceptionValue = symbolTable.newSymbol(); exceptionValue = symbolTable.newSymbol();
s = insts.GetCaughtExceptionInstruction(bb.getLastInstructionIndex(), bbNumber, exceptionValue); s = insts.GetCaughtExceptionInstruction(bb.getLastInstructionIndex(), bbNumber, exceptionValue);
newBB.setCatchInstruction(s); newBB.setCatchInstruction(s);
} else { } else {
@ -387,7 +391,7 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
this.symbolTable = symbolTable; this.symbolTable = symbolTable;
this.loader = dexCFG.getMethod().getDeclaringClass().getClassLoader().getReference(); this.loader = dexCFG.getMethod().getDeclaringClass().getClassLoader().getReference();
// this.localMap = localMap; // this.localMap = localMap;
init(this.new NodeVisitor(), this.new EdgeVisitor()); init(this.new NodeVisitor(cfg), this.new EdgeVisitor());
} }
@Override @Override
@ -449,7 +453,13 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
* Update the machine state to account for an instruction * Update the machine state to account for an instruction
*/ */
class NodeVisitor extends BasicRegisterMachineVisitor { class NodeVisitor extends BasicRegisterMachineVisitor {
// TODO: make sure all visit functions are overridden private final SSACFG cfg;
public NodeVisitor(SSACFG cfg) {
this.cfg = cfg;
}
// TODO: make sure all visit functions are overridden
/** /**
* @see com.ibm.wala.shrikeBT.Instruction.Visitor#visitArrayLength(ArrayLengthInstruction) * @see com.ibm.wala.shrikeBT.Instruction.Visitor#visitArrayLength(ArrayLengthInstruction)
@ -1229,6 +1239,11 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
} }
emitInstruction(insts.ConversionInstruction(getCurrentInstructionIndex(), result, val, fromType, toType, overflows)); emitInstruction(insts.ConversionInstruction(getCurrentInstructionIndex(), result, val, fromType, toType, overflows));
} }
else if (instruction.op == UnaryOperation.OpID.MOVE_EXCEPTION) {
int source = ((DexIMethod)dexCFG.getMethod()).getExceptionReg();
workingState.setLocal(instruction.destination, source);
}
else else
{ {
emitInstruction(insts.UnaryOpInstruction(getCurrentInstructionIndex(), instruction.getOperator(), result, val)); emitInstruction(insts.UnaryOpInstruction(getCurrentInstructionIndex(), instruction.getOperator(), result, val));
@ -1243,7 +1258,6 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
else else
workingState.setLocal(instruction.destination+1, workingState.getLocal(instruction.source+1)); workingState.setLocal(instruction.destination+1, workingState.getLocal(instruction.source+1));
} }
} }
} }

View File

@ -352,6 +352,9 @@ nextMethod:
final Collection<IMethod> ifMethods = iFace.getDeclaredMethods(); final Collection<IMethod> ifMethods = iFace.getDeclaredMethods();
for (final IMethod ifMethod : ifMethods) { for (final IMethod ifMethod : ifMethods) {
final IMethod method = appClass.getMethod(ifMethod.getSelector()); final IMethod method = appClass.getMethod(ifMethod.getSelector());
if (method == null || method.isAbstract()) {
continue;
}
if (method.getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application)) { if (method.getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application)) {
// The function is overridden // The function is overridden
final AndroidEntryPoint ep = new AndroidEntryPoint(selectPositionForHeuristic(method), method, cha); final AndroidEntryPoint ep = new AndroidEntryPoint(selectPositionForHeuristic(method), method, cha);