Skip to content

Commit 7f865f6

Browse files
committed
first commit
0 parents  commit 7f865f6

File tree

24 files changed

+652
-0
lines changed

24 files changed

+652
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
16+
/.idea/*

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Xposed 模块模板 (基于 libxposed)
2+
3+
这是一个通用的 Xposed 模块模板,基于 [libxposed](https://github.com/libxposed/api) 构建。
4+
5+
## 如何使用
6+
7+
1. **修改包名**: 将 `app/build.gradle` 中的 `namespace``applicationId` 修改为你自己的包名。
8+
2. **重命名包目录**: 将 `app/src/main/java/com/example/module` 目录重命名为匹配你包名的目录结构。
9+
3. **更新模块入口**:
10+
- 修改 `MainModule.java` 以实现你的逻辑。
11+
- 更新 `app/src/main/resources/META-INF/xposed/java_init.list` 里的类名,确保它指向你的 `XposedModule` 实现类。
12+
4. **配置作用域**:
13+
-`app/src/main/resources/META-INF/xposed/scope.list` 中列出你想要 Hook 的应用包名(每行一个)。
14+
5. **设置编译参数**:
15+
- 根据需要修改 `app/build.gradle` 中的 `compileSdk``targetSdkVersion`
16+
17+
## 主要类介绍
18+
19+
- `MainModule.java`: 模块的主入口,继承自 `XposedModule`
20+
- `java_init.list`: 告诉 libxposed 模块的入口类是谁。
21+
- `scope.list`: 定义模块生效的作用域(应用)。
22+
- `module.prop`: 模块的元数据信息。
23+
24+
## 注意事项
25+
26+
- 本模板使用了 `libxposed` API,请参考其官方文档以了解更多高级用法。
27+
- 确保在开发过程中正确配置 `compileOnly` 依赖,以避免将 Xposed API 打包进你的 APK。

app/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/build
2+
/release
3+
/debug

app/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.example.module'
7+
compileSdk 34 // 可以根据需要修改
8+
9+
defaultConfig {
10+
applicationId "com.example.module"
11+
minSdkVersion 31
12+
targetSdkVersion 34
13+
versionCode 1
14+
versionName "1.0.0"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled true
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_21
26+
targetCompatibility JavaVersion.VERSION_21
27+
}
28+
29+
lint {
30+
checkReleaseBuilds false
31+
}
32+
33+
dependenciesInfo.includeInApk false
34+
}
35+
36+
dependencies {
37+
compileOnly 'androidx.annotation:annotation:1.9.1'
38+
compileOnly 'io.github.libxposed:api:100' // 请参考 libxposed 文档查看最新版本
39+
compileOnly project(":libxposed-compat")
40+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-adaptresourcefilecontents META-INF/xposed/java_init.list
2+
-keepattributes RuntimeVisibleAnnotations
3+
4+
-keep,allowobfuscation,allowoptimization public class * extends io.github.libxposed.api.XposedModule {
5+
public <init>(...);
6+
public void onPackageLoaded(...);
7+
public void onSystemServerLoaded(...);
8+
}
9+
-keep,allowshrinking,allowoptimization,allowobfuscation class ** implements io.github.libxposed.api.XposedInterface$Hooker
10+
-keepclassmembers,allowoptimization class ** implements io.github.libxposed.api.XposedInterface$Hooker {
11+
public *** before(***);
12+
public *** after(***);
13+
public static *** before();
14+
public static *** before(io.github.libxposed.api.XposedInterface$BeforeHookCallback);
15+
public static void after();
16+
public static void after(io.github.libxposed.api.XposedInterface$AfterHookCallback);
17+
public static void after(io.github.libxposed.api.XposedInterface$AfterHookCallback, ***);
18+
}
19+
20+
-repackageclasses
21+
-allowaccessmodification

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:label="@string/app_name"
8+
android:description="@string/xposed_description"
9+
android:supportsRtl="true"
10+
tools:ignore="AllowBackup,MissingApplicationIcon" />
11+
12+
</manifest>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.example.module;
2+
3+
import android.annotation.SuppressLint;
4+
5+
import androidx.annotation.NonNull;
6+
7+
import io.github.libxposed.api.XposedInterface;
8+
import io.github.libxposed.api.XposedModule;
9+
import io.github.libxposed.api.annotations.BeforeInvocation;
10+
import io.github.libxposed.api.annotations.XposedHooker;
11+
12+
/**
13+
* 这是 Xposed 模块的入口类。
14+
* 客户化建议:
15+
* 1. 修改包名 `com.example.module` 为你自己的包名。
16+
* 2. 在 `onSystemServerLoaded` 或 `onPackageLoaded` 中添加你的 Hook 逻辑。
17+
*/
18+
@SuppressLint({"PrivateApi", "BlockedPrivateApi"})
19+
public class MainModule extends XposedModule {
20+
21+
public MainModule(XposedInterface base, ModuleLoadedParam param) {
22+
super(base, param);
23+
}
24+
25+
@Override
26+
public void onSystemServerLoaded(@NonNull SystemServerLoadedParam param) {
27+
super.onSystemServerLoaded(param);
28+
// 在这里添加针对 System Server 的 Hook 逻辑
29+
// 例如:
30+
// try {
31+
// var classLoader = param.getClassLoader();
32+
// var clazz = classLoader.loadClass("com.android.server.wm.WindowManagerService");
33+
// // hook(method, MyHooker.class);
34+
// } catch (Throwable t) {
35+
// log("Hook failed", t);
36+
// }
37+
}
38+
39+
@Override
40+
public void onPackageLoaded(@NonNull PackageLoadedParam param) {
41+
super.onPackageLoaded(param);
42+
// 在这里添加针对特定应用的 Hook 逻辑
43+
// if (param.getPackageName().equals("com.target.package")) {
44+
// // ...
45+
// }
46+
}
47+
48+
/**
49+
* 这是一个简单的 Hooker 示例。
50+
*/
51+
@XposedHooker
52+
private static class ExampleHooker implements Hooker {
53+
@BeforeInvocation
54+
public static void before(@NonNull BeforeHookCallback callback) {
55+
// 在方法执行前执行的逻辑
56+
}
57+
58+
// @AfterInvocation
59+
// public static void after(@NonNull AfterHookCallback callback) {
60+
// // 在方法执行后执行的逻辑
61+
// }
62+
}
63+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<string name="app_name">Xposed Module Template</string>
3+
<string name="xposed_description">这是一个基于 libxposed 的 Xposed 模块模板。</string>
4+
</resources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.example.module.MainModule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# libxposed 模块属性
2+
# 最小 API 版本 (libxposed)
3+
minApiVersion=100
4+
# 目标 API 版本 (libxposed)
5+
targetApiVersion=100
6+
# 是否为静态作用域
7+
staticScope=true

0 commit comments

Comments
 (0)