Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PegasusHook for v8.17.0+ #1560

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,28 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
param.result.callMethod("ensureListIsMutable")
param.result.callMethodAs<MutableList<Any>>("getListList").filter()
}
// v8.17.0+
instance.viewMossClass?.hookAfterMethod("executeView", instance.viewReqClass) { param ->
param.result ?: return@hookAfterMethod
if (removeRelatePromote && removeRelateOnlyAv && removeRelateNothing) {
param.result.callMethod("clearRelates")
param.result.callMethod("clearPagination")
return@hookAfterMethod
}
param.result.callMethod("ensureRelatesIsMutable")
param.result.callMethodAs<MutableList<Any>>("getRelatesList").filter()
}
instance.viewMossClass?.hookAfterMethod(
"executeRelatesFeed",
"com.bapis.bilibili.app.view.v1.RelatesFeedReq"
) { param ->
param.result ?: return@hookAfterMethod
param.result.callMethod("ensureListIsMutable")
param.result.callMethodAs<MutableList<Any>>("getListList").filter()
}



instance.viewUniteMossClass?.run {
hookAfterMethod("view", instance.viewUniteReqClass) { param ->
param.result ?: return@hookAfterMethod
Expand Down Expand Up @@ -543,6 +565,35 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
callMethodAs<MutableList<Any>>("getRelatesList").filterUnite()
}
}
// v8.17.0+
hookAfterMethod("executeView", instance.viewUniteReqClass) { param ->
param.result ?: return@hookAfterMethod
param.result.callMethod("getTab")?.run {
callMethod("ensureTabModuleIsMutable")
callMethodAs<MutableList<Any>>("getTabModuleList").map { originalTabModules ->
if (!originalTabModules.callMethodAs<Boolean>("hasIntroduction")) return@map
originalTabModules.callMethodAs<Any>("getIntroduction").run {
callMethod("ensureModulesIsMutable")
callMethodAs<MutableList<Any>>("getModulesList").map { module ->
if (!module.callMethodAs<Boolean>("hasRelates")) return@map
module.callMethodAs<Any>("getRelates").run {
callMethod("ensureCardsIsMutable")
callMethodAs<MutableList<Any>>("getCardsList").filterUnite()
}
}
}
}
}
}
hookAfterMethod(
"executeRelatesFeed",
"com.bapis.bilibili.app.viewunite.v1.RelatesFeedReq"
) { param ->
param.result?.run {
callMethod("ensureRelatesIsMutable")
callMethodAs<MutableList<Any>>("getRelatesList").filterUnite()
}
}
}

instance.cardClickProcessorClass?.declaredMethods
Expand Down Expand Up @@ -588,6 +639,8 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
param.result = null
}



fun MutableList<Any>.filterPopular() = removeIf {
when (it.callMethod("getItemCase")?.toString()) {
"SMALL_COVER_V5" -> {
Expand Down Expand Up @@ -625,7 +678,6 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
param.args[0].setObjectField("lastParam_", popularDataVersion)
param.args[0].setLongField("idx_", popularDataCount)
}

instance.popularClass?.hookAfterMethod(
"index",
"com.bapis.bilibili.app.show.popular.v1.PopularResultReq"
Expand All @@ -635,5 +687,32 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
param.result.callMethod("ensureItemsIsMutable")
param.result.callMethodAs<MutableList<Any>>("getItemsList").filterPopular()
}

// v8.17.0+
instance.popularClass?.hookBeforeMethod(
"executeIndex",
"com.bapis.bilibili.app.show.popular.v1.PopularResultReq"
) { param ->
param.args ?: return@hookBeforeMethod

val idx = param.args[0].getLongFieldOrNull("idx_")
if (idx == null || idx == 0L) {
popularDataCount = 0
popularDataVersion = ""
return@hookBeforeMethod
}

param.args[0].setObjectField("lastParam_", popularDataVersion)
param.args[0].setLongField("idx_", popularDataCount)
}
instance.popularClass?.hookAfterMethod(
"executeIndex",
"com.bapis.bilibili.app.show.popular.v1.PopularResultReq"
) { param ->
param.result ?: return@hookAfterMethod

param.result.callMethod("ensureItemsIsMutable")
param.result.callMethodAs<MutableList<Any>>("getItemsList").filterPopular()
}
}
}
Loading