Skip to content

Commit

Permalink
update hook
Browse files Browse the repository at this point in the history
  • Loading branch information
littleWhiteDuck committed Jan 21, 2023
1 parent ce77259 commit ef32973
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 41 deletions.
31 changes: 31 additions & 0 deletions hook/HookInit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.simpleHook.hook

import android.app.Application
import android.content.Context
import com.github.kyuubiran.ezxhelper.init.EzXHelperInit
import com.github.kyuubiran.ezxhelper.utils.findMethod
import com.github.kyuubiran.ezxhelper.utils.hookAfter
import com.github.kyuubiran.ezxhelper.utils.hookReturnConstant
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage
import me.simpleHook.BuildConfig

class HookInit : IXposedHookLoadPackage {

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
EzXHelperInit.initHandleLoadPackage(lpparam)
if (lpparam.packageName == BuildConfig.APPLICATION_ID) {
findMethod("me.simpleHook.ui.activity.MainActivity") {
name == "isModuleLive"
}.hookReturnConstant(true)

} else {
findMethod(Application::class.java) {
name == "attach"
}.hookAfter {
EzXHelperInit.initAppContext(context = it.args[0] as Context)
MainHook.startHook(lpparam.packageName)
}
}
}
}
39 changes: 0 additions & 39 deletions hook/HookUtils.kt

This file was deleted.

42 changes: 40 additions & 2 deletions hook/utils/LogUtil.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package me.simpleHook.hook.utils

import android.net.Uri
import android.os.Build.VERSION_CODES
import androidx.core.content.contentValuesOf
import com.github.kyuubiran.ezxhelper.init.InitFields
import com.google.gson.Gson
import me.simpleHook.bean.LogBean
import me.simpleHook.constant.Constant
Expand All @@ -8,11 +12,26 @@ import me.simpleHook.hook.Tip
import me.simpleHook.util.*

object LogUtil {

private val PRINT_URI = Uri.parse("content://littleWhiteDuck/print_logs")
fun toLogMsg(log: String, packageName: String, type: String) {
if (type == "null") return
InitFields.appContext.getExternalFilesDirs("")
val time = TimeUtil.getDateTime(System.currentTimeMillis(), "yy-MM-dd HH:mm:ss")
val tempPackageName = if (type.startsWith("Error")) "error.hook.tip" else packageName
val targetSdkVersion = AppUtils.getTargetSdkVer(InitFields.appContext, packageName)
targetSdkVersion?.let {
if (it > VERSION_CODES.Q) {
outLogFile(log, packageName, tempPackageName, type, time)
} else {
outLogDB(log, packageName, tempPackageName, type, time)
}
} ?: outLogFile(log, packageName, tempPackageName, type, time)

}

private fun outLogFile(
log: String, packageName: String, tempPackageName: String, type: String, time: String
) {
try {
val printLog =
PrintLog(log = log, packageName = tempPackageName, type = type, time = time)
Expand All @@ -26,6 +45,25 @@ object LogUtil {
}
}

private fun outLogDB(
log: String, packageName: String, tempPackageName: String, type: String, time: String
) {
try {
val contentValues = contentValuesOf(
"packageName" to tempPackageName,
"log" to log,
"read" to 0,
"type" to type,
"time" to time,
"isMark" to 0
)
InitFields.appContext.contentResolver?.insert(PRINT_URI, contentValues)
} catch (e: Exception) {
"error occurred while saving log to the database".tip(packageName)
outLogFile(log, packageName, tempPackageName, type, time)
}
}

fun getStackTrace(): List<String> {
val stackTrace = Throwable().stackTrace
val isNotChinese = LanguageUtils.isNotChinese()
Expand Down Expand Up @@ -55,7 +93,7 @@ object LogUtil {
list: List<String>, packageName: String, type: String
) {
val logBean = LogBean(type = type, other = list, "error.hook.tip")
LogUtil.toLogMsg(Gson().toJson(logBean), packageName, type)
toLogMsg(Gson().toJson(logBean), packageName, type)
}

fun notFoundClass(
Expand Down

0 comments on commit ef32973

Please sign in to comment.