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

Commit

Permalink
Explicitly check throwm exception type
Browse files Browse the repository at this point in the history
Refs #1398
  • Loading branch information
M66B committed Feb 20, 2014
1 parent d7056d4 commit b5dc85a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/biz/bokhorst/xprivacy/XIoBridge.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package biz.bokhorst.xprivacy;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.ArrayList;
Expand Down Expand Up @@ -69,15 +68,15 @@ public static List<XHook> getInstances() {
@SuppressLint("SdCardPath")
protected void before(XParam param) throws Throwable {
if (mMethod == Methods.connect) {
if (param.args.length > 2 && param.args[1] instanceof InetAddress) {
if (param.args.length > 2 && param.args[1] instanceof InetAddress && param.doesThrow(SocketException.class)) {
InetAddress address = (InetAddress) param.args[1];
int port = (Integer) param.args[2];
if (isRestrictedExtra(param, address.toString() + ":" + port))
param.setThrowable(new IOException("XPrivacy"));
param.setThrowable(new SocketException("XPrivacy"));
}

} else if (mMethod == Methods.open) {
if (param.args.length > 0 && param.args[0] != null) {
if (param.args.length > 0 && param.args[0] != null && param.doesThrow(FileNotFoundException.class)) {
String fileName = (String) param.args[0];
if (mFileName == null) {
String externalStorage = System.getenv("EXTERNAL_STORAGE");
Expand Down Expand Up @@ -119,7 +118,7 @@ protected void before(XParam param) throws Throwable {
}

} else if (mMethod == Methods.socket) {
if (isRestricted(param))
if (isRestricted(param) && param.doesThrow(SocketException.class))
param.setThrowable(new SocketException("XPrivacy"));

} else
Expand Down
15 changes: 15 additions & 0 deletions src/biz/bokhorst/xprivacy/XParam.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package biz.bokhorst.xprivacy;

import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -29,6 +30,12 @@ public static XParam fromXposed(MethodHookParam param) {
return xparam;
}

public boolean doesReturn(Class<?> result) {
if (this.method instanceof Method)
return (((Method) this.method).getReturnType().equals(result));
return false;
}

public void setResult(Object result) {
mResult = result;
mHasResult = true;
Expand All @@ -42,6 +49,14 @@ public Object getResult() {
return mResult;
}

public boolean doesThrow(Class<?> ex) {
if (this.method instanceof Method)
for (Class<?> t : ((Method) this.method).getExceptionTypes())
if (t.equals(ex))
return true;
return false;
}

public void setThrowable(Throwable ex) {
mThrowable = ex;
mHasThrowable = true;
Expand Down

0 comments on commit b5dc85a

Please sign in to comment.