mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 02:35:40 +08:00
...
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 HighCapable
|
||||||
|
*
|
||||||
|
* This file is part of YukiHookAPI.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/2/8.
|
||||||
|
*/
|
||||||
|
package com.highcapable.yukihookapi.demo
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
|
// for test
|
||||||
|
@Keep
|
||||||
|
class InjectLucky {
|
||||||
|
|
||||||
|
// for test
|
||||||
|
@Keep
|
||||||
|
private var string = "没有"
|
||||||
|
|
||||||
|
// for test
|
||||||
|
@Keep
|
||||||
|
constructor() {
|
||||||
|
string = "原始数据"
|
||||||
|
}
|
||||||
|
|
||||||
|
// for test
|
||||||
|
@Keep
|
||||||
|
constructor(string: String = "原始数据复写") {
|
||||||
|
this.string = string
|
||||||
|
}
|
||||||
|
|
||||||
|
// for test
|
||||||
|
@Keep
|
||||||
|
fun getString() = string
|
||||||
|
}
|
@@ -59,10 +59,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.setMessage(InjectTest("文字未更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
.setMessage(InjectTest("文字未更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
||||||
.setPositiveButton("下一个") { _, _ ->
|
.setPositiveButton("下一个") { _, _ ->
|
||||||
AlertDialog.Builder(this)
|
AlertDialog.Builder(this)
|
||||||
.setTitle("Hook 构造方法测试(名称)")
|
.setTitle("Hook 构造方法测试(多个)")
|
||||||
.setMessage(InjectTestName("文字没更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
.setMessage(InjectLucky().getString() + "\n" + InjectLucky(string = "没更改的文字").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
||||||
.setPositiveButton("完成") { _, _ -> toast() }
|
.setPositiveButton("下一个") { _, _ ->
|
||||||
.show()
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle("Hook 构造方法测试(名称)")
|
||||||
|
.setMessage(InjectTestName("文字没更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
||||||
|
.setPositiveButton("完成") { _, _ -> toast() }
|
||||||
|
.show()
|
||||||
|
}.show()
|
||||||
}.show()
|
}.show()
|
||||||
}.show()
|
}.show()
|
||||||
}.show()
|
}.show()
|
||||||
|
@@ -34,6 +34,7 @@ import android.widget.Toast
|
|||||||
import com.highcapable.yukihookapi.YukiHookAPI
|
import com.highcapable.yukihookapi.YukiHookAPI
|
||||||
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
|
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
|
||||||
import com.highcapable.yukihookapi.demo.BuildConfig
|
import com.highcapable.yukihookapi.demo.BuildConfig
|
||||||
|
import com.highcapable.yukihookapi.demo.InjectLucky
|
||||||
import com.highcapable.yukihookapi.demo.InjectTest
|
import com.highcapable.yukihookapi.demo.InjectTest
|
||||||
import com.highcapable.yukihookapi.demo.MainActivity
|
import com.highcapable.yukihookapi.demo.MainActivity
|
||||||
import com.highcapable.yukihookapi.hook.factory.encase
|
import com.highcapable.yukihookapi.hook.factory.encase
|
||||||
@@ -106,6 +107,17 @@ class MainInjecter : YukiHookXposedInitProxy {
|
|||||||
beforeHook { args().set("方法参数已被 Hook 成功") }
|
beforeHook { args().set("方法参数已被 Hook 成功") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
InjectLucky::class.java.hook {
|
||||||
|
injectMember {
|
||||||
|
allConstructors()
|
||||||
|
afterHook {
|
||||||
|
field {
|
||||||
|
name = "string"
|
||||||
|
type = StringType
|
||||||
|
}.set(instance, "内容被改掉了")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
InjectTest::class.java.hook {
|
InjectTest::class.java.hook {
|
||||||
injectMember {
|
injectMember {
|
||||||
constructor { param(StringType) }
|
constructor { param(StringType) }
|
||||||
|
@@ -150,6 +150,7 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
|||||||
* - ⚡如果 [hookClass] 中没有构造方法可能会发生错误
|
* - ⚡如果 [hookClass] 中没有构造方法可能会发生错误
|
||||||
*/
|
*/
|
||||||
fun allConstructors() {
|
fun allConstructors() {
|
||||||
|
allMethodsName = "<init>"
|
||||||
hookAllMembers = HookAllMembers.HOOK_ALL_CONSTRUCTORS
|
hookAllMembers = HookAllMembers.HOOK_ALL_CONSTRUCTORS
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
}
|
}
|
||||||
@@ -295,14 +296,14 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
|||||||
*/
|
*/
|
||||||
@DoNotUseMethod
|
@DoNotUseMethod
|
||||||
fun hook() {
|
fun hook() {
|
||||||
/** 定义替换回调方法体 */
|
/** 定义替换 Hook 回调方法体 */
|
||||||
val replaceMent = object : XC_MethodReplacement() {
|
val replaceMent = object : XC_MethodReplacement() {
|
||||||
override fun replaceHookedMethod(baseParam: MethodHookParam?): Any? {
|
override fun replaceHookedMethod(baseParam: MethodHookParam?): Any? {
|
||||||
if (baseParam == null) return null
|
if (baseParam == null) return null
|
||||||
return HookParam(baseParam).let { param ->
|
return HookParam(baseParam).let { param ->
|
||||||
try {
|
try {
|
||||||
if (replaceHookCallback != null)
|
if (replaceHookCallback != null)
|
||||||
onHookLogMsg(msg = "Replace Hook Member [${member}] done [$tag]")
|
onHookLogMsg(msg = "Replace Hook Member [${member ?: "All Member $allMethodsName"}] done [$tag]")
|
||||||
replaceHookCallback?.invoke(param)
|
replaceHookCallback?.invoke(param)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
onConductFailureCallback?.invoke(param, e)
|
onConductFailureCallback?.invoke(param, e)
|
||||||
@@ -323,7 +324,7 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
|||||||
runCatching {
|
runCatching {
|
||||||
beforeHookCallback?.invoke(param)
|
beforeHookCallback?.invoke(param)
|
||||||
if (beforeHookCallback != null)
|
if (beforeHookCallback != null)
|
||||||
onHookLogMsg(msg = "Before Hook Member [${member}] done [$tag]")
|
onHookLogMsg(msg = "Before Hook Member [${member ?: "All of \"$allMethodsName\""}] done [$tag]")
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
onConductFailureCallback?.invoke(param, it)
|
onConductFailureCallback?.invoke(param, it)
|
||||||
onAllFailureCallback?.invoke(it)
|
onAllFailureCallback?.invoke(it)
|
||||||
@@ -339,7 +340,7 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
|||||||
runCatching {
|
runCatching {
|
||||||
afterHookCallback?.invoke(param)
|
afterHookCallback?.invoke(param)
|
||||||
if (afterHookCallback != null)
|
if (afterHookCallback != null)
|
||||||
onHookLogMsg(msg = "After Hook Member [${member}] done [$tag]")
|
onHookLogMsg(msg = "After Hook Member [${member ?: "All of \"$allMethodsName\""}] done [$tag]")
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
onConductFailureCallback?.invoke(param, it)
|
onConductFailureCallback?.invoke(param, it)
|
||||||
onAllFailureCallback?.invoke(it)
|
onAllFailureCallback?.invoke(it)
|
||||||
|
Reference in New Issue
Block a user