首页
社区
课程
招聘
[原创]脱离pc开发Albatross可用的插件教程
发表于: 2025-10-1 19:34 829

[原创]脱离pc开发Albatross可用的插件教程

2025-10-1 19:34
829

Albatross 插件开发文档

相关项目

与 AlbatrossServer 的区别

特性 AlbatrossManager AlbatrossServer
运行环境 脱离 PC 独立运行 需电脑控制
适用场景 个人玩家(广告拦截、刷步数、抢红包等) 群控采集
开发状态 测试版 长期使用中
稳定性 不保证稳定 有保证
兼容性 支持其的插件在 Server 上一定可用 反之不成立
开发要求 需严格按照规范开发 -

概览

Albatross 插件分为两种类型,均继承 qing.albatross.agent.AlbatrossPlugin,通过 Albatross 的注入与 RPC 机制被加载与管理:

  • 应用态插件(App Scope):注入到目标 App 进程执行(示例:inapp)
  • 系统态插件(System Scope):注入到 system_server 或以系统 UID 范围生效(示例:insystem)

目录与构建

  • 每个插件是独立的 Android Application 模块(构建 APK/DEX 供注入)
  • 典型依赖(仅编译期,运行时由宿主/Agent 提供):
dependencies {
    compileOnly(files("lib/albatross.jar"))
}

插件基类与生命周期

自定义插件需继承 AlbatrossPlugin,常用回调方法:

方法 说明
beforeMakeApplication() 进程早期(Application 尚未创建)
load() 插件加载阶段
parseParams(String argString, int flags) 解析管理端下发的参数(强烈建议可向后兼容)
onConfigChange(String config, int flags) 运行时更新配置
beforeApplicationCreate(Application application) Application.onCreate 前,适合初始化 Hook
afterApplicationCreate(Application application) Application.onCreate
onAttachSystem(Application application) 系统态附着(仅系统插件)

应用态插件示例(inapp)

解析包名列表并在 beforeApplicationCreate 初始化 Hook:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class HideAppPlugin extends AlbatrossPlugin {
  public static List<String> hideApps;
 
  public HideAppPlugin(String libName, String argString, int flags) {
    super(libName, argString, flags);
    hideApps = new ArrayList<>();
  }
 
  @Override
  public boolean parseParams(String argString, int flags) {
    hideApps.clear();
    if (argString != null) {
      String[] packages = argString.split(",");
      Collections.addAll(hideApps, packages);
    }
    return true;
  }
 
  @Override
  public void beforeApplicationCreate(Application application) {
    String targetPackage = application.getPackageName();
    hideApps.remove(targetPackage); // 避免影响宿主自身
    IPackageManagerH.init(); // 初始化 Hook
  }
}

系统态插件示例(insystem)

解析规则并在系统附着时安装 Hook:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class HideAppSystemPlugin extends AlbatrossPlugin {
  public static Map<Integer, List<String>> hideRules = new HashMap<>();
 
  @Override
  public boolean parseParams(String hideRulesStr, int flags) {
    hideRules.clear();
    if (hideRulesStr != null) {
      Application application = Albatross.currentApplication();
      PackageManager pm = application.getPackageManager();
      String[] entries = hideRulesStr.split("\\|"); // pkg:rule1,rule2|pkg2:ruleA
      for (String e : entries) {
        String[] parts = e.split(":");
        if (parts.length != 2) continue;
        String pkg = parts[0];
        try {
          int uid = pm.getPackageInfo(pkg, 0).applicationInfo.uid;
          List<String> rules = new ArrayList<>();
          for (String r : parts[1].split(",")) if (!r.isEmpty()) rules.add(r);
          hideRules.put(uid, rules);
        } catch (PackageManager.NameNotFoundException ignore) {}
      }
    }
    return true;
  }
 
  @Override
  public void onAttachSystem(Application application) {
    if (!PackageManagerServiceH.initHook()) {
      Albatross.log("init hook err");
    }
  }
}

配置 Activity 与参数协议

插件通常提供一个"配置 Activity"以便采集用户配置,并通过 setResult(RESULT_OK, intent) 返回以下关键数据:

  • plugin_class:插件实现类全名(供管理端/Agent 加载)
  • plugin_params:文本参数(插件自定义格式)
  • plugin_flags:标志(插件自定义如何解析)

应用态示例(inapp)

返回 HideAppPlugin 与以逗号分隔的包名串:

1
2
3
4
// 结果回传(节选)
result.putExtra("plugin_params", "com.a.x,com.b.y");
result.putExtra("plugin_class", this.getClass().getName().replace("PluginConfigActivity", "HideAppPlugin"));
setResult(RESULT_OK, result);

系统态示例(insystem)

返回 HideAppSystemPlugin 与规则串 pkgA:rule1,rule2|pkgB:ruleX

1
2
3
4
5
StringBuilder rules = new StringBuilder();
// 组装为 pkg:rule1,rule2|pkg2:ruleA
result.putExtra("plugin_params", rules.toString());
result.putExtra("plugin_class", this.getClass().getName().replace("PluginConfigActivity", "HideAppSystemPlugin"));
setResult(RESULT_OK, result);

建议

  • 设计 plugin_params 时,保持向后兼容与健壮解析;必要时添加版本前缀如 v1|...
  • UI 可支持"显示系统应用"开关、全选/反选、详情配置等;配置即时落库,返回时再汇总

