2021-12-13 03:57:27 -08:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.ContextWrapper;
|
2022-02-13 03:32:11 -08:00
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2021-12-13 03:57:27 -08:00
|
|
|
import android.util.Log;
|
|
|
|
|
2022-02-13 03:32:11 -08:00
|
|
|
import java.io.File;
|
2021-12-13 03:57:27 -08:00
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
|
|
|
|
import io.michaelrocks.paranoid.Obfuscate;
|
|
|
|
|
|
|
|
@Obfuscate
|
|
|
|
public class DelegateRootService extends ContextWrapper {
|
|
|
|
|
|
|
|
public DelegateRootService() {
|
|
|
|
super(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void attachBaseContext(Context base) {
|
2022-02-13 03:32:11 -08:00
|
|
|
if (!DynLoad.loadApk(base))
|
2021-12-13 03:57:27 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
2022-02-13 03:32:11 -08:00
|
|
|
// 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);
|
2021-12-13 03:57:27 -08:00
|
|
|
ctor.setAccessible(true);
|
|
|
|
Object service = ctor.newInstance(this);
|
2022-02-01 22:43:44 -08:00
|
|
|
DynLoad.attachContext(service, base);
|
2021-12-13 03:57:27 -08:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(DelegateRootService.class.getSimpleName(), "", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|