Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Only hook what needs to be hooked
Browse files Browse the repository at this point in the history
Refs #1757
  • Loading branch information
M66B committed Feb 15, 2015
1 parent f98f514 commit 01a7e4f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 95 deletions.
14 changes: 8 additions & 6 deletions src/biz/bokhorst/xprivacy/XAccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ private enum Methods {
};
// @formatter:on

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
className = cClassName;

listHook.add(new XAccountManager(Methods.Srv_getAccounts, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getAccountsAsUser, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getAccountsByFeatures, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getAccountsForPackage, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getSharedAccountsAsUser, PrivacyManager.cAccounts));
if (server) {
listHook.add(new XAccountManager(Methods.Srv_getAccounts, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getAccountsAsUser, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getAccountsByFeatures, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getAccountsForPackage, PrivacyManager.cAccounts));
listHook.add(new XAccountManager(Methods.Srv_getSharedAccountsAsUser, PrivacyManager.cAccounts));
}

listHook.add(new XAccountManager(Methods.addOnAccountsUpdatedListener, PrivacyManager.cAccounts, className));
listHook.add(new XAccountManager(Methods.blockingGetAuthToken, PrivacyManager.cAccounts, className));
Expand Down
15 changes: 8 additions & 7 deletions src/biz/bokhorst/xprivacy/XActivityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ private enum Methods {
};
// @formatter:on

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
className = cClassName;

for (Methods act : Methods.values())
if (act.name().startsWith("Srv_"))
if (act.name().startsWith("Srv_start"))
listHook.add(new XActivityManager(act, null, null));
else
listHook.add(new XActivityManager(act, PrivacyManager.cSystem, null));
else
if (act.name().startsWith("Srv_")) {
if (server)
if (act.name().startsWith("Srv_start"))
listHook.add(new XActivityManager(act, null, null));
else
listHook.add(new XActivityManager(act, PrivacyManager.cSystem, null));
} else
listHook.add(new XActivityManager(act, PrivacyManager.cSystem, className));
}
return listHook;
Expand Down
11 changes: 6 additions & 5 deletions src/biz/bokhorst/xprivacy/XClipboardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ private enum Methods {
};
// @formatter:on

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
className = cClassName;

for (Methods clip : Methods.values())
if (clip.name().startsWith("Srv_")) {
if (clip == Methods.Srv_removePrimaryClipChangedListener)
listHook.add(new XClipboardManager(clip, null));
else
listHook.add(new XClipboardManager(clip, PrivacyManager.cClipboard));
if (server)
if (clip == Methods.Srv_removePrimaryClipChangedListener)
listHook.add(new XClipboardManager(clip, null));
else
listHook.add(new XClipboardManager(clip, PrivacyManager.cClipboard));
} else {
if (clip == Methods.removePrimaryClipChangedListener)
listHook.add(new XClipboardManager(clip, null, className));
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XConnectivityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private enum Methods {
getActiveNetworkInfo, getAllNetworkInfo, getNetworkInfo
};

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
Expand Down
16 changes: 9 additions & 7 deletions src/biz/bokhorst/xprivacy/XLocationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private enum Methods {
};
// @formatter:on

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
Expand All @@ -114,12 +114,14 @@ public static List<XHook> getInstances(String className) {
for (Methods loc : Methods.values())
if (loc == Methods.removeUpdates)
listHook.add(new XLocationManager(loc, null, className));
else if (loc.name().startsWith("Srv_remove"))
listHook.add(new XLocationManager(loc, null, "com.android.server.LocationManagerService"));
else if (loc.name().startsWith("Srv_"))
listHook.add(new XLocationManager(loc, PrivacyManager.cLocation,
"com.android.server.LocationManagerService"));
else
else if (loc.name().startsWith("Srv_remove")) {
if (server)
listHook.add(new XLocationManager(loc, null, "com.android.server.LocationManagerService"));
} else if (loc.name().startsWith("Srv_")) {
if (server)
listHook.add(new XLocationManager(loc, PrivacyManager.cLocation,
"com.android.server.LocationManagerService"));
} else
listHook.add(new XLocationManager(loc, PrivacyManager.cLocation, className));
}
return listHook;
Expand Down
32 changes: 17 additions & 15 deletions src/biz/bokhorst/xprivacy/XPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,28 @@ private enum Methods {
};
// @formatter:on

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
className = cClassName;

listHook.add(new XPackageManager(Methods.Srv_getPackageInfo, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getApplicationInfo, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getInstalledApplications, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getInstalledPackages, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPackagesForUid, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPackagesHoldingPermissions, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPersistentApplications, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPreferredPackages, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryContentProviders, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentActivities, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentActivityOptions, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentContentProviders, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentReceivers, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentServices, PrivacyManager.cSystem));
if (server) {
listHook.add(new XPackageManager(Methods.Srv_getPackageInfo, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getApplicationInfo, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getInstalledApplications, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getInstalledPackages, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPackagesForUid, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPackagesHoldingPermissions, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPersistentApplications, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_getPreferredPackages, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryContentProviders, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentActivities, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentActivityOptions, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentContentProviders, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentReceivers, PrivacyManager.cSystem));
listHook.add(new XPackageManager(Methods.Srv_queryIntentServices, PrivacyManager.cSystem));
}

listHook.add(new XPackageManager(Methods.getInstalledApplications, PrivacyManager.cSystem, className));
listHook.add(new XPackageManager(Methods.getInstalledPackages, PrivacyManager.cSystem, className));
Expand Down
46 changes: 23 additions & 23 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (Util.hasLBE())
return;

handleLoadPackage(lpparam.packageName, lpparam.classLoader, mSecret);
handleLoadPackage(lpparam.packageName, lpparam.classLoader, lpparam.isFirstApplication, mSecret);
}

