mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 17:55:24 +08:00
...
This commit is contained in:
1
demo-module/src/main/assets/yukihookapi_init
Normal file
1
demo-module/src/main/assets/yukihookapi_init
Normal file
@@ -0,0 +1 @@
|
|||||||
|
com.highcapable.yukihookapi.demo_module.hook.MainHook
|
@@ -25,8 +25,6 @@
|
|||||||
*
|
*
|
||||||
* This file is Created by fankes on 2022/2/9.
|
* This file is Created by fankes on 2022/2/9.
|
||||||
*/
|
*/
|
||||||
@file:Suppress("unused")
|
|
||||||
|
|
||||||
package com.highcapable.yukihookapi.demo_module.hook
|
package com.highcapable.yukihookapi.demo_module.hook
|
||||||
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
|
@@ -12,10 +12,6 @@ java {
|
|||||||
kotlin { sourceSets.main { kotlin.srcDir("src/api/kotlin") } }
|
kotlin { sourceSets.main { kotlin.srcDir("src/api/kotlin") } }
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Used 82 API Version
|
|
||||||
compileOnly 'de.robv.android.xposed:api:82'
|
|
||||||
compileOnly 'androidx.annotation:annotation:1.3.0'
|
|
||||||
implementation project(':yukihookapi')
|
|
||||||
implementation 'com.google.auto.service:auto-service-annotations:1.0.1'
|
implementation 'com.google.auto.service:auto-service-annotations:1.0.1'
|
||||||
compileOnly 'com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2'
|
compileOnly 'com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2'
|
||||||
ksp 'dev.zacsweers.autoservice:auto-service-ksp:1.0.0'
|
ksp 'dev.zacsweers.autoservice:auto-service-ksp:1.0.0'
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
*
|
*
|
||||||
* This file is Created by fankes on 2022/2/5.
|
* This file is Created by fankes on 2022/2/5.
|
||||||
*/
|
*/
|
||||||
@file:Suppress("unused")
|
@file:Suppress("unused", "KDocUnresolvedReference")
|
||||||
|
|
||||||
package com.highcapable.yukihookapi_ksp_xposed
|
package com.highcapable.yukihookapi_ksp_xposed
|
||||||
|
|
||||||
@@ -34,7 +34,6 @@ import com.google.devtools.ksp.processing.*
|
|||||||
import com.google.devtools.ksp.symbol.FileLocation
|
import com.google.devtools.ksp.symbol.FileLocation
|
||||||
import com.google.devtools.ksp.symbol.KSAnnotated
|
import com.google.devtools.ksp.symbol.KSAnnotated
|
||||||
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
||||||
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,6 +48,12 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
|
|
||||||
override fun create(environment: SymbolProcessorEnvironment) = object : SymbolProcessor {
|
override fun create(environment: SymbolProcessorEnvironment) = object : SymbolProcessor {
|
||||||
|
|
||||||
|
/** 自动处理程序的 TAG */
|
||||||
|
private val TAG = "YukiHookAPI"
|
||||||
|
|
||||||
|
/** 查找的注释名称 */
|
||||||
|
private val annotationName = "com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed"
|
||||||
|
|
||||||
/** 插入 Xposed 尾部的名称 */
|
/** 插入 Xposed 尾部的名称 */
|
||||||
private val xposedClassShortName = "_YukiHookXposedInit"
|
private val xposedClassShortName = "_YukiHookXposedInit"
|
||||||
|
|
||||||
@@ -78,10 +83,18 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
* @param msg 错误消息
|
* @param msg 错误消息
|
||||||
*/
|
*/
|
||||||
private fun SymbolProcessorEnvironment.error(msg: String) {
|
private fun SymbolProcessorEnvironment.error(msg: String) {
|
||||||
logger.error(msg)
|
val helpMsg = "Looking for help? see " +
|
||||||
throw RuntimeException(msg)
|
"https://github.com/fankes/YukiHookAPI/wiki/%E4%BD%9C%E4%B8%BA-Xposed-%E6%A8%A1%E5%9D%97%E4%BD%BF%E7%94%A8%E7%9A%84%E7%9B%B8%E5%85%B3%E9%85%8D%E7%BD%AE"
|
||||||
|
logger.error(message = "[$TAG] $msg\n$helpMsg")
|
||||||
|
throw RuntimeException("[$TAG] $msg\n$helpMsg")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发出警告
|
||||||
|
* @param msg 错误消息
|
||||||
|
*/
|
||||||
|
private fun SymbolProcessorEnvironment.warn(msg: String) = logger.warn(message = "[$TAG] $msg")
|
||||||
|
|
||||||
override fun process(resolver: Resolver) = emptyList<KSAnnotated>().let {
|
override fun process(resolver: Resolver) = emptyList<KSAnnotated>().let {
|
||||||
injectProcess(resolver)
|
injectProcess(resolver)
|
||||||
it
|
it
|
||||||
@@ -93,7 +106,7 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
*/
|
*/
|
||||||
private fun injectProcess(resolver: Resolver) = environment {
|
private fun injectProcess(resolver: Resolver) = environment {
|
||||||
var injectOnce = true
|
var injectOnce = true
|
||||||
resolver.getSymbolsWithAnnotation(InjectYukiHookWithXposed::class.java.name).apply {
|
resolver.getSymbolsWithAnnotation(annotationName).apply {
|
||||||
/**
|
/**
|
||||||
* 检索需要注入的类
|
* 检索需要注入的类
|
||||||
* @param sourcePath 指定的 source 路径
|
* @param sourcePath 指定的 source 路径
|
||||||
@@ -118,8 +131,14 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
}
|
}
|
||||||
forEach {
|
forEach {
|
||||||
it.annotations.forEach { e ->
|
it.annotations.forEach { e ->
|
||||||
val sourcePath = e.arguments[0].value.toString()
|
var sourcePath = ""
|
||||||
val modulePackageName = e.arguments[1].value.toString()
|
var modulePackageName = ""
|
||||||
|
e.arguments.forEach { pease ->
|
||||||
|
if (pease.name?.asString() == "sourcePath")
|
||||||
|
sourcePath = pease.value.toString()
|
||||||
|
if (pease.name?.asString() == "modulePackageName")
|
||||||
|
modulePackageName = pease.value.toString()
|
||||||
|
}
|
||||||
if ((modulePackageName.startsWith(".") ||
|
if ((modulePackageName.startsWith(".") ||
|
||||||
modulePackageName.endsWith(".") ||
|
modulePackageName.endsWith(".") ||
|
||||||
!modulePackageName.contains(".") ||
|
!modulePackageName.contains(".") ||
|
||||||
@@ -141,7 +160,8 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
*/
|
*/
|
||||||
private fun injectAssets(codePath: String, sourcePath: String, packageName: String, className: String) =
|
private fun injectAssets(codePath: String, sourcePath: String, packageName: String, className: String) =
|
||||||
environment {
|
environment {
|
||||||
if (codePath.isBlank()) error("Project CodePath is empty")
|
if (codePath.isBlank()) error(msg = "Project CodePath not available")
|
||||||
|
if (sourcePath.isBlank()) error(msg = "Project SourcePath not available")
|
||||||
val projectPath = when (File.separator) {
|
val projectPath = when (File.separator) {
|
||||||
"\\" -> sourcePath.replace("/", "\\")
|
"\\" -> sourcePath.replace("/", "\\")
|
||||||
"/" -> sourcePath.replace("\\", "/")
|
"/" -> sourcePath.replace("\\", "/")
|
||||||
@@ -159,6 +179,8 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
}
|
}
|
||||||
File("${assFile.absolutePath}${File.separator}xposed_init")
|
File("${assFile.absolutePath}${File.separator}xposed_init")
|
||||||
.writeText(text = "$packageName.$className$xposedClassShortName")
|
.writeText(text = "$packageName.$className$xposedClassShortName")
|
||||||
|
File("${assFile.absolutePath}${File.separator}yukihookapi_init")
|
||||||
|
.writeText(text = "$packageName.$className")
|
||||||
} else error(msg = "Project Source Path \"$sourcePath\" verify failed! Is this an Android Project?")
|
} else error(msg = "Project Source Path \"$sourcePath\" verify failed! Is this an Android Project?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,12 +193,12 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
*/
|
*/
|
||||||
private fun injectClass(packageName: String, className: String, modulePackageName: String) =
|
private fun injectClass(packageName: String, className: String, modulePackageName: String) =
|
||||||
environment(ignoredError = true) {
|
environment(ignoredError = true) {
|
||||||
if (modulePackageName.isNotBlank()) logger.warn(message = "You set the customize module package name to \"$modulePackageName\",please check for yourself if it is correct")
|
if (modulePackageName.isNotBlank()) warn(msg = "You set the customize module package name to \"$modulePackageName\",please check for yourself if it is correct")
|
||||||
val realPackageName =
|
val realPackageName =
|
||||||
modulePackageName.ifBlank {
|
modulePackageName.ifBlank {
|
||||||
if (packageName.contains(".hook.") || packageName.endsWith(".hook"))
|
if (packageName.contains(".hook.") || packageName.endsWith(".hook"))
|
||||||
packageName.split(".hook")[0]
|
packageName.split(".hook")[0]
|
||||||
else error(msg = "YukiHookAPI cannot identify your App's package name,please refer to the wiki https://github.com/fankes/YukiHookAPI/wiki to fix the package name or manually configure the package name")
|
else error(msg = "Cannot identify your App's package name,please manually configure the package name")
|
||||||
}
|
}
|
||||||
codeGenerator.createNewFile(
|
codeGenerator.createNewFile(
|
||||||
Dependencies.ALL_FILES,
|
Dependencies.ALL_FILES,
|
||||||
|
Reference in New Issue
Block a user