mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 23:14:03 -05:00
Refactor DynLoad
This commit is contained in:
@@ -2,8 +2,11 @@ package com.topjohnwu.magisk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import io.michaelrocks.paranoid.Obfuscate;
|
||||
@@ -17,12 +20,21 @@ public class DelegateRootService extends ContextWrapper {
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
if (DynLoad.createApp(base) == null)
|
||||
if (!DynLoad.loadApk(base))
|
||||
return;
|
||||
|
||||
// Create the actual RootService and call its attachBaseContext
|
||||
try {
|
||||
Constructor<?> ctor = DynLoad.apkData.getRootService().getConstructor(Object.class);
|
||||
// Create application to get the real root service class
|
||||
var data = DynLoad.createApkData();
|
||||
File apk = StubApk.current(base);
|
||||
PackageManager pm = base.getPackageManager();
|
||||
PackageInfo pkgInfo = pm.getPackageArchiveInfo(apk.getPath(), 0);
|
||||
DynLoad.loader.loadClass(pkgInfo.applicationInfo.className)
|
||||
.getConstructor(Object.class)
|
||||
.newInstance(data.getObject());
|
||||
|
||||
// Create the actual RootService and call its attachBaseContext
|
||||
Constructor<?> ctor = data.getRootService().getConstructor(Object.class);
|
||||
ctor.setAccessible(true);
|
||||
Object service = ctor.newInstance(this);
|
||||
DynLoad.attachContext(service, base);
|
||||
|
||||
Reference in New Issue
Block a user