[Practice] Android5.1.1 source code, android5.1.1 source code
Preface
In this article, we need to modify the Android source code. However, as long as the system service is written, the system_server process can be injected to load the system service to system_server.
Procedure
1. Add an aidl file. I will add the aidl file to this path:
Frameworks/base/core/java/android/content/bw/IBWService. aidl, IBWService. aidl is my aidl file. The following is an example:
2. in frameworks/base/Android. many aidl files are added to the LOCAL_SRC_FILES file of the mk file. We add a line in the file list added by the system: core/java/android/content/bw/IBWService. aidl
3. Write a service file to inherit the Stub class in aidl. I added this class to this path:
Frameworks/base/services/core/java/com/android/server/bw/BWService. java. Here is a tip: You can first write an aidl and a class that inherits its Stub in your Android project. When the code is written correctly, copy the two files to the Android source code directory. The following is an example of a service file:
4. Add custom system services to the SystemServer class. For details about how to add system services, refer to Android5.1.1 source code-Analysis of when Android system services will be added to ServiceManager. The following is an example of adding a custom system service:
5. because SeAndroid is available in Android5.1.1, a white list of system services is maintained in this system. If the system service you want to add is not in this white list, adding the system service will fail, the whitelist path is external/sepolicy/service_contexts.
The following is the line I added to the whitelist:
Bwservice u: object_r: system_server_service: s0
Bwservice is the service name entered when ServiceManager. addService is used.
Now the system service has been added. just re-compile the Android source code.
Author: xunyu @ Alibaba Cloud universal security. For more security technical articles, visit the Alibaba Cloud universal security blog.