import{_ as s}from"./chunks/PButton.S_oBmBtO.js";import{_ as e,c as t,a0 as i,o as n}from"./chunks/framework.CGHvQLJz.js";const g=JSON.parse('{"title":"Installation","description":"","frontmatter":{},"headers":[],"relativePath":"install.md","filePath":"install.md"}'),o={name:"install.md"};function l(p,a,h,c,r,d){return n(),t("div",null,a[0]||(a[0]=[i(`<h1 id="installation" tabindex="-1">Installation <a class="header-anchor" href="#installation" aria-label="Permalink to &quot;Installation&quot;">​</a></h1><h2 id="preparations" tabindex="-1">Preparations <a class="header-anchor" href="#preparations" aria-label="Permalink to &quot;Preparations&quot;">​</a></h2><ol><li><p>Ensure your device&#39;s bootloader is unlocked before rooting.</p></li><li><p>You can execute command <code>zcat /proc/config.gz | grep -w CONFIG_KALLSYMS</code> in terminal or ADB to ensure your kernel is support to patch (root required).</p></li><li><p><a href="https://github.com/bmax121/APatch/releases" target="_blank" rel="noreferrer">Click here</a> to get the latest stable version of APatch Manager.</p></li><li><p>Extract the <code>boot.img</code> from your ROM or from another source containing the stock <code>boot.img</code> of your device. You will need it later for patching.</p></li><li><p>Backup the <code>boot.img</code> you extracted to a computer, USB drive, or another device. If any issues occur, you can flash your original <code>boot.img</code> via fastboot to recover your device from a dump.</p></li></ol><div class="tip custom-block"><p class="custom-block-title">TIP</p><ol><li><p>Ensure to use the latest ADB and fastboot tools and have knowledge about them to proceed to the next step. If you have not learned about them yet, we recommend researching to learn about them first.</p></li><li><p>APatch always patch the <code>boot.img</code> of any device. Do not attempt to patch or flash the <code>init_boot</code> or other partition image files. The APatch developers are not responsible for the failure of resulting patch and boot.</p></li><li><p>Avoid using the <code>boot.img</code> file that has been patched by other managers to avoid unexpected situations.</p></li></ol></div><h2 id="install-requirements" tabindex="-1">Install requirements <a class="header-anchor" href="#install-requirements" aria-label="Permalink to &quot;Install requirements&quot;">​</a></h2><p>APatch installation requirements are mainly reflected in the kernel configuration. Here are the requirements of kernel:</p><div class="language-txt vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>CONFIG_KALLSYMS=y</span></span>
<span class="line"><span>CONFIG_KALLSYMS_ALL=y</span></span></code></pre></div><p>or:</p><div class="language-txt vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>CONFIG_KALLSYMS=y</span></span>
<span class="line"><span>CONFIG_KALLSYMS_ALL=n (Initial support)</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>You can execute command <code>zcat /proc/config.gz | grep -w CONFIG_KALLSYMS</code> in terminal or ADB to ensure your kernel is support to patch (root required).</p></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p><strong>Only supports the ARM64 architecture.</strong></p><p><strong>Only supports Android kernel versions 3.18 - 6.1</strong></p></div><h2 id="how-to-patch" tabindex="-1">Patch <a class="header-anchor" href="#how-to-patch" aria-label="Permalink to &quot;Patch {#how-to-patch}&quot;">​</a></h2><p>There are several ways to patch APatch.</p><h3 id="automatically-patching" tabindex="-1">Automatically patching <a class="header-anchor" href="#automatically-patching" aria-label="Permalink to &quot;Automatically patching {#automatically-patching}&quot;">​</a></h3><ol><li><p>Download the latest version of APatch Manager from <a href="https://github.com/bmax121/APatch/releases" target="_blank" rel="noreferrer">GitHub</a>.</p></li><li><p>Click on the button <img src="`+s+`" alt="Patch Button"> at the top right corner, and click <code>Select a boot image to Patch</code>.</p></li><li><p>Select your <code>boot.img</code>.</p></li><li><p>Set a SuperKey at &quot;SuperKey&quot; card. The SuperKey needs to have <strong>numbers and letters</strong> and at least <strong>8 characters</strong> length. It will be used later to unlock root privileges.</p></li></ol><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>It is strictly prohibited to set weak keys like <code>12345678</code>. The latest versions of APatch <a href="/warn.html">requires the use of strong keys</a>.</p></div><ol start="5"><li>Click on &quot;Start&quot; and wait for a minute. After the patch is successful, the patched <code>boot.img</code> path will be displayed. For example: <code>/storage/emulated/0/Download/apatch_version_version_randomletter.img</code>.</li></ol><p>Finally, you can <a href="#Flash">Flash</a> as needed.</p><h3 id="manually-patching" tabindex="-1">Manually patching <a class="header-anchor" href="#manually-patching" aria-label="Permalink to &quot;Manually patching&quot;">​</a></h3><p>When the KernelPatch is updated and APatch Manager remains unchanged, you can choose to manually patch the kernel.</p><p>You can go to <a href="https://github.com/bmax121/KernelPatch/releases" target="_blank" rel="noreferrer">KernelPatch</a> project to get the latest <code>KP</code> files.</p><h4 id="windows" tabindex="-1">Windows <a class="header-anchor" href="#windows" aria-label="Permalink to &quot;Windows&quot;">​</a></h4><ol><li><p>Download <code>kptools-win.zip</code>, <code>kpimg-android</code> and <code>magiskboot</code>. Extract them into the same directory for use.</p></li><li><p>Execute this command:</p></li></ol><div class="language-cmd vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cmd</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">magiskboot.exe unpack boot.img</span></span></code></pre></div><p>to unpack the <code>boot.img</code> and get the kernel file. Rename the kernel to <strong>kernel-b</strong>. (kernel-b can be any third-party kernel, but third-party kernels come with no guarantees and will not be supported).</p><p>Windows users can patch using <code>CMD</code> or <code>PowerShell</code>.</p><p>Execute this command to patch:</p><div class="language-cmd vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cmd</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kptools</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">x86_64</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">win.exe </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">p </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">image kernel</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">skey </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;YourKey&quot;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> --</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kpimg kpimg</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">android </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">out kernel</span></span></code></pre></div><p>Alternatively, it is recommended to use <code>WSL</code> with <code>Linux</code> for patching:</p><div class="language-cmd vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cmd</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">./kptools</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">linux </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">p </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">image kernel</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">skey </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;YourKey&quot;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> --</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kpimg kpimg</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">android </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">out kernel</span></span></code></pre></div><p>If no errors were reported during patching, execute this command:</p><div class="language-cmd vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cmd</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">magiskboot.exe repack boot.img</span></span></code></pre></div><p>to pack and generate the image. The generated <code>new-boot.img</code> is the patched image.</p><hr><h4 id="linux" tabindex="-1">Linux <a class="header-anchor" href="#linux" aria-label="Permalink to &quot;Linux&quot;">​</a></h4><ol><li><p>Download <code>kptools-linux</code>, <code>kpimg-android</code> and <code>magiskboot</code>.</p></li><li><p>Execute this command:</p></li></ol><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">magiskboot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> unpack</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot.img</span></span></code></pre></div><p>to unpack the <code>boot.img</code> to get the kernel file. Rename the kernel to <strong>kernel-b</strong> (Say again, kernel-b can be any third-party kernel, but third-party kernels come with no guarantees and will not be supported).</p><p>Execute this command to patch:</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./kptools-linux</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --image</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> kernel-b</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --skey</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;YourKey&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --kpimg</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> kpimg-android</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --out</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> kernel</span></span></code></pre></div><p>If no errors were reported during patching, execute this command:</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">magiskboot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> repack</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot.img</span></span></code></pre></div><p>to pack and generate the image. The generated <code>new-boot.img</code> is the patched image.</p><div class="info custom-block"><p class="custom-block-title">INFO</p><p>You can also try <a href="https://kernelpatch-on-web.pages.dev/" target="_blank" rel="noreferrer">online patching</a>.</p></div><h3 id="kp-commands-and-comments" tabindex="-1">KP commands and comments: <a class="header-anchor" href="#kp-commands-and-comments" aria-label="Permalink to &quot;KP commands and comments:&quot;">​</a></h3><div class="info custom-block"><p class="custom-block-title">INFO</p><p>You can click <a href="https://exame.apatch.top/" target="_blank" rel="noreferrer">this</a> to have a try.</p></div><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>COMMAND:</span></span>
<span class="line"><span>  -h, --help                       Print this message.</span></span>
<span class="line"><span>  -v, --version                    Print version number. Print kpimg version if -k specified.</span></span>
<span class="line"><span>  -p, --patch                      Patch or Update patch of kernel image(-i) with specified kpimg(-k) and superkey(-s).</span></span>
<span class="line"><span>  -u, --unpatch                    Unpatch patched kernel image(-i).</span></span>
<span class="line"><span>  -r, --reset-skey                 Reset superkey of patched image(-i).</span></span>
<span class="line"><span>  -d, --dump                       Dump kallsyms infomations of kernel image(-i).</span></span>
<span class="line"><span>  -l, --list                       Print all patch informations of kernel image if (-i) specified.</span></span>
<span class="line"><span>                                   Print extra item informations if (-M) specified.</span></span>
<span class="line"><span>                                   Print KernelPatch image informations if (-k) specified.</span></span>
<span class="line"><span>Options:</span></span>
<span class="line"><span>  -i, --image PATH                 Kernel image path.</span></span>
<span class="line"><span>  -k, --kpimg PATH                 KernelPatch image path.</span></span>
<span class="line"><span>  -s, --skey KEY                   Set the superkey and save it directly in the boot.img.</span></span>
<span class="line"><span>  -S, --root-skey KEY              Set the root-superkey that uses hash verification, and the superkey can be changed dynamically.</span></span>
<span class="line"><span>  -o, --out PATH                   Patched image path.</span></span>
<span class="line"><span>  -a  --addition KEY=VALUE         Add additional information.</span></span>
<span class="line"><span>  -K, --kpatch PATH                Embed kpatch executable binary into patches.</span></span>
<span class="line"><span>  -M, --embed-extra-path PATH      Embed new extra item.</span></span>
<span class="line"><span>  -E, --embeded-extra-name NAME    Preserve and modifiy embedded extra item.</span></span>
<span class="line"><span>  -T, --extra-type TYPE            Set type of previous extra item.</span></span>
<span class="line"><span>  -N, --extra-name NAME            Set name of previous extra item.</span></span>
<span class="line"><span>  -V, --extra-event EVENT          Set trigger event of previous extra item.</span></span>
<span class="line"><span>  -A, --extra-args ARGS            Set arguments of previous extra item.</span></span>
<span class="line"><span>  -D, --extra-detach               Detach previous extra item from patches.</span></span></code></pre></div><h2 id="flash" tabindex="-1">Flash <a class="header-anchor" href="#flash" aria-label="Permalink to &quot;Flash&quot;">​</a></h2><h3 id="using-fastboot" tabindex="-1">Using fastboot <a class="header-anchor" href="#using-fastboot" aria-label="Permalink to &quot;Using fastboot&quot;">​</a></h3><div class="info custom-block"><p class="custom-block-title">INFO</p><p>This method is convenient and stable, you can easily recover your device if your device is corrupted. We strongly recommend using this way to flash.</p></div><p>Connect your device using <code>ADB</code> and execute the following command to enter the fastboot mode:</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">adb</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> reboot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bootloader</span></span></code></pre></div><p>When entering fastboot mode, execute this command:</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">fastboot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> flash</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot.img</span></span></code></pre></div><div class="info custom-block"><p class="custom-block-title">INFO</p><p>If your device supports command <code>fastboot boot</code>, you can use <code>fastboot boot boot.img</code> command to boot the system before you flash the image. If any accident occured, just reboot again then your device will started to boot correctly.</p></div><p>When complete, reboot your device:</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">fastboot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> reboot</span></span></code></pre></div><h3 id="directly-flashing" tabindex="-1">Directly flashing <a class="header-anchor" href="#directly-flashing" aria-label="Permalink to &quot;Directly flashing&quot;">​</a></h3><p>The LATEST version of APatch supports directly flashing via third-party Recovery; for example, TWRP.</p><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Directly flashing is firstly introduced at version <code>10888</code> and earlier version of APatch do <strong>NOT</strong> support this method.</p></div><p>Change the suffix name of APatch Manager file (.apk) to <code>.zip</code>. For example:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[username@localhost Demo] $ ls</span></span>
<span class="line"><span>APatch-10888-release.apk</span></span>
<span class="line"><span>[username@localhost Demo] $ mv APatch-10888-release.apk APatch-10888-release.zip</span></span>
<span class="line"><span>[username@localhost Demo] $ ls</span></span>
<span class="line"><span>APatch-10888-release.zip</span></span>
<span class="line"><span>[username@localhost Demo] $</span></span></code></pre></div><p>After done, you can flash this <code>.zip</code> file via third-party Recovery&#39;s Flash function. APatch will be automatically installed just like Magisk.</p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>Same as Flash, <code>adb sideload</code> function used by Recovery provided by third-party AOSP-like ROMs is also supported.</p></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Directly flashing is <strong>NOT</strong> supported customizing SuperKey! Instead, SuperKey will be set as a combination with random numbers and letters. If you need customize SuperKey, please go to APatch Manager after booting and repatch to reset SuperKey.</p></div><h2 id="uninstall" tabindex="-1">Uninstall <a class="header-anchor" href="#uninstall" aria-label="Permalink to &quot;Uninstall&quot;">​</a></h2><h3 id="automatically-uninstall" tabindex="-1">Automatically uninstall <a class="header-anchor" href="#automatically-uninstall" aria-label="Permalink to &quot;Automatically uninstall&quot;">​</a></h3><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Automatically uninstall is firstly introduced at version <code>10888</code> and earlier version of APatch do <strong>NOT</strong> support this method.</p></div><p>Change the suffix name of APatch Manager file (.apk) to <code>.zip</code> and add modify file name to anything with <code>uninstall</code>. For example:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[username@localhost Demo] $ ls</span></span>
<span class="line"><span>APatch-10888-release.apk</span></span>
<span class="line"><span>[username@localhost Demo] $ mv APatch-10888-release.apk APatch-10888-release-uninstall.zip</span></span>
<span class="line"><span>[username@localhost Demo] $ ls</span></span>
<span class="line"><span>APatch-10888-release-uninstall.zip</span></span>
<span class="line"><span>[username@localhost Demo] $</span></span></code></pre></div><p>After done, you can flash this <code>.zip</code> file via third-party Recovery&#39;s Flash function. APatch will be automatically removed just like Magisk.</p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>Same as Flash, <code>adb sideload</code> function used by Recovery provided by third-party AOSP-like ROMs is also supported.</p></div><h3 id="manually-uninstall" tabindex="-1">Manually uninstall <a class="header-anchor" href="#manually-uninstall" aria-label="Permalink to &quot;Manually uninstall&quot;">​</a></h3><p>Flash your stock <code>boot.img</code> in <code>bootloader</code> mode.</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">fastboot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> flash</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> PATH/TO/boot.img</span></span></code></pre></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Do NOT use <code>init_boot</code>!</p></div>`,76)]))}const m=e(o,[["render",l]]);export{g as __pageData,m as default};
