Search in sources :

Example 1 with InstrumentationHook

use of android.taobao.atlas.runtime.InstrumentationHook in project atlas by alibaba.

the class Atlas method init.

/**
     * Init the framework
     * 
     * @param application
     * @return
     * @throws Exception
     */
public void init(Application application, boolean reset) throws AssertionArrayException, Exception {
    if (application == null) {
        throw new RuntimeException("application is null");
    }
    ApplicationInfo app_info = application.getApplicationInfo();
    sAPKSource = app_info.sourceDir;
    boolean DEBUG = (app_info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    RuntimeVariables.androidApplication = application;
    RuntimeVariables.delegateResources = application.getResources();
    Framework.containerVersion = RuntimeVariables.sInstalledVersionName;
    ClassLoader cl = Atlas.class.getClassLoader();
    Framework.systemClassLoader = cl;
    // defineAndVerify
    String packageName = application.getPackageName();
    // 
    DelegateClassLoader newClassLoader = new DelegateClassLoader(cl);
    // init RuntimeVariables
    RuntimeVariables.delegateClassLoader = newClassLoader;
    //        try{
    //        	RuntimeVariables.delegateResources = getResources(application);
    //        }catch(Throwable e){
    //            e.printStackTrace();
    //        }
    // inject DelegateClassLoader & DelegateResources & InstrumentationHook
    AndroidHack.injectClassLoader(packageName, newClassLoader);
    AndroidHack.injectInstrumentationHook(new InstrumentationHook(AndroidHack.getInstrumentation(), application.getBaseContext()));
    // add listeners
    bundleLifecycleHandler = new BundleLifecycleHandler();
    Framework.syncBundleListeners.add(bundleLifecycleHandler);
    frameworkLifecycleHandler = new FrameworkLifecycleHandler();
    Framework.frameworkListeners.add(frameworkLifecycleHandler);
    /**
         * TODO NEED CHECK
         * 解决某些自带LBE机制无法hook execstartactivity以及service start service的hook
         */
    try {
        ActivityManagrHook activityManagerProxy = new ActivityManagrHook();
        Object gDefault = AtlasHacks.ActivityManagerNative_gDefault.get(AtlasHacks.ActivityManagerNative.getmClass());
        AtlasHacks.Singleton_mInstance.hijack(gDefault, activityManagerProxy);
    } catch (Throwable e) {
    }
    AndroidHack.hackH();
}
Also used : BundleLifecycleHandler(android.taobao.atlas.runtime.BundleLifecycleHandler) ActivityManagrHook(android.taobao.atlas.runtime.ActivityManagrHook) ApplicationInfo(android.content.pm.ApplicationInfo) InstrumentationHook(android.taobao.atlas.runtime.InstrumentationHook) DelegateClassLoader(android.taobao.atlas.runtime.DelegateClassLoader) DelegateClassLoader(android.taobao.atlas.runtime.DelegateClassLoader) FrameworkLifecycleHandler(android.taobao.atlas.runtime.FrameworkLifecycleHandler)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1 ActivityManagrHook (android.taobao.atlas.runtime.ActivityManagrHook)1 BundleLifecycleHandler (android.taobao.atlas.runtime.BundleLifecycleHandler)1 DelegateClassLoader (android.taobao.atlas.runtime.DelegateClassLoader)1 FrameworkLifecycleHandler (android.taobao.atlas.runtime.FrameworkLifecycleHandler)1 InstrumentationHook (android.taobao.atlas.runtime.InstrumentationHook)1