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

Commit

Permalink
Fixed restricting browser user agent
Browse files Browse the repository at this point in the history
Fixes #825
  • Loading branch information
M66B committed Nov 26, 2013
1 parent 42f016c commit f0f6895
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 150 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
**Next release**

* Fixed Android KitKat message permissions
* Fixed restricting browser user agent ([issue](https://github.com/M66B/XPrivacy/issues/825))
* Do not disable Android/extra usage data when not in expert mode
* Separate setting to enable restricting dangerous functions, thanks @[jpeg729](https://github.com/jpeg729)
* Show exported file name while sharing, thanks @[jpeg729](https://github.com/jpeg729)
Expand Down
5 changes: 1 addition & 4 deletions assets/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@
<Hook restriction="system" method="android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE" dangerous="true" permissions="" sdk="14" />
<Hook restriction="system" method="ApplicationsProvider" permissions="" sdk="14" />

<Hook restriction="view" method="getDefaultUserAgent" permissions="" sdk="17" />
<Hook restriction="view" method="getDefaultUserAgentForLocale" permissions="" sdk="17" />
<Hook restriction="view" method="getUserAgentString" permissions="" sdk="3" />
<Hook restriction="view" method="setUserAgentString" permissions="" sdk="3" />
<Hook restriction="view" method="getSettings" permissions="" sdk="1" />
<Hook restriction="view" method="android.intent.action.VIEW" permissions="" sdk="14" />
</Meta>
5 changes: 2 additions & 3 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ public void initZygote(StartupParam startupParam) throws Throwable {
// Telephony
hookAll(XTelephonyManager.getInstances());

// Web settings
hookAll(XWebSettings.getInstances());
hookAll(XWebSettingsClassic.getInstances());
// Web view
hookAll(XWebView.getInstances());

// Wi-Fi manager
hookAll(XWifiManager.getInstances());
Expand Down
62 changes: 0 additions & 62 deletions src/biz/bokhorst/xprivacy/XWebSettings.java

This file was deleted.

81 changes: 0 additions & 81 deletions src/biz/bokhorst/xprivacy/XWebSettingsClassic.java

This file was deleted.

106 changes: 106 additions & 0 deletions src/biz/bokhorst/xprivacy/XWebView.java
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);
}
}

0 comments on commit f0f6895

Please sign in to comment.