import{_ as l,r as p,o as i,c,b as s,d as a,a as o,e as n}from"./app.f643a53b.js";const t={},r=o(`<h1 id="usage-example" tabindex="-1"><a class="header-anchor" href="#usage-example" aria-hidden="true">#</a> Usage Example</h1><blockquote><p>Here is an introduction to the basic working method of <code>YukiHookAPI</code> and a list of simple Hook examples and common functions.</p></blockquote><h2 id="structure-diagram" tabindex="-1"><a class="header-anchor" href="#structure-diagram" aria-hidden="true">#</a> Structure Diagram</h2><blockquote><p>The structure below describes the basic working and principle of <code>YukiHookAPI</code>.</p></blockquote><div class="language-text ext-text"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#adbac7;">Host Environment</span></span>
<span class="line"><span style="color:#adbac7;">\u2514\u2500\u2500 YukiMemberHookCreator</span></span>
<span class="line"><span style="color:#adbac7;">    \u2514\u2500\u2500 Class</span></span>
<span class="line"><span style="color:#adbac7;">        \u2514\u2500\u2500 MemberHookCreator</span></span>
<span class="line"><span style="color:#adbac7;">            \u2514\u2500\u2500 Member</span></span>
<span class="line"><span style="color:#adbac7;">                \u251C\u2500\u2500 Before</span></span>
<span class="line"><span style="color:#adbac7;">                \u2514\u2500\u2500 After</span></span>
<span class="line"><span style="color:#adbac7;">            MemberHookCreator</span></span>
<span class="line"><span style="color:#adbac7;">            \u2514\u2500\u2500 Member</span></span>
<span class="line"><span style="color:#adbac7;">                \u251C\u2500\u2500 Before</span></span>
<span class="line"><span style="color:#adbac7;">                \u2514\u2500\u2500 After</span></span>
<span class="line"><span style="color:#adbac7;">            ...</span></span>
<span class="line"><span style="color:#adbac7;">    YukiResourcesHookCreator</span></span>
<span class="line"><span style="color:#adbac7;">    \u2514\u2500\u2500 Resources</span></span>
<span class="line"><span style="color:#adbac7;">        \u2514\u2500\u2500 ResourcesHookCreator</span></span>
<span class="line"><span style="color:#adbac7;">            \u2514\u2500\u2500 Drawable</span></span>
<span class="line"><span style="color:#adbac7;">                \u2514\u2500\u2500 Replace</span></span>
<span class="line"><span style="color:#adbac7;">            ResourcesHookCreator</span></span>
<span class="line"><span style="color:#adbac7;">            \u2514\u2500\u2500 Layout</span></span>
<span class="line"><span style="color:#adbac7;">                \u2514\u2500\u2500 Inject</span></span>
<span class="line"><span style="color:#adbac7;">            ...</span></span>
<span class="line"><span style="color:#adbac7;"></span></span></code></pre></div><blockquote><p>The above structure can be written in the following form in code.</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F69D50;">TargetClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">        method {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        beforeHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#ADBAC7;">resources().hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectResource {</span></span>
<span class="line"><span style="color:#ADBAC7;">        conditions {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        replaceTo(...)</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="demo" tabindex="-1"><a class="header-anchor" href="#demo" aria-hidden="true">#</a> Demo</h2><blockquote><p>You can find the demo provided by the API below to learn how to use <code>YukiHookAPI</code>.</p></blockquote>`,9),d=n("Host App Demo "),u={href:"https://github.com/fankes/YukiHookAPI/tree/master/demo-app",target:"_blank",rel:"noopener noreferrer"},A=n("click here to view"),m=n("Module App Demo "),v={href:"https://github.com/fankes/YukiHookAPI/tree/master/demo-module",target:"_blank",rel:"noopener noreferrer"},y=n("click here to view"),h=o(`<p>Install the Host App and Module App Demo at the same time, and test the hooked function in the Host App by activating the Module App.</p><h2 id="a-simple-hook-example" tabindex="-1"><a class="header-anchor" href="#a-simple-hook-example" aria-hidden="true">#</a> A Simple Hook Example</h2><blockquote><p>Here are examples of Hook App, Hook System Framework and Hook Resources for reference.</p></blockquote><h3 id="hook-app" tabindex="-1"><a class="header-anchor" href="#hook-app" aria-hidden="true">#</a> Hook App</h3><p>Suppose, we want to hook the <code>onCreate</code> method in <code>com.android.browser</code> and show a dialog.</p><p>Add code in the body of the <code>encase</code> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.android.browser&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#F69D50;">ActivityClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">            method {</span></span>
<span class="line"><span style="color:#ADBAC7;">                name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;onCreate&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">                param(</span><span style="color:#F69D50;">BundleClass</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                returnType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">UnitType</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">                </span><span style="color:#F69D50;">AlertDialog</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Builder</span><span style="color:#ADBAC7;">(instance())</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .setTitle(</span><span style="color:#96D0FF;">&quot;Hooked&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .setMessage(</span><span style="color:#96D0FF;">&quot;I am hook!&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .setPositiveButton(</span><span style="color:#96D0FF;">&quot;OK&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">null</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .show()</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>At this point, the <code>onCreate</code> method will be successfully hooked and this dialog will show when every <code>Activity</code> in <code>com.android.browser</code> starts.</p><p>So, what should I do if I want to continue the Hook <code>onStart</code> method?</p><p>In the code just now, continue to insert an <code>injectMember</code> method body.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.android.browser&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#F69D50;">ActivityClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">            method {</span></span>
<span class="line"><span style="color:#ADBAC7;">                name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;onCreate&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">                param(</span><span style="color:#F69D50;">BundleClass</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                returnType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">UnitType</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">                </span><span style="color:#F69D50;">AlertDialog</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Builder</span><span style="color:#ADBAC7;">(instance())</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .setTitle(</span><span style="color:#96D0FF;">&quot;Hooked&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .setMessage(</span><span style="color:#96D0FF;">&quot;I am hook!&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .setPositiveButton(</span><span style="color:#96D0FF;">&quot;OK&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">null</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                    .show()</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">            method {</span></span>
<span class="line"><span style="color:#ADBAC7;">                name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;onStart&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">                emptyParam()</span></span>
<span class="line"><span style="color:#ADBAC7;">                returnType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">UnitType</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">                </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>For the <code>Class</code> that does not exist in the current project, you can use the <code>stub</code> method or the <code>findClass</code> method to get the class that needs to be hooked.</p><p>For example, I want to get <code>com.example.demo.TestClass</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">findClass(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo.TestClass&quot;</span><span style="color:#ADBAC7;">).hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If <code>com.example.demo</code> is the app you want to hook, then the writing method can be simpler.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">findClass(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;$packageName.TestClass&quot;</span><span style="color:#ADBAC7;">).hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Some people may have started to say that <code>findClass</code> is a bit cumbersome in some scenarios.</p><p>Because some people may have the following needs.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">const</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">TestClass</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo.TestClass&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F69D50;">TestClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>That&#39;s okay, you can also create a Hook directly using the string class name.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#96D0FF;">&quot;$packageName.TestClass&quot;</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator#memberhookcreator-class">MemberHookCreator</a>.</p></div><h3 id="hook-zygote" tabindex="-1"><a class="header-anchor" href="#hook-zygote" aria-hidden="true">#</a> Hook Zygote</h3><p>The first event <code>initZygote</code> after the new process is forked when the app starts.</p><p>Suppose we want to globally Hook the <code>onCreate</code> event of an app <code>Activity</code></p><p>Add code in the body of the <code>encase</code> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadZygote {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#F69D50;">ActivityClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">            method {</span></span>
<span class="line"><span style="color:#ADBAC7;">                name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;onCreate&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">                param(</span><span style="color:#F69D50;">BundleClass</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">                returnType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">UnitType</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">                </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>The functionality performed in <strong>loadZygote</strong> is very limited, and the <strong>loadZygote</strong> method is rarely needed.</p></div><h3 id="hook-system-framework" tabindex="-1"><a class="header-anchor" href="#hook-system-framework" aria-hidden="true">#</a> Hook System Framework</h3><p>In <code>YukiHookAPI</code>, the implementation of the Hook System Framework is very simple.</p><p>Suppose, you want to get <code>ApplicationInfo</code> and <code>PackageInfo</code> and do something with them.</p><p>Add code in the body of the <code>encase</code> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadSystem {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#F69D50;">ApplicationInfoClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#F69D50;">PackageInfoClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p><strong>loadZygote</strong> is directly different from <strong>loadSystem</strong>, <strong>loadZygote</strong> will be loaded in <strong>initZygote</strong>, and the System Framework is regarded as <strong>loadApp(name = &quot;android&quot;)</strong> and exists, To Hook the System Framework, you can use <strong>loadSystem</strong> directly.</p></div><h3 id="hook-resources" tabindex="-1"><a class="header-anchor" href="#hook-resources" aria-hidden="true">#</a> Hook Resources</h3><p>Suppose, we want to replace the content of <code>app_name</code> of type <code>string</code> in Hook <code>com.android.browser</code> with <code>123</code>.</p><p>Add code in the body of the <code>encase</code> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.android.browser&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    resources().hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        injectResource {</span></span>
<span class="line"><span style="color:#ADBAC7;">            conditions {</span></span>
<span class="line"><span style="color:#ADBAC7;">                name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;app_name&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">                string()</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            replaceTo(</span><span style="color:#96D0FF;">&quot;123&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If the current app has a title bar text set with <code>app_name</code>, it will become our <code>123</code>.</p><p>You can also replace the Hook App&#39;s Resources with the current Xposed Module&#39;s Resources.</p><p>Suppose, we want to continue to hook <code>ic_launcher</code> of type <code>mipmap</code> in <code>com.android.browser</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.android.browser&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    resources().hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        injectResource {</span></span>
<span class="line"><span style="color:#ADBAC7;">            conditions {</span></span>
<span class="line"><span style="color:#ADBAC7;">                name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;ic_launcher&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">                mipmap()</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            replaceToModuleResource(</span><span style="color:#F69D50;">R</span><span style="color:#ADBAC7;">.mipmap.ic_launcher)</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>At this point, the icon of the target app will be replaced with the icon we set.</p><p>If you want to replace the Resources of the System Framework, you can do the same, just replace <code>loadApp</code> with <code>loadZygote</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadZygote {</span></span>
<span class="line"><span style="color:#ADBAC7;">    resources().hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/core/YukiResourcesHookCreator#resourceshookcreator-class">ResourcesHookCreator</a>.</p></div><h3 id="remove-hook" tabindex="-1"><a class="header-anchor" href="#remove-hook" aria-hidden="true">#</a> Remove Hook</h3><p>The native Xposed provides us with a <code>XC_MethodHook.Unhook</code> function, which can remove the current Hook from the Hook queue, and <code>YukiHookAPI</code> can also implement this function.</p><p>The first way, save the <code>Result</code> instance of the current injected object, and call <code>remove</code> at the appropriate time and place to remove the injected object.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Set a variable to save the current instance</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> hookResult </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    method {</span></span>
<span class="line"><span style="color:#ADBAC7;">        name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;test&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">        returnType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">UnitType</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#768390;">// Call the following method when appropriate</span></span>
<span class="line"><span style="color:#ADBAC7;">hookResult.remove()</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>The second method, call <code>removeSelf</code> in the Hook callback method to remove itself.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    method {</span></span>
<span class="line"><span style="color:#ADBAC7;">        name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;test&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">        returnType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">UnitType</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Just call the following method directly</span></span>
<span class="line"><span style="color:#ADBAC7;">        removeSelf()</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator#memberhookcreator-class">MemberHookCreator</a>.</p></div><h2 id="exception-handling" tabindex="-1"><a class="header-anchor" href="#exception-handling" aria-hidden="true">#</a> Exception Handling</h2><blockquote><p><code>YukiHookAPI</code> has redesigned the monitoring of exceptions, any exception will not be thrown during the hook process, to avoid interrupting the next hook process and causing the hook process to &quot;die&quot;.</p></blockquote><h3 id="listen-for-exceptions" tabindex="-1"><a class="header-anchor" href="#listen-for-exceptions" aria-hidden="true">#</a> Listen for Exceptions</h3><p>You can handle exceptions that occur during the Hook method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}.result {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Handle the exception at the start of the hook</span></span>
<span class="line"><span style="color:#ADBAC7;">    onHookingFailure {}</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Handle exceptions in the hook process</span></span>
<span class="line"><span style="color:#ADBAC7;">    onConductFailure { param, throwable </span><span style="color:#F47067;">-&gt;</span><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Handle all exceptions</span></span>
<span class="line"><span style="color:#ADBAC7;">    onAllFailure {}</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>This method also works in the Resources Hook.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">injectResource {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}.result {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Handle arbitrary exceptions when hooking</span></span>
<span class="line"><span style="color:#ADBAC7;">    onHookingFailure {}</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also handle exceptions that occur when the Hook&#39;s <code>Class</code> does not exist.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F69D50;">TargetClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}.onHookClassNotFoundFailure {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also handle exceptions when looking up methods.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">method {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}.onNoSuchMethod {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator#result-class">MemberHookCreator.Result</a>, <a href="../api/public/com/highcapable/yukihookapi/hook/core/YukiResourcesHookCreator#result-class">ResourcesHookCreator.Result</a>.</p></div><p>Common exceptions that may occur are described here. For more information, please refer to <a href="../config/api-exception">API Exception Handling</a>.</p><h3 id="throw-an-exception" tabindex="-1"><a class="header-anchor" href="#throw-an-exception" aria-hidden="true">#</a> Throw an Exception</h3><p>In some cases, you can <strong>manually throw exceptions</strong> to alert some functionality that there is a problem.</p><p>As mentioned above, the exception thrown in the <code>hook</code> method body will be taken over by the <code>YukiHookAPI</code> to avoid interrupting the next Hook process and causing the Hook process to &quot;die&quot;.</p><p>Here&#39;s how these exceptions work when <code>YukiHookAPI</code> takes over.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// &lt;Scenario 1&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    method {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#F47067;">throw</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">RuntimeException</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;Exception Test&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}.result {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Can catch RuntimeException</span></span>
<span class="line"><span style="color:#ADBAC7;">    onHookingFailure {}</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#768390;">// &lt;Scenario 2&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    method {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#F47067;">throw</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">RuntimeException</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;Exception Test&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}.result {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Can catch RuntimeException</span></span>
<span class="line"><span style="color:#ADBAC7;">    onConductFailure { param, throwable </span><span style="color:#F47067;">-&gt;</span><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>The above scenarios will only be processed in the (Xposed) Host App environment and will not have any impact on the host itself.</p><p>If we want to throw these exceptions directly to the Host App, the native Xposed provides us with the <code>param.throwable</code> method, and <code>YukiHookAPI</code> can also implement this function.</p><p>If you want to throw an exception directly to the Host App in the Hook callback method body, you can implement the following methods.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    method {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#F69D50;">RuntimeException</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;Exception Test&quot;</span><span style="color:#ADBAC7;">).throwToApp()</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also throw exceptions directly in the Hook callback method body, and then mark the exception to be thrown to the Host App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    method {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">    afterHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#F47067;">throw</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">RuntimeException</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;Exception Test&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">    }.onFailureThrowToApp()</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>The above two methods can receive an exception at the Host App and cause the Host App process to crash.</p><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>In order to ensure that the Hook calling domain and the calling domain within the Host App are isolated from each other, exceptions can only be thrown to the Host App in the <strong>beforeHook</strong> and <strong>afterHook</strong> callback method bodies.</p></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/param/HookParam#throwable-throwtoapp-i-ext-method">Throwable.throwToApp</a>, <a href="../api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator#hookcallback-class">YukiMemberHookCreator.MemberMookCreator.HookCallback</a>.</p></div><h2 id="status-monitor" tabindex="-1"><a class="header-anchor" href="#status-monitor" aria-hidden="true">#</a> Status Monitor</h2><p>People who use <code>XposedHelpers</code> often print <code>Unhook</code> after the Hook to determine whether the Hook is successful.</p><p>In <code>YukiHookAPI</code>, you can easily reimplement this functionality with the following methods.</p><p>First we can monitor that the Hook is ready to start.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F69D50;">YourClass</span><span style="color:#ADBAC7;">.hook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}.onPrepareHook {</span></span>
<span class="line"><span style="color:#ADBAC7;">    loggerD(msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;$instanceClass hook start&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p><strong>instanceClass</strong> is recommended to be used only in <strong>onPrepareHook</strong>, otherwise the Hook&#39;s <strong>Class</strong> does not exist and an uninterceptable exception will be thrown, causing the Hook process to &quot;die&quot;.</p></div><p>Then, we can also monitor the success of the method result of the Hook.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">injectMember {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}.onHooked { member </span><span style="color:#F47067;">-&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">    loggerD(msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;$member has hooked&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="expansion-usage" tabindex="-1"><a class="header-anchor" href="#expansion-usage" aria-hidden="true">#</a> Expansion Usage</h2><blockquote><p>You can use the following methods to easily implement various judgments and functions in the Hook process.</p></blockquote><h3 id="multiple-hosts" tabindex="-1"><a class="header-anchor" href="#multiple-hosts" aria-hidden="true">#</a> Multiple Hosts</h3><p>If your Module App needs to handle Hook events of multiple apps at the same time, you can use the <code>loadApp</code> method body to distinguish the app you want to hook.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.android.browser&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.android.phone&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/param/PackageParam#loadapp-method">PackageParam.loadApp</a>.</p></div><h3 id="multiple-processes" tabindex="-1"><a class="header-anchor" href="#multiple-processes" aria-hidden="true">#</a> Multiple Processes</h3><p>If your Hook&#39;s Host App has multiple processes, you can use the <code>withProcess</code> method body to hook them separately.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">withProcess(mainProcessName) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#ADBAC7;">withProcess(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;$packageName:tool&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/hook/param/PackageParam#withprocess-method">PackageParam.withProcess</a>.</p></div><h2 id="writing-optimization" tabindex="-1"><a class="header-anchor" href="#writing-optimization" aria-hidden="true">#</a> Writing Optimization</h2><p>To make the code more concise, you can omit the name of <code>YukiHookAPI</code> and write your <code>onHook</code> entry as <code>lambda</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onHook</span><span style="color:#ADBAC7;">() </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> encase {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="xposed-module-status" tabindex="-1"><a class="header-anchor" href="#xposed-module-status" aria-hidden="true">#</a> Xposed Module Status</h2><p>Usually, the developer of the Xposed Module will choose to read the activation information of the current Xposed Module to better show the user the effective status of the current function.</p><p>In addition to the basic Hook functions, <code>YukiHookAPI</code> also designed a set of Xposed Module status judgment functions for developers, such as activation status and Hook Framework information.</p><h3 id="determine-self-activation-status" tabindex="-1"><a class="header-anchor" href="#determine-self-activation-status" aria-hidden="true">#</a> Determine Self-activation Status</h3><p>Usually, we will choose to write a method to make it return <code>false</code>, and then hook this method to make it return <code>true</code> to prove that the Hook has taken effect.</p><p>In <code>YukiHookAPI</code>, you don\u2019t need to do this at all, <code>YukiHookAPI</code> has already encapsulated this operation for you, and you can use it directly.</p><p>Now, you can directly use <code>YukiHookAPI.Status.isXposedModuleActive</code> to determine whether it is activated in the Module App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">if</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">YukiHookAPI</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Status</span><span style="color:#ADBAC7;">.isXposedModuleActive) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Due to some special reasons, the Xposed Modules in TaiChi and Wuji cannot use the standard method to detect the activation state.</p><p>At this point you can use <code>YukiHookAPI.Status.isTaiChiModuleActive</code> to determine whether it is activated.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">if</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">YukiHookAPI</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Status</span><span style="color:#ADBAC7;">.isTaiChiModuleActive) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If you want to use both judgment schemes, <code>YukiHookAPI</code> also encapsulates a convenient way for you.</p><p>At this point, you can use <code>YukiHookAPI.Status.isModuleActive</code> to determine whether you are activated in Xposed or TaiChi and Wuji.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">if</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">YukiHookAPI</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Status</span><span style="color:#ADBAC7;">.isModuleActive) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/YukiHookAPI#status-object">YukiHookAPI.Status</a>.</p></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>If your Module App&#39;s API version is higher than 29 and is running on a system whose target API is 29 or higher, you need to add the following permission statement in <strong>AndroidManifest.xml</strong> to judge the activation status of the module in TaiChi and Wuji.</p><blockquote><p>The following example</p></blockquote><div class="language-xml ext-xml line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">&lt;</span><span style="color:#8DDB8C;">queries</span><span style="color:#ADBAC7;">&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">    &lt;</span><span style="color:#8DDB8C;">intent</span><span style="color:#ADBAC7;">&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">        &lt;</span><span style="color:#8DDB8C;">action</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:name</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;android.intent.action.MAIN&quot;</span><span style="color:#ADBAC7;"> /&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">    &lt;/</span><span style="color:#8DDB8C;">intent</span><span style="color:#ADBAC7;">&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">&lt;/</span><span style="color:#8DDB8C;">queries</span><span style="color:#ADBAC7;">&gt;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>There is another solution, you can directly declare the <strong>android.permission.QUERY_ALL_PACKAGES</strong> permission, but it is not recommended and will be warned by code inspection.</p><blockquote><p>The following example</p></blockquote><div class="language-xml ext-xml line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">&lt;</span><span style="color:#8DDB8C;">uses-permission</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:name</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;android.permission.QUERY_ALL_PACKAGES&quot;</span><span style="color:#ADBAC7;"> /&gt;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>If the activation status of TaiChi and Wuji is included in the Module App activation judgment, the <strong>Application</strong> of the Module App must be extends from <strong>ModuleApplication</strong> or directly use <strong>ModuleApplication</strong>.</p></div><h3 id="get-hook-framework-information" tabindex="-1"><a class="header-anchor" href="#get-hook-framework-information" aria-hidden="true">#</a> Get Hook Framework Information</h3><p>In addition to judging your own activation status, you can also get information about the current Hook Framework through the <code>Executor</code> in <code>YukiHookAPI.Status</code>.</p><p>For example, we can use <code>YukiHookAPI.Status.Executor.name</code> to get the name of the current Hook Framework.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> frameworkName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">YukiHookAPI</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Status</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Executor</span><span style="color:#ADBAC7;">.name</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>We can also use <code>YukiHookAPI.Status.Executor.apiLevel</code> to get the API Level of the current Hook Framework.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> frameworkApiLevel </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">YukiHookAPI</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Status</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">Executor</span><span style="color:#ADBAC7;">.apiLevel</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../api/public/com/highcapable/yukihookapi/YukiHookAPI#executor-object">YukiHookAPI.Status.Executor</a>.</p></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p><strong>YukiHookAPI</strong> after <strong>1.0.91</strong> version modifies the logical judgment method of obtaining the status of the Xposed Module, and now you can use this API in the Module App and Host App at the same time;</p><p>Need to make sure <strong>YukiHookAPI.Configs.isEnableHookModuleStatus</strong> is enabled;</p><p><strong>YukiHookAPI</strong> only connects to the known acquisition methods.</p><p>Except for the Hook Framework that provides standard APIs, in other cases, the Xposed Module may not be able to determine whether it is activated or obtain information about the Hook Framework.</p></div>`,155);function b(k,D){const e=p("ExternalLinkIcon");return i(),c("div",null,[r,s("ul",null,[s("li",null,[s("p",null,[d,s("a",u,[A,a(e)])])]),s("li",null,[s("p",null,[m,s("a",v,[y,a(e)])])])]),h])}const B=l(t,[["render",b],["__file","example.html.vue"]]);export{B as default};
