private Bundle initProcess(Bundle extras) { ConditionVariable lock = VirtualCore.get().getInitLock(); if (lock != null) { lock.block(); } IBinder token = BundleCompat.getBinder(extras,"_VA_|_binder_"); int vuid = extras.getInt("_VA_|_vuid_"); VClientImpl client = VClientImpl.get(); client.initProcess(token, vuid); Bundle res = new Bundle(); BundleCompat.putBinder(res, "_VA_|_client_", client.asBinder()); res.putInt("_VA_|_pid_", Process.myPid()); return res; }
if (!VClientImpl.get().isBound()) { ServiceInfo info = Reflect.on(msg.obj).get("info"); VClientImpl.get().bindApplication(info.packageName, info.processName);
public void bindApplication(final String packageName, final String processName) { if (Looper.getMainLooper() == Looper.myLooper()) { bindApplicationNoCheck(packageName, processName, new ConditionVariable()); } else { final ConditionVariable lock = new ConditionVariable(); VirtualRuntime.getUIHandler().post(new Runnable() { @Override public void run() { bindApplicationNoCheck(packageName, processName, lock); lock.open(); } }); lock.block(); } }
public static int onGetUid(int uid) { return VClientImpl.get().getBaseVUid(); } }
public static String getAppPkg() { return VClientImpl.get().getCurrentPackage(); }
private void bindApplicationNoCheck(String packageName, String processName, ConditionVariable lock) { VDeviceInfo deviceInfo = getDeviceInfo(); if (processName == null) { processName = packageName; setupUncaughtHandler(); } catch (Throwable e) { e.printStackTrace(); fixInstalledProviders(); } catch (Throwable e) { e.printStackTrace(); data.processName = processName; data.appInfo.processName = processName; data.providers = VPackageManager.get().queryContentProviders(processName, getVUid(), PackageManager.GET_META_DATA); VLog.i(TAG, String.format("Binding application %s, (%s)", data.appInfo.packageName, data.processName)); mBoundApplication = data; startIOUniformer(); Context context = createPackageContext(data.appInfo.packageName); try { Object boundApp = fixBoundApp(mBoundApplication); mBoundApplication.info = ContextImpl.mPackageInfo.get(context); mirror.android.app.ActivityThread.AppBindData.info.set(boundApp, data.info); ContextFixer.fixContext(mInitialApplication); if (Build.VERSION.SDK_INT >= 24 && "com.tencent.mm:recovery".equals(processName)) {
IBinder token = ActivityThread.ActivityClientRecord.token.get(r); ActivityInfo info = saveInstance.info; if (VClientImpl.get().getToken() == null) { InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0); if(installedAppInfo == null){ return false; if (!VClientImpl.get().isBound()) { VClientImpl.get().bindApplicationForActivity(info.packageName, info.processName, intent); getH().sendMessageAtFrontOfQueue(Message.obtain(msg)); return false; ); VActivityManager.get().onActivityCreate(ComponentUtils.toComponentName(info), caller, token, info, intent, ComponentUtils.getTaskAffinity(info), taskId, info.launchMode, info.flags); ClassLoader appClassLoader = VClientImpl.get().getClassLoader(info.applicationInfo); intent.setExtrasClassLoader(appClassLoader); ActivityThread.ActivityClientRecord.intent.set(r, intent);
IBinder token = ActivityThread.ActivityClientRecord.token.get(r); ActivityInfo info = saveInstance.info; if (VClientImpl.get().getToken() == null) { InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0); if(installedAppInfo == null){ return false; if (!VClientImpl.get().isBound()) { VClientImpl.get().bindApplication(info.packageName, info.processName); getH().sendMessageAtFrontOfQueue(Message.obtain(msg)); return false; ); VActivityManager.get().onActivityCreate(ComponentUtils.toComponentName(info), caller, token, info, intent, ComponentUtils.getTaskAffinity(info), taskId, info.launchMode, info.flags); ClassLoader appClassLoader = VClientImpl.get().getClassLoader(info.applicationInfo); intent.setExtrasClassLoader(appClassLoader); ActivityThread.ActivityClientRecord.intent.set(r, intent);
public void connected(ComponentName name, IBinder service, boolean dead) throws RemoteException { IBinderDelegateService delegateService = IBinderDelegateService.Stub.asInterface(service); if (delegateService != null) { name = delegateService.getComponent(); service = delegateService.getService(); IBinder proxy = ProxyServiceFactory.getProxyService(VClientImpl.get().getCurrentApplication(), name, service); if (proxy != null) { service = proxy; } } if(Build.VERSION.SDK_INT>=26) { IServiceConnectionO.connected.call(mConn, name, service, dead); }else { mConn.connected(name, service); } } }
@Override public Bundle call(MethodBox methodBox, String method, String arg, Bundle extras) throws InvocationTargetException { if (!VClientImpl.get().isBound()) { return methodBox.call(); } int methodType = getMethodType(method); if (METHOD_GET == methodType) { String presetValue = PRE_SET_VALUES.get(arg); if (presetValue != null) { return wrapBundle(arg, presetValue); } if ("android_id".equals(arg)) { return wrapBundle("android_id", VClientImpl.get().getDeviceInfo().androidId); } } if (METHOD_PUT == methodType) { if (isSecureMethod(method)) { return null; } } try { return methodBox.call(); } catch (InvocationTargetException e) { if (e.getCause() instanceof SecurityException) { return null; } throw e; } }
public void setCrashHandler(CrashHandler handler) { VClientImpl.get().setCrashHandler(handler); }
protected static VDeviceInfo getDeviceInfo() { return VClientImpl.get().getDeviceInfo(); }
private void handleReceiver(ReceiverData data) { BroadcastReceiver.PendingResult result = data.resultData.build(); try { if (!isBound()) { bindApplication(data.component.getPackageName(), data.processName); } Context context = mInitialApplication.getBaseContext(); Context receiverContext = ContextImpl.getReceiverRestrictedContext.call(context); String className = data.component.getClassName(); BroadcastReceiver receiver = (BroadcastReceiver) context.getClassLoader().loadClass(className).newInstance(); mirror.android.content.BroadcastReceiver.setPendingResult.call(receiver, result); data.intent.setExtrasClassLoader(context.getClassLoader()); if (data.intent.getComponent() == null) { data.intent.setComponent(data.component); } receiver.onReceive(receiverContext, data.intent); if (mirror.android.content.BroadcastReceiver.getPendingResult.call(receiver) != null) { result.finish(); } } catch (Exception e) { // must be this for misjudge of anti-virus!! throw new RuntimeException(String.format("Unable to start receiver: %s ", data.component), e); } VActivityManager.get().broadcastFinish(data.resultData); }
return super.beforeCall(who, method, args); ApplicationInfo currentApplicationInfo = VClientImpl.get().getCurrentApplicationInfo(); if (currentApplicationInfo == null) { return super.beforeCall(who, method, args);
public ClassLoader getClassLoader(String packageName) { Context context = createPackageContext(packageName); return context.getClassLoader(); }
private void clearSettingProvider() { Object cache; cache = Settings.System.sNameValueCache.get(); if (cache != null) { clearContentProvider(cache); } cache = Settings.Secure.sNameValueCache.get(); if (cache != null) { clearContentProvider(cache); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && Settings.Global.TYPE != null) { cache = Settings.Global.sNameValueCache.get(); if (cache != null) { clearContentProvider(cache); } } }
private void fixInstalledProviders() { clearSettingProvider(); Map clientMap = ActivityThread.mProviderMap.get(VirtualCore.mainThread()); for (Object clientRecord : clientMap.values()) {
public void bindApplicationForActivity(final String packageName, final String processName, final Intent intent) { mUiCallback = VirtualCore.getUiCallback(intent); bindApplication(packageName, processName); }
private void bindApplicationNoCheck(String packageName, String processName, ConditionVariable lock) { VDeviceInfo deviceInfo = getDeviceInfo(); if (processName == null) { processName = packageName; setupUncaughtHandler(); } catch (Throwable e) { e.printStackTrace(); fixInstalledProviders(); } catch (Throwable e) { e.printStackTrace(); data.providers = VPackageManager.get().queryContentProviders(processName, getVUid(), PackageManager.GET_META_DATA); Log.i(TAG, "Binding application " + data.appInfo.packageName + " (" + data.processName + ")"); mBoundApplication = data; startIOUniformer(); Context context = createPackageContext(data.appInfo.packageName); System.setProperty("java.io.tmpdir", context.getCacheDir().getAbsolutePath()); File codeCacheDir; Object boundApp = fixBoundApp(mBoundApplication); mBoundApplication.info = ContextImpl.mPackageInfo.get(context); mirror.android.app.ActivityThread.AppBindData.info.set(boundApp, data.info); ContextFixer.fixContext(mInitialApplication); if (Build.VERSION.SDK_INT >= 24 && "com.tencent.mm:recovery".equals(processName)) { fixWeChatRecovery(mInitialApplication);