Skip to content

Commit 4386bb8

Browse files
committed
bili: copy raw link & remove ad under video
1 parent 0378757 commit 4386bb8

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.github.a13e300.myinjector
2+
3+
import android.net.Uri
4+
import android.os.Bundle
5+
import io.github.a13e300.myinjector.arch.IHook
6+
import io.github.a13e300.myinjector.arch.createObfsTable
7+
import io.github.a13e300.myinjector.arch.hookAllBefore
8+
import io.github.a13e300.myinjector.arch.hookAllNop
9+
import io.github.a13e300.myinjector.arch.toObfsInfo
10+
11+
class BiliHandler : IHook() {
12+
private fun hookShare() {
13+
val b23TvRegex = Regex("https?://b23\\.tv/[0-9a-zA-Z]+")
14+
val filterOutParams = listOf("share_session_id", "share_source", "bbid", "share_medium")
15+
runCatching {
16+
findClass("com.bilibili.lib.sharewrapper.ShareHelperV2").hookAllBefore("shareTo") { param ->
17+
val b = param.args[1] as Bundle
18+
val content = b.getString("params_content") ?: return@hookAllBefore
19+
val url = b.getString("params_target_url") ?: return@hookAllBefore
20+
val res = b23TvRegex.find(content) ?: return@hookAllBefore
21+
val sanitizedUrl = Uri.parse(url).run {
22+
val newUrl = buildUpon().clearQuery()
23+
queryParameterNames.forEach {
24+
if (it !in filterOutParams) {
25+
newUrl.appendQueryParameter(it, getQueryParameter(it))
26+
}
27+
}
28+
newUrl.build().toString()
29+
}
30+
logD("url $url -> $sanitizedUrl")
31+
b.putString("params_content", content.replaceRange(res.range, sanitizedUrl))
32+
}
33+
}.onFailure {
34+
logE("hookShare", it)
35+
}
36+
}
37+
38+
private fun hookAd() {
39+
runCatching {
40+
// 视频底部广告
41+
val tbl = createObfsTable("bili", 1) { bridge ->
42+
val method =
43+
bridge.findMethod {
44+
matcher {
45+
usingEqStrings("DetailAdService", "-", "onCreateViews")
46+
}
47+
}.single().toObfsInfo()
48+
49+
mutableMapOf("DetailAdService-onCreateViews" to method)
50+
}
51+
val adCreateView = tbl["DetailAdService-onCreateViews"]!!
52+
findClass(adCreateView.className).hookAllNop(adCreateView.memberName)
53+
}.onFailure {
54+
logE("hookAd", it)
55+
}
56+
}
57+
58+
override fun onHook() {
59+
hookShare()
60+
hookAd()
61+
}
62+
}

app/src/main/java/io/github/a13e300/myinjector/Entry.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Entry : IXposedHookLoadPackage, IXposedHookZygoteInit {
6161
"com.easybrain.sudoku.android" -> SudokuHandler()
6262
"com.xingin.xhs" -> XhsHandler
6363
"com.miui.gallery" -> MiuiGalleryHandler()
64+
"tv.danmaku.bili" -> BiliHandler()
6465
else -> return
6566
}
6667
logPrefix = "[${handler.javaClass.simpleName}] "

app/src/main/res/values/arrays.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<item>com.easybrain.sudoku.android</item>
3232
<item>com.xingin.xhs</item>
3333
<item>com.miui.gallery</item>
34+
<item>tv.danmaku.bili</item>
3435
</string-array>
3536
</resources>

0 commit comments

Comments
 (0)