This commit is contained in:
2022-02-03 03:31:26 +08:00
parent e34b9658d2
commit c9cc80c351
17 changed files with 1068 additions and 209 deletions

View File

@@ -0,0 +1,35 @@
/**
* 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/3.
*/
package com.highcapable.yukihookapi.demo
// for test
class InjectTest(private val string: String) {
// for test
fun getString() = string
}

View File

@@ -0,0 +1,35 @@
/**
* 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/3.
*/
package com.highcapable.yukihookapi.demo
// for test
class InjectTestName(private val string: String) {
// for test
fun getString() = string
}

View File

@@ -25,11 +25,14 @@
*
* This file is Created by fankes on 2022/1/29.
*/
@file:Suppress("SameParameterValue")
package com.highcapable.yukihookapi.demo
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.highcapable.yukihookapi.hook.xposed.YukiHookModuleStatus
class MainActivity : AppCompatActivity() {
@@ -38,11 +41,30 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
// for test
AlertDialog.Builder(this)
.setMessage(hello())
.setPositiveButton("OK", null)
.show()
.setTitle("Hook 方法返回值测试")
.setMessage(test() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setPositiveButton("下一个") { _, _ ->
AlertDialog.Builder(this)
.setTitle("Hook 方法参数测试")
.setMessage(test("这是没有更改的文字") + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setPositiveButton("下一个") { _, _ ->
AlertDialog.Builder(this)
.setTitle("Hook 构造方法测试(stub)")
.setMessage(InjectTest("文字未更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setPositiveButton("下一个") { _, _ ->
AlertDialog.Builder(this)
.setTitle("Hook 构造方法测试(名称)")
.setMessage(InjectTestName("文字没更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setPositiveButton("完成", null)
.show()
}.show()
}.show()
}.show()
}
// for test
private fun hello() = "正常显示的一行文字"
private fun test() = "正常显示的一行文字"
// for test
private fun test(string: String) = string
}

View File

@@ -25,29 +25,68 @@
*
* This file is Created by fankes on 2022/2/2.
*/
@file:Suppress("unused")
package com.highcapable.yukihookapi.demo.hook
import android.app.Activity
import android.app.AlertDialog
import android.widget.Toast
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
import com.highcapable.yukihookapi.demo.InjectTest
import com.highcapable.yukihookapi.demo.MainActivity
import com.highcapable.yukihookapi.hook.factory.encase
import com.highcapable.yukihookapi.hook.proxy.YukiHookInitializeProxy
import com.highcapable.yukihookapi.hook.type.ActivityClass
import com.highcapable.yukihookapi.hook.type.BundleClass
import com.highcapable.yukihookapi.hook.type.StringType
@InjectYukiHookWithXposed
class HookMain : YukiHookInitializeProxy {
override fun onHook() = encase {
loadApp(name = "com.highcapable.yukihookapi.demo") {
loadClass(name = "$packageName.MainActivity").hook {
grabMember = hookClass.loadMethod(name = "hello")
replaceTo(any = "这是一段 Hook 的文字内容")
private val moduleName = "com.highcapable.yukihookapi.demo"
override fun onHook() = encase(moduleName) {
loadApp(name = moduleName) {
MainActivity::class.java.hook {
injectMethod {
name = "test"
returnType = StringType
replaceTo("这段文字已被 Hook 成功")
}
injectMethod {
name = "test"
param(StringType)
returnType = StringType
beforeHook { args().set("方法参数已被 Hook 成功") }
}
}
InjectTest::class.java.hook {
injectConstructor {
param(StringType)
beforeHook { args().set("构造方法已被 Hook 成功") }
}
}
findClass(name = "$packageName.InjectTestName").hook {
injectConstructor {
param(StringType)
beforeHook { args().set("构造方法已被 Hook 成功 [2]") }
}
}
}
loadApp(name = "com.android.browser") {
ActivityClass.hook {
grabMember = hookClass.loadMethod(name = "onCreate", BundleClass)
afterHook {
Toast.makeText(thisAny as Activity, "Hook Success", Toast.LENGTH_SHORT).show()
injectMethod {
name = "onCreate"
param(BundleClass)
afterHook {
AlertDialog.Builder(instance())
.setCancelable(false)
.setTitle("测试 Hook")
.setMessage("Hook 已成功")
.setPositiveButton("OK") { _, _ ->
Toast.makeText(instance(), "Hook Success", Toast.LENGTH_SHORT).show()
}.show()
}
}
}
}