-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3b9e07
Showing
32 changed files
with
793 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/ | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
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 @@ | ||
/build |
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,40 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
compileSdk 32 | ||
|
||
defaultConfig { | ||
applicationId "cn.wankkoree.xposed.enablewebviewdebugging" | ||
minSdk 21 | ||
targetSdk 32 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled true | ||
zipAlignEnabled true | ||
shrinkResources true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
signingConfig signingConfigs.release | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly 'de.robv.android.xposed:api:82' | ||
compileOnly 'de.robv.android.xposed:api:82:sources' | ||
} |
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,23 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile | ||
|
||
-keep public class cn.wankkoree.xposed.enablewebviewdebugging.MainActivity |
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="cn.wankkoree.xposed.enablewebviewdebugging"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true"> | ||
<meta-data | ||
android:name="xposedmodule" | ||
android:value="true" /> | ||
<meta-data | ||
android:name="xposeddescription" | ||
android:value="@string/app_description" /> | ||
<meta-data | ||
android:name="xposedminversion" | ||
android:value="53"/> | ||
</application> | ||
|
||
</manifest> |
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 @@ | ||
cn.wankkoree.xposed.enablewebviewdebugging.MainActivity |
142 changes: 142 additions & 0 deletions
142
app/src/main/java/cn/wankkoree/xposed/enablewebviewdebugging/MainActivity.kt
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,142 @@ | ||
package cn.wankkoree.xposed.enablewebviewdebugging | ||
|
||
import de.robv.android.xposed.IXposedHookLoadPackage | ||
import de.robv.android.xposed.XC_MethodHook | ||
import de.robv.android.xposed.XposedBridge | ||
import de.robv.android.xposed.XposedHelpers | ||
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam | ||
import kotlin.collections.HashSet | ||
|
||
|
||
class MainActivity : IXposedHookLoadPackage { | ||
private val webViewClassesHashSet = HashSet<String>() | ||
private val webViewClientClassesHashSet = HashSet<String>() | ||
private val loadVConsole = """ | ||
if(typeof loadJS === 'undefined'){ | ||
function loadJS(url, callback) { | ||
var script = document.createElement("script"), | ||
fn = callback || (()=>{}); | ||
script.type = "text/javascript"; | ||
script.onload = ()=>fn(); | ||
script.src = url; | ||
document.getElementsByTagName("head")[0].appendChild(script); | ||
} | ||
} | ||
if(typeof VConsole === 'undefined') | ||
loadJS("https://cdn.bootcdn.net/ajax/libs/vConsole/3.11.2/vconsole.min.js", ()=>new VConsole()); | ||
""".trimIndent() | ||
|
||
@Throws(Throwable::class) | ||
override fun handleLoadPackage(lpparam: LoadPackageParam) { | ||
val packageName = lpparam.packageName | ||
|
||
if (packageName.equals("com.android.webview")) | ||
return // 不 hook WebView 本身 | ||
|
||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName> loading.") | ||
hookWebView(lpparam.classLoader, packageName) | ||
hookWebViewClient(lpparam.classLoader, packageName) | ||
} | ||
|
||
/** Hook WebView类,实现: | ||
* | ||
* WebView.setWebContentsDebuggingEnabled(true) | ||
* | ||
* webView.getSettings().setJavaScriptEnabled(true) | ||
**/ | ||
private fun hookWebView(classLoader: ClassLoader?, packageName: String?) { | ||
val targetClasses = arrayOf( | ||
"android.webkit.WebView", | ||
"com.tencent.smtt.sdk.WebView", | ||
) | ||
for (targetClass in targetClasses) { | ||
val clazz = try{ XposedHelpers.findClass(targetClass, classLoader) }catch(e: XposedHelpers.ClassNotFoundError){null} | ||
if (clazz != null && checkWebView(clazz)){ // 目标类存在且未hook | ||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(${getClassString(clazz)}) hooking.") | ||
XposedBridge.hookAllConstructors(clazz, object: XC_MethodHook() { | ||
// 创建对象时hook为默认开启调试、JS | ||
override fun afterHookedMethod(param: MethodHookParam) { | ||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(new ${getClassString(clazz)}).setWebContentsDebuggingEnabled(true)") | ||
XposedHelpers.callStaticMethod(clazz, "setWebContentsDebuggingEnabled", true) | ||
|
||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(new ${getClassString(clazz)}).setJavaScriptEnabled(true)") | ||
val webView = param.thisObject | ||
val webSettings = XposedHelpers.callMethod(webView, "getSettings") | ||
XposedHelpers.callMethod(webSettings, "setJavaScriptEnabled", true) | ||
XposedBridge.hookAllMethods(webSettings.javaClass, "setJavaScriptEnabled", object: XC_MethodHook() { | ||
// 声明不开启JS时hook为开启JS | ||
override fun beforeHookedMethod(param: MethodHookParam) { | ||
if (param.args[0] != true) { | ||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(${getClassString(clazz)}).setJavaScriptEnabled(${param.args[0]} -> true)") | ||
param.args[0] = true | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
XposedBridge.hookAllMethods(clazz, "setWebContentsDebuggingEnabled", object: XC_MethodHook() { | ||
// 声明不开启调试时hook为开启调试 | ||
override fun beforeHookedMethod(param: MethodHookParam) { | ||
if (param.args[0] != true) { | ||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(${getClassString(clazz)}).setWebContentsDebuggingEnabled(${param.args[0]} -> true)") | ||
param.args[0] = true | ||
} | ||
} | ||
}) | ||
|
||
} | ||
} | ||
} | ||
|
||
/** Hook WebViewClient类,实现: | ||
* | ||
* WebViewClient.setWebContentsDebuggingEnabled(true) | ||
* | ||
* WebViewClient.getSettings().setJavaScriptEnabled(true) | ||
**/ | ||
private fun hookWebViewClient(classLoader: ClassLoader?, packageName: String?) { | ||
val targetClasses = arrayOf( | ||
arrayOf("android.webkit.WebViewClient", "android.webkit.ValueCallback"), | ||
arrayOf("com.tencent.smtt.sdk.WebViewClient", "com.tencent.smtt.sdk.ValueCallback"), | ||
) | ||
for (targetClass in targetClasses) { | ||
val clazz = try{ XposedHelpers.findClass(targetClass[0], classLoader) }catch(e: XposedHelpers.ClassNotFoundError){null} | ||
if (clazz != null && checkWebViewClient(clazz)){ // 目标类存在且未hook | ||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(${getClassString(clazz)}) hooking.") | ||
XposedBridge.hookAllMethods(clazz, "onPageFinished", object: XC_MethodHook() { | ||
// 设置WebViewClient时,设置页面开始加载时注入vConsole | ||
override fun beforeHookedMethod(param: MethodHookParam) { | ||
XposedBridge.log("[EnableWebViewDebugging]: <$packageName>(new ${getClassString(clazz)}).onPageFinished(vConsole)") | ||
val webView = param.args[0] | ||
XposedHelpers.callMethod(webView, "evaluateJavascript", arrayOf(String::class.java, XposedHelpers.findClass(targetClass[1], classLoader)), "javascript:$loadVConsole", null) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
|
||
private fun getClassString(clazz: Class<*>): String { | ||
return "${clazz.name}@${clazz.hashCode()}<=${clazz.classLoader.javaClass.name}@${clazz.classLoader!!.hashCode()}" | ||
} | ||
|
||
private fun checkWebView(targetClass: Class<*>): Boolean { | ||
val targetClassS = getClassString(targetClass) | ||
return if (webViewClassesHashSet.contains(targetClassS)) { | ||
false | ||
} else { | ||
webViewClassesHashSet.add(targetClassS) | ||
true | ||
} | ||
} | ||
|
||
private fun checkWebViewClient(targetClass: Class<*>): Boolean { | ||
val targetClassS = getClassString(targetClass) | ||
return if (webViewClientClassesHashSet.contains(targetClassS)) { | ||
false | ||
} else { | ||
webViewClientClassesHashSet.add(targetClassS) | ||
true | ||
} | ||
} | ||
|
||
} |
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,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.