Modify add debug log and change crash log in FrameworkHooker

This commit is contained in:
2022-10-05 04:32:58 +08:00
parent 5320ce1b0e
commit 6fbaf6d7a2

View File

@@ -51,7 +51,10 @@ import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.hook.factory.field import com.highcapable.yukihookapi.hook.factory.field
import com.highcapable.yukihookapi.hook.factory.hasMethod import com.highcapable.yukihookapi.hook.factory.hasMethod
import com.highcapable.yukihookapi.hook.factory.method import com.highcapable.yukihookapi.hook.factory.method
import com.highcapable.yukihookapi.hook.log.loggerD
import com.highcapable.yukihookapi.hook.log.loggerE import com.highcapable.yukihookapi.hook.log.loggerE
import com.highcapable.yukihookapi.hook.log.loggerI
import com.highcapable.yukihookapi.hook.log.loggerW
import com.highcapable.yukihookapi.hook.type.android.BundleClass import com.highcapable.yukihookapi.hook.type.android.BundleClass
import com.highcapable.yukihookapi.hook.type.android.MessageClass import com.highcapable.yukihookapi.hook.type.android.MessageClass
@@ -98,19 +101,35 @@ object FrameworkHooker : YukiBaseHooker() {
onCreate { appErrorsRecords = ConfigData.getResolverString(ConfigData.APP_ERRORS_DATA).toEntity() ?: arrayListOf() } onCreate { appErrorsRecords = ConfigData.getResolverString(ConfigData.APP_ERRORS_DATA).toEntity() ?: arrayListOf() }
} }
FrameworkTool.Host.with(instance = this) { FrameworkTool.Host.with(instance = this) {
onOpenAppUsedFramework { appContext?.openApp(it.first, it.second) } onOpenAppUsedFramework {
onPushAppErrorInfoData { appErrorsRecords.firstOrNull { e -> e.pid == it } ?: AppErrorsInfoBean.createEmpty() } appContext?.openApp(it.first, it.second)
loggerI(msg = "Opened \"${it.first}\"${it.second.takeIf { e -> e > 0 }?.let { e -> " --user $e" } ?: ""}")
}
onPushAppErrorInfoData {
appErrorsRecords.firstOrNull { e -> e.pid == it } ?: run {
loggerW(msg = "Cannot received crash application data --pid $it")
AppErrorsInfoBean.createEmpty()
}
}
onPushAppErrorsInfoData { appErrorsRecords } onPushAppErrorsInfoData { appErrorsRecords }
onRemoveAppErrorsInfoData { onRemoveAppErrorsInfoData {
loggerI(msg = "Removed app errors info data for package \"${it.packageName}\"")
appErrorsRecords.remove(it) appErrorsRecords.remove(it)
saveAllAppErrorsRecords() saveAllAppErrorsRecords()
} }
onClearAppErrorsInfoData { onClearAppErrorsInfoData {
loggerI(msg = "Cleared all app errors info data, size ${appErrorsRecords.size}")
appErrorsRecords.clear() appErrorsRecords.clear()
saveAllAppErrorsRecords() saveAllAppErrorsRecords()
} }
onMutedErrorsIfUnlock { mutedErrorsIfUnlockApps.add(it) } onMutedErrorsIfUnlock {
onMutedErrorsIfRestart { mutedErrorsIfRestartApps.add(it) } mutedErrorsIfUnlockApps.add(it)
loggerI(msg = "Muted \"$it\" until unlocks")
}
onMutedErrorsIfRestart {
mutedErrorsIfRestartApps.add(it)
loggerI(msg = "Muted \"$it\" until restarts")
}
onPushMutedErrorsAppsData { onPushMutedErrorsAppsData {
arrayListOf<MutedErrorsAppBean>().apply { arrayListOf<MutedErrorsAppBean>().apply {
mutedErrorsIfUnlockApps.takeIf { it.isNotEmpty() } mutedErrorsIfUnlockApps.takeIf { it.isNotEmpty() }
@@ -121,11 +140,18 @@ object FrameworkHooker : YukiBaseHooker() {
} }
onUnmuteErrorsApp { onUnmuteErrorsApp {
when (it.type) { when (it.type) {
MutedErrorsAppBean.MuteType.UNTIL_UNLOCKS -> mutedErrorsIfUnlockApps.remove(it.packageName) MutedErrorsAppBean.MuteType.UNTIL_UNLOCKS -> {
MutedErrorsAppBean.MuteType.UNTIL_REBOOTS -> mutedErrorsIfRestartApps.remove(it.packageName) loggerI(msg = "Unmuted if unlocks errors app \"${it.packageName}\"")
mutedErrorsIfUnlockApps.remove(it.packageName)
}
MutedErrorsAppBean.MuteType.UNTIL_REBOOTS -> {
loggerI(msg = "Unmuted if restarts errors app \"${it.packageName}\"")
mutedErrorsIfRestartApps.remove(it.packageName)
}
} }
} }
onUnmuteAllErrorsApps { onUnmuteAllErrorsApps {
loggerI(msg = "Unmute all errors apps --unlocks ${mutedErrorsIfUnlockApps.size} --restarts ${mutedErrorsIfRestartApps.size}")
mutedErrorsIfUnlockApps.clear() mutedErrorsIfUnlockApps.clear()
mutedErrorsIfRestartApps.clear() mutedErrorsIfRestartApps.clear()
} }
@@ -144,6 +170,7 @@ object FrameworkHooker : YukiBaseHooker() {
/** 移除模块自身 */ /** 移除模块自身 */
removeIf { it.packageName == BuildConfig.APPLICATION_ID } removeIf { it.packageName == BuildConfig.APPLICATION_ID }
} }
loggerD(msg = "Fetched installed packages list, size $size")
} }
} ?: arrayListOf() } ?: arrayListOf()
} }
@@ -261,12 +288,14 @@ object FrameworkHooker : YukiBaseHooker() {
appUserIdRecords[pid] = userId appUserIdRecords[pid] = userId
/** 打印错误日志 */ /** 打印错误日志 */
if (isApp) loggerE( if (isApp) loggerE(
msg = "Application \"$packageName\"${if (packageName != processName) " --process \"$processName\"" else ""}" + msg = "Application \"$packageName\" ${if (isRepeating) "keeps stopping" else "has stopped"}" +
"${if (userId != 0) " --user $userId" else ""} --pid $pid has crashed${if (isRepeating) " again" else ""}" (if (packageName != processName) " --process \"$processName\"" else "") +
) else loggerE(msg = "Process \"$processName\" --pid $pid has crashed${if (isRepeating) " again" else ""}") "${if (userId != 0) " --user $userId" else ""} --pid $pid"
) else loggerE(msg = "Process \"$processName\" ${if (isRepeating) "keeps stopping" else "has stopped"} --pid $pid")
/** 判断是否为模块自身崩溃 */ /** 判断是否为模块自身崩溃 */
if (packageName == BuildConfig.APPLICATION_ID) { if (packageName == BuildConfig.APPLICATION_ID) {
context.toast(msg = "AppErrorsTracking has crashed, please see the log in console") context.toast(msg = "AppErrorsTracking has crashed, please see the log in console")
loggerE(msg = "AppErrorsTracking has crashed itself, please see the Android Runtime Exception in console")
return@afterHook return@afterHook
} }
/** 判断是否为已忽略的 APP */ /** 判断是否为已忽略的 APP */
@@ -320,7 +349,7 @@ object FrameworkHooker : YukiBaseHooker() {
} }
afterHook { afterHook {
/** 当前进程信息 */ /** 当前进程信息 */
val proc = args().first().any() ?: return@afterHook val proc = args().first().any() ?: return@afterHook loggerW(msg = "Received but got null ProcessRecord")
/** 当前 pid 信息 */ /** 当前 pid 信息 */
val pid = ProcessRecordClass.toClass().field { name { it == "mPid" || it == "pid" } }.get(proc).int() val pid = ProcessRecordClass.toClass().field { name { it == "mPid" || it == "pid" } }.get(proc).int()
@@ -335,6 +364,7 @@ object FrameworkHooker : YukiBaseHooker() {
appErrorsRecords.add( appErrorsRecords.add(
0, AppErrorsInfoBean.clone(pid, appInfo?.packageName, appUserIdRecords[pid], args().last().cast()) 0, AppErrorsInfoBean.clone(pid, appInfo?.packageName, appUserIdRecords[pid], args().last().cast())
) )
loggerI(msg = "Received crash application data --pid $pid")
} }
/** 保存异常记录到本地 */ /** 保存异常记录到本地 */
saveAllAppErrorsRecords() saveAllAppErrorsRecords()