Java Code Examples for org.jf.dexlib2.builder.MutableMethodImplementation

Following code examples demonstrate how to use org.jf.dexlib2.builder.MutableMethodImplementationfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.jf.dexlib2.builder.MutableMethodImplementationand various code implementation of this class.

    private MethodImplementation searchAndReplaceInvocations(MethodImplementation origImplementation) {
        MutableMethodImplementation newImplementation = null;
        int i = -1;
        for (Instruction instruction : origImplementation.getInstructions()) {
            ++i;
            Opcode opcode = instruction.getOpcode();

            if (opcode == Opcode.INVOKE_VIRTUAL || opcode == Opcode.INVOKE_STATIC || opcode == Opcode.INVOKE_DIRECT) {
                assert instruction instanceof Instruction35c;
                Instruction35c invokeInstr = (Instruction35c) instruction;

                Instruction35c newInstruction = checkInstruction(invokeInstr);
                if (newInstruction == invokeInstr)
                    continue;
                if (newImplementation == null)
                    newImplementation = new MutableMethodImplementation(origImplementation);
                ++nInstrumented;
                if (opcode == Opcode.INVOKE_DIRECT)
                    newImplementation.addInstruction(++i,(BuilderInstruction35c)newInstruction);
                else
                    newImplementation.replaceInstruction(i, (BuilderInstruction35c)newInstruction);
            }
        }
        return newImplementation!=null ? newImplementation : origImplementation;
    } 


					                public Iterator<Method> iterator() {
					                	Iterable<? extends Method> iterators =  classDef.getDirectMethods();
					                	List<Method> list = new ArrayList<>();
					                	list.add(BuilderReference.makeMethod(className, 
					                			methodName, ImmutableList.of(), "V", 
					                			AccessFlags.PUBLIC.getValue() | AccessFlags.STATIC.getValue(), 
					                			new MutableMethodImplementation(1)));
					                	return Iterators.concat(iterators.iterator(), list.iterator());
					                } 

	public void modify() throws IOException{
		DexFile rewrittenDexFile = rewriter.rewriteDexFile(this.dexFile);
		DexPool.writeTo(config.outPath, rewrittenDexFile);
		config.hasModifed = true;
	} 

						public void modify(MutableMethodImplementation impl, DexBackedDexFile dexfile) {
							impl.addInstruction(0, InstructionBuilder.newConstStringIns(0, 
			        				"com.cc.test"));
							impl.addInstruction(1, InstructionBuilder.newConst4Ins(1, 0));
							impl.addInstruction(2, InstructionBuilder.newInvokeStaticIns(2, 
			                		0, 1, 0, 0, 0, "Lcom/cc/test/ProxyShell;", "startshell", dexfile));
							if (impl.getRegisterCount() < 2)
								impl.setRegisterCount(2);
						} 

    public List<BuilderTryBlock> getTryBlocks() {
        MutableMethodImplementation implementation = (MutableMethodImplementation) method.getImplementation();
        if (implementation == null) {
            return new LinkedList<>();
        }

        return implementation.getTryBlocks();
    } 

Advertisement
Advertisement