Skip to content

Commit 55158a7

Browse files
authored
fix: 竖屏模式视频广告净化 (yujincheng08#1675)
- 修复: 竖屏模式视频广告净化 - 更新: 累计净化计数器移动到竖屏净化弹窗中
1 parent 1b179ff commit 55158a7

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
184184
val videoDownloadEntryClass by Weak { "com.bilibili.videodownloader.model.VideoDownloadEntry" from mClassLoader }
185185
val rewardAdClass by Weak { mHookInfo.rewardAd.class_ from mClassLoader }
186186
val tripleSpeedServiceClass by Weak { "com.bilibili.ship.theseus.united.player.TripleSpeedService\$runOldTripleSpeed\$1\$listener\$1\$onLongPress\$1" from mClassLoader }
187+
val storyPagerPlayerClass by Weak { mHookInfo.storyPagerPlayer.class_ from mClassLoader }
187188

188189
// for v8.17.0+
189190
val useNewMossFunc = instance.viewMossClass?.declaredMethods?.any {
@@ -370,6 +371,8 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
370371

371372
fun rewardFlag() = mHookInfo.rewardAd.rewardFlag.orNull
372373

374+
fun addVideo() = mHookInfo.storyPagerPlayer.addVideo.orNull
375+
373376
private fun readHookInfo(context: Context): Configs.HookInfo {
374377
try {
375378
val hookInfoFile = File(context.cacheDir, Constant.HOOK_INFO_FILE_NAME)
@@ -2398,6 +2401,29 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
23982401
rewardFlag = field { name = rewardFlagField.name }
23992402

24002403
}
2404+
storyPagerPlayer = storyPagerPlayer {
2405+
val storyPagerPlayerClass =
2406+
"com.bilibili.video.story.player.StoryPagerPlayer".from(classloader) ?: return@storyPagerPlayer
2407+
2408+
class_ = class_ { name = storyPagerPlayerClass.name }
2409+
2410+
val addVideoMethod = dexHelper.findMethodUsingString(
2411+
" add ",
2412+
false,
2413+
-1,
2414+
-1,
2415+
null,
2416+
dexHelper.encodeClassIndex(storyPagerPlayerClass),
2417+
null,
2418+
longArrayOf(dexHelper.encodeClassIndex(List::class.java)),
2419+
null,
2420+
true
2421+
).asSequence().mapNotNull {
2422+
dexHelper.decodeMethodIndex(it)
2423+
}.firstOrNull() ?: return@storyPagerPlayer
2424+
2425+
addVideo = method { name = addVideoMethod.name }
2426+
}
24012427

24022428
dexHelper.close()
24032429
}

app/src/main/java/me/iacn/biliroaming/SettingDialog.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class SettingDialog(context: Context) : AlertDialog.Builder(context) {
8080
packageName + "_preferences",
8181
Context.MODE_MULTI_PROCESS
8282
)
83-
updatePurifyStoryVideoAdBlockedCount()
8483
if (!prefs.getBoolean("hidden", false)) {
8584
val hiddenGroup = findPreference("hidden_group") as PreferenceCategory
8685
preferenceScreen.removePreference(hiddenGroup)
@@ -886,16 +885,16 @@ class SettingDialog(context: Context) : AlertDialog.Builder(context) {
886885
val prefKey = "purify_story_video_ad_tags"
887886
val oldPurifyAdTags = sPrefs.getStringSet(prefKey, emptySet()) ?: emptySet()
888887

889-
890888
val keys = tagMap.keys.toList()
891889
val values = tagMap.values.toTypedArray()
892890

893891
val checkedTags = BooleanArray(keys.size) { index ->
894892
keys[index] in oldPurifyAdTags
895893
}
896894

895+
val blockedCount = sPrefs.getInt("purify_story_video_ad_blocked_count", 0)
897896

898-
setTitle(context.getString(R.string.purify_story_video_ad_title))
897+
setTitle(context.getString(R.string.purify_story_video_ad_title) + "(累计拦截 $blockedCount 条)")
899898
setPositiveButton(context.getString(android.R.string.ok)) { _, _ ->
900899
val selected = mutableSetOf<String>()
901900
for (i in keys.indices) {
@@ -918,12 +917,6 @@ class SettingDialog(context: Context) : AlertDialog.Builder(context) {
918917
return true
919918
}
920919

921-
private fun updatePurifyStoryVideoAdBlockedCount() {
922-
val blockedCount = sPrefs.getInt("purify_story_video_ad_blocked_count", 0)
923-
findPreference("purify_story_video_ad")?.summary = getString(R.string.purify_story_video_ad_summary) +
924-
"(累计拦截 $blockedCount 条)"
925-
}
926-
927920
private fun onLongPressSpeedClick(): Boolean {
928921
AlertDialog.Builder(activity).run {
929922
val view = context.inflateLayout(R.layout.seekbar_dialog)

app/src/main/java/me/iacn/biliroaming/hook/StoryPlayerAdHook.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.iacn.biliroaming.hook
22

3+
import me.iacn.biliroaming.BiliBiliPackage.Companion.instance
34
import me.iacn.biliroaming.utils.Log
45
import me.iacn.biliroaming.utils.from
56
import me.iacn.biliroaming.utils.hookBeforeMethod
@@ -12,10 +13,10 @@ class StoryPlayerAdHook(classLoader: ClassLoader) : BaseHook(classLoader) {
1213
val purifyTags = sPrefs.getStringSet("purify_story_video_ad_tags", emptySet()) ?: emptySet()
1314
if (purifyTags.isEmpty()) return
1415

15-
Log.d("startHook: StoryPlayerAd, purifyTags: ${purifyTags}")
16+
Log.d("startHook: StoryPlayerAd, purifyTags: $purifyTags")
1617

17-
"com.bilibili.video.story.player.StoryPagerPlayer".from(mClassLoader)
18-
?.hookBeforeMethod("n1", List::class.java) { params ->
18+
instance.storyPagerPlayerClass?.hookBeforeMethod(
19+
instance.addVideo(), List::class.java) { params ->
1920
val storyDetailList = params.args[0] as? MutableList<*> ?: return@hookBeforeMethod
2021
val toRemove = mutableListOf<Any>()
2122

app/src/main/proto/me/iacn/biliroaming/configs.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ message RewardAd {
335335
optional Field rewardFlag = 2;
336336
}
337337

338+
message StoryPagerPlayer {
339+
optional Class class = 1;
340+
optional Method addVideo = 2;
341+
}
342+
338343
message HookInfo {
339344
int64 last_update_time = 1;
340345
optional MapIds map_ids = 2;
@@ -407,4 +412,5 @@ message HookInfo {
407412
optional ResolveClientCompanion resolveClientCompanion = 102;
408413
optional GCommonResolverParams gCommonResolverParams = 103;
409414
optional RewardAd rewardAd = 104;
415+
optional StoryPagerPlayer storyPagerPlayer = 105;
410416
}

0 commit comments

Comments
 (0)