HookEntry.java 5.3 KB
Newer Older
LAPTOP-146U5DF5\28422 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
package com.fear1ess.reyunaditool;

import android.app.Activity;
import android.app.Application;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;

import com.fear1ess.reyunaditool.adsfinder.AdmobFinder;
import com.fear1ess.reyunaditool.adsfinder.Finder;
import com.fear1ess.reyunaditool.adsfinder.FinderUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static com.fear1ess.reyunaditool.pangle.pangleModule.hook_AppID;
import static com.fear1ess.reyunaditool.pangle.pangleModule.hook_SlotID;
import static com.fear1ess.reyunaditool.pangle.pangleModule.hook_doFinal;

public class HookEntry implements IXposedHookLoadPackage {
    public Context cxt = null;
    public static ClassLoader cl = null;
    public static ArrayList<String> admobDataList = new ArrayList<>();
    public static IDoCommandService hdService = null;
    public static ServiceConnection conn = null;
    public static String processName = null;
    public static String TAG = "adihookplugin_log";
    public static String[] notNeedAppList = {"android", "system_server", "org.meowcat.edxposed.manager"};

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        processName = (String)Class.forName("android.app.ActivityThread").getDeclaredMethod("currentProcessName").invoke(null);

        Log.d(TAG, "handleLoadPackage processName :" + processName);

        if((lpparam.appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) return;


        for(String item : notNeedAppList) {
            if(item.contains(processName)) return;
        }
//        MLog.d(lpparam.packageName);
//        if(lpparam.packageName.contains("com.union_test.internationad")){
//            MLog.d(lpparam.packageName+"进入了");
////            hook_AppID(lpparam);
////            hook_SlotID(lpparam);
//            hook_doFinal(lpparam);
//        }
        cl = lpparam.classLoader;
        XposedHelpers.findAndHookMethod("android.view.ContextThemeWrapper", cl, "attachBaseContext",
                Context.class, new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        Log.d(TAG, "enter app attach....");
                        cxt = (Context) param.args[0];

                        if(processName.equals("com.topjohnwu.magisk")){
                            Log.d(TAG, "open app");
                            ExecuteCmdUtils.startApp(cxt, "com.fear1ess.reyunaditool");
                            return;
                        }

                        if(lpparam.processName.contains("com.fear1ess.reyunaditool")) return;

                        Log.d(TAG, "start hook " + processName);

                        Log.d(TAG, "start bindservice...");
                        bindAdiToolService();
                        Log.d("reyunadihookplugin_adsfinder", "beforeHookedMethod: "+lpparam.packageName);
                        FinderUtils.doWork(cl,null);
                    }
                });


    }



    public void bindAdiToolService(){
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.fear1ess.reyunaditool",
                "com.fear1ess.reyunaditool.DoCommandService"));

        conn = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                hdService = IDoCommandService.Stub.asInterface(service);

                new Thread(){
                    @Override
                    public void run() {
                        try {
                            String curPkgName = hdService.doCommand(OperateCmd.QUERY_CURRENT_PKGNAME, null);
                        //    if(!processName.equals(curPkgName)) return;
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                        FinderUtils.notifyServiceBound(hdService);
                    }
                }.start();
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {

            }
        };

        boolean res = cxt.bindService(intent, conn, Service.BIND_AUTO_CREATE);
        if(res == false) Log.d(TAG, "bindAdiToolService failed!");
        if(res == true) Log.d(TAG, "bindAdiToolService success!");
    }
}