protected DexlibAbstractInstruction getTargetInstruction(DexBody body) { int offset = ((OffsetInstruction) instruction).getCodeOffset(); int targetAddress = codeAddress + offset; targetInstruction = body.instructionAtAddress(targetAddress); return targetInstruction; } }
private boolean isUselessBranch(int address) { Op op = manipulator.getOp(address); if (!(op instanceof GotoOp)) { return false; } // Branch is useless if it branches to the next instruction. OffsetInstruction instruction = (OffsetInstruction) manipulator.getInstruction(address); int branchOffset = instruction.getCodeOffset(); if (branchOffset != instruction.getCodeUnits()) { return false; } return true; }
private String getLabelPrefix() { Opcode opcode = instruction.getOpcode(); switch (opcode.format) { case Format10t: case Format20t: case Format30t: return "goto_"; case Format21t: case Format22t: return "cond_"; case Format31t: if (opcode == Opcode.FILL_ARRAY_DATA) { return "array_"; } if (opcode == Opcode.PACKED_SWITCH) { return "pswitch_data_"; } // Opcode.SPARSE_SWITCH; return "sswitch_data_"; } assert false; return null; } }
private String getLabelPrefix() { Opcode opcode = instruction.getOpcode(); switch (opcode.format) { case Format10t: case Format20t: case Format30t: return "goto_"; case Format21t: case Format22t: return "cond_"; case Format31t: if (opcode == Opcode.FILL_ARRAY_DATA) { return "array_"; } if (opcode == Opcode.PACKED_SWITCH) { return "pswitch_data_"; } // Opcode.SPARSE_SWITCH; return "sswitch_data_"; } assert false; return null; } }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); int address = location.getCodeAddress(); int branchOffset = ((OffsetInstruction) location.getInstruction()).getCodeOffset(); int targetAddress = address + branchOffset; MethodLocation target = addressToLocation.get(targetAddress); Instruction31t instr = (Instruction31t) location.getInstruction(); int register = instr.getRegisterA(); return new SwitchOp(location, child, target, register); }
private String getLabelPrefix() { Opcode opcode = instruction.getOpcode(); switch (opcode.format) { case Format10t: case Format20t: case Format30t: return "goto_"; case Format21t: case Format22t: return "cond_"; case Format31t: if (opcode == Opcode.FILL_ARRAY_DATA) { return "array_"; } if (opcode == Opcode.PACKED_SWITCH) { return "pswitch_data_"; } // Opcode.SPARSE_SWITCH; return "sswitch_data_"; } assert false; return null; } }
boolean valid = true; int codeOffset = instructionOffsetMap.getInstructionCodeOffset(i); int targetOffset = codeOffset + ((OffsetInstruction)instruction).getCodeOffset(); try { targetOffset = findPayloadOffset(targetOffset, Opcode.PACKED_SWITCH_PAYLOAD); boolean valid = true; int codeOffset = instructionOffsetMap.getInstructionCodeOffset(i); int targetOffset = codeOffset + ((OffsetInstruction)instruction).getCodeOffset(); try { targetOffset = findPayloadOffset(targetOffset, Opcode.SPARSE_SWITCH_PAYLOAD);
private String getLabelPrefix() { Opcode opcode = instruction.getOpcode(); switch (opcode.format) { case Format10t: case Format20t: case Format30t: return "goto_"; case Format21t: case Format22t: return "cond_"; case Format31t: if (opcode == Opcode.FILL_ARRAY_DATA) { return "array_"; } if (opcode == Opcode.PACKED_SWITCH) { return "pswitch_data_"; } // Opcode.SPARSE_SWITCH; return "sswitch_data_"; } assert false; return null; } }
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); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int address = instruction.getLocation().getCodeAddress(); int returnAddress = address + instruction.getCodeUnits(); MethodLocation returnLocation = addressToLocation.get(returnAddress); int branchOffset = ((OffsetInstruction) instruction).getCodeOffset(); int childAddress = address + branchOffset; MethodLocation child = addressToLocation.get(childAddress); Instruction31t instr = (Instruction31t) location.getInstruction(); int register = instr.getRegisterA(); return new FillArrayDataOp(location, child, returnLocation, register); } }
@Test public void constantPredicateReplacedWithUnconditionalBranch() { // I say phrases like "unconditional branch" instead of "goto". // I'm also a riot at dinner parties. ExecutionGraphManipulator manipulator = getOptimizedGraph(METHOD_NAME); BuilderInstruction instruction = manipulator.getInstruction(1); assertEquals(Opcode.GOTO_32, instruction.getOpcode()); assertEquals(4, ((OffsetInstruction) instruction).getCodeOffset()); }
instructionCodeAddress + offsetInstruction.getCodeOffset()); if (analyzedSwitchPayload == null) { throw new AnalysisException("Invalid switch payload offset"); int targetAddressOffset = offsetInstruction.getCodeOffset(); AnalyzedInstruction targetInstruction = analyzedInstructions.get(instructionCodeAddress + targetAddressOffset);
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int address = instruction.getLocation().getCodeAddress(); int branchOffset = ((OffsetInstruction) instruction).getCodeOffset(); int targetAddress = address + branchOffset; MethodLocation child = Utils.getNextLocation(location, addressToLocation); MethodLocation target = addressToLocation.get(targetAddress); String opName = instruction.getOpcode().name; IfType ifType = getIfType(opName); int register1 = ((OneRegisterInstruction) instruction).getRegisterA(); if (instruction instanceof Instruction22t) { // if-* vA, vB, :label Instruction22t instr = (Instruction22t) location.getInstruction(); return new IfOp(location, child, ifType, target, register1, instr.getRegisterB()); } else { // if-*z vA, vB, :label (Instruction 21t) return new IfOp(location, child, ifType, target, register1); } }
public OffsetInstructionFormatMethodItem(@Nonnull BaksmaliOptions options, @Nonnull MethodDefinition methodDef, int codeAddress, OffsetInstruction instruction) { super(methodDef, codeAddress, instruction); label = new LabelMethodItem(options, codeAddress + instruction.getCodeOffset(), getLabelPrefix()); label = methodDef.getLabelCache().internLabel(label); }
public OffsetInstructionFormatMethodItem(@Nonnull BaksmaliOptions options, @Nonnull MethodDefinition methodDef, int codeAddress, OffsetInstruction instruction) { super(methodDef, codeAddress, instruction); label = new LabelMethodItem(options, codeAddress + instruction.getCodeOffset(), getLabelPrefix()); label = methodDef.getLabelCache().internLabel(label); }
public OffsetInstructionFormatMethodItem(@Nonnull baksmaliOptions options, @Nonnull MethodDefinition methodDef, int codeAddress, OffsetInstruction instruction) { super(methodDef, codeAddress, instruction); label = new LabelMethodItem(options, codeAddress + instruction.getCodeOffset(), getLabelPrefix()); label = methodDef.getLabelCache().internLabel(label); }
public OffsetInstructionFormatMethodItem(@Nonnull baksmaliOptions options, @Nonnull MethodDefinition methodDef, int codeAddress, OffsetInstruction instruction) { super(methodDef, codeAddress, instruction); label = new LabelMethodItem(options, codeAddress + instruction.getCodeOffset(), getLabelPrefix()); label = methodDef.getLabelCache().internLabel(label); }
if(bbinsn.destinations == null) bbinsn.destinations = new ArrayList<Integer>(); offset = ((OffsetInstruction) bbinsn.instruction).getCodeOffset() + bbinsn.address; bbinsn.destinations.add(offset); if(!leaders.contains(offset)) case PACKED_SWITCH: // switches (to payload) case SPARSE_SWITCH: offset = ((OffsetInstruction) bbinsn.instruction).getCodeOffset(); switchMap.put(bbinsn.address+offset, bbinsn.address); case IF_EQ: // ifs reg cmp reg bbinsn.destinations = new ArrayList<Integer>(); offset = ((OffsetInstruction) bbinsn.instruction).getCodeOffset() + bbinsn.address; if(!leaders.contains(offset)) leaders.add(offset);
args.add(ReferenceUtil.getReferenceString(((ReferenceInstruction)instruction).getReference())); } else if (instruction instanceof OffsetInstruction) { int offset = ((OffsetInstruction)instruction).getCodeOffset(); String sign = offset>=0?"+":"-"; args.add(String.format("%s0x%x", sign, Math.abs(offset)));
args.add(ReferenceUtil.getReferenceString(((ReferenceInstruction)instruction).getReference())); } else if (instruction instanceof OffsetInstruction) { int offset = ((OffsetInstruction)instruction).getCodeOffset(); String sign = offset>=0?"+":"-"; args.add(String.format("%s0x%x", sign, Math.abs(offset)));