我正在创建一个POC,我需要创建一个POC,然后在一个root设备的/data/data
目录中删除一个文件。我试图以标准方式创建一个文件,但它会按预期抛出一个PERMISSION_DENNIED
异常。我知道这是可能的,因为Root Explorer应用程序可以做到这一点。
如何通过root以编程方式创建/删除文件?
预先感谢!
基于@GabeSechan评论,我能够使用此命令实现此目的。
创建新文件:
final String[] sCommand = {"su", "-c", "touch /data/..."};
try {
Runtime.getRuntime().exec(sCommand);
} catch (Exception e) {
Log.e(TAG, "Issue occurred while creating new file " + e.getMessage());
}
}
并删除文件:
final String[] sCommand = {"su", "-c", "rm /data/..."};
try {
Runtime.getRuntime().exec(sCommand);
} catch (Exception e) {
Log.e(TAG, "Issue occurred while deleting " + e.getMessage());
}