Skip to content

Commit

Permalink
修复酷狗音乐会重复获取歌词
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowine committed Oct 6, 2024
1 parent 57aca16 commit 13cf485
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/src/main/kotlin/cn/lyric/getter/hook/app/Kugou.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package cn.lyric.getter.hook.app

import android.app.ActivityManager
import android.content.Context
import android.content.Intent
import cn.lyric.getter.hook.BaseHook
import cn.lyric.getter.tool.HookTools
import cn.lyric.getter.tool.HookTools.eventTools
import cn.lyric.getter.tool.HookTools.fuckTinker
import cn.lyric.getter.tool.Tools.getVersionCode
import cn.xiaowine.xkt.LogTool.log
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.EzXHelper.classLoader
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import android.os.Process

object Kugou : BaseHook() {
override fun init() {
Expand All @@ -20,6 +24,7 @@ object Kugou : BaseHook() {
val verCode: Int = app.packageManager?.getPackageInfo(app.packageName, 0)?.getVersionCode() ?: 0
when (app.packageName) {
"com.kugou.android" -> {
if (getProcessName(app) == "com.kugou.android") return@getApplication
when {
verCode <= 10000 -> hookMethodForVersionA()
verCode <= 12009 -> {
Expand Down Expand Up @@ -52,6 +57,17 @@ object Kugou : BaseHook() {
}
}

private fun getProcessName(context: Context): String? {
val pid = Process.myPid()
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
for (process in manager.runningAppProcesses) {
if (process.pid == pid) {
return process.processName
}
}
return null
}

private fun hookMethodForVersionA() {
loadClass("com.kugou.framework.player.c").methodFinder()
.filterByParamTypes(HashMap::class.java).first { name == "a" }
Expand Down

0 comments on commit 13cf485

Please sign in to comment.