Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android根应用程序echo无法使用设备驱动程序_Android_Bash_Terminal - Fatal编程技术网

Android根应用程序echo无法使用设备驱动程序

Android根应用程序echo无法使用设备驱动程序,android,bash,terminal,Android,Bash,Terminal,我目前正在尝试将数据写入我手机上运行的HID驱动程序。如果我在shell中运行以下命令(通过adb)echo-e\\x00\\x00\\x07\\x04\\x00\\x00\\x00>/dev/hidg0&&echo-e\\x00\\x00\\x00\\x00\\x00\\x00\\x00>/dev/hidg0,则在连接到设备的计算机上键入正确的字符,在本例中为da。但是,如果我在android应用程序中发送相同的命令,就像这样 Runtime shell = Runtime.getRuntim

我目前正在尝试将数据写入我手机上运行的HID驱动程序。如果我在shell中运行以下命令(通过adb)
echo-e\\x00\\x00\\x07\\x04\\x00\\x00\\x00>/dev/hidg0&&echo-e\\x00\\x00\\x00\\x00\\x00\\x00\\x00>/dev/hidg0
,则在连接到设备的计算机上键入正确的字符,在本例中为da。但是,如果我在android应用程序中发送相同的命令,就像这样

Runtime shell = Runtime.getRuntime();
Process p = shell.exec("su");
DataOutputStream out = new DataOutputStream(p.getOutputStream());
out.writeBytes("echo -e \\x00\\x00\\x07\\x04\\x00\\x00\\x00 > /dev/hidg0 && echo -e \\x00\\x00\\x00\\x00\\x00\\x00\\x00 > /dev/hidg0\n");
打印了2个单引号,但没有其他内容。我已经证明,该应用程序通过将文件写入只能由root用户访问的位置来获得root权限

那么,为什么像这样的命令在shell中的行为与抛出process类的方式不同呢?对于如何将数据发送到设备驱动程序,有人有什么建议吗

谢谢 阿德里安


PS我也尝试过
shell.exec(“echo-e\\x00\\x00\\x07\\x04\\x16\\x06\\x00>/dev/hidg0&&echo-e\\x00\\x00\\x00\\x00\\x00\\x00>/dev/hidg0”)但是这没有给我任何东西

在Java处理流之后,shell会看到以下命令:

echo -e \x00\x00\x07\x04\x00\x00\x00...
i、 例如,Java本身正在处理双反斜杠。您需要添加另一组转义反斜杠,以便shell实际看到单个转义反斜杠。你可以

out.writeBytes("echo -e \\\\x00\\\\x00...")
但这看起来很可怕。只需将带引号的字符串传递给shell

out.writeBytes("echo -e '\\x00\\x00\\x07\\x04\\x00\\x00\\x00' > /dev/hidg0 && echo -e '\\x00\\x00\\x00\\x00\\x00\\x00\\x00' > /dev/hidg0\n");

Java处理流后,shell将看到以下命令:

echo -e \x00\x00\x07\x04\x00\x00\x00...
i、 例如,Java本身正在处理双反斜杠。您需要添加另一组转义反斜杠,以便shell实际看到单个转义反斜杠。你可以

out.writeBytes("echo -e \\\\x00\\\\x00...")
但这看起来很可怕。只需将带引号的字符串传递给shell

out.writeBytes("echo -e '\\x00\\x00\\x07\\x04\\x00\\x00\\x00' > /dev/hidg0 && echo -e '\\x00\\x00\\x00\\x00\\x00\\x00\\x00' > /dev/hidg0\n");

工作得很好。真不敢相信我居然没看见。谢天谢地。真不敢相信我居然没看见。谢谢