|
2 | 2 | using System.IO; |
3 | 3 | using System.Linq; |
4 | 4 | using System.Threading.Tasks; |
| 5 | +using UotanToolbox.Common.PatchHelper.KernelSUPatcher; |
5 | 6 |
|
6 | 7 | namespace UotanToolbox.Common.PatchHelper |
7 | 8 | { |
@@ -42,14 +43,32 @@ public static async Task<string> LKM_Patch(PatchInfo zipInfo, BootInfo bootInfo) |
42 | 43 | { |
43 | 44 | throw new Exception("unsupported arch" + bootInfo.Arch); |
44 | 45 | } |
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) |
47 | 48 | { |
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 | + |
53 | 72 | (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); |
54 | 73 | if (exitcode != 0) |
55 | 74 | { |
|
0 commit comments