Skip to content

🎛️ ApiMonitorHookManager

敏感 API 监控层的唯一入口——单例管理器,负责在模块加载时批量实例化并启动全部 17 个(代码中实际注册)Hook 对象。

属性
源码路径ApiMonitorHookManager.java
类型普通类(单例)
所在包com.android.reverse.apimonitor
关键依赖全部 17 个 ApiMonitorHook 子类

🎯 职责

ApiMonitorHookManager 是整个 API 监控子系统的调度中枢。它以单例模式持有所有具体 Hook 对象的引用,并通过 startMonitor() 方法统一触发注册。调用方(ReverseXposedModule)只需调用一行代码即可开启对短信、电话、网络、通讯录、账号、摄像头、录音等 17 类敏感行为的全面拦截。

🔍 监控的 API

本类自身不直接 Hook 任何方法,而是将职责委托给各个具体 Hook 类。

委托 Hook 类监控目标
SmsManagerHook短信发送 / 读取
TelephonyManagerHook电话号码读取 / 电话状态监听
MediaRecorderHook视频/音频录制
AccountManagerHook账号信息读取
ActivityManagerHookActivity 管理操作
AlarmManagerHook闹钟/定时任务
ConnectivityManagerHook网络连接状态
ContentResolverHook通讯录/短信/通话记录 CRUD
ContextImplHook系统服务获取
PackageManagerHook应用包信息查询
RuntimeHookShell 命令执行
ActivityThreadHook主线程 / 广播接收
AudioRecordHook麦克风录音
CameraHook摄像头拍照 / 预览
NetWorkHookHTTP 网络请求
NotificationManagerHook通知发送
ProcessBuilderHook进程创建

🧠 关键实现

单例模式

java
private static ApiMonitorHookManager hookmger;

public static ApiMonitorHookManager getInstance(){
    if(hookmger == null)
        hookmger = new ApiMonitorHookManager();
    return hookmger;
}

线程安全提示

此处为非线程安全的懒汉式单例。在 Xposed 模块的 handleLoadPackage 回调中调用,由于 Zygote fork 机制保证了调用时机的单线程性,实际运行中不存在竞争问题。

构造函数:批量实例化

java
private ApiMonitorHookManager(){
    this.smsManagerHook = new SmsManagerHook();
    this.telephonyManagerHook = new TelephonyManagerHook();
    this.mediaRecorderHook = new MediaRecorderHook();
    this.accountManagerHook = new AccountManagerHook();
    this.activityManagerHook = new ActivityManagerHook();
    this.alarmManagerHook = new AlarmManagerHook();
    this.connectivityManagerHook = new ConnectivityManagerHook();
    this.contentResolverHook = new ContentResolverHook();
    this.contextImplHook = new ContextImplHook();
    this.packageManagerHook = new PackageManagerHook();
    this.runtimeHook = new RuntimeHook();
    this.activityThreadHook = new ActivityThreadHook();
    this.audioRecordHook = new AudioRecordHook();
    this.cameraHook = new CameraHook();
    this.networkHook = new NetWorkHook();
    this.notificationManagerHook = new NotificationManagerHook();
    this.processBuilderHook = new ProcessBuilderHook();
}

设计说明

所有 Hook 对象在构造时仅完成实例化,不执行任何 Hook 操作。真正的 XposedBridge.hookMethod() 调用推迟到 startMonitor() 中进行,确保构造期间的无副作用性。

startMonitor:统一激活

java
public void startMonitor(){
    this.smsManagerHook.startHook();
    this.telephonyManagerHook.startHook();
    // ... 共 17 次 startHook() 调用
    this.processBuilderHook.startHook();
}

每个 startHook() 内部通过 RefInvoke.findMethodExact() 定位目标方法,再调用 HookHelperInterface.hookMethod() 完成注册。整个过程在目标 App 进程加载时同步完成。

🔗 调用关系

📌 小结

ApiMonitorHookManager 是一个外观模式(Facade)+ 单例的组合体。它将复杂的多 Hook 注册逻辑隐藏在 startMonitor() 背后,使调用方代码极为简洁。若需新增监控目标,只需新建 ApiMonitorHook 子类、在构造函数中实例化、在 startMonitor() 中调用即可,完全符合开闭原则。

相关文档:

基于 MIT 协议发布 · 本文档仅用于安全研究与教学目的