V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yivanus
V2EX  ›  程序员

2017 年第一发。。。。分享代码。

  •  1
     
  •   yivanus · 2017-01-01 11:59:59 +08:00 · 6181 次点击
    这是一个创建于 2881 天前的主题,其中的信息可能已经有所发展或是发生改变。
    package com.xfunforx.zfbar;
    import android.content.pm.ApplicationInfo;
    import android.content.pm.PackageInfo;
    import android.os.Bundle;
    import android.view.View;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    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;
    
    public class ARzfb implements IXposedHookLoadPackage {
        static {
            XposedBridge.log("===============zfb module========");
    
        }
    
        public static final String apmClassName = "android.app.ApplicationPackageManager";
        public static final String apmClassMethodName1 = "getInstalledApplications";
        public static final String apmClassMethodName2 = "getInstalledPackages";
        static Object af;
        Map hooed = new HashMap();
    
        @Override
        public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
            if (loadPackageParam.packageName.equals("com.eg.android.AlipayGphone")) {
                XposedBridge.log("===============zfb found========");
    
                XposedHelpers.findAndHookMethod("com.alipay.mobile.base.security.CheckInject", loadPackageParam.classLoader, "a", new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        XposedBridge.log("****** w假装没有root");
                        param.setResult(false);
                    }
                });
    
                XposedHelpers.findAndHookMethod("java.lang.ClassLoader", loadPackageParam.classLoader, "loadClass", String.class, new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        final Class re;
                        if (param.getResult() != null) {
                            re = (Class) param.getResult();
                            String cn = re.getName();
    //                        关键字判断
                            
                            if (!cn.contains("arenvelope")) {
                                return;
                            }
    //                        下面逻辑防止重复hook,加快速度
    
                            if (hooed.containsKey(cn)){
                                return;
                            }else{
                                hooed.put(cn,cn);
                            }
    
                            if (cn.equals("com.alipay.android.phone.arenvelope.ui.find.ArFindActivity")){
                                XposedHelpers.findAndHookMethod(re, "onCreate", Bundle.class, new XC_MethodHook() {
                                    @Override
                                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
    //                                    这里保存 af,到时打开红包需要用到
    
                                        af = param.thisObject;
                                        XposedBridge.log("save the af=="+af.getClass().getName());
                                    }
                                });
                            }
    
                            if (cn.equals("com.alipay.android.phone.arenvelope.ui.find.ah")){
    //                            这个是投诉红包的那个菜单栏
    
                                XposedHelpers.findAndHookMethod(re, "onClick", View.class, new XC_MethodReplacement() {
                                    @Override
                                    protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
                                        Object lc = XposedHelpers.getObjectField(af,"f");
    //                                  可以把下面这个id换成你自己找的图片id
    //                                  调用下载的方法直接开启红包
    
                                        XposedHelpers.callMethod(af, "a", lc, "m0hkS3iXQNKXet4dGUVkNAAAACMAAQED");
                                        return null;
                                    }
                                });
                            }
                        }
                    }
                });
    
                final Class<?> apmClass;
                try {
                    apmClass = XposedHelpers.findClass(apmClassName, loadPackageParam.classLoader);
                } catch (XposedHelpers.ClassNotFoundError e) {
    
                    return;
                }
    
                try {
    //                隐藏xposed
    
                    XposedHelpers.findAndHookMethod(apmClass, apmClassMethodName1, int.class, new XC_MethodHook() {
                        @Override
                        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                            XposedBridge.log("****************InstalledApplicationsHook");
                            List installedApplications = (List) param.getResult();
    
                            ArrayList<ApplicationInfo> sortedOutApplications = new ArrayList<>();
    
                            for (Object application : installedApplications) {
                                ApplicationInfo applicationInfo = (ApplicationInfo) application;
    
                                if (!applicationInfo.packageName.contains("de.robv.android.xposed.installer")) {
                                    sortedOutApplications.add(applicationInfo);
                                }
                            }
    
                            param.setResult(sortedOutApplications);
                        }
                    });
                } catch (NoSuchMethodError error) {
                    ;
                }
    
                try {
    //                隐藏xposed
    
                    XposedHelpers.findAndHookMethod(apmClass, apmClassMethodName2, int.class, new XC_MethodHook() {
                        @Override
                        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                            XposedBridge.log("**************InstalledPackagesHook");
                            List installedPackages = (List) param.getResult();
    
                            ArrayList<PackageInfo> sortedOutPackages = new ArrayList<>();
    
                            for (Object installedPackage : installedPackages) {
                                PackageInfo packageInfo = (PackageInfo) installedPackage;
    
                                if (!packageInfo.packageName.contains("de.robv.android.xposed.installer")) {
                                    sortedOutPackages.add(packageInfo);
                                }
                            }
                            param.setResult(sortedOutPackages);
                        }
                    });
                } catch (NoSuchMethodError error) {
    
                }
    
            }
    
        }
    }
    
    3 条回复    2017-01-02 05:06:43 +08:00
    JasperWong
        1
    JasperWong  
       2017-01-01 13:45:45 +08:00
    可惜 android 7.1 还没有 xposed 框架
    isnowify
        2
    isnowify  
       2017-01-01 18:54:04 +08:00 via Android
    有已经编译的 apk 嘛
    Yuwen
        3
    Yuwen  
       2017-01-02 05:06:42 +08:00 via Android
    很感谢,可以拿去研究,但是也和遗憾,我是 Android 7.1
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1240 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 23:25 · PVG 07:25 · LAX 15:25 · JFK 18:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.