首页
社区
课程
招聘
[原创]Xposed 模块开发中用到的万能代码
发表于: 2020-11-30 10:12 17652

[原创]Xposed 模块开发中用到的万能代码

2020-11-30 10:12
17652

1,问题提出,日出开发xposed 模块,遇到各种壳,hook 都是有点困难,比如乐加固,360加固等。
2,解决: 使用hook ClassLoader.class, 这样就可以找到需要的类, 但是要注意,找到之后就不要继续往下找,return 即可,不然就是递归调用。

public class Main implements IXposedHookLoadPackage {

插入代码
插入代码
public static String xxx_PACKAGE = "com.xxx";
 
 
 
 
public static boolean xxx_PACKAGE_ISHOOK = false;
 
@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam)
        throws Throwable {
 
    final String packageName = lpparam.packageName;
    XposedBridge.log("pkgname:" + packageName);
    final String processName = lpparam.processName;
 
    try {
 
       final Set<XC_MethodHook.Unhook> unhooks = XposedBridge.hookAllMethods(ClassLoader.class, "loadClass",  new XC_MethodHook() {
 
 
           @Override
           protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
               if(NXES_PACKAGE_ISHOOK){
                   throw  new Throwable("exp");
               }
           }
            @Override
            protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
 
                try {
                    if (param.hasThrowable()) {
                        return;
                    }
                    if (param.args.length != 1) {
                        return;
                    }
                    if(NXES_PACKAGE_ISHOOK){
                        return;
                    }
 
 
                    Class<?> cls = (Class<?>) param.getResult();
                    String name = cls.getName();
                    XposedBridge.log("className1:" + name);
 
                    if("me.weishu.epic.art.entry.Entry".equals(name)) {
                        return;
                    }
                    if("me.weishu.epic.art.method.ArtMethod".equals(name)){
                        return;
                    }
 
                    if ("s.h.e.l.l.S".equals(name)) {
                        LogUtil.printLog("s.h.e.l.l.S-------hooked");
 
 
                        XposedHelpers.findAndHookMethod("s.h.e.l.l.S", (ClassLoader) param.thisObject, "attachBaseContext",
                                Context.class,
                                new XC_MethodHook() {
                                    @Override
                                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                        super.afterHookedMethod(param);
                                        LogUtil.printLog("afterHookedMethod s.h.l.l.S.attachBaseContext ...");
                                        Context context = (Context) param.args[0];
                                        ClassLoader appClassLoader = context.getClassLoader();
                                        LogUtil.printLog("--->processName:" + processName + " isHooked :" + CITTC_PACKAGE_ISHOOK);
                                        if (xxx_PACKAGE.equals(processName) && !NXES_PACKAGE_ISHOOK) {
                                            NXES_PACKAGE_ISHOOK = true;
 
                                            PayHelperUtils.sendmsg(context, "xxx hook成功,当前xxx 版本:" + PayHelperUtils.getVerName(context));
                                            new NXESHook().hook(appClassLoader, context);
 
                                        }
 
 
                                    }
                                }
 
                        );
                    }
                }catch (Exception exp) {
                    LogUtil.printLog(exp.toString());
                }
            }
 
 
        });
 
 
    } catch (Throwable e) {
        XposedBridge.log(e);
    }
}
public static String xxx_PACKAGE = "com.xxx";
 
 
 
 
public static boolean xxx_PACKAGE_ISHOOK = false;
 
@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam)
        throws Throwable {
 
    final String packageName = lpparam.packageName;
    XposedBridge.log("pkgname:" + packageName);
    final String processName = lpparam.processName;
 
    try {
 
       final Set<XC_MethodHook.Unhook> unhooks = XposedBridge.hookAllMethods(ClassLoader.class, "loadClass",  new XC_MethodHook() {
 
 
           @Override
           protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
               if(NXES_PACKAGE_ISHOOK){
                   throw  new Throwable("exp");
               }
           }
            @Override
            protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
 
                try {
                    if (param.hasThrowable()) {
                        return;
                    }
                    if (param.args.length != 1) {
                        return;
                    }
                    if(NXES_PACKAGE_ISHOOK){
                        return;
                    }
 
 
                    Class<?> cls = (Class<?>) param.getResult();
                    String name = cls.getName();
                    XposedBridge.log("className1:" + name);
 

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 5
支持
分享
最新回复 (26)
雪    币: 3907
活跃值: (5817)
能力值: ( LV12,RANK:200 )
在线值:
发帖
回帖
粉丝
2

你这根本不叫万能,还得看壳的类是不是S.H.E.L.L

给你个真正万能的 ~~

if (loadPackageParam.packageName.equals("com.cz.babySister")) {
            XposedBridge.log(" has Hooked!");
            XposedBridge.log("inner  => " + loadPackageParam.processName);
            Class ActivityThread = XposedHelpers.findClass("android.app.ActivityThread",loadPackageParam.classLoader);
            XposedBridge.hookAllMethods(ActivityThread, "performLaunchActivity", new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    super.afterHookedMethod(param);
                    Object mInitialApplication = (Application) XposedHelpers.getObjectField(param.thisObject,"mInitialApplication");
                    ClassLoader finalCL = (ClassLoader) XposedHelpers.callMethod(mInitialApplication,"getClassLoader");
                    XposedBridge.log("found classload is => "+finalCL.toString());
                    Class BabyMain = (Class)XposedHelpers.callMethod(finalCL,"findClass","com.cz.babySister.activity.MainActivity");
                    XposedBridge.log("found final class is => "+BabyMain.getName().toString());
                    fart(finalCL);
                }
            });
        }


2020-11-30 10:36
4
雪    币: 1041
活跃值: (733)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
这个要咋学习
2020-11-30 11:58
0
雪    币: 106
活跃值: (381)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
roysue 你这根本不叫万能,还得看壳的类是不是S.H.E.L.L给你个真正万能的 ~~ if&nbsp;(loadPackageParam.packageName.equals(&quot;c ...
版主有点过分了,这么好的代码现在才发出来
2020-11-30 13:31
0
雪    币: 1867
活跃值: (3958)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
5
https://gitee.com/virjar/xposed-extention/blob/master/src/main/java/com/virjar/xposed_extention/ClassLoadMonitor.java#L216

很多年前的所谓万能。

ps:直接hookclassloader部分手机有问题的,有些手机是隐式加载class。部分class不会进入到classloader里面
2020-11-30 15:40
1
雪    币: 2141
活跃值: (4522)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
roysue 你这根本不叫万能,还得看壳的类是不是S.H.E.L.L给你个真正万能的 ~~ if&nbsp;(loadPackageParam.packageName.equals(&quot;c ...
好家伙 这好东西星球都不发的
2020-12-4 10:08
0
雪    币: 6087
活跃值: (5495)
能力值: ( LV5,RANK:65 )
在线值:
发帖
回帖
粉丝
7
看上去是好东西,先收藏再说!
2020-12-4 10:29
0
雪    币: 576
活跃值: (2035)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8

mark

if (loadPackageParam.packageName.equals("com.cz.babySister")) {

            XposedBridge.log(" has Hooked!");

            XposedBridge.log("inner  => " + loadPackageParam.processName);

            Class ActivityThread = XposedHelpers.findClass("android.app.ActivityThread",loadPackageParam.classLoader);

            XposedBridge.hookAllMethods(ActivityThread, "performLaunchActivity"new XC_MethodHook() {

                @Override

                protected void afterHookedMethod(MethodHookParam param) throws Throwable {

                    super.afterHookedMethod(param);

                    Object mInitialApplication = (Application) XposedHelpers.getObjectField(param.thisObject,"mInitialApplication");

                    ClassLoader finalCL = (ClassLoader) XposedHelpers.callMethod(mInitialApplication,"getClassLoader");

                    XposedBridge.log("found classload is => "+finalCL.toString());

                    Class BabyMain = (Class)XposedHelpers.callMethod(finalCL,"findClass","com.cz.babySister.activity.MainActivity");

                    XposedBridge.log("found final class is => "+BabyMain.getName().toString());

                    fart(finalCL);

                }

            });

        }


2021-6-11 17:37
0
雪    币: 8
活跃值: (519)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
roysue 你这根本不叫万能,还得看壳的类是不是S.H.E.L.L给你个真正万能的 ~~ if&nbsp;(loadPackageParam.packageName.equals(&quot;c ...
越底层越万能哇
2021-6-11 18:06
0
雪    币: 29
活跃值: (5652)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10

楼上这些也配叫万能,遇到个手动合并dexElement的壳直接歇菜

直接hook art的class初始化函数,每个类初始化完成时自动调用回调函数传入本次初始化的类,在回调函数内直接操作,无视所有骚操作

最后于 2021-6-12 18:44 被不吃早饭编辑 ,原因:
2021-6-12 18:38
0
雪    币: 3212
活跃值: (743)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
不吃早饭 楼上这些也配叫万能,遇到个手动合并dexElement的壳直接歇菜直接hook art的class初始化函数,每个类初始化完成时自动调用回调函数传入本次初始化的类,在回调函数内直接操作,无视所有骚操作
能不能贴出来,贴个链接也行
2021-6-13 10:38
0
雪    币: 29
活跃值: (5652)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
疯子Tear 能不能贴出来,贴个链接也行

调用PendingHookHandler.addClassInitCallBack添加要等待初始化的类,以及对应的回调函数即可


https://github.com/necuil/SandHook_with_x86/blob/4a0c1aa7f7e4d5f29e1a20b5d0e2b6a505161902/sandhook/src/main/cpp/utils/hide_api.cpp#L352

最后于 2021-6-13 17:02 被不吃早饭编辑 ,原因:
2021-6-13 16:57
0
雪    币: 2334
活跃值: (10386)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
·恐怖如斯~~花式秀代码
2021-6-14 16:20
0
雪    币: 116
活跃值: (1012)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
2021-6-17 11:23
0
雪    币: 102
活跃值: (2045)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
15
mark
2021-6-17 11:51
0
雪    币: 1867
活跃值: (3958)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
16
不吃早饭 楼上这些也配叫万能,遇到个手动合并dexElement的壳直接歇菜直接hook art的class初始化函数,每个类初始化完成时自动调用回调函数传入本次初始化的类,在回调函数内直接操作,无视所有骚操作
我看到了当年我fixsandhook一个问题的时候写的代码注释了
2021-6-17 18:25
0
雪    币: 29
活跃值: (5652)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
2021-6-17 22:06
0
雪    币: 237
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
18
除了膜拜 不能说一句话了
2021-7-11 14:26
0
雪    币: 237
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
19
https://github.com/asLody/SandHook 不吃早饭老大的源码在这里了 
2021-7-11 15:04
0
雪    币: 116
活跃值: (1012)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
20
小白躲在角落瑟瑟发抖
2022-1-25 10:49
0
雪    币: 40
活跃值: (68)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
21
射射发抖
2022-2-20 22:59
0
雪    币: 1759
活跃值: (2334)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
22
roysue 你这根本不叫万能,还得看壳的类是不是S.H.E.L.L给你个真正万能的 ~~ if&nbsp;(loadPackageParam.packageName.equals(&quot;c ...
这个也不是万能的,遇到不启动activity的就拦截不到了
2023-7-12 13:28
0
雪    币: 1759
活跃值: (2334)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
23
不吃早饭 楼上这些也配叫万能,遇到个手动合并dexElement的壳直接歇菜直接hook art的class初始化函数,每个类初始化完成时自动调用回调函数传入本次初始化的类,在回调函数内直接操作,无视所有骚操作
这个是挺万能的,不过既然是native层,感觉跟Xposed已经没啥关系了
2023-7-12 13:34
0
雪    币: 1490
活跃值: (9913)
能力值: ( LV9,RANK:240 )
在线值:
发帖
回帖
粉丝
24
又见飞刀z 这个是挺万能的,不过既然是native层,感觉跟Xposed已经没啥关系了
xposed也是可以hook native的。native实际就是so咯。xposed注入so就行了。网上有现成例子。
2023-7-12 16:33
0
雪    币: 14824
活跃值: (6063)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
25
misskings xposed也是可以hook native的。native实际就是so咯。xposed注入so就行了。网上有现成例子。
注入so,同Xposed有什么关系?是so去hook native,xposed又没hook native
2023-7-12 20:13
0
游客
登录 | 注册 方可回帖
返回
//