Skip to content

Commit

Permalink
Refactor init logic
Browse files Browse the repository at this point in the history
Follow native changes, a bit of cleaner separation.
  • Loading branch information
rovo89 committed Jun 26, 2016
1 parent a2b8d19 commit 69773d4
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions app/src/main/java/de/robv/android/xposed/XposedBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,34 @@ private XposedBridge() {}
protected static void main(String[] args) {
// Initialize the Xposed framework and modules
try {
SELinuxHelper.initOnce();
SELinuxHelper.initForProcess(null);
if (!hadInitErrors()) {
SELinuxHelper.initOnce();
SELinuxHelper.initForProcess(null);

runtime = getRuntime();
if (initNative()) {
runtime = getRuntime();
XPOSED_BRIDGE_VERSION = getXposedVersion();

if (isZygote) {
startsSystemServer = startsSystemServer();
initForZygote();
hookResources();
}

loadModules();
} else {
log("Errors during native Xposed initialization");
Log.e(TAG, "Not initializing Xposed because of previous errors");
}
} catch (Throwable t) {
log("Errors during Xposed initialization");
log(t);
Log.e(TAG, "Errors during Xposed initialization", t);
disableHooks = true;
}

// Call the original startup code
if (isZygote)
if (isZygote) {
ZygoteInit.main(args);
else
} else {
RuntimeInit.main(args);
}
}

/** @hide */
Expand All @@ -147,6 +149,7 @@ protected static void main(String[] args) {
}
}

private native static boolean hadInitErrors();
private static native String getStartClassName();
private static native int getRuntime();
private static native boolean startsSystemServer();
Expand Down Expand Up @@ -283,16 +286,21 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
app.uid == Process.myUid() ? app.sourceDir : app.publicSourceDir);
}
});
}

if (!SELinuxHelper.getAppDataFileService().checkFileExists(BASE_DIR + "conf/disable_resources")) {
hookResources();
} else {
private static void hookResources() throws Throwable {
if (SELinuxHelper.getAppDataFileService().checkFileExists(BASE_DIR + "conf/disable_resources")) {
Log.w(TAG, "Found " + BASE_DIR + "conf/disable_resources, not hooking resources");
disableResources = true;
return;
}

if (!initXResourcesNative()) {
Log.e(TAG, "Cannot hook resources");
disableResources = true;
return;
}
}

private static void hookResources() throws Throwable {
/*
* getTopLevelResources(a)
* -> getTopLevelResources(b)
Expand Down Expand Up @@ -803,7 +811,7 @@ public static void hookInitPackageResources(XC_InitPackageResources callback) {
}
}

private native static boolean initNative();
private native static boolean initXResourcesNative();

/**
* Intercept every call to the specified method and call a handler function instead.
Expand Down

0 comments on commit 69773d4

Please sign in to comment.