@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
@Override boolean overridesRegister(int register) { OneRegisterInstruction i = (OneRegisterInstruction) instruction; int dest = i.getRegisterA(); return register == dest; } }
protected void writeFirstRegister(IndentingWriter writer) throws IOException { writeRegister(writer, ((OneRegisterInstruction)instruction).getRegisterA()); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int destRegister = ((OneRegisterInstruction) instruction).getRegisterA(); return new MonitorExitOp(location, child, destRegister); } }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int destRegister = ((OneRegisterInstruction) instruction).getRegisterA(); return new MonitorEnterOp(location, child, destRegister); } }
private void fixInstructions(@Nonnull MutableMethodImplementation methodImplementation) { List<? extends Instruction> instructions = methodImplementation.getInstructions(); for (int i=0; i<instructions.size(); i++) { Instruction instruction = instructions.get(i); if (instruction.getOpcode() == Opcode.CONST_STRING) { if (stringSection.getItemIndex( (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) { methodImplementation.replaceInstruction(i, new BuilderInstruction31c(Opcode.CONST_STRING_JUMBO, ((OneRegisterInstruction)instruction).getRegisterA(), ((ReferenceInstruction)instruction).getReference())); } } } }
private static ExecutionGraphManipulator getMockedGraph(int address, HeapItem value) { ExecutionGraphManipulator manipulator = mock(ExecutionGraphManipulator.class); BuilderInstruction instruction = mock(BuilderInstruction.class, withSettings().extraInterfaces(OneRegisterInstruction.class)); when(((OneRegisterInstruction) instruction).getRegisterA()).thenReturn(REGISTER); when(manipulator.getRegisterConsensus(address, REGISTER)).thenReturn(value); when(manipulator.getInstruction(address)).thenReturn(instruction); return manipulator; }
private void analyzeNewInstance(@Nonnull AnalyzedInstruction analyzedInstruction) { ReferenceInstruction instruction = (ReferenceInstruction)analyzedInstruction.instruction; int register = ((OneRegisterInstruction)analyzedInstruction.instruction).getRegisterA(); RegisterType destRegisterType = analyzedInstruction.getPostInstructionRegisterType(register); if (destRegisterType.category != RegisterType.UNKNOWN) { //the post-instruction destination register will only be set if we have already analyzed this instruction //at least once. If this is the case, then the uninit reference has already been propagated to all //successors and nothing else needs to be done. assert destRegisterType.category == RegisterType.UNINIT_REF; return; } TypeReference typeReference = (TypeReference)instruction.getReference(); RegisterType classType = RegisterType.getRegisterType(classPath, typeReference); setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, RegisterType.getRegisterType(RegisterType.UNINIT_REF, classType.type)); }
@Test public void constantizableHandlesNull() { ExecutionGraphManipulator graph = mock(ExecutionGraphManipulator.class); ConstantBuilder builder = mock(ConstantBuilder.class); BuilderInstruction instruction = mock(BuilderInstruction.class, withSettings().extraInterfaces(OneRegisterInstruction.class)); ConstantPropagationStrategy strategy = new ConstantPropagationStrategy(graph); strategy.setDependencies(builder); when(graph.getAddresses()).thenReturn(new int[] { 1 }); when(graph.getInstruction(1)).thenReturn(null).thenReturn(instruction); when(graph.wasAddressReached(1)).thenReturn(true); when(graph.getOp(1)).thenReturn(null); when(((OneRegisterInstruction) instruction).getRegisterA()).thenReturn(2); when(graph.getRegisterConsensus(1, 2)).thenReturn(null); when(builder.canConstantizeOp(null)).thenReturn(true); boolean changesMade = strategy.perform(); assertFalse(changesMade); }
public void deferredJimplify(DexBody body) { int keyRegister = ((OneRegisterInstruction) instruction).getRegisterA(); int offset = ((OffsetInstruction) instruction).getCodeOffset(); Local key = body.getRegisterLocal(keyRegister); int targetAddress = codeAddress + offset; Instruction targetData = body.instructionAtAddress(targetAddress).instruction; Stmt stmt = switchStatement(body, targetData, key); body.getBody().getUnits().insertAfter(stmt, markerUnit); }
public static BuilderInstruction buildConstant(int address, ExecutionGraphManipulator manipulator) { DexBuilder dexBuilder = manipulator.getDexBuilder(); OneRegisterInstruction instruction = (OneRegisterInstruction) manipulator.getInstruction(address); int register = instruction.getRegisterA(); HeapItem item = manipulator.getRegisterConsensus(address, register); Object value = item.getValue(); String type = item.isPrimitive() ? item.getType() : item.getUnboxedValueType(); BuilderInstruction constant = buildConstant(value, type, register, dexBuilder); return constant; }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); String opName = instruction.getOpcode().name; int toRegister = ((OneRegisterInstruction) instruction).getRegisterA(); MoveType moveType = getMoveType(opName); switch (moveType) { case RESULT: case EXCEPTION: return new MoveOp(location, child, toRegister, moveType); case REGISTER: int targetRegister = ((TwoRegisterInstruction) instruction).getRegisterB(); return new MoveOp(location, child, toRegister, targetRegister); default: return null; } }
@Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction21c)) { throw new IllegalArgumentException("Expected Instruction21c but got: " + instruction.getClass()); } ReferenceInstruction constClass = (ReferenceInstruction) this.instruction; TypeReference tidi = (TypeReference) (constClass.getReference()); Constant cst = ClassConstant.v(tidi.getType()); int dest = ((OneRegisterInstruction) instruction).getRegisterA(); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { // DalvikTyper.v().captureAssign((JAssignStmt)assign, op); //TODO: // classtype could be null! DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false); } }
@Override public void jimplify(DexBody body) { int reg = ((OneRegisterInstruction) instruction).getRegisterA(); Local object = body.getRegisterLocal(reg); ExitMonitorStmt exitMonitorStmt = Jimple.v().newExitMonitorStmt(object); setUnit(exitMonitorStmt); addTags(exitMonitorStmt); body.add(exitMonitorStmt); if (IDalvikTyper.ENABLE_DVKTYPER) { // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ exitMonitorStmt); DalvikTyper.v().setType(exitMonitorStmt.getOpBox(), RefType.v("java.lang.Object"), true); } } }