Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Optimize api hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zjns committed May 5, 2023
1 parent 5c99bc5 commit fb6d4a8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/main/java/me/iacn/biliroaming/hook/OkHttpHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class OkHttpHook(classLoader: ClassLoader) : BaseHook(classLoader) {
val longType = Long::class.javaPrimitiveType!!
val contentLengthField = responseBody.javaClass.findFieldByExactTypeOrNull(longType)
?: return@out
val respString = responseBody.callMethod(stringMethod)?.toString() ?: return@out
val respString = if (hook.decodeResponse()) {
responseBody.callMethod(stringMethod)?.toString() ?: return@out
} else ""
val newResponse = hook.hook(respString)
val stream = newResponse.byteInputStream()
val length = stream.available()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/me/iacn/biliroaming/hook/api/ApiHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ interface ApiHook {
val enabled: Boolean

fun canHandler(api: String): Boolean
fun decodeResponse(): Boolean = true
fun hook(response: String): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object CardsHook : ApiHook {
}

override fun canHandler(api: String) = cardsApis.any { api.startsWith(it) }
override fun decodeResponse() = false

override fun hook(response: String): String {
return JSONObject().apply {
Expand Down

0 comments on commit fb6d4a8

Please sign in to comment.