8000 android: Share in-process helper between sessions by kkuehl · Pull Request #1299 · frida/frida-core · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/android-helper/helper.dex
Binary file not shown.
39 changes: 25 additions & 14 deletions src/android-helper/re/frida/HelperBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,11 @@ public class HelperBackend {
private Method mReadlink;
private Object mReadlinkReceiver;

public HelperBackend() {
Looper.prepareMainLooper();

preInitVendorExtensions();
private static Context sSystemContext;
private static RuntimeException sSystemContextError;

Context context;
try {
Class<?> ActivityThread = Class.forName("android.app.ActivityThread");
Object activityThread = ActivityThread.getDeclaredMethod("systemMain").invoke(null);
mContext = (Context) ActivityThread.getDeclaredMethod("getSystemContext").invoke(activityThread);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getCause());
} catch (Throwable e) {
throw new RuntimeException(e);
}
public HelperBackend() {
mContext = getSystemContext();
mPackageManager = mContext.getPackageManager();
mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);

Expand Down Expand Up @@ -194,6 +184,27 @@ public HelperBackend() {
}
}

private static Context getSystemContext() {
if (sSystemContext == null && sSystemContextError == null) {
try {
Looper.prepareMainLooper();

preInitVendorExtensions();

Class<?> ActivityThread = Class.forName("android.app.ActivityThread");
Object activityThread = ActivityThread.getDeclaredMethod("systemMain").invoke(null);
sSystemContext = (Context) ActivityThread.getDeclaredMethod("getSystemContext").invoke(activityThread);
} catch (InvocationTargetException e) {
sSystemContextError = new RuntimeException(e.getCause());
} catch (Throwable e) {
sSystemContextError = new RuntimeException(e);
}
}
if (sSystemContextError != null)
throw sSystemContextError;
return sSystemContext;
}

private static void preInitVendorExtensions() {
// Nothing OS: AppOpsManager.<clinit> chains into NtAppOpsManager.<clinit>, which
// calls NtExtFactory.getOrCreate(...). The factory dispatches through a static
Expand Down
Loading
Loading
0