如何以编程方式实现生根?

时间:2013-07-26 18:37:38

标签: android

我最近试图让自己进入更多Android开发阶段而且我一直很好奇如何在根本上完成root工作。理想情况下,即使现在只有一部手机,我也希望自己开发一款可以根据手机开发的产品。

我根植了我所拥有的所有Android手机,并且很好地了解了它的工作原理以及该怎么做。我也非常熟悉Linux及其背后的大多数概念。我一直无法找到的是如何创建像SuperOneClick或Galaxy Nexus Toolkit这样的工具,以及他们在幕后做什么来为您提供root权限。

在编程级别实际需要做什么才能获得root访问权限?我如何制作自己的应用程序/包来执行此操作?这只能通过利用漏洞来获得吗?

2 个答案:

答案 0 :(得分:5)

Rooting实质上是非法的权限提升。在大多数其他计算领域,它被认为是 crime 大规模利用。

根据品牌和型号的不同,生根可以是通过世界可读写/dev/exynos-mem翻转几个字节的任何内容,这使您可以访问任何进程的内存以详细说明内核攻击或在后面执行守护进程设备(例如,adb)。

例如,here是一种在SuperOneClick中使用的流行漏洞利用程序。略过它,它是某种缓冲区溢出,可能在vold上,但你可以看到理解这些漏洞并不容易,更不用说复制它们了。

答案 1 :(得分:0)

      Step 1 : copy this method...
         public static boolean isDeviceRooted() {
                        return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
                    }

                    private static boolean checkRootMethod1() {
                        String buildTags = android.os.Build.TAGS;
                        return buildTags != null && buildTags.contains("test-keys");
                    }

                    private static boolean checkRootMethod2() {
                        String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
                                "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
                        for (String path : paths) {
                            if (new File(path).exists()) return true;
                        }
                        return false;
                    }

                    private static boolean checkRootMethod3() {
                        Process process = null;
                        try {
                            process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
                            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
                            if (in.readLine() != null) return true;
                            return false;
                        } catch (Throwable t) {
                            return false;
                        } finally {
                            if (process != null) process.destroy();
                        }
                    }

Step 2:  check the condition in the first activity or login activity

if(isDeviceRooted()){
Toast.makeText(this,"Rooted",Toast.LENTH_LONG).show();
}else{
Toast.makeText(this,"Not Rooted",Toast.LENTH_LONG).show();
}
相关问题