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

Commit

Permalink
Reverted "Prevent applications from bypassing Android APIs"
Browse files Browse the repository at this point in the history
Closed #1039
  • Loading branch information
M66B committed Dec 29, 2013
1 parent 5f279b0 commit fe4e38b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Test and beta releases will have experimental functions enabled by default.

**Next release**

* Reverted "Prevent applications from bypassing Android APIs" ([issue](https://github.com/M66B/XPrivacy/issues/1039))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

**Version 1.11.2 TEST**
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class Util {

public static void log(XHook hook, int priority, String msg) {
// Check if logging enabled
if (Process.myUid() != 0 && !mLogDetermined) {
if (Process.myUid() > 0 && !mLogDetermined) {
mLog = false;
mLogDetermined = true;
mLog = PrivacyManager.getSettingBool(null, null, 0, PrivacyManager.cSettingLog, false, false);
Expand Down
65 changes: 37 additions & 28 deletions src/biz/bokhorst/xprivacy/XBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Process;
import android.util.Log;

import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
Expand All @@ -19,6 +20,8 @@ public class XBinder extends XHook {
private static boolean mMagical = false;
private static int FLAG_XPRIVACY = 0x00000010;
private static int BITS_MAGIC = 16;
private static boolean cEnabled = false;
private static boolean cRestrict = false;

private XBinder(Methods method, String restrictionName) {
super(restrictionName, method.name(), null);
Expand Down Expand Up @@ -49,8 +52,10 @@ private enum Methods {

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XBinder(Methods.execTransact, null)); // Binder
listHook.add(new XBinder(Methods.transact, null)); // BinderProxy
if (cEnabled) {
listHook.add(new XBinder(Methods.execTransact, null)); // Binder
listHook.add(new XBinder(Methods.transact, null)); // BinderProxy
}
return listHook;
}

Expand Down Expand Up @@ -83,33 +88,37 @@ private void checkIPC(MethodHookParam param) {
param.args[3] = flags;

try {
int uid = Binder.getCallingPid();
if ((flagged || magic != getMagic()) && PrivacyManager.isApplication(uid)) {
// Application bypassed API
Binder binder = (Binder) param.thisObject;
String name = binder.getInterfaceDescriptor();
Log.w("XPrivacy/XBinder", "restrict name=" + name + " uid=" + uid);

// Get reply parcel
Parcel reply = null;
try {
// static protected final Parcel obtain(int obj)
// frameworks/base/core/java/android/os/Parcel.java
Method methodObtain = Parcel.class.getDeclaredMethod("obtain", int.class);
methodObtain.setAccessible(true);
reply = (Parcel) methodObtain.invoke(null, param.args[2]);
} catch (NoSuchMethodException ex) {
Util.bug(null, ex);
}

// Block IPC
if (reply == null)
Log.w("XPrivacy/XBinder", "reply is null uid=" + uid);
else {
reply.setDataPosition(0);
reply.writeException(new SecurityException("XPrivacy"));
if (Process.myUid() > 0) {
int uid = Binder.getCallingUid();
if ((flagged || magic != getMagic()) && PrivacyManager.isApplication(uid)) {
// Application bypassed API
Binder binder = (Binder) param.thisObject;
String name = binder.getInterfaceDescriptor();
Log.w("XPrivacy/XBinder", "restrict name=" + name + " uid=" + uid + " my=" + Process.myUid());

if (cRestrict) {
// Get reply parcel
Parcel reply = null;
try {
// static protected final Parcel obtain(int obj)
// frameworks/base/core/java/android/os/Parcel.java
Method methodObtain = Parcel.class.getDeclaredMethod("obtain", int.class);
methodObtain.setAccessible(true);
reply = (Parcel) methodObtain.invoke(null, param.args[2]);
} catch (NoSuchMethodException ex) {
Util.bug(null, ex);
}

// Block IPC
if (reply == null)
Log.w("XPrivacy/XBinder", "reply is null uid=" + uid);
else {
reply.setDataPosition(0);
reply.writeException(new SecurityException("XPrivacy"));
}
param.setResult(true);
}
}
param.setResult(true);
}
} catch (Throwable ex) {
Log.e("XPrivacy/XBinder", ex.toString());
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void before(MethodHookParam param) throws Throwable {
}
} else if (mMethod == Methods.load || mMethod == Methods.loadLibrary) {
// Skip pre Android
if (Process.myUid() != 0)
if (Process.myUid() > 0)
if (isRestricted(param))
param.setResult(new UnsatisfiedLinkError());
} else
Expand Down

0 comments on commit fe4e38b

Please sign in to comment.