mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 10:45:47 +08:00
Merge code
This commit is contained in:
@@ -74,7 +74,7 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
* 终止并报错
|
* 终止并报错
|
||||||
* @param msg 错误消息
|
* @param msg 错误消息
|
||||||
*/
|
*/
|
||||||
private fun SymbolProcessorEnvironment.error(msg: String) {
|
private fun SymbolProcessorEnvironment.problem(msg: String) {
|
||||||
val helpMsg = "Looking for help? see https://fankes.github.io/YukiHookAPI/#/config/xposed-using"
|
val helpMsg = "Looking for help? see https://fankes.github.io/YukiHookAPI/#/config/xposed-using"
|
||||||
logger.error(message = "[$TAG] $msg\n$helpMsg")
|
logger.error(message = "[$TAG] $msg\n$helpMsg")
|
||||||
throw RuntimeException("[$TAG] $msg\n$helpMsg")
|
throw RuntimeException("[$TAG] $msg\n$helpMsg")
|
||||||
@@ -109,7 +109,7 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
if (isInjectOnce) when {
|
if (isInjectOnce) when {
|
||||||
it.superTypes.any { type -> type.element.toString() == "IYukiHookXposedInit" } -> {
|
it.superTypes.any { type -> type.element.toString() == "IYukiHookXposedInit" } -> {
|
||||||
val xcName = xInitClassName.ifBlank { "${it.simpleName.asString()}$xposedClassShortName" }
|
val xcName = xInitClassName.ifBlank { "${it.simpleName.asString()}$xposedClassShortName" }
|
||||||
if (xInitClassName == it.simpleName.asString()) error(msg = "Duplicate entryClassName \"$xInitClassName\"")
|
if (xInitClassName == it.simpleName.asString()) problem(msg = "Duplicate entryClassName \"$xInitClassName\"")
|
||||||
injectAssets(
|
injectAssets(
|
||||||
codePath = (it.location as? FileLocation?)?.filePath ?: "",
|
codePath = (it.location as? FileLocation?)?.filePath ?: "",
|
||||||
sourcePath = sourcePath,
|
sourcePath = sourcePath,
|
||||||
@@ -120,10 +120,10 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
injectClass(it.packageName.asString(), modulePackageName, it.simpleName.asString(), xcName)
|
injectClass(it.packageName.asString(), modulePackageName, it.simpleName.asString(), xcName)
|
||||||
}
|
}
|
||||||
it.superTypes.any { type -> type.element.toString() == "YukiHookXposedInitProxy" } ->
|
it.superTypes.any { type -> type.element.toString() == "YukiHookXposedInitProxy" } ->
|
||||||
error(msg = "\"YukiHookXposedInitProxy\" was deprecated, please replace to \"IYukiHookXposedInit\"")
|
problem(msg = "\"YukiHookXposedInitProxy\" was deprecated, please replace to \"IYukiHookXposedInit\"")
|
||||||
else -> error(msg = "HookEntryClass \"${it.simpleName.asString()}\" must be implements \"IYukiHookXposedInit\"")
|
else -> problem(msg = "HookEntryClass \"${it.simpleName.asString()}\" must be implements \"IYukiHookXposedInit\"")
|
||||||
}
|
}
|
||||||
else error(msg = "\"@InjectYukiHookWithXposed\" only can be use in once times")
|
else problem(msg = "\"@InjectYukiHookWithXposed\" only can be use in once times")
|
||||||
/** 仅处理第一个标记的类 - 再次处理将拦截并报错 */
|
/** 仅处理第一个标记的类 - 再次处理将拦截并报错 */
|
||||||
isInjectOnce = false
|
isInjectOnce = false
|
||||||
}
|
}
|
||||||
@@ -146,11 +146,11 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
modulePackageName.contains(".").not() ||
|
modulePackageName.contains(".").not() ||
|
||||||
modulePackageName.contains("..")) &&
|
modulePackageName.contains("..")) &&
|
||||||
modulePackageName.isNotEmpty()
|
modulePackageName.isNotEmpty()
|
||||||
) error(msg = "Invalid modulePackageName \"$modulePackageName\"")
|
) problem(msg = "Invalid modulePackageName \"$modulePackageName\"")
|
||||||
if ((Pattern.compile("[*,.:~`'\"|/\\\\?!^()\\[\\]{}%@#$&\\-+=<>]").matcher(entryClassName).find() ||
|
if ((Pattern.compile("[*,.:~`'\"|/\\\\?!^()\\[\\]{}%@#$&\\-+=<>]").matcher(entryClassName).find() ||
|
||||||
true.let { for (i in 0..9) if (entryClassName.startsWith(i.toString())) return@let true;false })
|
true.let { for (i in 0..9) if (entryClassName.startsWith(i.toString())) return@let true;false })
|
||||||
&& entryClassName.isNotEmpty()
|
&& entryClassName.isNotEmpty()
|
||||||
) error(msg = "Invalid entryClassName \"$entryClassName\"")
|
) problem(msg = "Invalid entryClassName \"$entryClassName\"")
|
||||||
else fetchKSClassDeclaration(sourcePath, modulePackageName, entryClassName)
|
else fetchKSClassDeclaration(sourcePath, modulePackageName, entryClassName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,8 +167,8 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
*/
|
*/
|
||||||
private fun injectAssets(codePath: String, sourcePath: String, packageName: String, entryClassName: String, xInitClassName: String) =
|
private fun injectAssets(codePath: String, sourcePath: String, packageName: String, entryClassName: String, xInitClassName: String) =
|
||||||
environment {
|
environment {
|
||||||
if (codePath.isBlank()) error(msg = "Project CodePath not available")
|
if (codePath.isBlank()) problem(msg = "Project CodePath not available")
|
||||||
if (sourcePath.isBlank()) error(msg = "Project SourcePath not available")
|
if (sourcePath.isBlank()) problem(msg = "Project SourcePath not available")
|
||||||
/**
|
/**
|
||||||
* Gradle 在这里自动处理了 Windows 和 Unix 下的反斜杠路径问题
|
* Gradle 在这里自动处理了 Windows 和 Unix 下的反斜杠路径问题
|
||||||
* 为了防止万一还是做了一下反斜杠处理防止旧版本不支持此用法
|
* 为了防止万一还是做了一下反斜杠处理防止旧版本不支持此用法
|
||||||
@@ -176,16 +176,16 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
val separator = when {
|
val separator = when {
|
||||||
codePath.contains("\\") -> "\\"
|
codePath.contains("\\") -> "\\"
|
||||||
codePath.contains("/") -> "/"
|
codePath.contains("/") -> "/"
|
||||||
else -> kotlin.error("Unix File Separator unknown")
|
else -> error("Unix File Separator unknown")
|
||||||
}
|
}
|
||||||
val projectPath = when {
|
val projectPath = when {
|
||||||
codePath.contains("\\") -> sourcePath.replace("/", "\\")
|
codePath.contains("\\") -> sourcePath.replace("/", "\\")
|
||||||
codePath.contains("/") -> sourcePath.replace("\\", "/")
|
codePath.contains("/") -> sourcePath.replace("\\", "/")
|
||||||
else -> kotlin.error("Unix File Separator unknown")
|
else -> error("Unix File Separator unknown")
|
||||||
}.let {
|
}.let {
|
||||||
if (codePath.contains(it))
|
if (codePath.contains(it))
|
||||||
codePath.split(it)[0] + it
|
codePath.split(it)[0] + it
|
||||||
else error(msg = "Project Source Path \"$it\" not matched")
|
else problem(msg = "Project Source Path \"$it\" not matched")
|
||||||
}
|
}
|
||||||
File("$projectPath${separator}assets").also { assFile ->
|
File("$projectPath${separator}assets").also { assFile ->
|
||||||
if (File("$projectPath${separator}AndroidManifest.xml").exists()) {
|
if (File("$projectPath${separator}AndroidManifest.xml").exists()) {
|
||||||
@@ -197,7 +197,7 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
.writeText(text = "$packageName.$xInitClassName")
|
.writeText(text = "$packageName.$xInitClassName")
|
||||||
File("${assFile.absolutePath}${separator}yukihookapi_init")
|
File("${assFile.absolutePath}${separator}yukihookapi_init")
|
||||||
.writeText(text = "$packageName.$entryClassName")
|
.writeText(text = "$packageName.$entryClassName")
|
||||||
} else error(msg = "Project Source Path \"$sourcePath\" verify failed! Is this an Android Project?")
|
} else problem(msg = "Project Source Path \"$sourcePath\" verify failed! Is this an Android Project?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ class YukiHookXposedProcessor : SymbolProcessorProvider {
|
|||||||
val fModulePackageName = modulePackageName.ifBlank {
|
val fModulePackageName = modulePackageName.ifBlank {
|
||||||
if (packageName.contains(other = ".hook.") || packageName.endsWith(suffix = ".hook"))
|
if (packageName.contains(other = ".hook.") || packageName.endsWith(suffix = ".hook"))
|
||||||
packageName.split(".hook")[0]
|
packageName.split(".hook")[0]
|
||||||
else kotlin.error("Cannot identify your Module App's package name, please manually configure the package name")
|
else error("Cannot identify your Module App's package name, please manually configure the package name")
|
||||||
}
|
}
|
||||||
val injectPackageName = "com.highcapable.yukihookapi.hook.xposed.application.inject"
|
val injectPackageName = "com.highcapable.yukihookapi.hook.xposed.application.inject"
|
||||||
/** 插入 ModuleApplication_Injector 代码 */
|
/** 插入 ModuleApplication_Injector 代码 */
|
||||||
|
Reference in New Issue
Block a user