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

Commit

Permalink
Backward compatiblity, fixes
Browse files Browse the repository at this point in the history
Refs #1757
  • Loading branch information
M66B committed Feb 14, 2015
1 parent f3db44b commit 09832e9
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 143 deletions.
27 changes: 23 additions & 4 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ public static void register(List<String> listError, ClassLoader classLoader, Str
XActivityManagerService.setSemaphore(mOndemandSemaphore);

// Get context
Field fContext = am.getClass().getDeclaredField("mContext");
fContext.setAccessible(true);
mContext = (Context) fContext.get(am);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Field fContext = am.getClass().getDeclaredField("mContext");
fContext.setAccessible(true);
mContext = (Context) fContext.get(am);
}

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

private Context getContext() {
return mContext;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
return mContext;
else {
// 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;
}
}
}

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

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// 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, null, mSecret, null);
}
});
} catch (Throwable ex) {
Util.bug(null, ex);
return;
}

hookAll(null);
}
}

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

if ("android".equals(packageName))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && "android".equals(packageName))
try {
Class<?> cSystemServer = Class.forName("com.android.server.am.ActivityManagerService", false,
classLoader);
Expand All @@ -114,141 +135,7 @@ private static void handleLoadPackage(String packageName, final ClassLoader clas
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
PrivacyService.register(mListHookError, classLoader, mSecret, param.thisObject);

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

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

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

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

// Application
hookAll(XApplication.getInstances(), classLoader, mSecret);

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

// Binder device
hookAll(XBinder.getInstances(), classLoader, mSecret);

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

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

// Camera
hookAll(XCamera.getInstances(), classLoader, mSecret);

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

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

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

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

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

// Environment
hookAll(XEnvironment.getInstances(), classLoader, mSecret);

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

// Input device
hookAll(XInputDevice.getInstances(), classLoader, mSecret);

// Intent firewall
hookAll(XIntentFirewall.getInstances(), classLoader, mSecret);

// IO bridge
hookAll(XIoBridge.getInstances(), classLoader, mSecret);

// IP prefix
hookAll(XIpPrefix.getInstances(), classLoader, mSecret);

// Link properties
hookAll(XLinkProperties.getInstances(), classLoader, mSecret);

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

// Media recorder
hookAll(XMediaRecorder.getInstances(), classLoader, mSecret);

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

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

// NFC adapter
hookAll(XNfcAdapter.getInstances(), classLoader, mSecret);

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

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

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

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

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

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

// Settings secure
hookAll(XSettingsSecure.getInstances(), classLoader, mSecret);

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

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

// System properties
hookAll(XSystemProperties.getInstances(), classLoader, mSecret);

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

// Usage statistics manager
hookAll(XUsageStatsManager.getInstances(), classLoader, mSecret);

// USB device
hookAll(XUsbDevice.getInstances(), classLoader, mSecret);

// Web view
hookAll(XWebView.getInstances(), classLoader, mSecret);

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

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

// Intent receive
hookAll(XActivityThread.getInstances(), classLoader, mSecret);

// Intent send
hookAll(XActivity.getInstances(), classLoader, mSecret);
hookAll(classLoader);
}
});
} catch (Throwable ex) {
Expand All @@ -263,8 +150,9 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}

// Build SERIAL
if (PrivacyManager.getRestrictionExtra(null, Process.myUid(), PrivacyManager.cIdentification, "SERIAL", null,
Build.SERIAL, secret))
if (Process.myUid() != Process.SYSTEM_UID
&& PrivacyManager.getRestrictionExtra(null, Process.myUid(), PrivacyManager.cIdentification, "SERIAL",
null, Build.SERIAL, secret))
try {
Field serial = Build.class.getField("SERIAL");
serial.setAccessible(true);
Expand Down Expand Up @@ -337,6 +225,143 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
hookAll(XContentResolver.getPackageInstances(packageName, classLoader), classLoader, secret);
}

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

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

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

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

// Application
hookAll(XApplication.getInstances(), classLoader, mSecret);

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

// Binder device
hookAll(XBinder.getInstances(), classLoader, mSecret);

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

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

// Camera
hookAll(XCamera.getInstances(), classLoader, mSecret);

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

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

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

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

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

// Environment
hookAll(XEnvironment.getInstances(), classLoader, mSecret);

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

// Input device
hookAll(XInputDevice.getInstances(), classLoader, mSecret);

// Intent firewall
hookAll(XIntentFirewall.getInstances(), classLoader, mSecret);

// IO bridge
hookAll(XIoBridge.getInstances(), classLoader, mSecret);

// IP prefix
hookAll(XIpPrefix.getInstances(), classLoader, mSecret);

// Link properties
hookAll(XLinkProperties.getInstances(), classLoader, mSecret);

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

// Media recorder
hookAll(XMediaRecorder.getInstances(), classLoader, mSecret);

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

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

// NFC adapter
hookAll(XNfcAdapter.getInstances(), classLoader, mSecret);

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

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

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

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

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

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

// Settings secure
hookAll(XSettingsSecure.getInstances(), classLoader, mSecret);

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

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

// System properties
hookAll(XSystemProperties.getInstances(), classLoader, mSecret);

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

// Usage statistics manager
hookAll(XUsageStatsManager.getInstances(), classLoader, mSecret);

// USB device
hookAll(XUsbDevice.getInstances(), classLoader, mSecret);

// Web view
hookAll(XWebView.getInstances(), classLoader, mSecret);

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

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

// Intent receive
hookAll(XActivityThread.getInstances(), classLoader, mSecret);

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

public static void handleGetSystemService(String name, String className, String secret) {
if (PrivacyManager.getTransient(className, null) == null) {
PrivacyManager.setTransient(className, Boolean.toString(true));
Expand Down

0 comments on commit 09832e9

Please sign in to comment.