diff --git a/Cargo.lock b/Cargo.lock index 4a71d8dafbd9..7068f4acf62f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,6 +41,23 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "android-bootimg" +version = "0.1.0" +source = "git+https://github.com/5ec1cff/android_bootimg?rev=ae9c67a69cdcb1fdbdce523a09bcdd3b085a210b#ae9c67a69cdcb1fdbdce523a09bcdd3b085a210b" +dependencies = [ + "anyhow", + "bytemuck", + "bzip2", + "flate2", + "itertools 0.14.0", + "lz4", + "lzma-rust2 0.15.7", + "num-traits", + "paste", + "zopfli", +] + [[package]] name = "android-properties" version = "0.2.2" @@ -146,13 +163,19 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "bindgen" -version = "0.71.1" +version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ - "bitflags 2.11.0", + "bitflags 2.11.1", "cexpr", "clang-sys", "itertools 0.13.0", @@ -174,9 +197,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "block-buffer" @@ -187,6 +210,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +dependencies = [ + "hybrid-array", +] + [[package]] name = "bstr" version = "1.12.1" @@ -203,6 +235,12 @@ version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +[[package]] +name = "bytemuck" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" + [[package]] name = "byteorder" version = "1.5.0" @@ -215,11 +253,20 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +[[package]] +name = "bzip2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c" +dependencies = [ + "libbz2-rs-sys", +] + [[package]] name = "cc" -version = "1.2.58" +version = "1.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" dependencies = [ "find-msvc-tools", "jobserver", @@ -279,9 +326,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" dependencies = [ "clap_builder", "clap_derive", @@ -301,9 +348,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" dependencies = [ "heck", "proc-macro2", @@ -323,13 +370,20 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "const_format" -version = "0.2.35" +version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7faa7469a93a566e9ccc1c73fe783b4a65c274c5ace346038dca9c39fe0030ad" +checksum = "4481a617ad9a412be3b97c5d403fef8ed023103368908b9c50af598ff467cc1e" dependencies = [ "const_format_proc_macros", + "konst", ] [[package]] @@ -349,15 +403,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "core2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" -dependencies = [ - "memchr", -] - [[package]] name = "cpufeatures" version = "0.2.17" @@ -376,6 +421,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" + [[package]] name = "crc32fast" version = "1.5.0" @@ -451,11 +511,20 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710" +dependencies = [ + "hybrid-array", +] + [[package]] name = "dary_heap" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06d2e3287df1c007e74221c49ca10a95d557349e54b3a75dc2fb14712c751f04" +checksum = "8b1e3a325bc115f096c8b77bbf027a7c2592230e70be2d985be950d3d5e60ebe" [[package]] name = "deflate64" @@ -489,8 +558,19 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.0", + "const-oid", + "crypto-common 0.2.1", ] [[package]] @@ -586,9 +666,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" [[package]] name = "find-msvc-tools" @@ -602,6 +682,7 @@ version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" dependencies = [ + "crc32fast", "miniz_oxide", "zlib-rs", ] @@ -618,6 +699,30 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -713,6 +818,12 @@ dependencies = [ "foldhash 0.2.0", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + [[package]] name = "heck" version = "0.5.0" @@ -734,6 +845,15 @@ dependencies = [ "libm", ] +[[package]] +name = "hybrid-array" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da" +dependencies = [ + "typenum", +] + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -782,9 +902,9 @@ dependencies = [ [[package]] name = "include-flate" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a05fb00d9abc625268e0573a519506b264a7d6965de09bac13201bfb44e723d" +checksum = "23e233413926ef735f7d87024466cfda5a4b87467730846bd82ea7d504121347" dependencies = [ "include-flate-codegen", "include-flate-compress", @@ -792,9 +912,9 @@ dependencies = [ [[package]] name = "include-flate-codegen" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92c3c319a7527668538a8530c541e74e881e94c4f41e1425622d0a41c16468af" +checksum = "5e7148f24ef8922cc0e5574ebb908729ccdd3a110c440a45165733fedadd9969" dependencies = [ "include-flate-compress", "proc-macro-error2", @@ -805,9 +925,9 @@ dependencies = [ [[package]] name = "include-flate-compress" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed0bd9ea81b94169d61c5a397e9faef02153d3711fc62d3270bcde3ac85380d9" +checksum = "74783a9ed407e844e99d5e7a57bd650acbfa124cf6e97ffd790ba59d8ab8e7ff" dependencies = [ "libflate", "zstd", @@ -815,12 +935,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.16.1", + "hashbrown 0.17.1", "serde", "serde_core", ] @@ -886,10 +1006,12 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.91" +version = "0.3.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] @@ -913,14 +1035,31 @@ dependencies = [ "log", ] +[[package]] +name = "konst" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128133ed7824fcd73d6e7b17957c5eb7bacb885649bd8c69708b2331a10bcefb" +dependencies = [ + "konst_macro_rules", +] + +[[package]] +name = "konst_macro_rules" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" + [[package]] name = "ksud" version = "0.1.0" dependencies = [ "adb_client", + "android-bootimg", "android-properties", "android_logger", "anyhow", + "base16ct", "bindgen", "chrono", "clap", @@ -937,6 +1076,7 @@ dependencies = [ "ksuinit", "libc", "log", + "memmap2", "nom 8.0.0", "prop-rs-android", "regex-lite", @@ -976,33 +1116,39 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" +[[package]] +name = "libbz2-rs-sys" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a6a8c165077efc8f3a971534c50ea6a1a18b329ef4a66e897a7e3a1494565f" + [[package]] name = "libc" -version = "0.2.183" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "libflate" -version = "2.2.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3248b8d211bd23a104a42d81b4fa8bb8ac4a3b75e7a43d85d2c9ccb6179cd74" +checksum = "cd96e993e5f3368b0cb8497dae6c860c22af8ff18388c61c6c0b86c58d86b5df" dependencies = [ "adler32", - "core2", "crc32fast", "dary_heap", "libflate_lz77", + "no_std_io2", ] [[package]] name = "libflate_lz77" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a599cb10a9cd92b1300debcef28da8f70b935ec937f44fcd1b70a7c986a11c5c" +checksum = "ff7a10e427698aef6eef269482776debfef63384d30f13aad39a1a95e0e098fd" dependencies = [ - "core2", "hashbrown 0.16.1", + "no_std_io2", "rle-decode-fast", ] @@ -1040,6 +1186,35 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lz4" +version = "1.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20b523e860d03443e98350ceaac5e71c6ba89aea7d960769ec3ce37f4de5af4" +dependencies = [ + "lz4-sys", +] + +[[package]] +name = "lz4-sys" +version = "1.11.1+lz4-1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bd8c0d6c6ed0cd30b3652886bb8711dc4bb01d637a68105a3d5158039b418e6" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "lzma-rust2" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1670343e58806300d87950e3401e820b519b9384281bbabfb15e3636689ffd69" +dependencies = [ + "crc", + "sha2", +] + [[package]] name = "lzma-rust2" version = "0.16.2" @@ -1080,6 +1255,15 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "no_std_io2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418abd1b6d34fbf6cae440dc874771b0525a604428704c76e48b29a5e67b8003" +dependencies = [ + "memchr", +] + [[package]] name = "nom" version = "7.1.3" @@ -1148,6 +1332,12 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -1156,9 +1346,9 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkg-config" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" [[package]] name = "plain" @@ -1287,9 +1477,9 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] name = "rand" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", "getrandom 0.4.2", @@ -1298,15 +1488,15 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" [[package]] name = "rayon" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" dependencies = [ "either", "rayon-core", @@ -1400,16 +1590,16 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" [[package]] name = "rustix" version = "0.38.34" source = "git+https://github.com/Kernel-SU/rustix.git?rev=4a53fbc#4a53fbc7cb7a07cabe87125cc21dbc27db316259" dependencies = [ - "bitflags 2.11.0", + "bitflags 2.11.1", "errno 0.3.14", "libc", "linux-raw-sys 0.4.15", @@ -1422,7 +1612,7 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ - "bitflags 2.11.0", + "bitflags 2.11.1", "errno 0.3.14", "libc", "linux-raw-sys 0.12.1", @@ -1466,9 +1656,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" [[package]] name = "serde" @@ -1514,13 +1704,13 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" dependencies = [ "cfg-if", - "cpufeatures 0.2.17", - "digest", + "cpufeatures 0.3.0", + "digest 0.11.3", ] [[package]] @@ -1531,7 +1721,7 @@ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures 0.2.17", - "digest", + "digest 0.10.7", ] [[package]] @@ -1559,6 +1749,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214" +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "strsim" version = "0.11.1" @@ -1637,9 +1833,9 @@ checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" [[package]] name = "tokio" -version = "1.50.0" +version = "1.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" dependencies = [ "bytes", "pin-project-lite", @@ -1647,18 +1843,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "1.1.0+spec-1.1.0" +version = "1.1.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97251a7c317e03ad83774a8752a7e81fb6067740609f75ea2b585b569a59198f" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" dependencies = [ "serde_core", ] [[package]] name = "toml_edit" -version = "0.25.8+spec-1.1.0" +version = "0.25.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16bff38f1d86c47f9ff0647e6838d7bb362522bdf44006c7068c2b1e606f1f3c" +checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b" dependencies = [ "indexmap", "toml_datetime", @@ -1668,9 +1864,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.0+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2334f11ee363607eb04df9b8fc8a13ca1715a72ba8662a26ac285c98aabb4011" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" dependencies = [ "winnow", ] @@ -1683,9 +1879,9 @@ checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e" [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" [[package]] name = "unicode-ident" @@ -1729,11 +1925,11 @@ dependencies = [ [[package]] name = "wasip2" -version = "1.0.2+wasi-0.2.9" +version = "1.0.3+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.57.1", ] [[package]] @@ -1742,14 +1938,14 @@ version = "0.4.0+wasi-0.3.0-rc-2026-01-06" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.51.0", ] [[package]] name = "wasm-bindgen" -version = "0.2.114" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" dependencies = [ "cfg-if", "once_cell", @@ -1760,9 +1956,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.114" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1770,9 +1966,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.114" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" dependencies = [ "bumpalo", "proc-macro2", @@ -1783,9 +1979,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.114" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" dependencies = [ "unicode-ident", ] @@ -1818,7 +2014,7 @@ version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ - "bitflags 2.11.0", + "bitflags 2.11.1", "hashbrown 0.15.5", "indexmap", "semver", @@ -2081,9 +2277,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winnow" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8" +checksum = "2ee1708bef14716a11bae175f579062d4554d95be2c6829f518df847b7b3fdd0" dependencies = [ "memchr", ] @@ -2097,6 +2293,12 @@ dependencies = [ "wit-bindgen-rust-macro", ] +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + [[package]] name = "wit-bindgen-core" version = "0.51.0" @@ -2146,7 +2348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" dependencies = [ "anyhow", - "bitflags 2.11.0", + "bitflags 2.11.1", "indexmap", "log", "serde", @@ -2178,15 +2380,15 @@ dependencies = [ [[package]] name = "zip" -version = "8.4.0" +version = "8.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7756d0206d058333667493c4014f545f4b9603c4330ccd6d9b3f86dcab59f7d9" +checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b" dependencies = [ "crc32fast", "deflate64", "flate2", "indexmap", - "lzma-rust2", + "lzma-rust2 0.16.2", "memchr", "time", "typed-path", diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt index 02805a734aa5..52343d65c3fb 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt @@ -118,9 +118,8 @@ suspend fun getFeaturePersistValue(feature: String): Long? = withContext(Dispatc fun install() { val start = SystemClock.elapsedRealtime() - val magiskboot = File(ksuApp.applicationInfo.nativeLibraryDir, "libmagiskboot.so").absolutePath val libadbroot = File(ksuApp.applicationInfo.nativeLibraryDir, "libadbroot.so").absolutePath - val result = execKsud("install --magiskboot $magiskboot --libadbroot $libadbroot", true) + val result = execKsud("install --libadbroot $libadbroot", true) Log.w(TAG, "install result: $result, cost: ${SystemClock.elapsedRealtime() - start}ms") } @@ -241,16 +240,14 @@ fun runModuleAction( fun restoreBoot( onStdout: (String) -> Unit, onStderr: (String) -> Unit ): FlashResult { - val magiskboot = File(ksuApp.applicationInfo.nativeLibraryDir, "libmagiskboot.so") - val result = flashWithIO("${getKsuDaemonPath()} boot-restore -f --magiskboot $magiskboot", onStdout, onStderr) + val result = flashWithIO("${getKsuDaemonPath()} boot-restore -f", onStdout, onStderr) return FlashResult(result) } fun uninstallPermanently( onStdout: (String) -> Unit, onStderr: (String) -> Unit ): FlashResult { - val magiskboot = File(ksuApp.applicationInfo.nativeLibraryDir, "libmagiskboot.so") - val result = flashWithIO("${getKsuDaemonPath()} uninstall --magiskboot $magiskboot --package-name ${BuildConfig.APPLICATION_ID}", onStdout, onStderr) + val result = flashWithIO("${getKsuDaemonPath()} uninstall --package-name ${BuildConfig.APPLICATION_ID}", onStdout, onStderr) return FlashResult(result) } @@ -289,8 +286,7 @@ fun installBoot( } } - val magiskboot = File(ksuApp.applicationInfo.nativeLibraryDir, "libmagiskboot.so") - var cmd = "boot-patch --magiskboot ${magiskboot.absolutePath}" + var cmd = "boot-patch" cmd += if (bootFile == null) { // no boot.img, use -f to flash diff --git a/manager/app/src/main/jniLibs/arm64-v8a/libmagiskboot.so b/manager/app/src/main/jniLibs/arm64-v8a/libmagiskboot.so deleted file mode 100644 index ce7478d6bcc1..000000000000 Binary files a/manager/app/src/main/jniLibs/arm64-v8a/libmagiskboot.so and /dev/null differ diff --git a/userspace/ksud/Cargo.toml b/userspace/ksud/Cargo.toml index 7e9db25d8b75..014bb3cdbfe7 100644 --- a/userspace/ksud/Cargo.toml +++ b/userspace/ksud/Cargo.toml @@ -16,11 +16,14 @@ rust-embed = { version = "8", features = [ "compression", # must clean build after updating binaries ] } which = "8" -sha1 = "0.10" +sha1 = "0.11" +base16ct = { version = "0.2", features = ["alloc"] } sha256 = "1" tempfile = "3" chrono = "0.4" regex-lite = "0.1" +memmap2 = "0.9" +android-bootimg = { git = "https://github.com/5ec1cff/android_bootimg", rev = "ae9c67a69cdcb1fdbdce523a09bcdd3b085a210b" } [target.'cfg(target_os = "android")'.dependencies] rustix = { version = "1", features = [ @@ -56,4 +59,4 @@ adb_client = { git = "https://github.com/Kernel-SU/adb_client" } prop-rs-android = { git = "https://github.com/Kernel-SU/ksu_props" } [build-dependencies] -bindgen = "0.71.0" +bindgen = "0.72" diff --git a/userspace/ksud/src/assets.rs b/userspace/ksud/src/assets.rs index 8218409ce42d..e1b806b02c43 100644 --- a/userspace/ksud/src/assets.rs +++ b/userspace/ksud/src/assets.rs @@ -1,6 +1,5 @@ use anyhow::Result; use rust_embed::RustEmbed; -use std::path::Path; #[cfg(target_os = "android")] mod android { @@ -47,15 +46,15 @@ struct Asset; #[folder = "bin/aarch64"] struct Asset; +#[allow(unused)] pub fn get_asset_data(name: &str) -> Result> { let asset = Asset::get(name).ok_or_else(|| anyhow::anyhow!("asset not found: {name}"))?; Ok(asset.data) } -pub fn copy_assets_to_file(name: &str, dst: impl AsRef) -> Result<()> { - let data = get_asset_data(name)?; - std::fs::write(dst, &*data)?; - Ok(()) +pub fn get_asset(name: &str) -> Result>> { + let asset = Asset::get(name).ok_or_else(|| anyhow::anyhow!("asset not found: {name}"))?; + Ok(Box::new(asset.data)) } pub fn list_supported_kmi() -> std::vec::Vec { diff --git a/userspace/ksud/src/boot_patch.rs b/userspace/ksud/src/boot_patch.rs index 8b24b31c6676..c83c33b2fdf3 100644 --- a/userspace/ksud/src/boot_patch.rs +++ b/userspace/ksud/src/boot_patch.rs @@ -1,31 +1,36 @@ #![allow(clippy::ref_option, clippy::needless_pass_by_value)] use std::fs::File; -use std::io::Write; -#[cfg(unix)] -use std::os::unix::fs::PermissionsExt; +use std::io::{Cursor, Seek, SeekFrom}; use std::path::Path; use std::path::PathBuf; -use std::process::Command; -use std::process::Stdio; +use android_bootimg::cpio::{Cpio, CpioEntry}; +use android_bootimg::parser::{BootImage, BootImageVersion, RamdiskImage}; +use android_bootimg::patcher::BootImagePatchOption; use anyhow::Context; use anyhow::Result; +use anyhow::anyhow; use anyhow::bail; use anyhow::ensure; +use memmap2::{Mmap, MmapOptions}; use regex_lite::Regex; -use which::which; use crate::assets; #[cfg(target_os = "android")] mod android { - use super::{PermissionsExt, Result, do_cpio_cmd}; + use super::Result; pub(super) use crate::defs::{BACKUP_FILENAME, KSU_BACKUP_DIR, KSU_BACKUP_FILE_PREFIX}; + use android_bootimg::cpio::{Cpio, CpioEntry}; use anyhow::{Context, anyhow, bail, ensure}; use regex_lite::Regex; + use std::fs::OpenOptions; + use std::io::Write; + use std::os::fd::AsRawFd; + use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; - use std::process::{Command, Stdio}; + use std::process::Command; use crate::utils; @@ -112,29 +117,33 @@ mod android { } let result = hasher.finalize(); - Ok(format!("{result:x}")) + Ok(base16ct::lower::encode_string(&result)) } - pub(super) fn do_backup( - magiskboot: &Path, - workdir: &Path, - cpio_path: &Path, - image: &Path, - ) -> Result<()> { + pub(super) fn do_backup(cpio: &mut Cpio, image: &Path) -> Result<()> { let sha1 = calculate_sha1(image)?; let filename = format!("{KSU_BACKUP_FILE_PREFIX}{sha1}"); println!("- Backup stock boot image"); - // magiskboot cpio ramdisk.cpio 'add 0755 $BACKUP_FILENAME' let target = format!("{KSU_BACKUP_DIR}{filename}"); - std::fs::copy(image, &target).with_context(|| format!("backup to {target}"))?; - std::fs::write(workdir.join(BACKUP_FILENAME), sha1.as_bytes()).context("write sha1")?; - do_cpio_cmd( - magiskboot, - workdir, - cpio_path, - &format!("add 0755 {BACKUP_FILENAME} {BACKUP_FILENAME}"), - )?; + let mut target_file = OpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open(&target)?; + let mut source = OpenOptions::new() + .create(false) + .truncate(false) + .read(true) + .write(false) + .open(image)?; + + // Use io::copy instead of fs::copy to allow copy block device + std::io::copy(&mut source, &mut target_file) + .with_context(|| format!("failed to backup to {target}"))?; + + let backup_file = CpioEntry::regular(0o755, Box::new(sha1)); + cpio.add(BACKUP_FILENAME, backup_file)?; println!("- Stock image has been backup to"); println!("- {target}"); Ok(()) @@ -162,16 +171,22 @@ mod android { Ok(()) } - pub(super) fn flash_boot(bootdevice: &Option, new_boot: &PathBuf) -> Result<()> { - let Some(bootdevice) = bootdevice else { - bail!("boot device not found") - }; - let status = Command::new("blockdev") - .arg("--setrw") - .arg(bootdevice) - .status()?; - ensure!(status.success(), "set boot device rw failed"); - dd(new_boot, bootdevice).context("flash boot failed")?; + pub(super) fn flash_partition(partition: &str, data: &[u8]) -> Result<()> { + let mut blk = std::fs::OpenOptions::new() + .write(true) + .truncate(false) + .create(false) + .open(partition) + .with_context(|| format!("open {partition}"))?; + unsafe { + const BLKROSET: i32 = libc::_IO(0x12, 93); + let mut val: libc::c_int = 0; + if libc::ioctl(blk.as_raw_fd(), BLKROSET, &raw mut val) != 0 { + bail!("Failed to set rw for {partition}: {}", *libc::__errno()); + } + } + blk.write_all(data).context("flash boot failed")?; + blk.sync_all().context("sync boot failed")?; Ok(()) } @@ -213,7 +228,6 @@ mod android { slot_suffix } - #[cfg(target_os = "android")] pub fn list_available_partitions() -> Vec { let slot_suffix = get_slot_suffix(false); let candidates = vec!["boot", "init_boot", "vendor_boot"]; @@ -224,7 +238,17 @@ mod android { .collect() } - #[cfg(target_os = "android")] + pub(super) fn auto_boot_partition_path( + kmi: &str, + ota: bool, + is_replace_kernel: bool, + partition: &Option, + ) -> PathBuf { + let slot_suffix = get_slot_suffix(ota); + let name = choose_boot_partition(kmi, is_replace_kernel, partition); + PathBuf::from(format!("/dev/block/by-name/{name}{slot_suffix}")) + } + pub(super) fn post_ota() -> Result<()> { use crate::assets::BOOTCTL_PATH; use crate::defs::ADB_DIR; @@ -258,188 +282,109 @@ rm -f /data/adb/post-fs-data.d/post_ota.sh ); std::fs::write(&post_ota_sh, sh_content)?; - #[cfg(unix)] std::fs::set_permissions(post_ota_sh, std::fs::Permissions::from_mode(0o755))?; Ok(()) } - - pub(super) fn dd, Q: AsRef>(ifile: P, ofile: Q) -> Result<()> { - let status = Command::new("dd") - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg(format!("if={}", ifile.as_ref().display())) - .arg(format!("of={}", ofile.as_ref().display())) - .status()?; - ensure!( - status.success(), - "dd if={} of={} failed", - ifile.as_ref().display(), - ofile.as_ref().display() - ); - Ok(()) - } } #[cfg(target_os = "android")] pub use android::*; -fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result { - use std::fs::{File, copy}; - use std::io::{BufReader, Read}; - let kernel_path = workdir.join("kernel"); - copy(kernel, &kernel_path).context("Failed to copy kernel")?; - - let file = File::open(&kernel_path).context("Failed to open kernel file")?; - let mut reader = BufReader::new(file); - let mut buffer = Vec::new(); - reader - .read_to_end(&mut buffer) - .context("Failed to read kernel file")?; - - let printable_strings: Vec<&str> = buffer - .split(|&b| b == 0) - .filter_map(|slice| std::str::from_utf8(slice).ok()) - .filter(|s| s.chars().all(|c| c.is_ascii_graphic() || c == ' ')) - .collect(); - - let re = - Regex::new(r"(?:.* )?(\d+\.\d+)(?:\S+)?(android\d+)").context("Failed to compile regex")?; - for s in printable_strings { - if let Some(caps) = re.captures(s) - && let (Some(kernel_version), Some(android_version)) = (caps.get(1), caps.get(2)) - { - let kmi = format!("{}-{}", android_version.as_str(), kernel_version.as_str()); - return Ok(kmi); - } - } - println!("- Failed to get KMI version"); - bail!("Try to choose LKM manually") +fn map_file(file: &Path) -> Result { + let mut f = File::open(file).with_context(|| format!("open {}", file.display()))?; + let len = f + .seek(SeekFrom::End(0)) + .with_context(|| format!("seek end of {}", file.display()))? as usize; + let mmap = unsafe { MmapOptions::new().len(len).map(&f)? }; + Ok(mmap) } -fn parse_kmi_from_boot(magiskboot: &Path, image: &PathBuf, workdir: &Path) -> Result { - let image_path = workdir.join("image"); - - std::fs::copy(image, &image_path).context("Failed to copy image")?; - - let status = Command::new(magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("unpack") - .arg(&image_path) - .status() - .context("Failed to execute magiskboot command")?; - - if !status.success() { - bail!("magiskboot unpack failed with status: {status:?}"); - } - - parse_kmi_from_kernel(&image_path, workdir) -} - -fn do_cpio_cmd(magiskboot: &Path, workdir: &Path, cpio_path: &Path, cmd: &str) -> Result<()> { - let status = Command::new(magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("cpio") - .arg(cpio_path) - .arg(cmd) - .status()?; - ensure!(status.success(), "magiskboot cpio {cmd} failed"); - Ok(()) -} - -fn is_magisk_patched(magiskboot: &Path, workdir: &Path, cpio_path: &Path) -> Result { - let status = Command::new(magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("cpio") - .arg(cpio_path) - .arg("test") - .status()?; - // 0: stock, 1: magisk - Ok(status.code() == Some(1)) +fn parse_kmi(buffer: &[u8]) -> Result { + let re = Regex::new(r"(\d+\.\d+)(?:\S+)?(android\d+)").context("Failed to compile regex")?; + buffer + .windows(4) + .enumerate() + .filter(|(_, x)| { + x[1] == b'.' + && x[2].is_ascii_digit() + && match x[0] { + b'5' => x[3].is_ascii_digit(), + b'6'..=b'9' => true, + _ => false, + } + }) + .find_map(|(i, _)| { + let a = &buffer[i..buffer.len().min(i + 100)]; + if let Some(e) = a.iter().position(|c| *c == 0) + && let Ok(s) = std::str::from_utf8(&a[..e]) + && let Some(caps) = re.captures(s) + && let (Some(kernel_version), Some(android_version)) = (caps.get(1), caps.get(2)) + { + Some(format!( + "{}-{}", + android_version.as_str(), + kernel_version.as_str() + )) + } else { + None + } + }) + .ok_or_else(|| { + println!("- Failed to get KMI version"); + anyhow!("Try to choose LKM manually") + }) } -fn is_kernelsu_patched(magiskboot: &Path, workdir: &Path, cpio_path: &Path) -> Result { - let status = Command::new(magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("cpio") - .arg(cpio_path) - .arg("exists kernelsu.ko") - .status()?; - - Ok(status.success()) +fn parse_kmi_from_kernel(kernel: &Path) -> Result { + let data = std::fs::read(kernel).context("Failed to read kernel file")?; + parse_kmi(&data) } -fn find_magiskboot(magiskboot_path: Option, workdir: &Path) -> Result { - let magiskboot = { - if which("magiskboot").is_ok() { - #[cfg(target_os = "android")] - let _ = assets::ensure_binaries(true); - "magiskboot".into() - } else { - // magiskboot is not in $PATH, use builtin or specified one - let magiskboot = if let Some(magiskboot_path) = magiskboot_path { - std::fs::canonicalize(magiskboot_path)? - } else { - let magiskboot_path = workdir.join("magiskboot"); - assets::copy_assets_to_file("magiskboot", &magiskboot_path) - .context("copy magiskboot failed")?; - magiskboot_path - }; - ensure!(magiskboot.exists(), "{} is not exist", magiskboot.display()); - #[cfg(unix)] - let _ = std::fs::set_permissions(&magiskboot, std::fs::Permissions::from_mode(0o755)); - magiskboot - } - }; - Ok(magiskboot) +fn parse_kmi_from_boot(image: &Path) -> Result { + let data = map_file(image)?; + let boot = BootImage::parse(&data)?; + if let Some(kernel) = boot.get_blocks().get_kernel() { + let mut output = Vec::::new(); + kernel.dump(&mut output, false)?; + parse_kmi(&output) + } else { + bail!("no kernel found in boot image") + } } -fn find_boot_image( - image: &Option, - kmi: &str, - ota: bool, - is_replace_kernel: bool, - workdir: &Path, - partition: &Option, -) -> Result<(PathBuf, Option)> { - let bootimage; - let mut bootdevice = None; - if let Some(ref image) = *image { - ensure!(image.exists(), "boot image not found"); - bootimage = std::fs::canonicalize(image)?; +/// For vendor boot, prefer the `init_boot` ramdisk entry over the one with empty name, +/// matching the original magiskboot lookup order (init_boot.cpio before ramdisk.cpio). +fn extract_ramdisk(ramdisk_image: &RamdiskImage) -> Result<(Cpio, Option)> { + if ramdisk_image.is_vendor_ramdisk() { + let (pos, target) = ramdisk_image + .iter_vendor_ramdisk() + .enumerate() + .find(|e| e.1.get_name_raw() == b"init_boot") + .or_else(|| { + ramdisk_image + .iter_vendor_ramdisk() + .enumerate() + .find(|e| e.1.get_name_raw() == b"") + }) + .ok_or_else(|| anyhow!("No suitable vendor ramdisk entry found"))?; + let mut buf = Vec::::new(); + target.dump(&mut buf, false)?; + Ok((Cpio::load_from_data(&buf)?, Some(pos))) } else { - #[cfg(not(target_os = "android"))] - { - println!("- Current OS is not android, refusing auto bootimage/bootdevice detection"); - bail!("Please specify a boot image"); - } - - #[cfg(target_os = "android")] - { - let slot_suffix = get_slot_suffix(ota); - let boot_partition_name = choose_boot_partition(kmi, is_replace_kernel, partition); - let boot_partition = format!("/dev/block/by-name/{boot_partition_name}{slot_suffix}"); - - println!("- Bootdevice: {boot_partition}"); - let tmp_boot_path = workdir.join("boot.img"); - - dd(&boot_partition, &tmp_boot_path)?; - - ensure!(tmp_boot_path.exists(), "boot image not found"); + let mut buf = Vec::::new(); + ramdisk_image.dump(&mut buf, false)?; + Ok((Cpio::load_from_data(&buf)?, None)) + } +} - bootimage = tmp_boot_path; - bootdevice = Some(boot_partition); - } +fn enforce_bootimage_version(boot: &BootImage<'_>) -> Result<()> { + if let BootImageVersion::Android(ver) = boot.get_header().get_version() + && ver < 3 + { + bail!("bootimage version {ver} is not supported!") } - Ok((bootimage, bootdevice)) + Ok(()) } #[allow(clippy::struct_excessive_bools)] @@ -483,10 +428,6 @@ pub struct BootPatchArgs { #[arg(short, long, default_value = None)] pub out: Option, - /// magiskboot path, if not specified, will search from $PATH - #[arg(long, default_value = None)] - pub magiskboot: Option, - /// KMI version, if specified, will use the specified KMI #[arg(long, default_value = None)] pub kmi: Option, @@ -536,7 +477,6 @@ pub fn patch(args: BootPatchArgs) -> Result<()> { kernel, module: kmod, out, - magiskboot: magiskboot_path, kmi, out_name, cmdline, @@ -554,6 +494,7 @@ pub fn patch(args: BootPatchArgs) -> Result<()> { println!(include_str!("banner")); + #[cfg(target_os = "android")] let patch_file = image.is_some(); #[cfg(target_os = "android")] @@ -570,15 +511,6 @@ pub fn patch(args: BootPatchArgs) -> Result<()> { ); } - let tmpdir = tempfile::Builder::new() - .prefix("KernelSU") - .tempdir() - .context("create temp dir failed")?; - let workdir = tmpdir.path(); - - // extract magiskboot - let magiskboot = find_magiskboot(magiskboot_path, workdir)?; - let kmi = kmi.map_or_else( || -> Result<_> { if kmod.is_some() { @@ -598,13 +530,13 @@ pub fn patch(args: BootPatchArgs) -> Result<()> { "- Trying to auto detect KMI version for {}", image_path.display() ); - parse_kmi_from_boot(&magiskboot, image_path, tmpdir.path())? + parse_kmi_from_boot(image_path)? } else if let Some(kernel_path) = &kernel { println!( "- Trying to auto detect KMI version for {}", kernel_path.display() ); - parse_kmi_from_kernel(kernel_path, tmpdir.path())? + parse_kmi_from_kernel(kernel_path)? } else { String::new() }) @@ -612,185 +544,162 @@ pub fn patch(args: BootPatchArgs) -> Result<()> { Ok, )?; - #[cfg(target_os = "android")] - let (bootimage, bootdevice) = - find_boot_image(&image, &kmi, ota, is_replace_kernel, workdir, &partition)?; - - #[cfg(not(target_os = "android"))] - let (bootimage, _) = - find_boot_image(&image, &kmi, false, is_replace_kernel, workdir, &None)?; + let boot_image_file = if let Some(image) = image { + ensure!(image.exists(), "boot image not found"); + std::fs::canonicalize(image)? + } else { + #[cfg(target_os = "android")] + { + auto_boot_partition_path(&kmi, ota, is_replace_kernel, &partition) + } + #[cfg(not(target_os = "android"))] + { + bail!("Please specify a boot image"); + } + }; - let bootimage = bootimage.as_path(); + #[cfg(target_os = "android")] + println!("- Bootdevice: {}", boot_image_file.display()); - // try extract magiskboot/bootctl + // try extract bootctl/busybox #[cfg(target_os = "android")] let _ = assets::ensure_binaries(false); - if let Some(kernel) = kernel { - std::fs::copy(kernel, workdir.join("kernel")).context("copy kernel from failed")?; - } - println!("- Preparing assets"); + println!("- Unpacking boot image"); + let boot_image_data = map_file(&boot_image_file)?; + let boot_image = BootImage::parse(&boot_image_data)?; + enforce_bootimage_version(&boot_image)?; - let kmod_file = workdir.join("kernelsu.ko"); - if let Some(kmod) = kmod { - std::fs::copy(kmod, kmod_file).context("copy kernel module failed")?; - } else if !no_install { - // If kmod is not specified, extract from assets - println!("- KMI: {kmi}"); - let name = format!("{kmi}_kernelsu.ko"); - assets::copy_assets_to_file(&name, kmod_file) - .with_context(|| format!("Failed to copy {name}"))?; + let mut patcher = BootImagePatchOption::new(&boot_image); + + if let Some(cmdline_value) = &cmdline { + patcher.override_cmdline(cmdline_value.as_bytes()); + println!("- Set cmdline to: {cmdline_value}"); } - let init_file = workdir.join("init"); - if let Some(init) = init { - std::fs::copy(init, init_file).context("copy init failed")?; - } else if !no_install { - assets::copy_assets_to_file("ksuinit", init_file).context("copy ksuinit failed")?; + if let Some(kernel_path) = kernel { + println!("- Adding Kernel"); + let kernel_data = map_file(&kernel_path)?; + patcher.replace_kernel(Box::new(Cursor::new(kernel_data)), false); } - println!("- Unpacking boot image"); - let status = Command::new(&magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("unpack") - .arg(bootimage) - .status()?; - ensure!(status.success(), "magiskboot unpack failed"); + let kernelsu_ko: Box> = if no_install { + Box::new(Vec::::new()) + } else if let Some(kmod_path) = kmod { + Box::new(map_file(&kmod_path)?) + } else { + println!("- KMI: {kmi}"); + let name = format!("{kmi}_kernelsu.ko"); + assets::get_asset(&name).with_context(|| format!("Failed to load {name}"))? + }; - if let Some(ref cmdline_value) = cmdline { - let header_path = workdir.join("header"); - std::fs::write(&header_path, format!("cmdline={cmdline_value}\n")) - .context("write header file failed")?; - println!("- Set cmdline to: {cmdline_value}"); - } + let ksu_init: Box> = if no_install { + Box::new(Vec::::new()) + } else if let Some(init_path) = init { + Box::new(map_file(&init_path)?) + } else { + assets::get_asset("ksuinit").context("Failed to load ksuinit")? + }; + + let (mut cpio, vendor_ramdisk_idx) = + if let Some(ramdisk_image) = boot_image.get_blocks().get_ramdisk() { + extract_ramdisk(ramdisk_image)? + } else { + println!("- No ramdisk, create by default"); + (Cpio::new(), None) + }; - let mut ramdisk = workdir.join("ramdisk.cpio"); - if !ramdisk.exists() { - ramdisk = workdir.join("vendor_ramdisk").join("init_boot.cpio"); - } - if !ramdisk.exists() { - ramdisk = workdir.join("vendor_ramdisk").join("ramdisk.cpio"); - } - if !ramdisk.exists() { - println!("- No ramdisk, create by default"); - ramdisk = "ramdisk.cpio".into(); - } - let ramdisk = ramdisk.as_path(); if !no_install { - let is_magisk_patched = is_magisk_patched(&magiskboot, workdir, ramdisk)?; - ensure!(!is_magisk_patched, "Cannot work with Magisk patched image"); + ensure!( + !cpio.is_magisk_patched(), + "Cannot work with Magisk patched image" + ); println!("- Adding KernelSU LKM"); - let is_kernelsu_patched = is_kernelsu_patched(&magiskboot, workdir, ramdisk)?; + let is_kernelsu_patched = cpio.exists("kernelsu.ko"); - if !is_kernelsu_patched { - // kernelsu.ko is not exist, backup init if necessary - let status = do_cpio_cmd(&magiskboot, workdir, ramdisk, "exists init"); - if status.is_ok() { - do_cpio_cmd(&magiskboot, workdir, ramdisk, "mv init init.real")?; - } + if !is_kernelsu_patched && cpio.exists("init") { + cpio.mv("init", "init.real")?; } - do_cpio_cmd(&magiskboot, workdir, ramdisk, "add 0755 init init")?; - do_cpio_cmd( - &magiskboot, - workdir, - ramdisk, - "add 0755 kernelsu.ko kernelsu.ko", - )?; + cpio.add("init", CpioEntry::regular(0o755, ksu_init))?; + cpio.add("kernelsu.ko", CpioEntry::regular(0o755, kernelsu_ko))?; #[cfg(target_os = "android")] if !is_kernelsu_patched && flash - && let Err(e) = do_backup(&magiskboot, workdir, ramdisk, bootimage) + && let Err(e) = do_backup(&mut cpio, &boot_image_file) { - println!("- Backup stock image failed: {e}"); + println!("- Backup stock image failed: {e:?}"); } } if allow_shell { println!("- Adding allow shell config"); - { - let allow_shell_file = workdir.join("ksu_allow_shell"); - File::create(allow_shell_file)?; - } - do_cpio_cmd( - &magiskboot, - workdir, - ramdisk, - "add 0644 ksu_allow_shell ksu_allow_shell", + cpio.add( + "ksu_allow_shell", + CpioEntry::regular(0o644, Box::new(Vec::::new())), )?; - } else if do_cpio_cmd(&magiskboot, workdir, ramdisk, "exists ksu_allow_shell").is_ok() { + } else if cpio.exists("ksu_allow_shell") { println!("- Removing allow shell config"); - do_cpio_cmd(&magiskboot, workdir, ramdisk, "rm ksu_allow_shell").ok(); + cpio.rm("ksu_allow_shell", false); } if enable_adbd || adb_debug_prop.is_some() { println!("- Adding adb_debug props"); - { - let force_debuggable_file = workdir.join("force_debuggable"); - File::create(force_debuggable_file)?; - } - do_cpio_cmd( - &magiskboot, - workdir, - ramdisk, - "add 0644 force_debuggable force_debuggable", + cpio.add( + "force_debuggable", + CpioEntry::regular(0o644, Box::new(Vec::::new())), )?; - { - let prop_path = workdir.join("adb_debug.prop"); - let mut prop_file = File::create(prop_path)?; - if enable_adbd { - println!("- Adding props to enable adbd"); - write!( - prop_file, - "ro.debuggable=1\nro.force.debuggable=1\nro.adb.secure=0\n" - )?; - } - if let Some(props) = adb_debug_prop { - println!("- Adding custom props"); - prop_file.write_all(props.as_bytes())?; - } + let mut prop = Vec::::new(); + if enable_adbd { + println!("- Adding props to enable adbd"); + prop.extend_from_slice( + b"ro.debuggable=1\nro.force.debuggable=1\nro.adb.secure=0\n", + ); } - do_cpio_cmd( - &magiskboot, - workdir, - ramdisk, - "add 0644 adb_debug.prop adb_debug.prop", - )?; + if let Some(extra) = adb_debug_prop { + println!("- Adding custom props"); + prop.extend_from_slice(extra.as_bytes()); + } + cpio.add("adb_debug.prop", CpioEntry::regular(0o644, Box::new(prop)))?; } else { - if do_cpio_cmd(&magiskboot, workdir, ramdisk, "exists force_debuggable").is_ok() { + if cpio.exists("force_debuggable") { println!("- Removing /force_debuggable"); - do_cpio_cmd(&magiskboot, workdir, ramdisk, "rm force_debuggable").ok(); + cpio.rm("force_debuggable", false); } - if do_cpio_cmd(&magiskboot, workdir, ramdisk, "exists adb_debug.prop").is_ok() { + if cpio.exists("adb_debug.prop") { println!("- Removing /adb_debug.prop"); - do_cpio_cmd(&magiskboot, workdir, ramdisk, "rm adb_debug.prop").ok(); + cpio.rm("adb_debug.prop", false); } } + let mut new_cpio = Vec::::new(); + cpio.dump(&mut new_cpio)?; + + if let Some(idx) = vendor_ramdisk_idx { + patcher.replace_vendor_ramdisk(idx, Box::new(Cursor::new(new_cpio)), false); + } else { + patcher.replace_ramdisk(Box::new(Cursor::new(new_cpio)), false); + } + println!("- Repacking boot image"); - // magiskboot repack boot.img - let status = Command::new(&magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("repack") - .arg(bootimage) - .status()?; - ensure!(status.success(), "magiskboot repack failed"); - let new_boot = workdir.join("new-boot.img"); + let mut new_boot_buf = Cursor::new(Vec::::new()); + patcher.patch(&mut new_boot_buf)?; + let new_boot_bytes = new_boot_buf.into_inner(); + + // Free the source mmap so the boot partition is no longer mapped read-only, + // otherwise some kernels reject the subsequent write. + drop(boot_image); + drop(boot_image_data); - // flash first, since the new_boot may be moved #[cfg(target_os = "android")] if flash { println!("- Flashing new boot image"); - flash_boot(&bootdevice, &new_boot)?; - + let bootdevice = boot_image_file.display().to_string(); + flash_partition(&bootdevice, &new_boot_bytes)?; if ota { post_ota()?; } @@ -799,19 +708,16 @@ pub fn patch(args: BootPatchArgs) -> Result<()> { #[cfg(target_os = "android")] let should_write_output = patch_file || !flash || out_name.is_some() || out.is_some(); #[cfg(not(target_os = "android"))] - let should_write_output = patch_file; + let should_write_output = true; if should_write_output { - // write patched image to output file when output is requested let output_dir = out.unwrap_or(std::env::current_dir()?); let name = out_name.unwrap_or_else(|| { let now = chrono::Utc::now(); format!("kernelsu_patched_{}.img", now.format("%Y%m%d_%H%M%S")) }); let output_image = output_dir.join(name); - if std::fs::rename(&new_boot, &output_image).is_err() { - std::fs::copy(&new_boot, &output_image).context("copy out new boot failed")?; - } + std::fs::write(&output_image, &new_boot_bytes).context("write out new boot failed")?; println!("- Output file is written to"); println!("- {}", output_image.display().to_string().trim_matches('"')); } @@ -838,10 +744,6 @@ pub struct BootRestoreArgs { #[arg(short, long, default_value = "false")] pub flash: bool, - /// magiskboot path, if not specified, will search from $PATH - #[arg(long, default_value = None)] - pub magiskboot: Option, - /// Output path. If not specified, will use current directory. /// If specified, the boot image will be written to the directory /// even if --flash is specified. @@ -869,86 +771,67 @@ pub struct BootRestoreArgs { pub fn restore(args: BootRestoreArgs) -> Result<()> { let BootRestoreArgs { boot: image, - magiskboot: magiskboot_path, out_name, out, #[cfg(target_os = "android")] flash, } = args; - let tmpdir = tempfile::Builder::new() - .prefix("KernelSU") - .tempdir() - .context("create temp dir failed")?; - let workdir = tmpdir.path(); - let magiskboot = find_magiskboot(magiskboot_path, workdir)?; - #[cfg(target_os = "android")] let kmi = get_current_kmi().unwrap_or_default(); #[cfg(target_os = "android")] - let (bootimage, bootdevice) = find_boot_image(&image, &kmi, false, false, workdir, &None)?; - #[cfg(not(target_os = "android"))] - let (bootimage, _) = find_boot_image(&image, "", false, false, workdir, &None)?; + let image_supplied = image.is_some(); - println!("- Unpacking boot image"); - let status = Command::new(&magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("unpack") - .arg(bootimage.display().to_string()) - .status()?; - ensure!(status.success(), "magiskboot unpack failed"); - - let mut ramdisk = workdir.join("ramdisk.cpio"); - if !ramdisk.exists() { - ramdisk = workdir.join("vendor_ramdisk").join("init_boot.cpio"); - } - if !ramdisk.exists() { - ramdisk = workdir.join("vendor_ramdisk").join("ramdisk.cpio"); - } - if !ramdisk.exists() { - bail!("No compatible ramdisk found.") - } - let ramdisk = ramdisk.as_path(); - let is_kernelsu_patched = is_kernelsu_patched(&magiskboot, workdir, ramdisk)?; - ensure!(is_kernelsu_patched, "boot image is not patched by KernelSU"); + let boot_image_file = if let Some(image) = image { + ensure!(image.exists(), "boot image not found"); + std::fs::canonicalize(image)? + } else { + #[cfg(target_os = "android")] + { + auto_boot_partition_path(&kmi, false, false, &None) + } + #[cfg(not(target_os = "android"))] + { + bail!("Please specify a boot image"); + } + }; #[cfg(target_os = "android")] - let mut new_boot = None; + println!("- Bootdevice: {}", boot_image_file.display()); + + println!("- Unpacking boot image"); + let bootimage_data = map_file(&boot_image_file)?; + let boot_image = BootImage::parse(&bootimage_data)?; + enforce_bootimage_version(&boot_image)?; + + let (mut cpio, vendor_ramdisk_idx) = + if let Some(ramdisk_image) = boot_image.get_blocks().get_ramdisk() { + extract_ramdisk(ramdisk_image)? + } else { + bail!("No compatible ramdisk found.") + }; + + ensure!( + cpio.exists("kernelsu.ko"), + "boot image is not patched by KernelSU" + ); + #[cfg(target_os = "android")] - let mut from_backup = false; - #[cfg(not(target_os = "android"))] - let from_backup = false; + let mut stock_boot: Option = None; #[cfg(target_os = "android")] - if do_cpio_cmd( - &magiskboot, - workdir, - ramdisk, - &format!("exists {BACKUP_FILENAME}"), - ) - .is_ok() - { - do_cpio_cmd( - &magiskboot, - workdir, - ramdisk, - &format!("extract {BACKUP_FILENAME} {BACKUP_FILENAME}"), - )?; - let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?; - let sha = String::from_utf8(sha)?; + if let Some(backup_file) = cpio.entry_by_name(BACKUP_FILENAME) { + let sha = String::from_utf8(backup_file.data().unwrap_or_default().to_vec())?; let sha = sha.trim(); let backup_path = PathBuf::from(KSU_BACKUP_DIR).join(format!("{KSU_BACKUP_FILE_PREFIX}{sha}")); if backup_path.is_file() { - new_boot = Some(backup_path); - from_backup = true; + println!("- Using backup file {}", backup_path.display()); + stock_boot = Some(backup_path); } else { println!("- Warning: no backup {} found!", backup_path.display()); } - if let Err(e) = clean_backup(sha) { println!("- Warning: Cleanup backup image failed: {e}"); } @@ -956,63 +839,85 @@ pub fn restore(args: BootRestoreArgs) -> Result<()> { println!("- Backup info is absent!"); } - let remove_ksu = || -> Result<_> { - // remove kernelsu.ko - do_cpio_cmd(&magiskboot, workdir, ramdisk, "rm kernelsu.ko")?; + #[cfg(target_os = "android")] + let mut stock_source: Option = None; - // if init.real exists, restore it - let status = do_cpio_cmd(&magiskboot, workdir, ramdisk, "exists init.real").is_ok(); - if status { - do_cpio_cmd(&magiskboot, workdir, ramdisk, "mv init.real init")?; + let new_boot_bytes: Vec = { + #[cfg(target_os = "android")] + { + if let Some(stock_path) = stock_boot { + let bytes = std::fs::read(&stock_path) + .with_context(|| format!("read stock boot {}", stock_path.display()))?; + stock_source = Some(stock_path); + bytes + } else { + rebuild_without_ksu(&boot_image, &mut cpio, vendor_ramdisk_idx)? + } + } + #[cfg(not(target_os = "android"))] + { + rebuild_without_ksu(&boot_image, &mut cpio, vendor_ramdisk_idx)? } - - println!("- Repacking boot image"); - let status = Command::new(&magiskboot) - .current_dir(workdir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .arg("repack") - .arg(&bootimage) - .status()?; - ensure!(status.success(), "magiskboot repack failed"); - Ok(workdir.join("new-boot.img")) }; - #[cfg(target_os = "android")] - let new_boot = new_boot.map_or_else(remove_ksu, Ok)?; - #[cfg(not(target_os = "android"))] - let new_boot = remove_ksu()?; - // flash first, since the new_boot may be moved + drop(boot_image); + drop(bootimage_data); + #[cfg(target_os = "android")] if flash { - if from_backup { - println!("- Flashing new boot image from {}", new_boot.display()); + if let Some(ref source) = stock_source { + println!("- Flashing new boot image from {}", source.display()); } else { println!("- Flashing new boot image"); } - flash_boot(&bootdevice, &new_boot)?; + let bootdevice = boot_image_file.display().to_string(); + flash_partition(&bootdevice, &new_boot_bytes)?; } #[cfg(target_os = "android")] - let should_write_output = image.is_some() || !flash || out_name.is_some() || out.is_some(); + let should_write_output = image_supplied || !flash || out_name.is_some() || out.is_some(); #[cfg(not(target_os = "android"))] - let should_write_output = image.is_some(); + let should_write_output = true; if should_write_output { - // write restored image to output file when output is requested let output_dir = out.unwrap_or(std::env::current_dir()?); let name = out_name.unwrap_or_else(|| { let now = chrono::Utc::now(); format!("kernelsu_restore_{}.img", now.format("%Y%m%d_%H%M%S")) }); let output_image = output_dir.join(name); - - if from_backup || std::fs::rename(&new_boot, &output_image).is_err() { - std::fs::copy(&new_boot, &output_image).context("copy out new boot failed")?; - } + std::fs::write(&output_image, &new_boot_bytes).context("copy out new boot failed")?; println!("- Output file is written to"); println!("- {}", output_image.display().to_string().trim_matches('"')); } + println!("- Done!"); Ok(()) } + +fn rebuild_without_ksu( + boot_image: &BootImage<'_>, + cpio: &mut Cpio, + vendor_ramdisk_idx: Option, +) -> Result> { + println!("- Removing KernelSU from boot image"); + cpio.rm("kernelsu.ko", false); + if cpio.exists("init.real") { + cpio.mv("init.real", "init")?; + } + + let mut new_cpio = Vec::::new(); + cpio.dump(&mut new_cpio)?; + + println!("- Repacking boot image"); + let mut patcher = BootImagePatchOption::new(boot_image); + if let Some(idx) = vendor_ramdisk_idx { + patcher.replace_vendor_ramdisk(idx, Box::new(Cursor::new(new_cpio)), false); + } else { + patcher.replace_ramdisk(Box::new(Cursor::new(new_cpio)), false); + } + + let mut buf = Cursor::new(Vec::::new()); + patcher.patch(&mut buf)?; + Ok(buf.into_inner()) +} diff --git a/userspace/ksud/src/cli.rs b/userspace/ksud/src/cli.rs index 7e04c3d95088..71564ef7c48b 100644 --- a/userspace/ksud/src/cli.rs +++ b/userspace/ksud/src/cli.rs @@ -76,9 +76,6 @@ enum Commands { /// Install KernelSU userspace component to system Install { - #[arg(long, default_value = None)] - magiskboot: Option, - #[arg(long, default_value = None)] libadbroot: Option, }, @@ -88,10 +85,6 @@ enum Commands { /// Uninstall KernelSU modules and itself(LKM Only) Uninstall { - /// magiskboot path, if not specified, will search from $PATH - #[arg(long, default_value = None)] - magiskboot: Option, - #[arg(long, default_value_t = String::from("me.weishu.kernelsu"))] package_name: String, }, @@ -602,15 +595,9 @@ pub fn run() -> Result<()> { } } } - Commands::Install { - magiskboot, - libadbroot, - } => utils::install(magiskboot, libadbroot), + Commands::Install { libadbroot } => utils::install(libadbroot), Commands::Unload => crate::unload::unload(), - Commands::Uninstall { - magiskboot, - package_name, - } => utils::uninstall(magiskboot, &package_name), + Commands::Uninstall { package_name } => utils::uninstall(&package_name), Commands::Sepolicy { command } => match command { Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy), Sepolicy::Apply { file } => crate::sepolicy::apply_file(file), diff --git a/userspace/ksud/src/defs.rs b/userspace/ksud/src/defs.rs index fd6ab3b46e52..2e10242666fe 100644 --- a/userspace/ksud/src/defs.rs +++ b/userspace/ksud/src/defs.rs @@ -15,7 +15,6 @@ mod android { pub const KSURC_PATH: &str = concatcp!(WORKING_DIR, ".ksurc"); pub const DAEMON_PATH: &str = concatcp!(ADB_DIR, "ksud"); - pub const MAGISKBOOT_PATH: &str = concatcp!(BINARY_DIR, "magiskboot"); pub const LIBADBROOT_PATH: &str = concatcp!(LIBRARY_DIR, "libadbroot.so"); pub const DAEMON_LINK_PATH: &str = concatcp!(BINARY_DIR, "ksud"); @@ -45,6 +44,7 @@ mod android { pub const BACKUP_FILENAME: &str = "stock_image.sha1"; } +#[allow(unused)] pub const VERSION_CODE: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_CODE")); pub const VERSION_NAME: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_NAME")); diff --git a/userspace/ksud/src/late_load.rs b/userspace/ksud/src/late_load.rs index 8e6f0fe6a308..0a71aca35b84 100644 --- a/userspace/ksud/src/late_load.rs +++ b/userspace/ksud/src/late_load.rs @@ -78,7 +78,7 @@ pub fn run(package_name: &String, kmi: Option, allow_shell: bool) -> Res warn!("clear temp configs failed: {e}"); } - utils::install(None, None).context("Failed to install ksud")?; + utils::install(None).context("Failed to install ksud")?; // 5. Handle module updates if let Err(e) = handle_updated_modules() { diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 87d6729ff9d9..7acffba08394 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -189,7 +189,7 @@ fn link_ksud_to_bin() -> Result<()> { Ok(()) } -pub fn install(magiskboot: Option, libadbroot: Option) -> Result<()> { +pub fn install(libadbroot: Option) -> Result<()> { ensure_dir_exists(defs::ADB_DIR)?; let _ = std::fs::remove_file(defs::DAEMON_PATH); std::fs::copy( @@ -202,12 +202,6 @@ pub fn install(magiskboot: Option, libadbroot: Option) -> Resu link_ksud_to_bin()?; - if let Some(magiskboot) = magiskboot { - ensure_dir_exists(defs::BINARY_DIR)?; - let _ = std::fs::remove_file(defs::MAGISKBOOT_PATH); - let _ = std::fs::copy(magiskboot, defs::MAGISKBOOT_PATH); - } - if let Some(libadbroot) = libadbroot { ensure_dir_exists(defs::LIBRARY_DIR)?; let _ = std::fs::remove_file(defs::LIBADBROOT_PATH); @@ -217,7 +211,7 @@ pub fn install(magiskboot: Option, libadbroot: Option) -> Resu Ok(()) } -pub fn uninstall(magiskboot_path: Option, package_name: &str) -> Result<()> { +pub fn uninstall(package_name: &str) -> Result<()> { if Path::new(defs::MODULE_DIR).exists() { println!("- Uninstall modules.."); module::uninstall_all_modules()?; @@ -231,7 +225,6 @@ pub fn uninstall(magiskboot_path: Option, package_name: &str) -> Result boot_patch::restore(BootRestoreArgs { boot: None, flash: true, - magiskboot: magiskboot_path, out: None, out_name: None, })?;