Skip to content

Commit

Permalink
Support HD 1.9.0
Browse files Browse the repository at this point in the history
Fix #624
  • Loading branch information
yujincheng08 committed May 24, 2022
1 parent 9f102b0 commit a4d5820
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 65 deletions.
78 changes: 41 additions & 37 deletions app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
?: "tv.danmaku.bili.MainActivityV2" from mClassLoader
}
val mainActivityClass by Weak { "tv.danmaku.bili.MainActivityV2" from mClassLoader }
val homeUserCenterClass by Weak { mHookInfo.settings.homeUserCenter from mClassLoader }
val homeUserCenterClass by Weak { if (mHookInfo.settings.homeUserCenterCount == 1) mHookInfo.settings.homeUserCenterList.first().class_ from mClassLoader else null }
val musicNotificationHelperClass by Weak { mHookInfo.musicNotification.helper from mClassLoader }
val liveNotificationHelperClass by Weak { mHookInfo.musicNotification.liveHelper from mClassLoader }
val notificationBuilderClass by Weak { mHookInfo.musicNotification.builder.class_ from mClassLoader }
Expand Down Expand Up @@ -159,7 +159,9 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex

fun themeReset() = mHookInfo.themeProcessor.methodsList.map { it.orNull }

fun addSetting() = mHookInfo.settings.addSetting.orNull
fun homeCenters() = mHookInfo.settings.homeUserCenterList.map {
it.class_ from mClassLoader to it.addSetting.orNull
}

fun requestField() = mHookInfo.okHttp.request.orNull

