简体   繁体   English

如何在Android中以编程方式执行ADB命令

[英]How to execute adb commands programmatically in android

I manually rooted my emulator using following commands 我使用以下命令手动将模拟器植根

adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system
adb push su /system/xbin/su
adb shell chmod 06755 /system
adb shell chmod 06755 /system/xbin/su
adb install superuser.apk

It is successfully rooted and working su command but while closing emulator and again opening emulator then su command is not working. 它已成功植根并运行su命令,但在关闭模拟器并再次打开模拟器时,su命令无法正常工作。 To overcome this one I want to create a sample app for execute above commands programmaticaly using 为了克服这个问题,我想创建一个示例应用程序,以使用程序以编程方式执行上述命令

Runtime.getRuntime().exec();

Please can one help me how to execute above commands programmatically. 请能帮助我如何以编程方式执行以上命令。

The emulator is rooted out of the box in that the ADB shell runs as root. 仿真器是开箱即用的,因为ADB shell以root身份运行。

What you've done is not "rooted" it, but rather used that pre-existing root shell to install a common hack which will then let application programs run helper tasks as root. 您所做的不是将其“植根”,而是使用该预先存在的根Shell来安装常见的hack,该hack将使应用程序以root身份运行帮助程序任务。

But you cannot do this from an application on the device which does not already have the ability to launch a helper as root - so you are stuck with a circular dependency or chicken-and-egg problem of needing root in order to install a root helper. 但是,您无法从尚无法以root用户身份启动助手的设备上的应用程序中执行此操作-因此,您陷入了循环依赖或需要root才能安装root helper的鸡与蛋的问题。

You will not be able to do this on the device or even emulator without finding a security hole (or pre-existing intentional privilege escalation mechanism) to exploit. 如果没有找到要利用的安全漏洞(或预先存在的故意特权升级机制),您将无法在设备甚至仿真器上执行此操作。

However: 然而:

  • you could read up on how to make the emulator's state persistent, and do it manually only once 您可以阅读有关如何使仿真器的状态持久化的信息,并且仅手动执行一次

  • you could issue the commands from a script running on the develpment machine, rather than on the device/emulator 您可以从在开发机器上而不是在设备/仿真器上运行的脚本中发出命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM