From 9c1b10d06eca876261b571e1d6f3131c263c918e Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 18 Dec 2014 08:44:50 +0100 Subject: [PATCH] Removed Cydia Substrate support Refs #2087 --- AndroidManifest.xml | 1 - CHANGELOG.md | 2 +- src/biz/bokhorst/xprivacy/XParam.java | 8 -- src/biz/bokhorst/xprivacy/XPrivacy.java | 164 ++---------------------- 4 files changed, 10 insertions(+), 165 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 517a61a25..7498a9503 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -33,7 +33,6 @@ - result) { if (this.method instanceof Method) return (((Method) this.method).getReturnType().equals(result)); diff --git a/src/biz/bokhorst/xprivacy/XPrivacy.java b/src/biz/bokhorst/xprivacy/XPrivacy.java index 8622163b2..80553350b 100644 --- a/src/biz/bokhorst/xprivacy/XPrivacy.java +++ b/src/biz/bokhorst/xprivacy/XPrivacy.java @@ -27,9 +27,7 @@ import de.robv.android.xposed.XC_MethodHook; import static de.robv.android.xposed.XposedHelpers.findClass; -// TODO: fix link error when using Cydia Substrate public class XPrivacy implements IXposedHookLoadPackage, IXposedHookZygoteInit { - private static boolean mCydia = false; private static String mSecret = null; private static List mListHookError = new ArrayList(); private static List mListDisabled = new ArrayList(); @@ -83,95 +81,6 @@ public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable { handleLoadPackage(lpparam.packageName, lpparam.classLoader, mSecret); } - // Cydia - public static void initialize() { - mCydia = true; - init(null); - - // Self - MS.hookClassLoad(Util.class.getName(), new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XUtilHook.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // TODO: Cydia: Build.SERIAL - - // Activity recognition - MS.hookClassLoad("com.google.android.gms.location.ActivityRecognitionClient", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XActivityRecognitionClient.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Advertising Id - MS.hookClassLoad("com.google.android.gms.ads.identifier.AdvertisingIdClient", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XAdvertisingIdClientInfo.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Google auth - MS.hookClassLoad("com.google.android.gms.auth.GoogleAuthUtil", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XGoogleAuthUtil.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // GoogleApiClient.Builder - MS.hookClassLoad("com.google.android.gms.common.api.GoogleApiClient", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XGoogleApiClient.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Google Map V1 - MS.hookClassLoad("com.google.android.maps.GeoPoint", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XGoogleMapV1.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Google Map V2 - MS.hookClassLoad("com.google.android.gms.maps.GoogleMap", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XGoogleMapV2.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Location client - MS.hookClassLoad("com.google.android.gms.location.LocationClient", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XLocationClient.getInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Phone interface manager - MS.hookClassLoad("com.android.phone.PhoneInterfaceManager", new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XTelephonyManager.getPhoneInstances(), clazz.getClassLoader(), mSecret); - } - }); - - // Providers - for (final String className : XContentResolver.cProviderClassName) - MS.hookClassLoad(className, new MS.ClassLoadHook() { - @Override - public void classLoaded(Class clazz) { - hookAll(XContentResolver.getInstances(className), clazz.getClassLoader(), mSecret); - } - }); - } - // Common private static void init(String path) { Util.log(null, Log.WARN, "Init path=" + path); @@ -199,21 +108,12 @@ private static void init(String path) { // frameworks/base/services/java/com/android/server/SystemServer.java Class cSystemServer = Class.forName("com.android.server.SystemServer"); Method mMain = cSystemServer.getDeclaredMethod("main", String[].class); - if (mCydia) - MS.hookMethod(cSystemServer, mMain, new MS.MethodAlteration() { - @Override - public Void invoked(Object thiz, Object... args) throws Throwable { - PrivacyService.register(mListHookError, mSecret); - return invoke(thiz, args); - } - }); - else - XposedBridge.hookMethod(mMain, new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - PrivacyService.register(mListHookError, mSecret); - } - }); + XposedBridge.hookMethod(mMain, new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) throws Throwable { + PrivacyService.register(mListHookError, mSecret); + } + }); } catch (Throwable ex) { Util.bug(null, ex); } @@ -318,9 +218,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { hookAll(XSensorManager.getInstances(null), null, mSecret); // Settings secure - // TODO: Cydia: android.provider.Settings.Secure - if (!mCydia) - hookAll(XSettingsSecure.getInstances(), null, mSecret); + hookAll(XSettingsSecure.getInstances(), null, mSecret); // SIP manager hookAll(XSipManager.getInstances(), null, mSecret); @@ -494,10 +392,7 @@ private static void hook(final XHook hook, ClassLoader classLoader, String secre // Find class Class hookClass = null; try { - if (mCydia) - hookClass = Class.forName(hook.getClassName(), false, classLoader); - else - hookClass = findClass(hook.getClassName(), classLoader); + hookClass = findClass(hook.getClassName(), classLoader); } catch (Throwable ex) { String message = "Class not found hook=" + hook; int level = (md != null && md.isOptional() ? Log.WARN : Log.ERROR); @@ -540,14 +435,7 @@ private static void hook(final XHook hook, ClassLoader classLoader, String secre // Hook members for (Member member : listMember) try { - if (mCydia) { - XMethodAlteration alteration = new XMethodAlteration(hook, member); - if (member instanceof Method) - MS.hookMethod(member.getDeclaringClass(), (Method) member, alteration); - else - MS.hookMethod(member.getDeclaringClass(), (Constructor) member, alteration); - } else - XposedBridge.hookMethod(member, new XMethodHook(hook)); + XposedBridge.hookMethod(member, new XMethodHook(hook)); } catch (NoSuchFieldError ex) { Util.log(hook, Log.WARN, ex.toString()); } catch (Throwable ex) { @@ -642,38 +530,4 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { } } }; - - private static class XMethodAlteration extends MS.MethodAlteration { - private XHook mHook; - private Member mMember; - - public XMethodAlteration(XHook hook, Member member) { - mHook = hook; - mMember = member; - } - - @Override - public Object invoked(Object thiz, Object... args) throws Throwable { - if (Process.myUid() <= 0) - return invoke(thiz, args); - - XParam xparam = XParam.fromCydia(mMember, thiz, args); - mHook.before(xparam); - - if (!xparam.hasResult() || xparam.hasThrowable()) { - try { - Object result = invoke(thiz, args); - xparam.setResult(result); - } catch (Throwable ex) { - xparam.setThrowable(ex); - } - - mHook.after(xparam); - } - - if (xparam.hasThrowable()) - throw xparam.getThrowable(); - return xparam.getResult(); - } - } }