-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxposed-module-generator.js
More file actions
executable file
·247 lines (193 loc) · 6.62 KB
/
Copy pathxposed-module-generator.js
File metadata and controls
executable file
·247 lines (193 loc) · 6.62 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env node
/**
* XPosed Module Generator — scaffold a full XPosed module structure
* Generates hook templates, manifest, and module.prop in seconds
*/
const fs = require('fs');
const path = require('path');
class XposedModuleGenerator {
constructor(moduleName, packageName, targetPackage, targetMethod) {
this.moduleName = moduleName;
this.packageName = packageName;
this.targetPackage = targetPackage;
this.targetMethod = targetMethod;
}
generateAndroidManifest() {
return `<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${this.packageName}"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="26"
android:targetSdkVersion="34" />
<application
android:label="@string/app_name"
android:icon="@drawable/icon">
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposeddescription"
android:value="${this.moduleName}" />
<meta-data
android:name="xposedminversion"
android:value="54" />
</application>
</manifest>`;
}
generateModuleProp() {
return `id=${this.packageName}
name=${this.moduleName}
version=1.0
versionCode=1
author=OutrageousStorm
description=XPosed module for ${this.targetPackage}`;
}
generateHookClass() {
return `package ${this.packageName}.hook;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import de.robv.android.xposed.XC_MethodHook;
public class HookManager implements IXposedHookLoadPackage {
private static final String TARGET_PACKAGE = "${this.targetPackage}";
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(TARGET_PACKAGE)) {
return;
}
try {
Class<?> targetClass = lpparam.classLoader.loadClass("${this.targetPackage}.${this.targetMethod}");
XposedBridge.hookAllMethods(targetClass, "${this.targetMethod}", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// Log method call
XposedBridge.log("[${this.moduleName}] ${this.targetMethod} called");
// TODO: Intercept/modify behavior
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// Log return value
XposedBridge.log("[${this.moduleName}] ${this.targetMethod} returned: " + param.getResult());
// TODO: Modify return value if needed
// param.setResult(modifiedValue);
}
});
XposedBridge.log("[${this.moduleName}] Successfully hooked ${this.targetMethod}");
} catch (ClassNotFoundException e) {
XposedBridge.log("[${this.moduleName}] Target class not found: " + e.getMessage());
}
}
}`;
}
generateGradleBuild() {
return `plugins {
id 'com.android.application'
}
android {
namespace "${this.packageName}"
compileSdk 34
defaultConfig {
applicationId "${this.packageName}"
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {
// XPosed
compileOnly 'de.robv.android.xposed:api:82'
// AndroidX
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}`;
}
generateREADME() {
return `# ${this.moduleName}
XPosed module for intercepting \`${this.targetMethod}\` in **${this.targetPackage}**.
## Installation
1. Install Xposed Framework (via Magisk LSPosed or similar)
2. Flash this module
3. Reboot device
4. Enable module in Xposed app
5. Reboot again
## How it works
- Hooks \`${this.targetPackage}.${this.targetMethod}\`
- Logs all calls with parameters and return values
- Ready for custom interception logic
## Customization
Edit \`HookManager.java\` to:
- Modify method arguments before execution
- Intercept and change return values
- Inject custom behavior
## Building
\`\`\`bash
./gradlew assembleRelease
\`\`\`
Output: \`app/build/outputs/apk/release/\`
## License
MIT`;
}
generate(outputDir) {
// Create directory structure
const dirs = [
outputDir,
path.join(outputDir, 'app', 'src', 'main', 'java',
...this.packageName.split('.'), 'hook'),
path.join(outputDir, 'app', 'src', 'main', 'res', 'values'),
];
dirs.forEach(dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
});
// Write files
fs.writeFileSync(
path.join(outputDir, 'AndroidManifest.xml'),
this.generateAndroidManifest()
);
fs.writeFileSync(
path.join(outputDir, 'module.prop'),
this.generateModuleProp()
);
const hookPath = path.join(
outputDir, 'app', 'src', 'main', 'java',
...this.packageName.split('.'), 'hook', 'HookManager.java'
);
fs.writeFileSync(hookPath, this.generateHookClass());
fs.writeFileSync(
path.join(outputDir, 'app', 'build.gradle.kts'),
this.generateGradleBuild()
);
fs.writeFileSync(
path.join(outputDir, 'README.md'),
this.generateREADME()
);
console.log(\`✅ XPosed module scaffold generated in \${outputDir}\`);
}
}
// CLI
if (require.main === module) {
const args = process.argv.slice(2);
if (args.length < 4) {
console.log(\`Usage: xposed-generator <name> <package> <target_package> <target_method>\`);
console.log(\`Example: xposed-generator "Screen Lock Bypass" com.example.screenbypass com.android.systemui updateLockIcon\`);
process.exit(1);
}
const [name, pkg, target, method] = args;
const generator = new XposedModuleGenerator(name, pkg, target, method);
generator.generate('.');
}
module.exports = XposedModuleGenerator;