Expand Down Expand Up @@ -713,7 +715,7 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
}
val contextIndex = dexHelper.encodeClassIndex(Context::class.java)
val listIndex = dexHelper.encodeClassIndex(List::class.java)
val homeUserCenterClass = dexHelper.findMethodUsingString(
dexHelper.findMethodUsingString(
"main.my-information.noportrait.0.show",
false,
-1,
Expand All @@ -723,40 +725,42 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
null,
null,
null,
true
).asSequence().firstNotNullOfOrNull {
dexHelper.decodeMethodIndex(it)
}?.declaringClass ?: return@settings
val homeUserCenterIndex = dexHelper.encodeClassIndex(homeUserCenterClass)
val addSettingMethod = dexHelper.findMethodUsingString(
"activity://main/preference",
true,
-1,
-1,
null,
homeUserCenterIndex,
null,
longArrayOf(contextIndex, listIndex),
null,
true
).asSequence().firstNotNullOfOrNull {
dexHelper.decodeMethodIndex(it)
} ?: dexHelper.findMethodUsingString(
"bilibili://main/preference",
true,
-1,
-1,
null,
homeUserCenterIndex,
null,
longArrayOf(contextIndex, listIndex),
null,
true
).asSequence().firstNotNullOfOrNull {
dexHelper.decodeMethodIndex(it)
} ?: return@settings
homeUserCenter = class_ { name = homeUserCenterClass.name }
addSetting = method { name = addSettingMethod.name }
false
).asSequence().mapNotNull { dexHelper.decodeMethodIndex(it)?.declaringClass }
.forEach { homeUserCenterClass ->
val homeUserCenterIndex = dexHelper.encodeClassIndex(homeUserCenterClass)
val addSettingMethod = dexHelper.findMethodUsingString(
"activity://main/preference",
true,
-1,
-1,
null,
homeUserCenterIndex,
null,
longArrayOf(contextIndex, listIndex),
null,
true
).asSequence().firstNotNullOfOrNull {
dexHelper.decodeMethodIndex(it)
} ?: dexHelper.findMethodUsingString(
"bilibili://main/preference",
true,
-1,
-1,
null,
homeUserCenterIndex,
null,
longArrayOf(contextIndex, listIndex),
null,
true
).asSequence().firstNotNullOfOrNull {
dexHelper.decodeMethodIndex(it)
} ?: return@settings
homeUserCenter += homeUserCenter {
class_ = class_ { name = homeUserCenterClass.name }
addSetting = method { name = addSettingMethod.name }
}
}
}
drawer = drawer {
val navigationViewClass =
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) {
private val bangumiSearchPageClass by Weak {
"com.bilibili.bangumi.data.page.search.BangumiSearchPage".findClassOrNull(
mClassLoader
) ?: "com.bilibili.search.result.bangumi.ogv.BangumiSearchPage".findClassOrNull(
mClassLoader
)
}
private val biliSearchOgvResultClass by Weak {
Expand Down Expand Up @@ -344,7 +346,13 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) {
val searchResultFragment =
"com.bilibili.bangumi.ui.page.search.BangumiSearchResultFragment".findClassOrNull(
mClassLoader
) ?: "com.bilibili.search.ogv.OgvSearchResultFragment".findClassOrNull(mClassLoader)
)
?: "com.bilibili.search.result.bangumi.ogv.BangumiSearchResultFragment".findClassOrNull(
mClassLoader
)
?: "com.bilibili.search.ogv.OgvSearchResultFragment".findClassOrNull(
mClassLoader
)
searchResultFragment?.run {
hookBeforeMethod(
"setUserVisibleCompat",
Expand Down
50 changes: 25 additions & 25 deletions app/src/main/java/me/iacn/biliroaming/hook/SettingHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,35 @@ class SettingHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}
}

instance.homeUserCenterClass?.hookBeforeAllMethods(
instance.addSetting()
) { param ->
val lastGroup = (param.args[1] as MutableList<*>).lastOrNull()
?: return@hookBeforeAllMethods
instance.homeCenters().forEach { (c, m) ->
c?.hookBeforeAllMethods(m) { param ->
val lastGroup = (param.args[1] as MutableList<*>).lastOrNull()
?: return@hookBeforeAllMethods

val itemList =
if (lastGroup.javaClass != instance.menuGroupItemClass) lastGroup.getObjectFieldAs<MutableList<Any>?>(
"itemList"
) else param.args[1] as MutableList<Any>
val itemList =
if (lastGroup.javaClass != instance.menuGroupItemClass) lastGroup.getObjectFieldAs<MutableList<Any>?>(
"itemList"
) else param.args[1] as MutableList<Any>

val item = instance.menuGroupItemClass?.new() ?: return@hookBeforeAllMethods
item.setIntField("id", SETTING_ID)
.setObjectField("title", "哔哩漫游设置")
.setObjectField(
"icon",
"https://i0.hdslb.com/bfs/album/276769577d2a5db1d9f914364abad7c5253086f6.png"
)
.setObjectField("uri", SETTING_URI)
val item = instance.menuGroupItemClass?.new() ?: return@hookBeforeAllMethods
item.setIntField("id", SETTING_ID)
.setObjectField("title", "哔哩漫游设置")
.setObjectField(
"icon",
"https://i0.hdslb.com/bfs/album/276769577d2a5db1d9f914364abad7c5253086f6.png"
)
.setObjectField("uri", SETTING_URI)

itemList?.forEach {
if (try {
it.getIntField("id") == SETTING_ID
} catch (t: Throwable) {
it.getLongField("id") == SETTING_ID.toLong()
}
) return@hookBeforeAllMethods
itemList?.forEach {
if (try {
it.getIntField("id") == SETTING_ID
} catch (t: Throwable) {
it.getLongField("id") == SETTING_ID.toLong()
}
) return@hookBeforeAllMethods
}
itemList?.add(item)
}
itemList?.add(item)
}

instance.settingRouterClass?.hookBeforeAllConstructors { param ->
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/proto/me/iacn/biliroaming/configs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ message DownloadThread {
optional ReportDownload report_download = 4;
}

message HomeUserCenter {
optional Class class = 1;
optional Method add_setting = 2;
}

message Settings {
optional Class home_user_center = 1;
optional Class menu_group_item = 2;
optional Class setting_router = 3;
optional Method add_setting = 4;
repeated HomeUserCenter home_user_center = 5;
}

message MusicNotification {
Expand Down

0 comments on commit a4d5820

Please sign in to comment.