Access protected UNIX domain sockets from Android app (using root)

冷暖自知 提交于 2020-01-17 07:55:28

问题


I need to access a UNIX domain socket from my Android app. Its file is located in /dev, so I need root permissions to open it. My phone is rooted, so gaining this permissions is not a problem. However, I failed to find a way to access this socket from root and forward the communication to my app.

AFAIK, the only way Android apps can get root permissions is through the su tool, so I need to find a native tool (already installed in the phone) that can make a bridge between STDIN/STDOUT and UNIX domain packets (so that my app can control the communication). The typical tools for that purpose are nc and socat. The former is available through busybox, but that version does not support UNIX domain sockets. The latter is not available at all. I'd rather avoid modifying the system partition to install a different tool.

My app could also launch a script that communicate with that socket from su directly without the need to forward the communication to my app, but again, I found no way to write such a script without the previously mentioned tools.

Is it possible to do what I want without installing/developing a native binary tool?

Maybe it is possible to do something with iptables/netfilter, but that does not seem to support this kind of sockets.

EDIT: well, I ended up developing a native binary executable which opens the Unix domain socket as root, and forwards it to the Java part using another Unix domain socket (created by the Java part). There is a hidden constructor for LocalSocket which takes a file descriptor and uses it as the opened socket. The biggest challenge was to find out how to compile a native executable with Android studio (not a library), but this answer helped a lot.

来源:https://stackoverflow.com/questions/45269285/access-protected-unix-domain-sockets-from-android-app-using-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!