如何在Android中使用root创建/删除/ data / data目录中的文件?

问题描述 投票:1回答:1

我正在创建一个POC,我需要创建一个POC,然后在一个root设备的/data/data目录中删除一个文件。我试图以标准方式创建一个文件,但它会按预期抛出一个PERMISSION_DENNIED异常。我知道这是可能的,因为Root Explorer应用程序可以做到这一点。

如何通过root以编程方式创建/删除文件?

预先感谢!

android mobile rooted
1个回答
0
投票

基于@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());
}
© www.soinside.com 2019 - 2024. All rights reserved.