import{_ as s,o as n,c as a,a as e}from"./app.78a03919.js";const o={},l=e(`<h1 id="api-basic-configs" tabindex="-1"><a class="header-anchor" href="#api-basic-configs" aria-hidden="true">#</a> API Basic Configs</h1><blockquote><p>The basic configuration method of <code>YukiHookAPI</code> is introduced here.</p></blockquote><h2 id="function-configs" tabindex="-1"><a class="header-anchor" href="#function-configs" aria-hidden="true">#</a> Function Configs</h2><blockquote><p>Either <a href="../config/xposed-using">Use as Xposed Module Configs</a> or <a href="../config/api-using">Use as Hook API Configs</a>, you can specify <code>YukiHookAPI</code> for configuration.</p></blockquote><h3 id="configs-method" tabindex="-1"><a class="header-anchor" href="#configs-method" aria-hidden="true">#</a> configs Method</h3><div class="language-kotlin ext-kt"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">configs</span><span style="color:#ADBAC7;">(initiate</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">Configs</span><span style="color:#ADBAC7;">.() </span><span style="color:#F47067;">-&gt;</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">Unit</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre></div><p>The <code>configs</code> method implements a <code>lambda</code> method body on the <code>Configs</code> class, which you can easily call for configuration.</p><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to the <a href="../api/public/com/highcapable/yukihookapi/YukiHookAPI#configs-method">YukiHookAPI.configs</a> method.</p></div><h2 id="hooker-configs" tabindex="-1"><a class="header-anchor" href="#hooker-configs" aria-hidden="true">#</a> Hooker Configs</h2><blockquote><p>The most important part of an Xposed Module or Hook API is the creation and use of Hooker. <code>YukiHookAPI</code> provides two ways to use it.</p></blockquote><h3 id="created-by-lambda" tabindex="-1"><a class="header-anchor" href="#created-by-lambda" aria-hidden="true">#</a> Created by lambda</h3><blockquote><p>This solution is the simplest. If your module has few functions and a small amount of code, and does not need to be classified, it is recommended to create it in this way.</p></blockquote><h4 id="encase-method" tabindex="-1"><a class="header-anchor" href="#encase-method" aria-hidden="true">#</a> encase Method</h4><div class="language-kotlin ext-kt"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">encase</span><span style="color:#ADBAC7;">(initiate</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">PackageParam</span><span style="color:#ADBAC7;">.() </span><span style="color:#F47067;">-&gt;</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">Unit</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre></div><p>The <code>encase</code> method is the beginning of all Hook life. In a Module App or a Hook process, the <code>encase</code> method can only be used once to create a Hooker.</p><p><code>PackageParam</code> is an important instance object of the Host App, and <code>PackageParam</code> is used to implement all Hook operations on the current Hook object.</p><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">PackageParam</a>.</p></div><p>The <code>encase</code> method can be created in the <code>onHook</code> method using two schemes.</p><blockquote><p>Sample Code 1</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;">YukiHookAPI</span><span style="color:#ADBAC7;">.encase {</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.example.demo&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<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.DemoClass&quot;</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 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><blockquote><p>Sample Code 2</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;">encase {</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.example.demo&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<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.DemoClass&quot;</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 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>Do your Hook operations in the <code>encase</code> method.</p><h3 id="created-by-custom-hooker" tabindex="-1"><a class="header-anchor" href="#created-by-custom-hooker" aria-hidden="true">#</a> Created by Custom Hooker</h3><blockquote><p>This scheme is more suitable for large-scale projects, such as the need to classify Hooker or classify the role of Hook.</p></blockquote><h4 id="encase-method-1" tabindex="-1"><a class="header-anchor" href="#encase-method-1" aria-hidden="true">#</a> encase Method</h4><div class="language-kotlin ext-kt"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">encase</span><span style="color:#ADBAC7;">(</span><span style="color:#F47067;">vararg</span><span style="color:#ADBAC7;"> hooker</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">YukiBaseHooker</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre></div><p>Also for the <code>encase</code> method, the variable array parameter <code>hooker</code> of the method here provides an object for creating an entry, you can load all Hookers extends <code>YukiBaseHooker</code> at one time.</p><h4 id="yukibasehooker-usage" tabindex="-1"><a class="header-anchor" href="#yukibasehooker-usage" aria-hidden="true">#</a> YukiBaseHooker Usage</h4><p><code>YukiBaseHooker</code> extends <code>PackageParam</code>, you need to extends your child Hooker from <code>YukiBaseHooker</code>.</p><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/entity/YukiBaseHooker">YukiBaseHooker</a>.</p></div><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;">object</span><span style="color:#ADBAC7;"> CustomHooker </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">YukiBaseHooker</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<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></div><p>Child Hooker <strong>recommended</strong> singleton <code>object</code> creation, you can also use <code>class</code> but not recommended.</p><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>You don&#39;t need to re-call <strong>encase</strong> in the <strong>onHook</strong> method extends <strong>YukiBaseHooker</strong>, this is wrong and <strong>will not take effect</strong>, you should start writing your Hook code directly .</p></div><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;">object</span><span style="color:#ADBAC7;"> CustomHooker </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">YukiBaseHooker</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<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.example.demo1&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<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.DemoClass&quot;</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 style="color:#ADBAC7;">        loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo2&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<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.CustomClass&quot;</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 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></div><p>As a child hooker, you can also call the <code>loadApp</code> method externally, and then directly start the Hook internally.</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;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">HookEntry</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">IYukiHookXposedInit</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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;">        loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">ChildCustomHooker</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>
<span class="line"><span style="color:#F47067;">object</span><span style="color:#ADBAC7;"> ChildCustomHooker </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">YukiBaseHooker</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<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.DemoClass&quot;</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 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></div><p>You can use the <code>loadHooker</code> method to load another Hooker in multiple layers in the child Hooker, please do as you like.</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;">object</span><span style="color:#ADBAC7;"> FirstHooker </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">YukiBaseHooker</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<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.DemoClass&quot;</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;">        loadHooker(</span><span style="color:#F69D50;">SecondHooker</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">        loadHooker(</span><span style="color:#F69D50;">ThirdHooker</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></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><p>Once all Hookers are set up, you can load your Hooker in the <code>onHook</code> method of your <code>HookEntryClass</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;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">HookEntry</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">IYukiHookXposedInit</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#F69D50;">YukiHookAPI</span><span style="color:#ADBAC7;">.encase(</span><span style="color:#F69D50;">FirstHooker</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">SecondHooker</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">ThirdHooker</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><p>Of course, we can also abbreviate it.</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;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">HookEntry</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">IYukiHookXposedInit</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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 style="color:#F69D50;">FirstHooker</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">SecondHooker</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">ThirdHooker</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></div><h3 id="expansion-features" tabindex="-1"><a class="header-anchor" href="#expansion-features" aria-hidden="true">#</a> Expansion Features</h3><p>If your current Hook Framework supports and enables the Resources Hook feature, you can now create Resources Hooks directly in <code>encase</code>.</p><p>You don&#39;t need to separate the <code>initZygote</code>, <code>handleLoadPackage</code>, <code>handleInitPackageResources</code> methods to perform different functions as before using the Xposed API.</p><p>In <code>YukiHookAPI</code>, these functions <strong>are seamless</strong>.</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;">encase {</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.example.demo&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<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.DemoClass&quot;</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:#768390;">// Create a Resources Hook (fixed usage)</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 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>You can also use the <code>loadZygote</code> method to load the first event <code>initZygote</code> after a new process has been forked.</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;">encase {</span></span>
<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;">            </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:#768390;">// Create a Resources Hook in Zygote</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 style="color:#ADBAC7;">    loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<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.DemoClass&quot;</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:#768390;">// Create a Resources Hook in the app</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 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></div><h3 id="precautions" tabindex="-1"><a class="header-anchor" href="#precautions" aria-hidden="true">#</a> Precautions</h3><p>It is wrong to load Hooker directly or start Hook directly, <code>encase</code> event will go through three callbacks after being loaded by Hook Framework.</p><ul><li><p>load <code>initZygote</code> \u2192 <code>encase</code></p></li><li><p>load <code>handleLoadPackage</code> \u2192 <code>encase</code></p></li><li><p>load <code>handleInitPackageResources</code> \u2192 <code>encase</code></p></li></ul><p>In this process, you need to use <code>loadApp</code>, <code>loadSystem</code>, <code>loadZygote</code> to distinguish the calling domain of each loading code, otherwise your code will be executed <u><strong>multiple times and cause errors</strong></u>.</p><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>Whether you use <strong>encase</strong> to create the <strong>lambda</strong> method body or use the Hooker form directly, you should not directly load the Hooker or start the Hook directly in the first <strong>onHook</strong> event.</p></div><p>Below are two <strong>error</strong> examples.</p><blockquote><p>Sample Code 1</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;">encase {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// \u2757 Wrong usage, can&#39;t start Hook directly</span></span>
<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.DemoClass&quot;</span><span style="color:#ADBAC7;">).hook {</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 style="color:#768390;">// \u2757 Wrong usage, can&#39;t start Hook directly</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;">// ...</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><blockquote><p>Sample Code 2</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;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">HookEntry</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">IYukiHookXposedInit</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// &lt;Scenario 1&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">        encase {</span></span>
<span class="line"><span style="color:#ADBAC7;">            loadHooker(</span><span style="color:#F69D50;">CustomHooker</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 style="color:#768390;">// &lt;Scenario 2&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">        encase(</span><span style="color:#F69D50;">CustomHooker</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>
<span class="line"><span style="color:#F47067;">object</span><span style="color:#ADBAC7;"> CustomHooker </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">YukiBaseHooker</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// \u2757 Wrong method of use</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// Because there is no judgment object in the outer layer, you cannot start Hook directly</span></span>
<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.DemoClass&quot;</span><span style="color:#ADBAC7;">).hook {</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:#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></div><p>Below is a <strong>correct</strong> example of the wrong example above.</p><blockquote><p>Sample Code 1</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;">encase {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// \u2705 Correct usage, load in Zygote</span></span>
<span class="line"><span style="color:#ADBAC7;">    loadZygote(</span><span style="color:#F69D50;">CustomHooker</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">     </span><span style="color:#768390;">// \u2705 Correct usage, load in Zygote</span></span>
<span class="line"><span style="color:#ADBAC7;">    loadZygote {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// \u2705 Correct usage, Hook in Zygote</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;">// ...</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 style="color:#768390;">// \u2705 The correct way to use it, use the app scope to load</span></span>
<span class="line"><span style="color:#ADBAC7;">    loadApp(</span><span style="color:#768390;">/** name parameter optional */</span><span style="color:#ADBAC7;">, hooker </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">CustomHooker</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// \u2705 The correct way to use it, load the Hooker after judging the scope of the app</span></span>
<span class="line"><span style="color:#ADBAC7;">    loadApp(</span><span style="color:#768390;">/** name parameter optional */</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">        loadHooker(</span><span style="color:#F69D50;">CustomHooker</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">         </span><span style="color:#768390;">// \u2705 Correct usage, Hook in app scope</span></span>
<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.DemoClass&quot;</span><span style="color:#ADBAC7;">).hook {</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 style="color:#768390;">// \u2705 Correct usage, Hook in app scope</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;">// ...</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></div><blockquote><p>Sample Code 2</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;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">HookEntry</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">IYukiHookXposedInit</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<span class="line"><span style="color:#ADBAC7;">        encase(</span><span style="color:#F69D50;">CustomHooker</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>
<span class="line"><span style="color:#F47067;">object</span><span style="color:#ADBAC7;"> CustomHooker </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">YukiBaseHooker</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">    </span><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>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// \u2705 The correct method of use, since there is no judgment object in the outer layer</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// it is necessary to judge the scope of the app before performing Hook</span></span>
<span class="line"><span style="color:#ADBAC7;">        loadApp(</span><span style="color:#768390;">/** name parameter optional */</span><span style="color:#ADBAC7;">) {</span></span>
<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.DemoClass&quot;</span><span style="color:#ADBAC7;">).hook {</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:#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></div><h2 id="precautions-when-using-as-hook-api" tabindex="-1"><a class="header-anchor" href="#precautions-when-using-as-hook-api" aria-hidden="true">#</a> Precautions when using as Hook API</h2><p>If you are using it as a Hook API, then you only need to differentiate the <code>encase</code> method at the entry point.</p><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>The <strong>encase</strong> method provides two identical methods for use as a Hook API, but with only one more parameter <strong>baseContext</strong> than the previous two.</p></div><blockquote><p>Method 1</p></blockquote><div class="language-kotlin ext-kt"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">encase</span><span style="color:#ADBAC7;">(baseContext</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">Context?</span><span style="color:#ADBAC7;">, initiate</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">PackageParam</span><span style="color:#ADBAC7;">.() </span><span style="color:#F47067;">-&gt;</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">Unit</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre></div><blockquote><p>Method 2</p></blockquote><div class="language-kotlin ext-kt"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">encase</span><span style="color:#ADBAC7;">(baseContext</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">Context?</span><span style="color:#ADBAC7;">, </span><span style="color:#F47067;">vararg</span><span style="color:#ADBAC7;"> hooker</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">YukiBaseHooker</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre></div><p>The <code>baseContext</code> here only needs to fill in the <code>Context</code> you got at <code>attachBaseContext</code>, and other usages are exactly the same as the above.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>Never use the <strong>encase</strong> method in an Xposed way without omitting the <strong>baseContext</strong> parameter, this will lead to your Hook not work at all.</p><p>The Resources Hook feature is not supported as Hook API.</p></div>`,82),p=[l];function c(i,r){return n(),a("div",null,p)}const d=s(o,[["render",c],["__file","api-example.html.vue"]]);export{d as default};
