基于xposed实现android注册系统服务,解决跨进程共享数据问题

昨花了点时间,参考github issues 总算实现了基于xposed的系统服务注入,本文目的是为了“解决应用之间hook后数据共享,任意app ServiceManager.getService就可以直接调用aidl实现了进程通信”(比如aidl service实现socket,http server等,或者从某app获取数据传递给另外个app等场景,能做什么大家自己想吧,当然也可以实现非xposed版本的,需要通过直接smali方式。因为需快速实现,我就基于xposed的方案凑活用着用吧)

Xposed我就不介绍了,Xposed有2个重要接口,一个是针对应用级别hook:IXposedHookLoadPackage,另一个就是针对系统级别的:IXposedHookZygoteInit

这里将使用IXposedHookZygoteInit实现aidl添加到系统服务中,当然,通过IXposedHookLoadPackage也是可以实现的,但是因为我们注入的服务是希望像系统服务一样,开机启动,关机停止,另外IXposedHookZygoteInit本身就是定位在针对系统hook,所以还是建议使用IXposedHookZygoteInit。

直接进入正题:

1.创建 android.os.ICustomService.aidl

 

package android.os;

// Declare any non-default types here with import statements

interface ICustomService {
    String sayHello();
}

 

2.创建CustomService实现类

 1 public class CustomService extends ICustomService.Stub {
 2     private Context mContext;
 3     public CustomService(Context context) {
 4         mContext = context;
 5     }
 6 
 7     @Override
 8     public String sayHello() throws RemoteException {
 9         return "Just Hello World";
10     }
11 
12     //ActivityManagerService的systemReady在所有服务初始化完成后触发,这定义这个是为了实现自定义服务的初始化代码实现
13     public void systemReady() {
14         // Make your initialization here
15     }
16 }

 

3.创建ApplicationSocket,实现IXposedHookZygoteInit接口,这实现系统启动时候触发hook

1 public class ApplicationSocket implements IXposedHookZygoteInit{
2     public static String TAG = "ApplicationSocket";
3     @Override
4     public void initZygote(StartupParam startupParam) throws Throwable {
5         XposedBridge.hookAllMethods(ActivityThread.class, "systemMain", 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值