public InstructionComparator(short[] insns1, short[] insns2) { this.insns1 = insns1; this.insns2 = insns2; if (insns1 != null) { ShortArrayCodeInput codeIn1 = new ShortArrayCodeInput(insns1); this.insnHolders1 = readInstructionsIntoHolders(codeIn1, insns1.length); } else { this.insnHolders1 = null; } if (insns2 != null) { ShortArrayCodeInput codeIn2 = new ShortArrayCodeInput(insns2); this.insnHolders2 = readInstructionsIntoHolders(codeIn2, insns2.length); } else { this.insnHolders2 = null; } visitedInsnAddrPairs = new HashSet<>(); }
public void accept(InstructionVisitor iv) throws EOFException { codeIn.reset(); while (codeIn.hasMore()) { int currentAddress = codeIn.cursor(); int opcodeUnit = codeIn.read(); int opcodeForSwitch = Opcodes.extractOpcodeFromUnit(opcodeUnit); switch (opcodeForSwitch) { int opcode = InstructionCodec.byte0(opcodeUnit); int literal = InstructionCodec.byte1(opcodeUnit); // should be zero int target = (short) codeIn.read(); // sign-extend iv.visitZeroRegisterInsn(currentAddress, opcode, 0, InstructionCodec.INDEX_TYPE_NONE, currentAddress + target, literal); break; int opcode = InstructionCodec.byte0(opcodeUnit); int a = InstructionCodec.byte1(opcodeUnit); int index = codeIn.read(); int indexType = InstructionCodec.getInstructionIndexType(opcode); iv.visitOneRegisterInsn(currentAddress, opcode, index, indexType, 0, 0L, a); int opcode = InstructionCodec.byte0(opcodeUnit); int a = InstructionCodec.byte1(opcodeUnit); long literal = (short) codeIn.read(); // sign-extend int opcode = InstructionCodec.byte0(opcodeUnit); int a = InstructionCodec.byte1(opcodeUnit); int literal = (short) codeIn.read(); // sign-extend iv.visitOneRegisterInsn(currentAddress, opcode, 0, InstructionCodec.INDEX_TYPE_NONE, 0, literal, a); break;
/** * Returns whether there are any more code units to read. This * is analogous to {@code hasNext()} on an interator. */ public boolean hasMore() { return cursor() < array.length; }
private InstructionHolder[] readInstructionsIntoHolders(ShortArrayCodeInput in, int length) { in.reset(); final InstructionHolder[] result = new InstructionHolder[length]; InstructionReader ir = new InstructionReader(in);
public void accept(InstructionVisitor iv) throws EOFException { codeIn.reset(); while (codeIn.hasMore()) { int currentAddress = codeIn.cursor(); int opcodeUnit = codeIn.read(); int opcodeForSwitch = Opcodes.extractOpcodeFromUnit(opcodeUnit); switch (opcodeForSwitch) { int opcode = InstructionCodec.byte0(opcodeUnit); int literal = InstructionCodec.byte1(opcodeUnit); // should be zero int target = (short) codeIn.read(); // sign-extend iv.visitZeroRegisterInsn(currentAddress, opcode, 0, InstructionCodec.INDEX_TYPE_NONE, currentAddress + target, literal); break; int opcode = InstructionCodec.byte0(opcodeUnit); int a = InstructionCodec.byte1(opcodeUnit); int index = codeIn.read(); int indexType = InstructionCodec.getInstructionIndexType(opcode); iv.visitOneRegisterInsn(currentAddress, opcode, index, indexType, 0, 0L, a); int opcode = InstructionCodec.byte0(opcodeUnit); int a = InstructionCodec.byte1(opcodeUnit); long literal = (short) codeIn.read(); // sign-extend int opcode = InstructionCodec.byte0(opcodeUnit); int a = InstructionCodec.byte1(opcodeUnit); int literal = (short) codeIn.read(); // sign-extend iv.visitOneRegisterInsn(currentAddress, opcode, 0, InstructionCodec.INDEX_TYPE_NONE, 0, literal, a); break;
/** * Returns whether there are any more code units to read. This * is analogous to {@code hasNext()} on an interator. */ public boolean hasMore() { return cursor() < array.length; }
private InstructionHolder[] readInstructionsIntoHolders(ShortArrayCodeInput in, int length) { in.reset(); final InstructionHolder[] result = new InstructionHolder[length]; InstructionReader ir = new InstructionReader(in);
private boolean isMethodReferToAnyClasses(DexClassInfo classInfo, ClassData.Method method, Set<String> refereeClassDescs) { if (method.codeOffset == ClassDef.NO_OFFSET) { return false; } Code methodCode = classInfo.owner.readCode(method); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(methodCode.instructions)); ReferToClassesCheckVisitor rtcv = new ReferToClassesCheckVisitor(classInfo.owner, method, refereeClassDescs); try { ir.accept(rtcv); } catch (EOFException e) { // Should not be here. } return rtcv.isReferToAnyRefereeClasses; }
public short[] transform(short[] encodedInstructions) throws DexException { ShortArrayCodeOutput out = new ShortArrayCodeOutput(encodedInstructions.length); InstructionPromoter ipmo = new InstructionPromoter(); InstructionWriter iw = new InstructionWriter(out, ipmo); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(encodedInstructions)); try { // First visit, we collect mappings from original target address to promoted target address. ir.accept(new InstructionTransformVisitor(ipmo)); // Then do the real transformation work. ir.accept(new InstructionTransformVisitor(iw)); } catch (EOFException e) { throw new DexException(e); } return out.getArray(); }
public InstructionComparator(short[] insns1, short[] insns2) { this.insns1 = insns1; this.insns2 = insns2; if (insns1 != null) { ShortArrayCodeInput codeIn1 = new ShortArrayCodeInput(insns1); this.insnHolders1 = readInstructionsIntoHolders(codeIn1, insns1.length); } else { this.insnHolders1 = null; } if (insns2 != null) { ShortArrayCodeInput codeIn2 = new ShortArrayCodeInput(insns2); this.insnHolders2 = readInstructionsIntoHolders(codeIn2, insns2.length); } else { this.insnHolders2 = null; } visitedInsnAddrPairs = new HashSet<>(); }
private boolean isMethodReferToAnyClasses(DexClassInfo classInfo, ClassData.Method method, Set<String> refereeClassDescs) { if (method.codeOffset == ClassDef.NO_OFFSET) { return false; } Code methodCode = classInfo.owner.readCode(method); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(methodCode.instructions)); ReferToClassesCheckVisitor rtcv = new ReferToClassesCheckVisitor(classInfo.owner, method, refereeClassDescs); try { ir.accept(rtcv); } catch (EOFException e) { // Should not be here. } return rtcv.isReferToAnyRefereeClasses; }
public short[] transform(short[] encodedInstructions) throws DexException { ShortArrayCodeOutput out = new ShortArrayCodeOutput(encodedInstructions.length); InstructionPromoter ipmo = new InstructionPromoter(); InstructionWriter iw = new InstructionWriter(out, ipmo); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(encodedInstructions)); try { // First visit, we collect mappings from original target address to promoted target address. ir.accept(new InstructionTransformVisitor(ipmo)); // Then do the real transformation work. ir.accept(new InstructionTransformVisitor(iw)); } catch (EOFException e) { throw new DexException(e); } return out.getArray(); }
public short[] transform(short[] encodedInstructions) throws DexException { ShortArrayCodeOutput out = new ShortArrayCodeOutput(encodedInstructions.length); InstructionPromoter ipmo = new InstructionPromoter(); InstructionWriter iw = new InstructionWriter(out, ipmo); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(encodedInstructions)); try { // First visit, we collect mappings from original target address to promoted target address. ir.accept(new InstructionTransformVisitor(ipmo)); // Then do the real transformation work. ir.accept(new InstructionTransformVisitor(iw)); } catch (EOFException e) { throw new DexException(e); } return out.getArray(); }