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

2017-01-01 11:59:59 +08:00
 yivanus
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) {

            }

        }

    }
}
6183 次点击
所在节点    程序员
3 条回复
JasperWong
2017-01-01 13:45:45 +08:00
可惜 android 7.1 还没有 xposed 框架
isnowify
2017-01-01 18:54:04 +08:00
有已经编译的 apk 嘛
Yuwen
2017-01-02 05:06:42 +08:00
很感谢,可以拿去研究,但是也和遗憾,我是 Android 7.1

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/331542

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX