美文网首页
Hook函数之Runtime.getRuntime().exec

Hook函数之Runtime.getRuntime().exec

作者: TMAC_EAH | 来源:发表于2018-11-06 10:48 被阅读0次

    因为需要,需要隐藏包名,具体干嘛我就不说了.当然,这只是隐藏包名的一部分.还有其他方式能查看到包名.

     public static List<String> getAppList(Context context) {
            List<String> appList = new ArrayList<>();
            if (context == null) {
                return appList;
            }
    
            try {
                Process process = Runtime.getRuntime().exec("pm list package -3");
                BufferedReader bis = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line = null;
                while ((line = bis.readLine()) != null) {
                    System.out.println("MainActivity.runCommand, line=" + line);
                    appList.add(line.replace("package:", ""));
                }
            } catch (IOException e) {
                System.out.println("MainActivity.runCommand,e=" + e);
            }
            return appList;
        }
    
    hook前
    I/System.out( 2657): =========>>>com.alibaba.android.rimet
    I/System.out( 2657): =========>>>com.oneweone.kangaroo
    I/System.out( 2657): =========>>>de.robv.android.xposed.installer
    I/System.out( 2657): =========>>>kaiqi.cn.xposed002
    I/System.out( 2657): =========>>>com.qxq.shenqi
    I/System.out( 2657): =========>>>kaiqi.cn.xposed003
    I/System.out( 2657): =========>>>ksh.skk
    I/System.out( 2657): =========>>>com.netease.faket_android_launcher.faket
    I/System.out( 2657): =========>>>kaiqi.cn.tst
    
    
    hook后
    I/System.out( 3702): 当前包名是-------->com.oneweone.kangaroo
    I/System.out( 3702): 当前包名是-------->kaiqi.cn.xposed002
    I/System.out( 3702): 当前包名是-------->com.qxq.shenqi
    I/System.out( 3702): 当前包名是-------->ksh.skk
    I/System.out( 3702): 当前包名是-------->com.netease.faket_android_launcher.faket
    I/System.out( 3702): 当前包名是-------->kaiqi.cn.tst
    

    hook核心代码

    public String[] skips = {
                "de.robv.android.xposed.installer", "kaiqi.cn.xposed003","com.alibaba.android.rimet"
        };
    
      try {
    
                    XposedHelpers.findAndHookMethod(Runtime.class, "exec", String.class, new XC_MethodHook() {
                        @Override
                        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                            Object[] args = param.args;
                            for (Object obj :
                                    args) {
                                XposedBridge.log("参数是:" + obj);
                            }
                            XposedBridge.log("获取信息:" + param.getResult());
                            //                XposedHelpers.findAndHookMethod("com.fukk.shiit", lpparam.classLoader, "methodName", Context.class, new XC_MethodHook() {
                            ////                    @Override
                            ////                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                            ////                        XposedBridge.log("hit me~");
                            ////                    }
                            ////                });
    
                            try {
                                XposedHelpers.findAndHookMethod(param.getResult().getClass(), "getInputStream",
                                        new XC_MethodHook() {
                                            @Override
                                            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                                                super.beforeHookedMethod(param);
    
                                            }
    
                                            protected void afterHookedMethod(MethodHookParam param)
                                                    throws Throwable {
                                                InputStream input = (InputStream) param.getResult();
                                                BufferedReader bis = new BufferedReader(new InputStreamReader(input));
                                                String line = null;
                                                StringBuilder sb = new StringBuilder();
                                                while ((line = bis.readLine()) != null) {
                                                    boolean flg = false;
                                                    for (String key : skips) {
                                                        if (line.contains(key)) {
                                                            XposedBridge.log("包名命中.....");
                                                            flg = true;
                                                            break;
                                                        }
                                                    }
                                                    if (flg) {
                                                        continue;
                                                    }
                                                    sb.append(line + "\n");
                                                }
                                                XposedBridge.log("结果集合:" + sb.toString());
                                                Logger.e(TAG, "结果集合:" + sb.toString());
                                                InputStream result = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
                                                param.setResult(result);
                                            }
    
                                        });
                            } catch (Throwable e) {
                                XposedBridge.log("UNIXProcess.修改命令失败" + e);
                                //Log.i("VVVV","修改" + method + "失败!" + e.getMessage());
                            }
                        }
    
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    XposedBridge.log("获取信息:失败;;;;;;;;;;;" + e);
                }
    

    相关文章

      网友评论

          本文标题:Hook函数之Runtime.getRuntime().exec

          本文链接:https://www.haomeiwen.com/subject/hkiyxqtx.html