@Nonnull private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) { return new BuilderInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
/** * Return the source register for this instruction. */ private int sourceRegister() { // I hate smali's API .. if (instruction instanceof Instruction23x) { return ((Instruction23x) instruction).getRegisterA(); } else if (instruction instanceof Instruction22c) { return ((Instruction22c) instruction).getRegisterA(); } else if (instruction instanceof Instruction21c) { return ((Instruction21c) instruction).getRegisterA(); } else { throw new RuntimeException("Instruction is not a instance, array or static op"); } }
private BuilderInstruction23x buildInstruction23x(Opcode opcode) { BuilderInstruction23x instruction = mock(BuilderInstruction23x.class); setupInstruction(instruction, opcode); when(((Instruction23x) instruction).getRegisterA()).thenReturn(DEST_REGISTER); when(((Instruction23x) instruction).getRegisterB()).thenReturn(ARG1_REGISTER); when(((Instruction23x) instruction).getRegisterC()).thenReturn(ARG2_REGISTER); return instruction; }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction23x instr = (Instruction23x) location.getInstruction(); int destRegister = instr.getRegisterA(); int lhsRegister = instr.getRegisterB(); int rhsRegister = instr.getRegisterC(); return new CmpOp(location, child, destRegister, lhsRegister, rhsRegister); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction23x instr = (Instruction23x) location.getInstruction(); int valueRegister = instr.getRegisterA(); int arrayRegister = instr.getRegisterB(); int indexRegister = instr.getRegisterC(); return new AGetOp(location, child, valueRegister, arrayRegister, indexRegister, vm.getExceptionFactory()); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction23x instr = (Instruction23x) location.getInstruction(); int putRegister = instr.getRegisterA(); int arrayRegister = instr.getRegisterB(); int indexRegister = instr.getRegisterC(); return new APutOp(location, child, putRegister, arrayRegister, indexRegister, vm.getClassManager(), vm.getExceptionFactory()); }
@Before public void setUp() { vm = mock(VirtualMachine.class); mState = mock(MethodState.class); node = mock(ExecutionNode.class); setItem = ArgumentCaptor.forClass(HeapItem.class); itemB = mock(HeapItem.class); when(itemB.isUnknown()).thenReturn(false); when(mState.readRegister(REGISTER_B)).thenReturn(itemB); itemC = mock(HeapItem.class); when(itemC.isUnknown()).thenReturn(false); when(mState.readRegister(REGISTER_C)).thenReturn(itemC); location = mock(MethodLocation.class); instruction = mock(BuilderInstruction.class, withSettings().extraInterfaces(Instruction23x.class)); when(location.getInstruction()).thenReturn(instruction); when(location.getCodeAddress()).thenReturn(ADDRESS); when(instruction.getLocation()).thenReturn(location); when(instruction.getCodeUnits()).thenReturn(0); when(((Instruction23x) instruction).getRegisterA()).thenReturn(REGISTER_A); when(((Instruction23x) instruction).getRegisterB()).thenReturn(REGISTER_B); when(((Instruction23x) instruction).getRegisterC()).thenReturn(REGISTER_C); addressToLocation = new TIntObjectHashMap<MethodLocation>(); addressToLocation.put(ADDRESS, location); opFactory = new CmpOpFactory(); }
@Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction23x)) { throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass()); } Instruction23x binOpInstr = (Instruction23x) instruction; int dest = binOpInstr.getRegisterA(); Local source1 = body.getRegisterLocal(binOpInstr.getRegisterB()); Local source2 = body.getRegisterLocal(binOpInstr.getRegisterC()); Value expr = getExpression(source1, source2); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr); assign.addTag(getTag()); setUnit(assign); addTags(assign); body.add(assign); /* * if (IDalvikTyper.ENABLE_DVKTYPER) { int op = (int)instruction.getOpcode().value; BinopExpr bexpr = (BinopExpr)expr; * JAssignStmt jassign = (JAssignStmt)assign; DalvikTyper.v().setType(bexpr.getOp1Box(), op1BinType[op-0x90], true); * DalvikTyper.v().setType(bexpr.getOp2Box(), op2BinType[op-0x90], true); DalvikTyper.v().setType(jassign.leftBox, * resBinType[op-0x90], false); } */ }
@Override public void jimplify(DexBody body) { if (!(instruction instanceof Instruction23x)) { throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass()); } Instruction23x aPutInstr = (Instruction23x) instruction; int source = aPutInstr.getRegisterA(); Local arrayBase = body.getRegisterLocal(aPutInstr.getRegisterB()); Local index = body.getRegisterLocal(aPutInstr.getRegisterC()); ArrayRef arrayRef = Jimple.v().newArrayRef(arrayBase, index); Local sourceValue = body.getRegisterLocal(source); AssignStmt assign = getAssignStmt(body, sourceValue, arrayRef); if (aPutInstr.getOpcode() == Opcode.APUT_OBJECT) { assign.addTag(new ObjectOpTag()); } setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox()); DalvikTyper.v().setType(arrayRef.getIndexBox(), IntType.v(), true); } }
@Override public void jimplify(DexBody body) throws InvalidDalvikBytecodeException { if (!(instruction instanceof Instruction23x)) { throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass()); } Instruction23x aGetInstr = (Instruction23x) instruction; int dest = aGetInstr.getRegisterA(); Local arrayBase = body.getRegisterLocal(aGetInstr.getRegisterB()); Local index = body.getRegisterLocal(aGetInstr.getRegisterC()); ArrayRef arrayRef = Jimple.v().newArrayRef(arrayBase, index); Local l = body.getRegisterLocal(dest); AssignStmt assign = Jimple.v().newAssignStmt(l, arrayRef); if (aGetInstr.getOpcode() == Opcode.AGET_OBJECT) { assign.addTag(new ObjectOpTag()); } setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox()); DalvikTyper.v().setType(arrayRef.getIndexBox(), IntType.v(), true); } }
int dest = cmpInstr.getRegisterA();
@Nonnull private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) { return new BuilderInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
@Nonnull private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) { return new BuilderInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
@Nonnull private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) { return new BuilderInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
@Nonnull private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) { return new BuilderInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
public static ImmutableInstruction23x of(Instruction23x instruction) { if (instruction instanceof ImmutableInstruction23x) { return (ImmutableInstruction23x)instruction; } return new ImmutableInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
public void write(@Nonnull Instruction23x instruction) { try { writer.write(instruction.getOpcode().value); writer.write(instruction.getRegisterA()); writer.write(instruction.getRegisterB()); writer.write(instruction.getRegisterC()); } catch (IOException ex) { throw new RuntimeException(ex); } }
public static ImmutableInstruction23x of(Instruction23x instruction) { if (instruction instanceof ImmutableInstruction23x) { return (ImmutableInstruction23x)instruction; } return new ImmutableInstruction23x( instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), instruction.getRegisterC()); }
public void write(@Nonnull Instruction23x instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(instruction.getRegisterA()); writer.write(instruction.getRegisterB()); writer.write(instruction.getRegisterC()); } catch (IOException ex) { throw new RuntimeException(ex); } }
public void write(@Nonnull Instruction23x instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(instruction.getRegisterA()); writer.write(instruction.getRegisterB()); writer.write(instruction.getRegisterC()); } catch (IOException ex) { throw new RuntimeException(ex); } }