private ViewProxyBuilder(Context context, Class<T> clazz) { mContext = context; mBaseClass = clazz; mParentClassLoader = context.getClassLoader(); }
@Override public ClassLoader getClassLoader() { return mBase.getClassLoader(); }
/** * Loads class for the given class name. */ static Class<?> loadViewClass(Context context, String name) throws ClassNotFoundException { return context.getClassLoader().loadClass(name).asSubclass(View.class); }
private void storeAndReplaceOriginalComponentName(Intent intent, String origPackageName, String origClassName, String stubClassName) { final ComponentName origComponentName = new ComponentName(origPackageName, origClassName); ShareIntentUtil.fixIntentClassLoader(intent, mContext.getClassLoader()); intent.putExtra(EnvConsts.INTENT_EXTRA_OLD_COMPONENT, origComponentName); final ComponentName stubComponentName = new ComponentName(origPackageName, stubClassName); intent.setComponent(stubComponentName); }
@Nullable private static Class<?> getClass(Context context, String className) { Class<?> classObj = classMap.get(className); if (classObj != null) { return classObj; } try { classObj = context.getClassLoader().loadClass(className); classMap.put(className, classObj); } catch (ClassNotFoundException e) { Log.e( TAG, className + " is not available, please add " + className + " to the project.", e); } return classObj; }
public ClassLoader getClassLoader(String packageName) { Context context = createPackageContext(packageName); return context.getClassLoader(); }
public ClassLoader getClassLoader(ApplicationInfo appInfo) { Context context = createPackageContext(appInfo.packageName); return context.getClassLoader(); }
private ParcelableResourceWithMimeType(Parcel in) { mimeType = in.readString(); resource = in.readParcelable(FacebookSdk.getApplicationContext().getClassLoader()); } }
@Override public Activity newActivity(Class<?> clazz, Context context, IBinder token, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, Object lastNonConfigurationInstance) throws InstantiationException, IllegalAccessException { processIntent(context.getClassLoader(), intent); return super.newActivity(clazz, context, token, application, intent, info, title, parent, id, lastNonConfigurationInstance); }
@SuppressLint("PrivateApi") private static void installCondomProcessPackageManager(final CondomCore condom) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { final Class<?> ActivityThread = Class.forName("android.app.ActivityThread"); final Field ActivityThread_sPackageManager = ActivityThread.getDeclaredField("sPackageManager"); ActivityThread_sPackageManager.setAccessible(true); final Class<?> IPackageManager = Class.forName("android.content.pm.IPackageManager"); final Object pm = ActivityThread_sPackageManager.get(null); final InvocationHandler handler; if (Proxy.isProxyClass(pm.getClass()) && (handler = Proxy.getInvocationHandler(pm)) instanceof CondomProcessPackageManager) { Log.w(TAG, "CondomPackageManager was already installed in this process."); ((CondomProcessPackageManager) handler).mCondom = condom; } else { final Object condom_pm = Proxy.newProxyInstance(condom.mBase.getClassLoader(), new Class[] { IPackageManager }, new CondomProcessPackageManager(condom, pm)); ActivityThread_sPackageManager.set(null, condom_pm); } }
private static String getSource(Context context){ if(template == null){ try{ InputStream is = context.getClassLoader().getResourceAsStream("com/androidquery/util/web_image.html"); template = new String(AQUtility.toBytes(is)); }catch(Exception e){ AQUtility.debug(e); } } return template; }
public static IBinder getProxyService(Context context, ComponentName component, IBinder binder) { if (context == null || binder == null) { return null; } try { String description = binder.getInterfaceDescriptor(); ServiceFetcher fetcher = sHookSecondaryServiceMap.get(description); if (fetcher != null) { IBinder res = fetcher.getService(context, context.getClassLoader(), binder); if (res != null) { return res; } } } catch (Throwable e) { e.printStackTrace(); } return null; }
public static List<Library> detect(Context mCtx, List<Library> libraries) { ArrayList<Library> foundLibraries = new ArrayList<>(); // Loop through known libraries for (Library library : libraries) { if (!TextUtils.isEmpty(library.getClassPath())) { try { Context ctx = mCtx.createPackageContext(mCtx.getPackageName(), Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); Class<?> clazz = Class.forName(library.getClassPath(), false, ctx.getClassLoader()); // Detected a library!!! if (clazz != null) { foundLibraries.add(library); } } catch (ClassNotFoundException e) { //e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { //e.printStackTrace(); } } } // Only return AppSource if app has a library //return libraries.size() > 0 ? new AppSource(pkg, libraries) : null; return foundLibraries; } }
/** * InputStream and OutputStreams are always closed after operating on them! */ private Intent executeApi(Intent data, ParcelFileDescriptor input, int outputPipeId) { try { // always send version from client data.putExtra(EXTRA_API_VERSION, OpenPgpApi.API_VERSION); Intent result; // blocks until result is ready result = mService.execute(data, input, outputPipeId); // set class loader to current context to allow unparcelling // of OpenPgpError and OpenPgpSignatureResult // http://stackoverflow.com/a/3806769 result.setExtrasClassLoader(mContext.getClassLoader()); return result; } catch (Exception e) { Log.e(OpenPgpApi.TAG, "Exception in executeApi call", e); Intent result = new Intent(); result.putExtra(RESULT_CODE, RESULT_CODE_ERROR); result.putExtra(RESULT_ERROR, new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage())); return result; } finally { // close() is required to halt the TransferThread closeLoudly(input); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button t = new Button(this); t.setText("test button"); setContentView(t); Log.d(TAG, "context classloader: " + getApplicationContext().getClassLoader()); t.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { Intent t = new Intent(); if (HOOK_METHOD == PATCH_BASE_CLASS_LOADER) { t.setComponent(new ComponentName("com.weishu.upf.dynamic_proxy_hook.app2", "com.weishu.upf.dynamic_proxy_hook.app2.MainActivity")); } else { t.setComponent(new ComponentName("com.weishu.upf.ams_pms_hook.app", "com.weishu.upf.ams_pms_hook.app.MainActivity")); } startActivity(t); } catch (Throwable e) { e.printStackTrace(); } } }); }
ShareIntentUtil.fixIntentClassLoader(maybeHackedIntent, mContext.getClassLoader());
Constructor constructor = sConstructors.get(className); if (constructor == null) { Class c = mContext.getClassLoader().loadClass(className) .asSubclass(expectedType); if (c != null) {
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 false; ClassLoader classLoader = context.getClassLoader(); if (classLoader == null) { TinkerLog.e(TAG, "classloader is null");
@Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(newBase); try { Utils.extractAssets(newBase, "dynamic-proxy-hook.apk"); Utils.extractAssets(newBase, "ams-pms-hook.apk"); Utils.extractAssets(newBase, "test.apk"); if (HOOK_METHOD == PATCH_BASE_CLASS_LOADER) { File dexFile = getFileStreamPath("test.apk"); File optDexFile = getFileStreamPath("test.dex"); BaseDexClassLoaderHookHelper.patchClassLoader(getClassLoader(), dexFile, optDexFile); } else { LoadedApkClassLoaderHookHelper.hookLoadedApkInActivityThread(getFileStreamPath("ams-pms-hook.apk")); } AMSHookHelper.hookActivityManagerNative(); AMSHookHelper.hookActivityThreadHandler(); } catch (Throwable e) { e.printStackTrace(); } }