-
Notifications
You must be signed in to change notification settings - Fork 2
/
HookAndroid.java
71 lines (63 loc) · 3.33 KB
/
HookAndroid.java
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
package com.obbedcode.xplex.hook;
import android.annotation.SuppressLint;
import android.app.IUidObserver;
import android.content.pm.IPackageManager;
import android.os.RemoteCallbackList;
import com.obbedcode.shared.hook.HookManager;
import com.obbedcode.shared.logger.XLog;
import com.obbedcode.shared.service.UserService;
import com.obbedcode.shared.utils.RuntimeUtils;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class HookAndroid {
private static final String TAG = "ObbedCode.XP.HookAndroid";
private static boolean hasFoundPackageService = false;
private static final HookManager manager = new HookManager();
public static void deployHook(final XC_LoadPackage.LoadPackageParam lpparam) {
if("android".equalsIgnoreCase(lpparam.packageName)) {
XLog.i(TAG, "Found (SYSTEM_SERVER) " + lpparam.packageName, true);
try {
@SuppressLint("PrivateApi")
Class<?> clazzSM = Class.forName("android.os.ServiceManager", false, lpparam.classLoader);
manager.hookAllMethods(clazzSM, "addService", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
String service = (String)param.args[0];
XLog.i(TAG, "Service: " + service, true);
if("package".equals(service)) {
if(hasFoundPackageService)
return;
IPackageManager pms = (IPackageManager)param.args[1];
if(pms == null) {
XLog.e(TAG, "Casting Param[1] to IPackageManager Interface failed", true, true);
return;
}
hasFoundPackageService = true;
manager.unHook("addService");
XLog.i(TAG, "Found [package] pms Service now creating our Service ?", true);
XLog.i(TAG, "All hooks are now unhooked from [addService]", true);
new Thread(() -> {
try {
XLog.i(TAG, "Starting XPL-EX Thread for Service...", true);
UserService.register(pms);
XLog.i(TAG, "Starting XPL-EX Service from PMS", true);
}catch (Exception e) {
XLog.e(TAG, "Failed to Start XPL-EX Service: " + e.getMessage(), true, true);
}
}).start();
}
}catch (Exception innerServiceManager) {
XLog.e(TAG, innerServiceManager, true);
} finally {
super.beforeHookedMethod(param);
}
}
});
}catch (Exception eServiceManager) {
XLog.e(TAG, eServiceManager);
}
}
}
}