-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathInject.java
More file actions
53 lines (46 loc) · 2.38 KB
/
Inject.java
File metadata and controls
53 lines (46 loc) · 2.38 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
package org.modfs.xposedmenu;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Objects;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
public class Inject implements IXposedHookZygoteInit {
boolean loaded = false;
String app_name = "com.app.here"; // EDIT THIS BEFORE COMPILING
String target_abi = Build.SUPPORTED_ABIS[0]; // SET THIS TO THE ABI YOU'RE TARGETING
public static InputStream resourceStream(String name) {
return Objects.requireNonNull(Inject.class.getClassLoader()).getResourceAsStream(name);
}
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
XposedHelpers.findAndHookMethod(Class.forName("android.app.LoadedApk"), "createAppFactory", ApplicationInfo.class,
ClassLoader.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
ApplicationInfo ai = (ApplicationInfo)param.args[0];
ClassLoader cl = (ClassLoader)param.args[1];
if (ai.toString().contains(app_name) && cl != null) {
if (!loaded) {
// load our menu before anything else, this is EXTREMELY fast so it might break lol
String pathname = "/data/user/0/" + app_name + "/cache/libxposedmenu.so";
File soFile = new File(pathname);
// NOTE: The ABI set has to be the one that the app uses
InputStream soFileStream = resourceStream("lib/" + target_abi + "/libxposedmenu.so");
byte[] soFileContent = new byte[soFileStream.available()];
soFileStream.read(soFileContent);
soFile.createNewFile();
FileOutputStream out = new FileOutputStream(soFile);
out.write(soFileContent);
XposedHelpers.callStaticMethod(XposedHelpers.findClass("java.lang.Runtime", cl), "nativeLoad", pathname, cl);
loaded = true;
}
}
super.beforeHookedMethod(param);
}
});
}
}