custom class loader for android?

后端 未结 1 992
忘了有多久
忘了有多久 2021-02-04 20:31

I\'m writing an instrumentation library that I\'d like to work on both desktop and mobile (Android).

It functions by:

  1. Exposing a main which takes a single
相关标签:
1条回答
  • 2021-02-04 21:12

    There is a project called droidbox to detect android malware. There is a code that can help you a lot.

    package com.loader;
    
    import dalvik.system.DexClassLoader;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    
    public class LoaderActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            DexClassLoader dLoader = new DexClassLoader("/sdcard/DroidBoxTests.apk","/sdcard/", null, ClassLoader.getSystemClassLoader().getParent());
    
            Class calledClass = null;
            try {
                calledClass = dLoader.loadClass("droidbox.tests.DroidBoxTests");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Intent it=new Intent(this, calledClass);
            it.setClassName("droidbox.tests", "droidbox.tests.DroidBoxTests");
            startActivity(it);
        }
    }
    
    0 讨论(0)
提交回复
热议问题