// Common
Expand Down Expand Up @@ -122,11 +122,11 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}

private static void handleLoadPackage(String packageName, final ClassLoader classLoader, String secret) {
private static void handleLoadPackage(String packageName, final ClassLoader classLoader, boolean main, String secret) {
// Util.log(null, Log.INFO, "Load package=" + packageName + " uid=" +
// Process.myUid());

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && "android".equals(packageName))
if (main && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && "android".equals(packageName))
try {
Class<?> cSystemServer = Class.forName("com.android.server.am.ActivityManagerService", false,
classLoader);
Expand Down Expand Up @@ -227,10 +227,10 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

private static void hookAll(final ClassLoader classLoader) {
// Account manager
hookAll(XAccountManager.getInstances(null), classLoader, mSecret);
hookAll(XAccountManager.getInstances(null, true), classLoader, mSecret);

// Activity manager
hookAll(XActivityManager.getInstances(null), classLoader, mSecret);
hookAll(XActivityManager.getInstances(null, true), classLoader, mSecret);

// Activity manager service
hookAll(XActivityManagerService.getInstances(), classLoader, mSecret);
Expand Down Expand Up @@ -260,10 +260,10 @@ private static void hookAll(final ClassLoader classLoader) {
hookAll(XCameraDevice2.getInstances(), classLoader, mSecret);

// Clipboard manager
hookAll(XClipboardManager.getInstances(null), classLoader, mSecret);
hookAll(XClipboardManager.getInstances(null, true), classLoader, mSecret);

// Connectivity manager
hookAll(XConnectivityManager.getInstances(null), classLoader, mSecret);
hookAll(XConnectivityManager.getInstances(null, true), classLoader, mSecret);

// Content resolver
hookAll(XContentResolver.getInstances(null), classLoader, mSecret);
Expand Down Expand Up @@ -293,7 +293,7 @@ private static void hookAll(final ClassLoader classLoader) {
hookAll(XLinkProperties.getInstances(), classLoader, mSecret);

// Location manager
hookAll(XLocationManager.getInstances(null), classLoader, mSecret);
hookAll(XLocationManager.getInstances(null, true), classLoader, mSecret);

// Media recorder
hookAll(XMediaRecorder.getInstances(), classLoader, mSecret);
Expand All @@ -308,7 +308,7 @@ private static void hookAll(final ClassLoader classLoader) {
hookAll(XNfcAdapter.getInstances(), classLoader, mSecret);

// Package manager service
hookAll(XPackageManager.getInstances(null), classLoader, mSecret);
hookAll(XPackageManager.getInstances(null, true), classLoader, mSecret);

// Process
hookAll(XProcess.getInstances(), classLoader, mSecret);
Expand All @@ -323,7 +323,7 @@ private static void hookAll(final ClassLoader classLoader) {
hookAll(XRuntime.getInstances(), classLoader, mSecret);

// Sensor manager
hookAll(XSensorManager.getInstances(null), classLoader, mSecret);
hookAll(XSensorManager.getInstances(null, true), classLoader, mSecret);

// Settings secure
hookAll(XSettingsSecure.getInstances(), classLoader, mSecret);
Expand All @@ -338,7 +338,7 @@ private static void hookAll(final ClassLoader classLoader) {
hookAll(XSystemProperties.getInstances(), classLoader, mSecret);

// Telephone service
hookAll(XTelephonyManager.getInstances(null), classLoader, mSecret);
hookAll(XTelephonyManager.getInstances(null, true), classLoader, mSecret);

// Usage statistics manager
hookAll(XUsageStatsManager.getInstances(), classLoader, mSecret);
Expand All @@ -350,10 +350,10 @@ private static void hookAll(final ClassLoader classLoader) {
hookAll(XWebView.getInstances(), classLoader, mSecret);

// Window service
hookAll(XWindowManager.getInstances(null), classLoader, mSecret);
hookAll(XWindowManager.getInstances(null, true), classLoader, mSecret);

// Wi-Fi service
hookAll(XWifiManager.getInstances(null), classLoader, mSecret);
hookAll(XWifiManager.getInstances(null, true), classLoader, mSecret);

// Intent receive
hookAll(XActivityThread.getInstances(), classLoader, mSecret);
Expand All @@ -367,25 +367,25 @@ public static void handleGetSystemService(String name, String className, String
PrivacyManager.setTransient(className, Boolean.toString(true));

if (name.equals(Context.ACCOUNT_SERVICE))
hookAll(XAccountManager.getInstances(className), null, secret);
hookAll(XAccountManager.getInstances(className, false), null, secret);
else if (name.equals(Context.ACTIVITY_SERVICE))
hookAll(XActivityManager.getInstances(className), null, secret);
hookAll(XActivityManager.getInstances(className, false), null, secret);
else if (name.equals(Context.CLIPBOARD_SERVICE))
hookAll(XClipboardManager.getInstances(className), null, secret);
hookAll(XClipboardManager.getInstances(className, false), null, secret);
else if (name.equals(Context.CONNECTIVITY_SERVICE))
hookAll(XConnectivityManager.getInstances(className), null, secret);
hookAll(XConnectivityManager.getInstances(className, false), null, secret);
else if (name.equals(Context.LOCATION_SERVICE))
hookAll(XLocationManager.getInstances(className), null, secret);
hookAll(XLocationManager.getInstances(className, false), null, secret);
else if (name.equals("PackageManager"))
hookAll(XPackageManager.getInstances(className), null, secret);
hookAll(XPackageManager.getInstances(className, false), null, secret);
else if (name.equals(Context.SENSOR_SERVICE))
hookAll(XSensorManager.getInstances(className), null, secret);
hookAll(XSensorManager.getInstances(className, false), null, secret);
else if (name.equals(Context.TELEPHONY_SERVICE))
hookAll(XTelephonyManager.getInstances(className), null, secret);
hookAll(XTelephonyManager.getInstances(className, false), null, secret);
else if (name.equals(Context.WINDOW_SERVICE))
hookAll(XWindowManager.getInstances(className), null, secret);
hookAll(XWindowManager.getInstances(className, false), null, secret);
else if (name.equals(Context.WIFI_SERVICE))
hookAll(XWifiManager.getInstances(className), null, secret);
hookAll(XWifiManager.getInstances(className, false), null, secret);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XSensorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private enum Methods {
getDefaultSensor, getSensorList, registerListener
};

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
Expand Down
48 changes: 25 additions & 23 deletions src/biz/bokhorst/xprivacy/XTelephonyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private enum Methods {
};
// @formatter:on

public static List<XHook> getInstances(String className) {
public static List<XHook> getInstances(String className, boolean server) {
List<XHook> listHook = new ArrayList<XHook>();
if (!cClassName.equals(className)) {
if (className == null)
Expand Down Expand Up @@ -188,28 +188,30 @@ public static List<XHook> getInstances(String className) {
listHook.add(new XTelephonyManager(Methods.getSimOperator, PrivacyManager.cPhone, className));
listHook.add(new XTelephonyManager(Methods.getSimOperatorName, PrivacyManager.cPhone, className));

// PhoneSubInfo
listHook.add(new XTelephonyManager(Methods.Srv_getDeviceId, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getGroupIdLevel1, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIccSerialNumber, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimDomain, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimImpi, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimImpu, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getLine1AlphaTag, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getLine1Number, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getMsisdn, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getSubscriberId, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getCompleteVoiceMailNumber, PrivacyManager.cPhone,
Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getVoiceMailAlphaTag, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getVoiceMailNumber, PrivacyManager.cPhone, Srv.SubInfo));

listHook.add(new XTelephonyManager(Methods.Srv_getImei, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimIst, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimPcscf, PrivacyManager.cPhone, Srv.SubInfo));

listHook.add(new XTelephonyManager(Methods.Srv_listen, PrivacyManager.cLocation, Srv.Registry));
listHook.add(new XTelephonyManager(Methods.Srv_listen, PrivacyManager.cPhone, Srv.Registry));
if (server) {
// PhoneSubInfo
listHook.add(new XTelephonyManager(Methods.Srv_getDeviceId, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getGroupIdLevel1, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIccSerialNumber, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimDomain, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimImpi, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimImpu, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getLine1AlphaTag, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getLine1Number, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getMsisdn, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getSubscriberId, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getCompleteVoiceMailNumber, PrivacyManager.cPhone,
Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getVoiceMailAlphaTag, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getVoiceMailNumber, PrivacyManager.cPhone, Srv.SubInfo));

listHook.add(new XTelephonyManager(Methods.Srv_getImei, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimIst, PrivacyManager.cPhone, Srv.SubInfo));
listHook.add(new XTelephonyManager(Methods.Srv_getIsimPcscf, PrivacyManager.cPhone, Srv.SubInfo));

listHook.add(new XTelephonyManager(Methods.Srv_listen, PrivacyManager.cLocation, Srv.Registry));
listHook.add(new XTelephonyManager(Methods.Srv_listen, PrivacyManager.cPhone, Srv.Registry));
}
}
return listHook;
}
Expand Down
Loading

0 comments on commit 01a7e4f

Please sign in to comment.