轉自:http://hi.baidu.com/tomken_zhang/blog/item/bd170aa9cbd0a2e61f17a207.html
ADB 是 Android 手機中的一個調試服務
他是由 ROOT 程序派生的,
看 adb.c 中有一樣一段代碼
property_get("ro.kernel.qemu", value, "");
if (strcmp(value, "1") != 0) {
property_get("ro.secure", value, "");
if (strcmp(value, "1") == 0) {
// don't run as root if ro.secure is set...
secure = 1;
// ... except we allow running as root in userdebug builds if the
// service.adb.root property has been set by the "adb root" command
property_get("ro.debuggable", value, "");
if (strcmp(value, "1") == 0) {
property_get("service.adb.root", value, "");
if (strcmp(value, "1") == 0) {
secure = 0;
}
}
}
}
只要讓 secure 不等於1,就是以 root 運行,否則就是以 shell 運行
secure 默認值是爲 0 的,看上面代碼,
property_get 是 Android 中屬性服務,用的是共享內存,因爲在這裏沒有加上合適的判斷,可以讓這片內存設定不不可讀,按上面的代碼邏輯,ADB 也就成 ROOT 用戶了。
如何設定,參見 psneuter.c 中,是這樣做的,
查找環境變量 ANDROID_PROPERTY_WORKSPACE,這裏記錄的是共享內存的句柄,及內存大小
調用了一個 ioctl 命令 ioctl(fd, ASHMEM_SET_PROT_MASK, 0),會導致這個共享內存不可讀,具體未研究!
看來用 ADB 來獲取 ROOT 還是有不少辦法的!