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

Commit

Permalink
Lollipop privacy service
Browse files Browse the repository at this point in the history
Refs #1757
  • Loading branch information
M66B committed Feb 14, 2015
1 parent e2ff987 commit 73097c6
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ else if (!listRestriction.contains(restrictionName))
mPermission.get(aPermission).add(hook);
}
}
Util.log(null, Log.WARN, listHook.size() + " hooks");
//Util.log(null, Log.WARN, listHook.size() + " hooks");
}

public static List<String> getRestrictions() {
Expand Down
29 changes: 13 additions & 16 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

public class PrivacyService extends IPrivacyService.Stub {
private static int mXUid = -1;
private static Context mContext;
private static String mSecret = null;
private static Thread mWorker = null;
private static Handler mHandler = null;
Expand Down Expand Up @@ -126,7 +127,7 @@ private PrivacyService() {

private static PrivacyService mPrivacyService = null;

public static void register(List<String> listError, String secret) {
public static void register(List<String> listError, ClassLoader classLoader, String secret, Object am) {
// Store secret and errors
mSecret = secret;
mListError.addAll(listError);
Expand All @@ -139,7 +140,11 @@ public static void register(List<String> listError, String secret) {
// public static void addService(String name, IBinder service)
// public static void addService(String name, IBinder service, boolean allowIsolated)
// @formatter:on
Class<?> cServiceManager = Class.forName("android.os.ServiceManager");

// Requires this in /service_contexts
// xprivacy453 u:object_r:system_server_service:s0

Class<?> cServiceManager = Class.forName("android.os.ServiceManager", false, classLoader);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Method mAddService = cServiceManager.getDeclaredMethod("addService", String.class, IBinder.class,
boolean.class);
Expand All @@ -155,6 +160,11 @@ public static void register(List<String> listError, String secret) {
// Publish semaphore to activity manager service
XActivityManagerService.setSemaphore(mOndemandSemaphore);

// Get context
Field fContext = am.getClass().getDeclaredField("mContext");
fContext.setAccessible(true);
mContext = (Context) fContext.get(am);

// Start a worker thread
mWorker = new Thread(new Runnable() {
@Override
Expand Down Expand Up @@ -2270,20 +2280,7 @@ private boolean isAMLocked(int uid) {
}

private Context getContext() {
// public static ActivityManagerService self()
// frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
try {
Class<?> cam = Class.forName("com.android.server.am.ActivityManagerService");
Object am = cam.getMethod("self").invoke(null);
if (am == null)
return null;
Field mContext = cam.getDeclaredField("mContext");
mContext.setAccessible(true);
return (Context) mContext.get(am);
} catch (Throwable ex) {
Util.bug(null, ex);
return null;
}
return mContext;
}

private int getIsolatedUid(int uid) {
Expand Down
220 changes: 110 additions & 110 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,161 +100,160 @@ private static void init(String path) {
} catch (Throwable ex) {
Util.bug(null, ex);
}
}

// System server
try {
// frameworks/base/services/java/com/android/server/SystemServer.java
Class<?> cSystemServer = Class.forName("com.android.server.SystemServer");
Method mMain = cSystemServer.getDeclaredMethod("main", String[].class);
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);
return;
}
private static void handleLoadPackage(String packageName, final ClassLoader classLoader, String secret) {
Util.log(null, Log.INFO, "Load package=" + packageName + " uid=" + Process.myUid());

// Account manager
hookAll(XAccountManager.getInstances(null), null, mSecret);
if ("android".equals(packageName))
try {
Class<?> cSystemServer = Class.forName("com.android.server.am.ActivityManagerService", false,
classLoader);
Method mMain = cSystemServer.getDeclaredMethod("setSystemProcess");
XposedBridge.hookMethod(mMain, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
PrivacyService.register(mListHookError, classLoader, mSecret, param.thisObject);

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

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

// App widget manager
hookAll(XAppWidgetManager.getInstances(), null, mSecret);
// Activity manager service
hookAll(XActivityManagerService.getInstances(), classLoader, mSecret);

// Application
hookAll(XApplication.getInstances(), null, mSecret);
// App widget manager
hookAll(XAppWidgetManager.getInstances(), classLoader, mSecret);

// Audio record
hookAll(XAudioRecord.getInstances(), null, mSecret);
// Application
hookAll(XApplication.getInstances(), classLoader, mSecret);

// Binder device
hookAll(XBinder.getInstances(), null, mSecret);
// Audio record
hookAll(XAudioRecord.getInstances(), classLoader, mSecret);

// Bluetooth adapater
hookAll(XBluetoothAdapter.getInstances(), null, mSecret);
// Binder device
hookAll(XBinder.getInstances(), classLoader, mSecret);

// Bluetooth device
hookAll(XBluetoothDevice.getInstances(), null, mSecret);
// Bluetooth adapater
hookAll(XBluetoothAdapter.getInstances(), classLoader, mSecret);

// Camera
hookAll(XCamera.getInstances(), null, mSecret);
// Bluetooth device
hookAll(XBluetoothDevice.getInstances(), classLoader, mSecret);

// Camera2 device
hookAll(XCameraDevice2.getInstances(), null, mSecret);
// Camera
hookAll(XCamera.getInstances(), classLoader, mSecret);

// Clipboard manager
hookAll(XClipboardManager.getInstances(null), null, mSecret);
// Camera2 device
hookAll(XCameraDevice2.getInstances(), classLoader, mSecret);

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

// Content resolver
hookAll(XContentResolver.getInstances(null), null, mSecret);
// Connectivity manager
hookAll(XConnectivityManager.getInstances(null), classLoader, mSecret);

// Context wrapper
hookAll(XContextImpl.getInstances(), null, mSecret);
// Content resolver
hookAll(XContentResolver.getInstances(null), classLoader, mSecret);

// Environment
hookAll(XEnvironment.getInstances(), null, mSecret);
// Context wrapper
hookAll(XContextImpl.getInstances(), classLoader, mSecret);

// Inet address
hookAll(XInetAddress.getInstances(), null, mSecret);
// Environment
hookAll(XEnvironment.getInstances(), classLoader, mSecret);

// Input device
hookAll(XInputDevice.getInstances(), null, mSecret);
// Inet address
hookAll(XInetAddress.getInstances(), classLoader, mSecret);

// Intent firewall
hookAll(XIntentFirewall.getInstances(), null, mSecret);
// Input device
hookAll(XInputDevice.getInstances(), classLoader, mSecret);

// IO bridge
hookAll(XIoBridge.getInstances(), null, mSecret);
// Intent firewall
hookAll(XIntentFirewall.getInstances(), classLoader, mSecret);

// IP prefix
hookAll(XIpPrefix.getInstances(), null, mSecret);
// IO bridge
hookAll(XIoBridge.getInstances(), classLoader, mSecret);

// Link properties
hookAll(XLinkProperties.getInstances(), null, mSecret);
// IP prefix
hookAll(XIpPrefix.getInstances(), classLoader, mSecret);

// Location manager
hookAll(XLocationManager.getInstances(null), null, mSecret);
// Link properties
hookAll(XLinkProperties.getInstances(), classLoader, mSecret);

// Media recorder
hookAll(XMediaRecorder.getInstances(), null, mSecret);
// Location manager
hookAll(XLocationManager.getInstances(null), classLoader, mSecret);

// Network info
hookAll(XNetworkInfo.getInstances(), null, mSecret);
// Media recorder
hookAll(XMediaRecorder.getInstances(), classLoader, mSecret);

// Network interface
hookAll(XNetworkInterface.getInstances(), null, mSecret);
// Network info
hookAll(XNetworkInfo.getInstances(), classLoader, mSecret);

// NFC adapter
hookAll(XNfcAdapter.getInstances(), null, mSecret);
// Network interface
hookAll(XNetworkInterface.getInstances(), classLoader, mSecret);

// Package manager service
hookAll(XPackageManager.getInstances(null), null, mSecret);
// NFC adapter
hookAll(XNfcAdapter.getInstances(), classLoader, mSecret);

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

// Process builder
hookAll(XProcessBuilder.getInstances(), null, mSecret);
// Process
hookAll(XProcess.getInstances(), classLoader, mSecret);

// Resources
hookAll(XResources.getInstances(), null, mSecret);
// Process builder
hookAll(XProcessBuilder.getInstances(), classLoader, mSecret);

// Runtime
hookAll(XRuntime.getInstances(), null, mSecret);
// Resources
hookAll(XResources.getInstances(), classLoader, mSecret);

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

// Settings secure
hookAll(XSettingsSecure.getInstances(), null, mSecret);
// Sensor manager
hookAll(XSensorManager.getInstances(null), classLoader, mSecret);

// SIP manager
hookAll(XSipManager.getInstances(), null, mSecret);
// Settings secure
hookAll(XSettingsSecure.getInstances(), classLoader, mSecret);

// SMS manager
hookAll(XSmsManager.getInstances(), null, mSecret);
// SIP manager
hookAll(XSipManager.getInstances(), classLoader, mSecret);

// System properties
hookAll(XSystemProperties.getInstances(), null, mSecret);
// SMS manager
hookAll(XSmsManager.getInstances(), classLoader, mSecret);

// Telephone service
hookAll(XTelephonyManager.getInstances(null), null, mSecret);
// System properties
hookAll(XSystemProperties.getInstances(), classLoader, mSecret);

// Usage statistics manager
hookAll(XUsageStatsManager.getInstances(), null, mSecret);
// Telephone service
hookAll(XTelephonyManager.getInstances(null), classLoader, mSecret);

// USB device
hookAll(XUsbDevice.getInstances(), null, mSecret);
// Usage statistics manager
hookAll(XUsageStatsManager.getInstances(), classLoader, mSecret);

// Web view
hookAll(XWebView.getInstances(), null, mSecret);
// USB device
hookAll(XUsbDevice.getInstances(), classLoader, mSecret);

// Window service
hookAll(XWindowManager.getInstances(null), null, mSecret);
// Web view
hookAll(XWebView.getInstances(), classLoader, mSecret);

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

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

// Intent send
hookAll(XActivity.getInstances(), null, mSecret);
}
// Intent receive
hookAll(XActivityThread.getInstances(), classLoader, mSecret);

private static void handleLoadPackage(String packageName, ClassLoader classLoader, String secret) {
Util.log(null, Log.INFO, "Load package=" + packageName + " uid=" + Process.myUid());
// Intent send
hookAll(XActivity.getInstances(), classLoader, mSecret);
}
});
} catch (Throwable ex) {
Util.bug(null, ex);
}

// Skip hooking self
String self = XPrivacy.class.getPackage().getName();
Expand Down Expand Up @@ -407,7 +406,8 @@ private static void hook(final XHook hook, ClassLoader classLoader, String secre
if (level == Log.ERROR)
mListHookError.add(message);
Util.log(hook, level, message);
Util.logStack(hook, level);
// Util.logStack(hook, level);
return;
}

// Get members
Expand Down Expand Up @@ -458,7 +458,7 @@ private static void hook(final XHook hook, ClassLoader classLoader, String secre
if (level == Log.ERROR)
mListHookError.add(message);
Util.log(hook, level, message);
Util.logStack(hook, level);
// Util.logStack(hook, level);
}
} catch (Throwable ex) {
mListHookError.add(ex.toString());
Expand Down

0 comments on commit 73097c6

Please sign in to comment.