import{_ as l,r as o,o as p,c,b as n,d as s,e as i,a}from"./app-BpUB8-Q8.js";const r={},t=a('

迁移至 YukiHookAPI 1.2.x

YukiHookAPI1.2.0 版本开始进行了大量调整,你可以继续向下阅读以查看有哪些注意事项和新功能。

注意

如果你正在使用 1.2.x 之前版本的 YukiHookAPI,建议先参考此文档迁移至 1.2.x 版本。

如果你正在使用 1.2.x 版本的 YukiHookAPI,请直接阅读 迁移至 YukiHookAPI 1.3.x 而不是此文档。

默认行为变更

1.2.0 版本开始,@InjectYukiHookWithXposedisUsingResourcesHook 功能默认不再启用,如有需要请手动启用。

注意

Resources Hook (资源钩子) 将在 2.0.0 版本被移除,现已被标记 LegacyResourcesHook,你可以使用 @OptIn(LegacyResourcesHook::class) 的方式消除警告以继续在 1.x.x 版本使用。

新版 API

',7),d=n("code",null,"YukiHookAPI",-1),A=n("code",null,"1.2.0",-1),u=n("code",null,"2.0.0",-1),D={href:"https://github.com/HighCapable/YukiHookAPI/issues/33",target:"_blank",rel:"noopener noreferrer"},B=n("code",null,"2.0.0",-1),y=a(`

注意

所有旧版 API 已被标记 LegacyHookApi,你可以使用 @OptIn(LegacyHookApi::class) 的方式消除警告以继续使用旧版 API。

例如,我们要 Hook com.example.Test 类中的 test 方法。

旧版 API

findClass("com.example.Test").hook {
    injectMember {
        method {
            name = "test"
        }
        beforeHook {
            // Your code here.
        }
        afterHook {
            // Your code here.
        }
    }
}

新版 API

"com.example.Test".toClass()
    .method {
        name = "test"
    }.hook {
        before {
            // Your code here.
        }
        after {
            // Your code here.
        }
    }

新版 API 的 Hook 对象从 Class 迁移至了 Member,这种方式将更加直观。

差异性功能

下面是对接新版 API 的部分差异性功能。

新的多重 Hook 用法

之前我们需要这样去 Hook 所有匹配条件的方法。

示例如下

injectMembers {
    method {
        name { it.contains("some") }
    }.all()
    afterHook {
        // Your code here.
    }
}

现在,你可以改用下面这种方式。

示例如下

method {
    name { it.contains("some") }
}.hookAll {
    after {
        // Your code here.
    }
}

新的 allMembers(...) 用法

之前我们需要这样去 Hook 所有方法、构造方法。

示例如下

injectMembers {
    allMembers(MembersType.METHOD)
    afterHook {
        // Your code here.
    }
}
injectMembers {
    allMembers(MembersType.CONSTRUCTOR)
    afterHook {
        // Your code here.
    }
}

现在,你可以改用下面这种方式。

示例如下

method().hookAll {
    after {
        // Your code here.
    }
}
constructor().hookAll {
    after {
        // Your code here.
    }
}

当不填写查找条件时,默认获取当前 Class 中的所有成员对象。

如果你想 Hook MembersType.ALL,目前暂时没有可以直接对接的方法,但是你可以将所有成员对象拼接后进行 Hook。

示例如下

(method().giveAll() + constructor().giveAll()).hookAll {
    after {
        // Your code here.
    }
}

但我们并不推荐这种做法,一次性 Hook 过多的成员是不可控的,还会发生问题。

`,30);function v(m,C){const e=o("ExternalLinkIcon");return p(),c("div",null,[t,n("p",null,[d,s(" 在 "),A,s(" 版本引入了 "),u,s(" 准备实现的 "),n("a",D,[s("New Hook Code Style"),i(e)]),s(" (新版 API),现处于实验性阶段,你可以在 "),B,s(" 版本正式发布前,开始迁移并体验新版 API。")]),y])}const k=l(r,[["render",v],["__file","move-to-api-1-2-x.html.vue"]]);export{k as default};