Skip to content

Commit

Permalink
Adjustments for Lollipop code changes
Browse files Browse the repository at this point in the history
Some internal methods have changed, so hooks need to be adjusted.

Also, the code for the system_server process is now stored in a separate
file and accessed with a separate classloader (not the boot classloader),
so the hook needs to be placed in two steps.
  • Loading branch information
rovo89 committed Feb 13, 2015
1 parent 31638a2 commit a1cf28c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
19 changes: 15 additions & 4 deletions src/android/content/res/XResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.getIntField;
import static de.robv.android.xposed.XposedHelpers.getLongField;
import static de.robv.android.xposed.XposedHelpers.getObjectField;

import java.io.File;
Expand All @@ -16,6 +17,7 @@
import android.graphics.Movie;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -201,7 +203,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
});

findAndHookMethod(LayoutInflater.class, "parseInclude", XmlPullParser.class, View.class, AttributeSet.class, new XC_MethodHook() {
final XC_MethodHook parseIncludeHook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
sIncludedLayouts.get().push(param);
Expand All @@ -226,7 +228,14 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XCallback.callAll(liparam);
}
}
});
};
if (Build.VERSION.SDK_INT < 21) {
findAndHookMethod(LayoutInflater.class, "parseInclude", XmlPullParser.class, View.class,
AttributeSet.class, parseIncludeHook);
} else {
findAndHookMethod(LayoutInflater.class, "parseInclude", XmlPullParser.class, View.class,
AttributeSet.class, boolean.class, parseIncludeHook);
}
}

public static class ResourceNames {
Expand Down Expand Up @@ -405,7 +414,9 @@ public XmlResourceParser getAnimation(int id) throws NotFoundException {
XmlResourceParser result = repRes.getAnimation(repId);

if (!loadedFromCache) {
int parseState = getIntField(result, "mParseState");
long parseState = (Build.VERSION.SDK_INT >= 21)
? getLongField(result, "mParseState")
: getIntField(result, "mParseState");
rewriteXmlReferencesNative(parseState, this, repRes);
}

Expand Down Expand Up @@ -757,7 +768,7 @@ private static boolean isXmlCached(Resources res, int id) {
return false;
}

private static native void rewriteXmlReferencesNative(int parserPtr, XResources origRes, Resources repRes);
private static native void rewriteXmlReferencesNative(long parserPtr, XResources origRes, Resources repRes);

/**
* Used to replace reference IDs in XMLs.
Expand Down
55 changes: 39 additions & 16 deletions src/de/robv/android/xposed/XposedBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,45 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
});

// system thread initialization
findAndHookMethod("com.android.server.ServerThread", null,
Build.VERSION.SDK_INT < 19 ? "run" : "initAndLoop", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
loadedPackagesInProcess.add("android");

LoadPackageParam lpparam = new LoadPackageParam(sLoadedPackageCallbacks);
lpparam.packageName = "android";
lpparam.processName = "android"; // it's actually system_server, but other functions return this as well
lpparam.classLoader = BOOTCLASSLOADER;
lpparam.appInfo = null;
lpparam.isFirstApplication = true;
XC_LoadPackage.callAll(lpparam);
}
});
// system_server initialization
if (Build.VERSION.SDK_INT < 21) {
findAndHookMethod("com.android.server.ServerThread", null,
Build.VERSION.SDK_INT < 19 ? "run" : "initAndLoop", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
loadedPackagesInProcess.add("android");

LoadPackageParam lpparam = new LoadPackageParam(sLoadedPackageCallbacks);
lpparam.packageName = "android";
lpparam.processName = "android"; // it's actually system_server, but other functions return this as well
lpparam.classLoader = BOOTCLASSLOADER;
lpparam.appInfo = null;
lpparam.isFirstApplication = true;
XC_LoadPackage.callAll(lpparam);
}
});
} else {
findAndHookMethod(ActivityThread.class, "systemMain", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
findAndHookMethod("com.android.server.SystemServer", cl, "startBootstrapServices", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
loadedPackagesInProcess.add("android");

LoadPackageParam lpparam = new LoadPackageParam(sLoadedPackageCallbacks);
lpparam.packageName = "android";
lpparam.processName = "android"; // it's actually system_server, but other functions return this as well
lpparam.classLoader = cl;
lpparam.appInfo = null;
lpparam.isFirstApplication = true;
XC_LoadPackage.callAll(lpparam);
}
});
}
});
}

// when a package is loaded for an existing process, trigger the callbacks as well
hookAllConstructors(LoadedApk.class, new XC_MethodHook() {
Expand Down

0 comments on commit a1cf28c

Please sign in to comment.