管理端(AlbatrossManager)职责

  • 插件列表:展示、启用/禁用、删除、详情
  • 启动插件配置 Activity,接收 plugin_class + plugin_params + plugin_flags
  • 通过连接器调用注入/加载 API,将插件部署到目标进程或系统

注入与通信(连接器)

管理端使用 PluginConnection 完成与 AlbatrossServer 的会话,主要方法:

  • 建立连接并设置 Agent:create(serverPath, secondLib, appAgentDex, systemAgentDex)
  • 注入目标 App 并加载插件:doInject(targetPkg, pluginDex, pluginClass, pluginParams, flags)
  • 加载系统态插件:loadSystemPlugin(pluginDex, pluginClass, pluginParams, flags)
  • 规则维度操作:addPluginRule(pluginId, pkg) / deletePluginRule(pluginId, pkg)(UID 维度)

应用态典型流程

  1. 启动配置 Activity,拿到 plugin_classplugin_params
  2. 调用 doInject(targetPkg, pluginDex, plugin_class, plugin_params, flags) 或在 app 重启时注入
  3. 插件在目标进程中执行 parseParamsbeforeApplicationCreate 等完成生效

系统态典型流程

  1. 启动配置 Activity,拿到 plugin_classplugin_params
  2. 调用 loadSystemPlugin(pluginDex, plugin_class, plugin_params, flags)
  3. 插件在 onAttachSystem 完成系统服务层 Hook 并按 UID 区分 app

Manifest 配置(必填)

为便于 AlbatrossManager 识别与跳转插件配置页,需要在插件的 AndroidManifest.xml 中添加 meta-data 与配置页 intent-filter

示例(应用态 hide_app,系统态同理):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<application
    android:label="HideApp"
    android:icon="@drawable/ic_launcher">
    <!-- 标记为 Albatross 可识别插件 -->
    <meta-data
        android:name="albatross_plugin"
        android:value="true" />
 
    <!-- 插件显示名称 -->
    <meta-data
        android:name="plugin_name"
        android:value="HideApp" />
 
    <!-- 插件实现类,用于注入加载 -->
    <meta-data
        android:name="plugin_class"
        android:value="qing.albatross.plugin.app.HideAppPlugin" />
 
    <!-- 插件描述与作者(可用于管理端展示) -->
    <meta-data
        android:name="plugin_description"
        android:value="隐藏指定app,只对app生效。" />
    <meta-data
        android:name="plugin_author"
        android:value="QingWan" />
 
    <!-- 可选:插件支持范围(示例),按需启用
    <meta-data
        android:name="plugin_support"
        android:value="pkg1,pkg2" />
    -->
 
    <!-- 插件配置页面,必须包含 qing.albatross.PluginConfig 动作 -->
    <activity
        android:name="qing.albatross.plugin.app.PluginConfigActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="qing.albatross.PluginConfig" />
        </intent-filter>
    </activity>
</application>

注意

  • albatross_plugin=true 是被扫描识别为插件的开关
  • plugin_class 必须与插件主类完全限定名一致(如 HideAppPlugin/HideAppSystemPlugin
  • 配置页 intent-filter 必须包含 qing.albatross.PluginConfig,否则管理端无法跳转到配置页面

参数协议约定(当前示例)

应用态(inapp)

  • plugin_classqing.albatross.plugin.app.HideAppPlugin
  • plugin_paramspkgA,pkgB,pkgC
  • 要点:插件端会排除当前宿主包名,避免误伤自身

系统态(insystem)

  • plugin_classqing.albatross.plugin.sys.HideAppSystemPlugin
  • plugin_paramspkgA:rule1,rule2|pkgB:ruleX
  • 要点:以 UID 为 key 存规则,用于区分 app

开发 Checklist(新插件)

  1. 新建 Android Application 模块,设置 namespaceapplicationId
  2. 依赖添加:compileOnly(lib/albatross.jar)
  3. 编写 YourPlugin extends AlbatrossPlugin,至少实现:
    • parseParams:定义并解析你的参数协议
    • beforeApplicationCreate / onAttachSystem:初始化 Hook/策略
  4. 提供配置 Activity:
    • 采集配置并封装为 plugin_params
    • 回传 plugin_classplugin_params
  5. 在管理端可见:确保 APK/DEX 被 Manager 识别(安装或登记到数据库/列表)
  6. 通过 Manager 配置生效的 app,验证插件是否生效

注意事项

  • 参数协议尽量简洁稳定,解析时对异常与空值做兜底
  • 应用态谨防影响宿主自身(建议排除 currentApplication().getPackageName()
  • 系统态以 UID 维度操作,适配多进程/多用户场景时请注意
  • 架构/ABI 与目标进程匹配;必要时为 32/64 位分别提供产物
  • 保持日志可观测性(Albatross.log)以便排查

参考文件


[培训]Windows内核深度攻防:从Hook技术到Rootkit实战!

最后于 2025-10-1 19:53 被WanQing编辑 ,原因:
上传的附件:
收藏
免费 1
支持
分享
最新回复 (1)
雪    币: 1766
活跃值: (2575)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
浅尝一下这个新方式镜像类hook框架
2025-10-2 19:19
0
游客
登录 | 注册 方可回帖
返回