Is it possible to inject code in an android application?

后端 未结 5 760
闹比i
闹比i 2020-12-15 13:58

I would like to inject code in an android application at runtime. I have tried to use dx tool to generate a dexfile in the sdcard but when i want to instantiate, it fails. A

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 14:23

    Dexmaker is new and designed just for this. Here's part of the example from the project website:

        DexMaker dexMaker = new DexMaker();
    
        // Generate a HelloWorld class.
        TypeId helloWorld = TypeId.get("LHelloWorld;");
        dexMaker.declare(helloWorld, "HelloWorld.generated", Modifier.PUBLIC, TypeId.OBJECT);
        generateHelloMethod(dexMaker, helloWorld);
    
        // Create the dex file and load it.
        File outputDir = new File(".");
        ClassLoader loader = dexMaker.generateAndLoad(HelloWorldMaker.class.getClassLoader(),
                outputDir, outputDir);
        Class helloWorldClass = loader.loadClass("HelloWorld");
    
        // Execute our newly-generated code in-process.
        helloWorldClass.getMethod("hello").invoke(null);
    

提交回复
热议问题