如何用cpp访问android中的服务?
我正在为 Android 开发一个取证项目。该项目的目标是使用 adb 连接到手机并调查案例,有时我需要访问 android 服务。我正在使用 c/cpp 开发我的项目,我可以运行 popen("service call bla bla") 命令来访问服务并获取结果。方法很奇怪:DI找到了Service的源码。我可以编译它并将其添加到我的项目中吗?我该如何编译这个?
https://android.googlesource.com/平台/frameworks/native/+/master/cmds/service/service.cpp
i am developing a forensic project for android. The goal of the project is to connect to the phone with adb and investigate cases, sometimes i need to access android services. I am developing my project with c/cpp, i can run the popen("service call bla bla") command to access the services and get the result. The method is very strange :D I found the source code of the Service. Can i compile this and add it to my project? How can i compile this?
https://android.googlesource.com/platform/frameworks/native/+/master/cmds/service/service.cpp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android 使用 AIDL 来定义客户端和服务器之间的接口。 AIDL后端可以是java/cpp/rust。这样就可以通过cpp访问android服务了。你应该找到你要调用的服务,并找到相关的aidl,然后找到生成的头文件和客户端的包装impl。然后就可以通过wrapped impl来调用服务了。
我们以 ActivityManager 为例:
请注意,在本例中,IActivityManager.h 仅包含 IActivityManager.aidl 中的几个方法。您可以自行使用所有方法生成。
首先,你应该检查是否可以在ndk中找到它。如果没有,检查是否可以在 AOSP 中找到,如果找到,请将 headers 和 impl 复制到您的项目中。如果没有,请使用 aidl-cpp 自己编写。
Android use AIDL to define the interface between the client and the server. And the AIDL backend can be java/cpp/rust. So you can access android serices with cpp. You should find the service you will call, and find the related aidl, then find the geneated header files and wrapped impl for client. Then you can call the service by wrapped impl.
Let's take ActivityManager as example:
Note that in this example, IActivityManager.h only include a few method in IActivityManager.aidl. You can generated with all method by yourself.
Fistly, you should check whether it can be found in ndk. If not, check whether it can be found in AOSP, if found, copy the headers and the impl to your project. If not, generated it with aidl-cpp by yourself.