Allow component classname obfuscation

This commit is contained in:
topjohnwu
2019-10-16 04:38:31 -04:00
parent c7033dd757
commit 43bda2d4a4
22 changed files with 132 additions and 63 deletions
@@ -8,12 +8,15 @@ import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentProvider;
import android.content.Intent;
import android.util.Log;
import com.topjohnwu.magisk.dummy.DummyActivity;
import com.topjohnwu.magisk.dummy.DummyProvider;
import com.topjohnwu.magisk.dummy.DummyReceiver;
import com.topjohnwu.magisk.dummy.DummyService;
import static com.topjohnwu.magisk.DownloadActivity.TAG;
@SuppressLint("NewApi")
public class DelegateComponentFactory extends AppComponentFactory {
@@ -22,39 +25,45 @@ public class DelegateComponentFactory extends AppComponentFactory {
@Override
public Application instantiateApplication(ClassLoader cl, String className) {
loader = cl;
if (loader == null) loader = cl;
Log.d(TAG, className);
return new DelegateApplication(this);
}
@Override
public Activity instantiateActivity(ClassLoader cl, String className, Intent intent)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Log.d(TAG, className);
if (delegate != null)
return delegate.instantiateActivity(loader, className, intent);
return delegate.instantiateActivity(loader, ComponentMap.get(className), intent);
return create(className, DummyActivity.class);
}
@Override
public BroadcastReceiver instantiateReceiver(ClassLoader cl, String className, Intent intent)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Log.d(TAG, className);
if (delegate != null)
return delegate.instantiateReceiver(loader, className, intent);
return delegate.instantiateReceiver(loader, ComponentMap.get(className), intent);
return create(className, DummyReceiver.class);
}
@Override
public Service instantiateService(ClassLoader cl, String className, Intent intent)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Log.d(TAG, className);
if (delegate != null)
return delegate.instantiateService(loader, className, intent);
return delegate.instantiateService(loader, ComponentMap.get(className), intent);
return create(className, DummyService.class);
}
@Override
public ContentProvider instantiateProvider(ClassLoader cl, String className)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Log.d(TAG, className);
if (loader == null) loader = cl;
if (delegate != null)
return delegate.instantiateProvider(loader, className);
return delegate.instantiateProvider(loader, ComponentMap.get(className));
return create(className, DummyProvider.class);
}
@@ -63,6 +72,7 @@ public class DelegateComponentFactory extends AppComponentFactory {
*/
private <T> T create(String name, Class<? extends T> dummy)
throws InstantiationException, IllegalAccessException {
Log.d(TAG, "create " + name);
try {
return (T) loader.loadClass(name).newInstance();
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException ignored) {