diff --git a/userspace/ksud/.gitignore b/userspace/ksud/.gitignore new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/userspace/ksud/.gitignore @@ -0,0 +1 @@ +/target diff --git a/userspace/ksud/Cargo.lock b/userspace/ksud/Cargo.lock new file mode 100644 index 00000000..a6b36581 --- /dev/null +++ b/userspace/ksud/Cargo.lock @@ -0,0 +1,936 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aes" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", + "opaque-debug", +] + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" + +[[package]] +name = "base64ct" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bzip2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6afcd980b5f3a45017c57e57a2fcccbb351cc43a356ce117ef760ef8052b89b0" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "cc" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array", +] + +[[package]] +name = "clap" +version = "4.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +dependencies = [ + "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "const_format" +version = "0.2.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7309d9b4d3d2c0641e018d449232f2e28f1b22933c137f157d3dbc14228b8c0e" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f47bf7270cf70d370f8f98c1abb6d2d4cf60a6845d30e05bfb90c6568650" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "encoding" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec" +dependencies = [ + "encoding-index-japanese", + "encoding-index-korean", + "encoding-index-simpchinese", + "encoding-index-singlebyte", + "encoding-index-tradchinese", +] + +[[package]] +name = "encoding-index-japanese" +version = "1.20141219.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91" +dependencies = [ + "encoding_index_tests", +] + +[[package]] +name = "encoding-index-korean" +version = "1.20141219.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81" +dependencies = [ + "encoding_index_tests", +] + +[[package]] +name = "encoding-index-simpchinese" +version = "1.20141219.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7" +dependencies = [ + "encoding_index_tests", +] + +[[package]] +name = "encoding-index-singlebyte" +version = "1.20141219.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a" +dependencies = [ + "encoding_index_tests", +] + +[[package]] +name = "encoding-index-tradchinese" +version = "1.20141219.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18" +dependencies = [ + "encoding_index_tests", +] + +[[package]] +name = "encoding_index_tests" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" + +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + +[[package]] +name = "itoa" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + +[[package]] +name = "java-properties" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1904d8654a1ef51034d02d5a9411b50bf91bea15b0ab644ae179d1325976263" +dependencies = [ + "encoding", + "lazy_static", + "regex", +] + +[[package]] +name = "jobserver" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +dependencies = [ + "libc", +] + +[[package]] +name = "ksud" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "const_format", + "env_logger", + "java-properties", + "log", + "regex", + "serde", + "serde_json", + "subprocess", + "zip 0.6.3", + "zip-extensions", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" + +[[package]] +name = "serde_json" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subprocess" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "time" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +dependencies = [ + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +dependencies = [ + "time-core", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + +[[package]] +name = "zip" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +dependencies = [ + "byteorder", + "bzip2", + "crc32fast", + "flate2", + "thiserror", + "time 0.1.45", +] + +[[package]] +name = "zip" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537ce7411d25e54e8ae21a7ce0b15840e7bfcff15b51d697ec3266cc76bdf080" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2", + "sha1", + "time 0.3.17", + "zstd", +] + +[[package]] +name = "zip-extensions" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c3c977bc3434ce2d4bcea8ad3c644672de0f2c402b72b9171ca80a8885d14" +dependencies = [ + "zip 0.5.13", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.4+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +dependencies = [ + "cc", + "libc", +] diff --git a/userspace/ksud/Cargo.toml b/userspace/ksud/Cargo.toml new file mode 100644 index 00000000..3c1ec3eb --- /dev/null +++ b/userspace/ksud/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "ksud" +version = "0.1.0" +edition = "2021" +rust-version = "1.65" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.68" +clap = { version = "4.0.32", features = ["derive"] } +const_format = "0.2.30" +subprocess = "0.2.9" +zip = "0.6.3" +zip-extensions = "0.6.1" +java-properties = "1.4.1" +log = "0.4.17" +env_logger = "0.10.0" +serde = { version = "1.0" } +serde_json = "1.0" +regex = "1.5.4" + +[profile.release] +strip = true +opt-level = "z" +lto = true \ No newline at end of file diff --git a/userspace/ksud/src/cli.rs b/userspace/ksud/src/cli.rs new file mode 100644 index 00000000..9c08348a --- /dev/null +++ b/userspace/ksud/src/cli.rs @@ -0,0 +1,99 @@ +use anyhow::Result; +use clap::Parser; + +use crate::{event, module}; + +/// KernelSU userspace cli +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + #[command(subcommand)] + command: Commands, +} + +#[derive(clap::Subcommand, Debug)] +enum Commands { + /// Start KernelSU userspace daemon + Daemon, + + /// Manage KernelSU modules + Module { + #[command(subcommand)] + command: Module, + }, + + /// Trigger `post-fs-data` event + PostFsData, + + /// Trigger `service` event + Services, + + /// Trigger `boot-complete` event + BootCompleted, + + /// Install KernelSU userspace component to system + Install, + + /// SELinux policy Patch tool + Sepolicy, +} + +#[derive(clap::Subcommand, Debug)] +enum Module { + /// Install module + Install { + /// module zip file path + zip: String, + }, + + /// Uninstall module + Uninstall { + /// module id + id: String, + }, + + /// enable module + Enable { + /// module id + id: String, + }, + + /// disable module + Disable { + // module id + id: String, + }, + + /// list all modules + List, +} + +pub fn run() -> Result<()> { + let cli = Args::parse(); + + let result = match cli.command { + Commands::Daemon => event::daemon(), + Commands::PostFsData => event::on_post_data_fs(), + Commands::BootCompleted => event::on_boot_completed(), + + Commands::Module { command } => { + env_logger::init(); + + match command { + Module::Install { zip } => module::install_module(zip), + Module::Uninstall { id } => module::uninstall_module(id), + Module::Enable { id } => module::enable_module(id), + Module::Disable { id } => module::disable_module(id), + Module::List => module::list_modules(), + } + } + Commands::Install => event::install(), + Commands::Sepolicy => todo!(), + Commands::Services => todo!(), + }; + + if let Err(e) = &result { + log::error!("Error: {}", e); + } + result +} diff --git a/userspace/ksud/src/defs.rs b/userspace/ksud/src/defs.rs new file mode 100644 index 00000000..bbdc0856 --- /dev/null +++ b/userspace/ksud/src/defs.rs @@ -0,0 +1,17 @@ +use const_format::concatcp; + +pub const DAEMON_PATH: &str = "/data/adb/ksud"; +pub const WORKING_DIR: &str = "/data/adb/ksu/"; + +pub const MODULE_DIR: &str = concatcp!(WORKING_DIR, "modules/"); +pub const MODULE_IMG: &str = concatcp!(WORKING_DIR, "modules.img"); +pub const MODULE_UPDATE_IMG: &str = concatcp!(WORKING_DIR, "modules_update.img"); + +pub const MODULE_UPDATE_TMP_IMG: &str = concatcp!(WORKING_DIR, "update_tmp.img"); + +// warning: this directory should not change, or you need to change the code in module_installer.sh!!! +pub const MODULE_UPDATE_TMP_DIR: &str = concatcp!(WORKING_DIR, "modules_update/"); + +pub const DISABLE_FILE_NAME: &str = "disable"; +pub const UPDATE_FILE_NAME: &str = "update"; +pub const REMOVE_FILE_NAME: &str = "remove"; \ No newline at end of file diff --git a/userspace/ksud/src/main.rs b/userspace/ksud/src/main.rs new file mode 100644 index 00000000..8e2519b5 --- /dev/null +++ b/userspace/ksud/src/main.rs @@ -0,0 +1,10 @@ +mod cli; +mod event; +mod module; +mod defs; +mod utils; +mod restorecon; + +fn main() -> anyhow::Result<()> { + cli::run() +} diff --git a/userspace/ksud/src/module.rs b/userspace/ksud/src/module.rs new file mode 100644 index 00000000..3aa50f26 --- /dev/null +++ b/userspace/ksud/src/module.rs @@ -0,0 +1,404 @@ +use const_format::concatcp; +use java_properties::PropertiesIter; +use log::{info, warn}; +use std::{ + collections::HashMap, + fs::{create_dir_all, remove_dir_all, File}, + io::Cursor, + path::{Path, PathBuf}, + process::{Command, Stdio}, + str::FromStr, +}; +use subprocess::Exec; +use zip_extensions::*; + +use crate::utils::*; +use crate::{defs, restorecon}; + +use anyhow::{bail, ensure, Context, Result}; + +const UTIL_FUNCTIONS: &str = include_str!("./installer.sh"); +const INSTALL_MODULE_SCRIPT: &str = + concatcp!(UTIL_FUNCTIONS, "\n", "install_module", "\n", "exit 0", "\n"); + +fn exec_install_script(module_file: &str) -> Result<()> { + let realpath = std::fs::canonicalize(module_file) + .with_context(|| format!("realpath: {} failed", module_file))?; + + let result = Command::new("/system/bin/sh") + .args(["-c", INSTALL_MODULE_SCRIPT]) + .env("OUTFD", "1") + .env("ZIPFILE", realpath) + .status()?; + ensure!(result.success(), "install module script failed!"); + Ok(()) +} + +// becuase we use something like A-B update +// we need to update the module state after the boot_completed +// if someone(such as the module) install a module before the boot_completed +// then it may cause some problems, just forbid it +fn ensure_boot_completed() -> Result<()> { + // ensure getprop sys.boot_completed = 1 + let output = Command::new("getprop") + .arg("sys.boot_completed") + .stdout(Stdio::piped()) + .output()?; + let output = String::from_utf8_lossy(&output.stdout); + if output.trim() != "1" { + bail!("Android is Booting!"); + } + Ok(()) +} + +fn mark_update() -> Result<()> { + let update_file = Path::new(defs::WORKING_DIR).join(defs::UPDATE_FILE_NAME); + if update_file.exists() { + return Ok(()); + } + + std::fs::File::create(update_file)?; + Ok(()) +} + +fn mark_module_state(module: &str, flag_file: &str, create_or_delete: bool) -> Result<()> { + let module_state_file = Path::new(defs::MODULE_DIR).join(module).join(flag_file); + if create_or_delete { + if module_state_file.exists() { + return Ok(()); + } + std::fs::File::create(module_state_file)?; + } else { + if !module_state_file.exists() { + return Ok(()); + } + std::fs::remove_file(module_state_file)?; + } + + Ok(()) +} + +fn get_minimal_image_size(img: &str) -> Result { + let output = Command::new("resize2fs") + .args(["-P", img]) + .stdout(Stdio::piped()) + .output()?; + + let output = String::from_utf8_lossy(&output.stdout); + println!("- {}", output); + let regex = regex::Regex::new(r"filesystem: (\d+)")?; + let result = regex + .captures(output.as_ref()) + .ok_or_else(|| anyhow::anyhow!("regex not match"))?; + let result = &result[1]; + let result = u64::from_str(result)?; + Ok(result) +} + +fn grow_image_size(img: &str, extra_size: u64) -> Result<()> { + let minimal_size = get_minimal_image_size(img)?; + let target_size = minimal_size + extra_size; + + // trim image + let result = Command::new("e2fsck") + .args(["-yf", img]) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .with_context(|| format!("Failed exec e2fsck {}", img))?; + ensure!(result.success(), "f2fsck exec failed."); + + let target_size = target_size / 1024 + 1; + println!("- Target size: {}K", target_size); + + let result = Exec::shell(format!("resize2fs {} {}K", img, target_size)) + .stdout(subprocess::NullFile) + .stderr(subprocess::Redirection::Merge) + .join() + .with_context(|| format!("Failed to resize2fs {}", img))?; + ensure!(result.success(), "resize2fs exec failed."); + + Ok(()) +} + +pub fn install_module(zip: String) -> Result<()> { + ensure_boot_completed()?; + + // print banner + println!(include_str!("banner")); + + // first check if workding dir is usable + let working_dir = Path::new(defs::WORKING_DIR); + if !working_dir.exists() { + create_dir_all(working_dir)?; + } + + ensure!( + working_dir.is_dir(), + "working dir exists but it is not a regular directory!" + ); + + // read the module_id from zip, if faild if will return early. + let mut buffer: Vec = Vec::new(); + let entry_path = PathBuf::from_str("module.prop")?; + let zip_path = PathBuf::from_str(&zip)?; + zip_extract_file_to_memory(&zip_path, &entry_path, &mut buffer)?; + + let mut module_prop = HashMap::new(); + PropertiesIter::new(Cursor::new(buffer)).read_into(|k, v| { + module_prop.insert(k, v); + })?; + + let Some(module_id) = module_prop.get("id") else { + bail!("module id not found in module.prop!"); + }; + info!("module id: {}", module_id); + + let modules_img = Path::new(defs::MODULE_IMG); + let modules_dir = Path::new(defs::MODULE_DIR); + let modules_update_img = Path::new(defs::MODULE_UPDATE_IMG); + let module_update_tmp_dir = defs::MODULE_UPDATE_TMP_DIR; + + let current_img_size = std::cmp::max( + modules_img.metadata().map_or(0, |meta| meta.len()), + modules_update_img.metadata().map_or(0, |meta| meta.len()), + ); + + let img_size_per_m = current_img_size / 1024 / 1024 + 256; + + let modules_exist = modules_dir.exists(); + let modules_update_exist = modules_update_img.exists(); + + // prepare the tmp module img + let tmp_module_img = defs::MODULE_UPDATE_TMP_IMG; + let tmp_module_path = Path::new(tmp_module_img); + if tmp_module_path.exists() { + std::fs::remove_file(tmp_module_path)?; + } + + let default_grow_size = 128 * 1024 * 1024; + + println!("- Preparing image"); + + if !modules_exist && !modules_update_exist { + // if no modules and modules_update, it is brand new installation, we should create a new img + // create a tmp module img and mount it to modules_update + let result = Exec::shell(format!( + "dd if=/dev/zero of={} bs=1M count={}", + tmp_module_img, img_size_per_m + )) + .stdout(subprocess::NullFile) + .stderr(subprocess::Redirection::Merge) + .join()?; + ensure!(result.success(), "create ext4 image failed!"); + + // format the img to ext4 filesystem + let result = Exec::shell(format!("mkfs.ext4 {}", tmp_module_img)) + .stdout(subprocess::NullFile) + .stderr(subprocess::Redirection::Merge) + .join()?; + ensure!(result.success(), "format ext4 image failed!"); + } else if modules_update_exist { + // modules_update.img exists, we should use it as tmp img + std::fs::copy(modules_update_img, tmp_module_img)?; + // grow size of the tmp image + grow_image_size(tmp_module_img, default_grow_size)?; + } else { + // modules.img exists, we should use it as tmp img + std::fs::copy(modules_img, tmp_module_img)?; + // grow size of the tmp image + grow_image_size(tmp_module_img, default_grow_size)?; + } + + // ensure modules_update exists + ensure_clean_dir(module_update_tmp_dir)?; + + // mount the modules_update.img to mountpoint + mount_image(tmp_module_img, module_update_tmp_dir)?; + + let result = { + let module_dir = format!("{}/{}", module_update_tmp_dir, module_id); + ensure_clean_dir(&module_dir)?; + info!("module dir: {}", module_dir); + + // unzip the image and move it to modules_update/ dir + let file = File::open(&zip)?; + let mut archive = zip::ZipArchive::new(file)?; + archive.extract(&module_dir)?; + + // set selinux for module/system dir + let mut module_system_dir = PathBuf::from(module_dir); + module_system_dir.push("system"); + let module_system_dir = module_system_dir.as_path(); + if module_system_dir.exists() { + let path = format!("{}", module_system_dir.display()); + restorecon::restore_syscon(&path)?; + } + + exec_install_script(&zip) + }; + + // umount the modules_update.img + let _ = umount_dir(module_update_tmp_dir); + + // remove modules_update dir, ignore the error + let _ = remove_dir_all(module_update_tmp_dir); + + // return if exec script failed + result?; + + // all done, rename the tmp image to modules_update.img + std::fs::rename(tmp_module_img, defs::MODULE_UPDATE_IMG)?; + + mark_update()?; + + Ok(()) +} + +fn do_module_update(update_dir: &str, id: &str, func: F) -> Result<()> +where + F: Fn(&str, &str) -> Result<()>, +{ + ensure_boot_completed()?; + + let modules_img = Path::new(defs::MODULE_IMG); + let modules_update_img = Path::new(defs::MODULE_UPDATE_IMG); + let modules_update_tmp_img = Path::new(defs::MODULE_UPDATE_TMP_IMG); + if !modules_update_img.exists() && !modules_img.exists() { + bail!("Please install module first!"); + } else if modules_update_img.exists() { + info!( + "copy {} to {}", + modules_update_img.display(), + modules_update_tmp_img.display() + ); + std::fs::copy(modules_update_img, modules_update_tmp_img)?; + } else { + info!( + "copy {} to {}", + modules_img.display(), + modules_update_tmp_img.display() + ); + std::fs::copy(modules_img, modules_update_tmp_img)?; + } + + // ensure modules_update dir exist + ensure_clean_dir(update_dir)?; + + // mount the modules_update img + mount_image(defs::MODULE_UPDATE_TMP_IMG, update_dir)?; + + // call the operation func + let result = func(id, update_dir); + + // umount modules_update.img + let _ = umount_dir(update_dir); + let _ = remove_dir_all(update_dir); + + std::fs::rename(modules_update_tmp_img, defs::MODULE_UPDATE_IMG)?; + + mark_update()?; + + result +} + +pub fn uninstall_module(id: String) -> Result<()> { + do_module_update(defs::MODULE_UPDATE_TMP_DIR, &id, |mid, update_dir| { + // found it in modules_update/enabled + let target_module_path = format!("{}/{}", update_dir, mid); + let target_module = Path::new(&target_module_path); + if target_module.exists() { + remove_dir_all(target_module)?; + } + + let _ = mark_module_state(&id, defs::REMOVE_FILE_NAME, true); + + Ok(()) + }) +} + +fn do_enable_module(module_dir: &str, mid: &str, enable: bool) -> Result<()> { + let src_module_path = format!("{}/{}", module_dir, mid); + let src_module = Path::new(&src_module_path); + if !src_module.exists() { + bail!("module: {} not found!", mid); + } + + let disable_path = src_module.join(defs::DISABLE_FILE_NAME); + if enable { + if disable_path.exists() { + std::fs::remove_file(&disable_path).with_context(|| { + format!("Failed to remove disable file: {}", &disable_path.display()) + })?; + } + } else if !disable_path.exists() { + std::fs::File::create(disable_path)?; + } + + let _ = mark_module_state(mid, defs::DISABLE_FILE_NAME, !enable); + + Ok(()) +} + +pub fn enable_module(id: String) -> Result<()> { + do_module_update(defs::MODULE_UPDATE_TMP_DIR, &id, |mid, update_dir| { + do_enable_module(update_dir, mid, true) + }) +} + +pub fn disable_module(id: String) -> Result<()> { + do_module_update(defs::MODULE_UPDATE_TMP_DIR, &id, |mid, update_dir| { + do_enable_module(update_dir, mid, false) + }) +} + +fn do_list_modules(path: &str) -> Vec> { + // first check enabled modules + let dir = std::fs::read_dir(path); + let Ok(dir) = dir else { + return Vec::new(); + }; + + let mut modules: Vec> = Vec::new(); + + for entry in dir.flatten() { + let path = entry.path(); + info!("path: {}", path.display()); + let module_prop = path.join("module.prop"); + if !module_prop.exists() { + continue; + } + let content = std::fs::read(&module_prop); + let Ok(content) = content else { + warn!("Failed to read file: {}", module_prop.display()); + continue; + }; + let mut module_prop_map = HashMap::new(); + let result = PropertiesIter::new(Cursor::new(content)).read_into(|k, v| { + module_prop_map.insert(k, v); + }); + + // Add enabled, update, remove flags + let enabled = !path.join(defs::DISABLE_FILE_NAME).exists(); + let update = path.join(defs::UPDATE_FILE_NAME).exists(); + let remove = path.join(defs::REMOVE_FILE_NAME).exists(); + + module_prop_map.insert("enabled".to_string(), enabled.to_string()); + module_prop_map.insert("update".to_string(), update.to_string()); + module_prop_map.insert("remove".to_string(), remove.to_string()); + + if result.is_err() { + warn!("Failed to parse module.prop: {}", module_prop.display()); + continue; + } + modules.push(module_prop_map); + } + + modules +} + +pub fn list_modules() -> Result<()> { + let modules = do_list_modules(defs::MODULE_DIR); + println!("{}", serde_json::to_string_pretty(&modules)?); + Ok(()) +} diff --git a/userspace/ksud/src/restorecon.rs b/userspace/ksud/src/restorecon.rs new file mode 100644 index 00000000..c0a9c82f --- /dev/null +++ b/userspace/ksud/src/restorecon.rs @@ -0,0 +1,15 @@ +use anyhow::ensure; +use anyhow::Ok; +use anyhow::Result; +use subprocess::Exec; + +const SYSTEM_CON: &str = "u:object_r:system_file:s0"; +const _ADB_CON: &str = "u:object_r:adb_data_file:s0"; + +pub fn restore_syscon(dir: &str) -> Result<()> { + // todo use libselinux directly + let cmd = format!("chcon -R {} {}", SYSTEM_CON, dir); + let result = Exec::shell(cmd).join()?; + ensure!(result.success(), "chcon for: {} failed.", dir); + Ok(()) +} \ No newline at end of file diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs new file mode 100644 index 00000000..31dd12b3 --- /dev/null +++ b/userspace/ksud/src/utils.rs @@ -0,0 +1,24 @@ +use std::path::Path; + +use anyhow::{Result, ensure}; +use subprocess::Exec; + +pub fn mount_image(src: &str, target: &str) -> Result<()> { + let result = Exec::shell(format!("mount {} {}", src, target)).join()?; + ensure!(result.success(), "mount: {} -> {} failed.", src, target); + Ok(()) +} + +pub fn umount_dir(src: &str) -> Result<()> { + let result = Exec::shell(format!("umount {}", src)).join()?; + ensure!(result.success(), "umount: {} failed", src); + Ok(()) +} + +pub fn ensure_clean_dir(dir: &str) -> Result<()> { + let path = Path::new(dir); + if path.exists() { + std::fs::remove_dir_all(path)?; + } + Ok(std::fs::create_dir_all(path)?) +} \ No newline at end of file diff --git a/userspace/su/.gitignore b/userspace/su/.gitignore new file mode 100644 index 00000000..720289cc --- /dev/null +++ b/userspace/su/.gitignore @@ -0,0 +1,2 @@ +/obj +/libs diff --git a/userspace/su/jni/Android.mk b/userspace/su/jni/Android.mk new file mode 100644 index 00000000..5391ce7f --- /dev/null +++ b/userspace/su/jni/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := su +LOCAL_SRC_FILES := su.c + +include $(BUILD_EXECUTABLE) diff --git a/userspace/su/jni/Application.mk b/userspace/su/jni/Application.mk new file mode 100644 index 00000000..873252b9 --- /dev/null +++ b/userspace/su/jni/Application.mk @@ -0,0 +1,3 @@ +APP_ABI := arm64-v8a x86_64 +APP_PLATFORM := android-24 +APP_STL := none diff --git a/userspace/su/jni/su.c b/userspace/su/jni/su.c new file mode 100644 index 00000000..695c1cce --- /dev/null +++ b/userspace/su/jni/su.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int main(){ + int32_t result = 0; + prctl(0xdeadbeef, 0, 0, 0, &result); + system("/system/bin/sh"); + return 0; +}