Skip to content

Commit 0221b63

Browse files
committed
Add libksud support and KMI selection
Add support for KernelSU packages distributed as libksud.so and allow choosing KMI/arch from the UI. Changes include: - Introduce Global.KSU_KMI to override detected KMI. - Add Libksud parser (Libksud.cs) to scan embedded zlib assets, parse rust-embed index, recover asset names and export ksuinit/kernelsu.ko. - Update KernelSUPatch to locate libksud.so, use Libksud to extract the correct kernelsu.ko for the selected KMI and ksuinit, then inject them into the ramdisk. - Update PatchDetect to search for "*libksud.so" and treat it as LKM mode (useful), instead of failing. - Extend BasicflashView to asynchronously populate arch/KMI list from libksud assets, refresh UI bindings, and set Global.KSU_KMI from the selected item. - Add extract_and_verify.py: a standalone Python helper to extract assets from libksud.so, optionally download KernelSU release assets and verify hashes. Also includes heuristics/improvements for asset name recovery when rust-embed parsing fails, and various UI binding/refresh fixes.
1 parent aea72aa commit 0221b63

9 files changed

Lines changed: 559 additions & 25 deletions

File tree

UotanToolbox/Common/Devices/AdbTransport.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
using Avalonia.Controls.Notifications;
2+
using SukiUI.Dialogs;
13
using System;
24
using System.Collections.Generic;
35
using System.Threading;
46
using System.Threading.Tasks;
5-
using SukiUI.Dialogs;
6-
using Avalonia.Controls.Notifications;
77

88
namespace UotanToolbox.Common.Devices
99
{
@@ -13,7 +13,7 @@ private static string GetTranslation(string key)
1313
{
1414
return FeaturesHelper.GetTranslation(key);
1515
}
16-
16+
1717
public TransportType Type => TransportType.Adb;
1818

1919
public async Task<IEnumerable<DeviceInfo>> ProbeAsync(CancellationToken cancel = default)
@@ -40,7 +40,7 @@ public async Task<IEnumerable<DeviceInfo>> ProbeAsync(CancellationToken cancel =
4040
.TryShow();
4141
Global.root = false;
4242
}
43-
43+
4444
}
4545

4646
foreach (var line in lines)

UotanToolbox/Common/Devices/FastbootTransport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
using Avalonia.Controls.Notifications;
2+
using SukiUI.Dialogs;
13
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Threading;
57
using System.Threading.Tasks;
6-
using SukiUI.Dialogs;
7-
using Avalonia.Controls.Notifications;
88

99
namespace UotanToolbox.Common.Devices
1010
{

UotanToolbox/Common/Devices/HdcTransport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
using Avalonia.Controls.Notifications;
2+
using SukiUI.Dialogs;
13
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Threading;
57
using System.Threading.Tasks;
6-
using SukiUI.Dialogs;
7-
using Avalonia.Controls.Notifications;
88

99
namespace UotanToolbox.Common.Devices
1010
{

UotanToolbox/Common/GetDevicesInfo.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Avalonia.Collections;
2-
using Avalonia.Controls.Notifications;
3-
using SukiUI.Dialogs;
42
using System;
53
using System.Collections.Generic;
64
using System.Linq;

UotanToolbox/Common/Global.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ internal class Global
4545
public static string MagiskAPKPath { get; internal set; } = string.Empty;
4646

4747
public static string VbmetaCommand { get; internal set; } = "--disable-verity --disable-verification";
48+
public static string KSU_KMI { get; set; } = string.Empty;
4849

4950
// 设备管理器实例
5051
public static UotanToolbox.Common.Devices.DeviceManager DeviceManager = null!;

UotanToolbox/Common/PatchHelper/KernelSUPatch.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using UotanToolbox.Common.PatchHelper.KernelSUPatcher;
56

67
namespace UotanToolbox.Common.PatchHelper
78
{
@@ -42,14 +43,32 @@ public static async Task<string> LKM_Patch(PatchInfo zipInfo, BootInfo bootInfo)
4243
{
4344
throw new Exception("unsupported arch" + bootInfo.Arch);
4445
}
45-
File.Copy(Path.Combine(zipInfo.TempPath, "kernelsu.ko"), Path.Combine(bootInfo.TempPath, "kernelsu.ko"), true);
46-
string archSubfolder = bootInfo.Arch switch
46+
string[] ksuFiles = Directory.GetFiles(zipInfo.TempPath, "*libksud.so", SearchOption.AllDirectories);
47+
if (ksuFiles.Length == 0)
4748
{
48-
"aarch64" => "arm64-v8a",
49-
"X86-64" => "x86_64",
50-
_ => throw new ArgumentException($"{GetTranslation("Basicflash_UnknowArch")}{bootInfo.Arch}")
51-
};
52-
File.Copy(Path.Combine(Global.bin_path, "ksud", archSubfolder, "init"), Path.Combine(bootInfo.TempPath, "init"));
49+
throw new Exception("Cannot find libksud.so");
50+
}
51+
var ksudinfo = Libksud.LoadFromFile(ksuFiles[0]);
52+
string kmi = bootInfo.KMI;
53+
if (!string.IsNullOrEmpty(Global.KSU_KMI))
54+
{
55+
kmi = Global.KSU_KMI;
56+
}
57+
var assets = ksudinfo.GetAssets();
58+
var kmiAsset = assets.FirstOrDefault(a => a.Name == $"{kmi}_kernelsu.ko");
59+
if (kmiAsset == null)
60+
{
61+
throw new Exception($"Cannot find kernelsu.ko for KMI: {kmi}");
62+
}
63+
kmiAsset.Export(Path.Combine(bootInfo.TempPath, "kernelsu.ko"));
64+
65+
var ksuinitAsset = assets.FirstOrDefault(a => a.Name == "ksuinit");
66+
if (ksuinitAsset == null)
67+
{
68+
throw new Exception("Cannot find ksuinit in ksud assets");
69+
}
70+
ksuinitAsset.Export(Path.Combine(bootInfo.TempPath, "ksuinit"));
71+
5372
(string mb_output, int exitcode) = await CallExternalProgram.MagiskBoot($"cpio ramdisk.cpio \"cp init init.real\" \"add 0755 ksuinit init\" \"add 0755 kernelsu.ko kernelsu.ko\"", bootInfo.TempPath);
5473
if (exitcode != 0)
5574
{

0 commit comments

Comments
 (0)