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

Commit

Permalink
Hook loadUrl, use WebView context
Browse files Browse the repository at this point in the history
Refs #825
  • Loading branch information
M66B committed Dec 4, 2013
1 parent 7dfb4ec commit ef3fd3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion assets/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@
<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="loadUrl" permissions="" sdk="1" />
<Hook restriction="view" method="WebView" permissions="" sdk="1" />
<Hook restriction="view" method="getDefaultUserAgent" permissions="" sdk="17" />
<Hook restriction="view" method="getUserAgent" permissions="" sdk="1" />
<Hook restriction="view" method="getUserAgentString" permissions="" sdk="1" />
<Hook restriction="view" method="setUserAgent" permissions="" sdk="1" />
<Hook restriction="view" method="setUserAgentString" permissions="" sdk="1" />
<Hook restriction="view" method="WebView.constructor" permissions="" sdk="1" />
<Hook restriction="view" method="addView" permissions="SYSTEM_ALERT_WINDOW" sdk="1" />
<Hook restriction="view" method="removeView" permissions="SYSTEM_ALERT_WINDOW" sdk="1" />
<Hook restriction="view" method="updateViewLayout" permissions="SYSTEM_ALERT_WINDOW" sdk="1" />
Expand Down
33 changes: 28 additions & 5 deletions src/biz/bokhorst/xprivacy/XWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Binder;
import android.util.Log;
import android.webkit.WebView;
Expand All @@ -14,26 +15,38 @@ public class XWebView extends XHook {
private static final List<String> mWebSettings = new ArrayList<String>();

private XWebView(Methods method, String restrictionName) {
super(restrictionName, (method == Methods.constructor ? null : method.name()),
(method == Methods.constructor ? "WebView.constructor" : null));
super(restrictionName, (method == Methods.WebView ? null : method.name()),
(method == Methods.WebView ? "WebView.constructor" : null));
mMethod = method;
}

public String getClassName() {
return "android.webkit.WebView";
}

// @formatter:off

// public WebView(Context context)
// public WebView(Context context, AttributeSet attrs)
// public WebView(Context context, AttributeSet attrs, int defStyle)
// public WebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing)
// protected WebView(Context context, AttributeSet attrs, int defStyle, Map<String, Object> javaScriptInterfaces, boolean privateBrowsing)
// public WebSettings getSettings()
// public void loadUrl(String url)
// public void loadUrl(String url, Map<String, String> additionalHttpHeaders)
// frameworks/base/core/java/android/webkit/WebView.java
// http://developer.android.com/reference/android/webkit/WebView.html

// @formatter:on

private enum Methods {
constructor, getSettings
WebView, loadUrl, getSettings
};

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XWebView(Methods.constructor, PrivacyManager.cView));
listHook.add(new XWebView(Methods.WebView, PrivacyManager.cView));
listHook.add(new XWebView(Methods.loadUrl, null));
listHook.add(new XWebView(Methods.getSettings, null));
return listHook;
}
Expand All @@ -45,7 +58,17 @@ protected void before(MethodHookParam param) throws Throwable {

@Override
protected void after(MethodHookParam param) throws Throwable {
if (mMethod == Methods.constructor) {
if (mMethod == Methods.WebView) {
if (param.args.length > 0) {
int uid = Binder.getCallingUid();
Context context = (Context) param.args[1];
if (getRestricted(context, uid, true)) {
String ua = (String) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "UA");
WebView webView = (WebView) param.thisObject;
webView.getSettings().setUserAgentString(ua);
}
}
} else if (mMethod == Methods.loadUrl) {
if (isRestricted(param)) {
String ua = (String) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "UA");
WebView webView = (WebView) param.thisObject;
Expand Down

0 comments on commit ef3fd3e

Please sign in to comment.