MCPcopy Create free account
hub / github.com/cinit/TMoe / StartupHook

Class StartupHook

app/src/main/java/cc/ioctl/tmoe/startup/StartupHook.java:11–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import de.robv.android.xposed.XposedHelpers;
10
11public class StartupHook {
12 public static final StartupHook INSTANCE = new StartupHook();
13
14 private StartupHook() {
15 }
16
17 private boolean sPre1Initialized = false;
18 private boolean sPost2Initialized = false;
19
20 private static void injectClassLoader(ClassLoader classLoader) {
21 if (classLoader == null) {
22 throw new NullPointerException("classLoader == null");
23 }
24 try {
25 Field fParent = ClassLoader.class.getDeclaredField("parent");
26 fParent.setAccessible(true);
27 ClassLoader mine = StartupHook.class.getClassLoader();
28 ClassLoader curr = (ClassLoader) fParent.get(mine);
29 if (curr == null) {
30 curr = XposedBridge.class.getClassLoader();
31 }
32 if (!curr.getClass().getName().equals(HybridClassLoader.class.getName())) {
33 fParent.set(mine, new HybridClassLoader(curr, classLoader));
34 }
35 } catch (Exception e) {
36 XposedBridge.log(e);
37 }
38 }
39
40 public void doInit(ClassLoader rtLoader) {
41 // our minSdk is 21 so there is no need to wait for MultiDex to initialize
42 if (sPre1Initialized) {
43 return;
44 }
45 if (rtLoader == null) {
46 throw new AssertionError("StartupHook.doInit: rtLoader == null");
47 }
48 Class<?> applicationClass = null;
49 try {
50 applicationClass = rtLoader.loadClass("org.telegram.messenger.ApplicationLoader");
51 } catch (ClassNotFoundException ignored) {
52 }
53 if (applicationClass == null) {
54 try {
55 applicationClass = rtLoader.loadClass("org.thunderdog.challegram.BaseApplication");
56 } catch (ClassNotFoundException ignored) {
57 }
58 }
59 if (applicationClass == null) {
60 throw new AssertionError("StartupHook.doInit: unable to find ApplicationLoader");
61 }
62 XposedHelpers.findAndHookMethod(applicationClass, "onCreate", new XC_MethodHook(51) {
63 @Override
64 protected void beforeHookedMethod(MethodHookParam param) {
65 Application app = (Application) param.thisObject;
66 if (app == null) {
67 throw new AssertionError("app == null");
68 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected