This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed restricting browser user agent
Fixes #825
- Loading branch information
M66B
committed
Nov 26, 2013
1 parent
42f016c
commit f0f6895
Showing
6 changed files
with
110 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package biz.bokhorst.xprivacy; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import android.content.Context; | ||
import android.os.Binder; | ||
import android.util.Log; | ||
|
||
import de.robv.android.xposed.XC_MethodHook; | ||
import de.robv.android.xposed.XposedBridge; | ||
import de.robv.android.xposed.XC_MethodHook.MethodHookParam; | ||
|
||
public class XWebView extends XHook { | ||
private Methods mMethod; | ||
private static final List<String> mWebSettings = new ArrayList<String>(); | ||
|
||
private XWebView(Methods method, String restrictionName) { | ||
super(restrictionName, method.name(), null); | ||
mMethod = method; | ||
} | ||
|
||
public String getClassName() { | ||
return "android.webkit.WebView"; | ||
} | ||
|
||
// public WebSettings getSettings() | ||
// frameworks/base/core/java/android/webkit/WebView.java | ||
// http://developer.android.com/reference/android/webkit/WebView.html | ||
|
||
// public synchronize String getUserAgentString() | ||
// public synchronized void setUserAgentString (String ua) | ||
// frameworks/base/core/java/android/webkit/WebSettings.java | ||
// http://developer.android.com/reference/android/webkit/WebSettings.html | ||
|
||
private enum Methods { | ||
getSettings | ||
}; | ||
|
||
public static List<XHook> getInstances() { | ||
List<XHook> listHook = new ArrayList<XHook>(); | ||
listHook.add(new XWebView(Methods.getSettings, PrivacyManager.cView)); | ||
return listHook; | ||
} | ||
|
||
@Override | ||
protected void before(MethodHookParam param) throws Throwable { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
protected void after(MethodHookParam param) throws Throwable { | ||
if (mMethod == Methods.getSettings) { | ||
if (param.getResult() != null) { | ||
// Check web settings type | ||
Class<?> clazzWebSettings = param.getResultOrThrowable().getClass(); | ||
if (!mWebSettings.contains(clazzWebSettings.getName())) { | ||
mWebSettings.add(clazzWebSettings.getName()); | ||
Util.log(this, Log.INFO, "Hooking " + clazzWebSettings.getName()); | ||
|
||
// getUserAgentString | ||
try { | ||
Method getUserAgentString = clazzWebSettings.getDeclaredMethod("getUserAgentString"); | ||
Util.log(this, Log.INFO, "Hooking " + getUserAgentString.getName()); | ||
XposedBridge.hookMethod(getUserAgentString, new XC_MethodHook() { | ||
@Override | ||
protected void afterHookedMethod(MethodHookParam param) throws Throwable { | ||
if (isRestricted(param)) | ||
param.setResult(PrivacyManager.getDefacedProp(Binder.getCallingUid(), "UA")); | ||
} | ||
}); | ||
} catch (NoSuchFieldError ex) { | ||
Util.bug(this, ex); | ||
} | ||
|
||
// setUserAgentString | ||
try { | ||
Method setUserAgentString = clazzWebSettings.getDeclaredMethod("setUserAgentString", | ||
String.class); | ||
Util.log(this, Log.INFO, "Hooking " + setUserAgentString.getName()); | ||
XposedBridge.hookMethod(setUserAgentString, new XC_MethodHook() { | ||
@Override | ||
protected void beforeHookedMethod(MethodHookParam param) throws Throwable { | ||
if (isRestricted(param)) | ||
param.args[0] = PrivacyManager.getDefacedProp(Binder.getCallingUid(), "UA"); | ||
} | ||
}); | ||
} catch (NoSuchFieldError ex) { | ||
Util.bug(this, ex); | ||
} | ||
} | ||
} | ||
} else | ||
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName()); | ||
} | ||
|
||
@Override | ||
protected boolean isRestricted(MethodHookParam param) throws Throwable { | ||
Context context = null; | ||
if (param.args.length > 0) | ||
context = (Context) param.args[0]; | ||
int uid = Binder.getCallingUid(); | ||
return getRestricted(context, uid, true); | ||
} | ||
} |