From be9148fcfa5af336f8bc6120b5fecb00280b346b Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:47:35 -0400 Subject: [PATCH] Ported all NUS download functions from libWiiPy and corresponding CLI commands Also adds the basics of U8 archive packing/unpacking, however they are not in a usable state yet and there are no working CLI commands associated with them. --- Cargo.lock | 1435 ++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/archive/u8.rs | 203 +++++ src/bin/rustii/archive/mod.rs | 1 + src/bin/rustii/archive/u8.rs | 44 + src/bin/rustii/main.rs | 35 +- src/bin/rustii/title/mod.rs | 1 + src/bin/rustii/title/nus.rs | 215 +++++ src/bin/rustii/title/wad.rs | 4 +- src/title/content.rs | 31 +- src/title/mod.rs | 27 +- src/title/nus.rs | 143 ++++ src/title/tmd.rs | 19 +- 13 files changed, 2126 insertions(+), 33 deletions(-) create mode 100644 src/bin/rustii/archive/u8.rs create mode 100644 src/bin/rustii/title/nus.rs create mode 100644 src/title/nus.rs diff --git a/Cargo.lock b/Cargo.lock index a20bdcc..fc913f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "aes" version = "0.8.4" @@ -58,7 +73,7 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -69,7 +84,7 @@ checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" dependencies = [ "anstyle", "once_cell", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -78,18 +93,51 @@ version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + [[package]] name = "block-buffer" version = "0.10.4" @@ -108,12 +156,24 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + [[package]] name = "cbc" version = "0.1.2" @@ -123,6 +183,15 @@ dependencies = [ "cipher", ] +[[package]] +name = "cc" +version = "1.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525046617d8376e3db1deffb079e91cef90a89fc3ca5c185bbf8c9ecdd15cd5c" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -191,6 +260,22 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -232,6 +317,128 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -250,15 +457,58 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + [[package]] name = "glob" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +[[package]] +name = "h2" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5017294ff4bb30944501348f6f8e42e6ad28f42c8bbef7a74029aff064a4e3c2" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "heck" version = "0.5.0" @@ -271,6 +521,268 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "libc", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "inout" version = "0.1.4" @@ -281,12 +793,34 @@ dependencies = [ "generic-array", ] +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -308,12 +842,73 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[package]] +name = "linux-raw-sys" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" + +[[package]] +name = "litemap" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -361,12 +956,65 @@ dependencies = [ "libm", ] +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +[[package]] +name = "openssl" +version = "0.10.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-sys" +version = "0.9.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8288979acd84749c744a9014b4382d42b8f7b2592847b5afb2ed29e5d16ede07" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -376,6 +1024,24 @@ dependencies = [ "base64ct", ] +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkcs1" version = "0.7.5" @@ -397,6 +1063,12 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -424,6 +1096,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + [[package]] name = "rand" version = "0.8.5" @@ -450,7 +1128,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", ] [[package]] @@ -482,6 +1160,65 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "reqwest" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.15", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rsa" version = "0.9.8" @@ -503,6 +1240,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + [[package]] name = "rustii" version = "0.1.0" @@ -515,11 +1258,152 @@ dependencies = [ "glob", "hex", "regex", + "reqwest", "rsa", "sha1", "thiserror", ] +[[package]] +name = "rustix" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustls" +version = "0.23.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" + +[[package]] +name = "rustls-webpki" +version = "0.103.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha1" version = "0.10.6" @@ -542,6 +1426,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -552,12 +1442,31 @@ dependencies = [ "rand_core", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +[[package]] +name = "socket2" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "spin" version = "0.9.8" @@ -574,6 +1483,12 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "strsim" version = "0.11.1" @@ -597,6 +1512,60 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf" +dependencies = [ + "fastrand", + "getrandom 0.3.2", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "thiserror" version = "2.0.12" @@ -617,6 +1586,116 @@ dependencies = [ "syn", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.44.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.18.0" @@ -629,31 +1708,209 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-registry" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.53.0", +] + +[[package]] +name = "windows-result" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -662,14 +1919,30 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" +dependencies = [ + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -678,48 +1951,141 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.8.24" @@ -740,8 +2106,51 @@ dependencies = [ "syn", ] +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index c933993..dacbde6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ regex = "1" clap = { version = "4", features = ["derive"] } anyhow = "1" thiserror = "2" +reqwest = { version = "0", features = ["blocking"] } diff --git a/src/archive/u8.rs b/src/archive/u8.rs index 98bdbb9..5040793 100644 --- a/src/archive/u8.rs +++ b/src/archive/u8.rs @@ -3,3 +3,206 @@ // // Implements the structures and methods required for parsing U8 archives. +use std::io::{Cursor, Read, Seek, SeekFrom, Write}; +use std::path::Path; +use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum U8Error { + #[error("invalid file name at offset {0}")] + InvalidFileName(u64), + #[error("this does not appear to be a U8 archive (missing magic number)")] + NotU8Data, + #[error("U8 data is not in a valid format")] + IO(#[from] std::io::Error), +} + +#[derive(Clone, Debug)] +struct U8Node { + node_type: u8, + name_offset: u32, // This is really type u24, so the most significant byte will be ignored. + data_offset: u32, + size: u32, +} + +#[derive(Debug)] +pub struct U8Archive { + u8_nodes: Vec, + file_names: Vec, + file_data: Vec>, + root_node_offset: u32, + header_size: u32, + data_offset: u32, + padding: [u8; 16], +} + +impl U8Archive { + /// Creates a new U8 instance from the binary data of a U8 file. + pub fn from_bytes(data: &[u8]) -> Result { + let mut buf = Cursor::new(data); + let mut magic = [0u8; 4]; + buf.read_exact(&mut magic)?; + // Check for an IMET header if the magic number isn't the correct value before throwing an + // error. + if &magic != b"\x55\xAA\x38\x2D" { + // Check for an IMET header immediately at the start of the file. + buf.seek(SeekFrom::Start(0x40))?; + buf.read_exact(&mut magic)?; + if &magic == b"\x49\x4D\x45\x54" { + // IMET with no build tag means the U8 archive should start at 0x600. + buf.seek(SeekFrom::Start(0x600))?; + buf.read_exact(&mut magic)?; + if &magic != b"\x55\xAA\x38\x2D" { + return Err(U8Error::NotU8Data); + } + println!("ignoring IMET header at 0x40"); + } + // Check for an IMET header that comes after a built tag. + else { + buf.seek(SeekFrom::Start(0x80))?; + buf.read_exact(&mut magic)?; + if &magic == b"\x49\x4D\x45\x54" { + // IMET with a build tag means the U8 archive should start at 0x600. + buf.seek(SeekFrom::Start(0x640))?; + buf.read_exact(&mut magic)?; + if &magic != b"\x55\xAA\x38\x2D" { + return Err(U8Error::NotU8Data); + } + println!("ignoring IMET header at 0x80"); + } + } + } + let root_node_offset = buf.read_u32::()?; + let header_size = buf.read_u32::()?; + let data_offset = buf.read_u32::()?; + let mut padding = [0u8; 16]; + buf.read_exact(&mut padding)?; + // Manually read the root node, since we need its size anyway to know how many nodes there + // are total. + let root_node_type = buf.read_u8()?; + let root_node_name_offset = buf.read_u24::()?; + let root_node_data_offset = buf.read_u32::()?; + let root_node_size = buf.read_u32::()?; + let root_node = U8Node { + node_type: root_node_type, + name_offset: root_node_name_offset, + data_offset: root_node_data_offset, + size: root_node_size, + }; + // Create a vec of nodes, push the root node, and then iterate over the remaining number + // of nodes in the file and push them to the vec. + let mut u8_nodes: Vec = Vec::new(); + u8_nodes.push(root_node); + for _ in 1..root_node_size { + let node_type = buf.read_u8()?; + let name_offset = buf.read_u24::()?; + let data_offset = buf.read_u32::()?; + let size = buf.read_u32::()?; + u8_nodes.push(U8Node { node_type, name_offset, data_offset, size }) + } + // Iterate over the loaded nodes and load the file names and data associated with them. + let base_name_offset = buf.position(); + let mut file_names = Vec::::new(); + let mut file_data = Vec::>::new(); + for node in &u8_nodes { + buf.seek(SeekFrom::Start(base_name_offset + node.name_offset as u64))?; + let mut name_bin = Vec::::new(); + // Read the file name one byte at a time until we find a null byte. + loop { + let byte = buf.read_u8()?; + if byte == b'\0' { + break; + } + name_bin.push(byte); + } + file_names.push(String::from_utf8(name_bin).map_err(|_| U8Error::InvalidFileName(base_name_offset + node.name_offset as u64))?.to_owned()); + // If this is a file node, read the data for the file. + if node.node_type == 0 { + buf.seek(SeekFrom::Start(node.data_offset as u64))?; + let mut data = vec![0u8; node.size as usize]; + buf.read_exact(&mut data)?; + file_data.push(data); + } else { + file_data.push(Vec::new()); + } + } + Ok(U8Archive { + u8_nodes, + file_names, + file_data, + root_node_offset, + header_size, + data_offset, + padding, + }) + } + + fn pack_dir() { + todo!(); + } + + pub fn from_dir(_input: &Path) -> Result { + todo!(); + } + + /// Dumps the data in a U8Archive instance back into binary data that can be written to a file. + pub fn to_bytes(&self) -> Result, U8Error> { + // Header size starts at 0 because the header size starts with the nodes and does not + // include the actual file header. + let mut header_size: u32 = 0; + // Add 12 bytes for each node, since that's how many bytes each one is made up of. + for _ in 0..self.u8_nodes.len() { + header_size += 12; + } + // Add the number of bytes used for each file/folder name in the string table. + for file_name in &self.file_names { + header_size += file_name.len() as u32 + 1 + } + // The initial data offset is equal to the file header (32 bytes) + node data aligned to + // 64 bytes. + let data_offset: u32 = (header_size + 32 + 63) & !63; + // Adjust all nodes to place file data in the same order as the nodes. For some reason + // Nintendo-made U8 archives don't necessarily do this? + let mut current_data_offset = data_offset; + let mut current_name_offset: u32 = 0; + let mut u8_nodes = self.u8_nodes.clone(); + for i in 0..u8_nodes.len() { + if u8_nodes[i].node_type == 0 { + u8_nodes[i].data_offset = (current_data_offset + 31) & !31; + current_data_offset += (u8_nodes[i].size + 31) & !31; + } + // Calculate the name offsets, including the extra 1 for the NULL byte. + u8_nodes[i].name_offset = current_name_offset; + current_name_offset += self.file_names[i].len() as u32 + 1 + } + // Begin writing file data. + let mut buf: Vec = Vec::new(); + buf.write_all(b"\x55\xAA\x38\x2D")?; + buf.write_u32::(0x20)?; // The root node offset is always 0x20. + buf.write_u32::(header_size)?; + buf.write_u32::(data_offset)?; + buf.write_all(&self.padding)?; + // Iterate over nodes and write them out. + for node in &u8_nodes { + buf.write_u8(node.node_type)?; + buf.write_u24::(node.name_offset)?; + buf.write_u32::(node.data_offset)?; + buf.write_u32::(node.size)?; + } + // Iterate over file names with a null byte at the end. + for file_name in &self.file_names { + buf.write_all(file_name.as_bytes())?; + buf.write_u8(b'\0')?; + } + // Pad to the nearest multiple of 64 bytes. + buf.resize((buf.len() + 63) & !63, 0); + // Iterate over the file data and dump it. The file needs to be aligned to 32 bytes after + // each write. + for data in &self.file_data { + buf.write_all(data)?; + buf.resize((buf.len() + 31) & !31, 0); + } + Ok(buf) + } +} diff --git a/src/bin/rustii/archive/mod.rs b/src/bin/rustii/archive/mod.rs index c52384b..dfe8815 100644 --- a/src/bin/rustii/archive/mod.rs +++ b/src/bin/rustii/archive/mod.rs @@ -3,3 +3,4 @@ pub mod ash; pub mod lz77; +pub mod u8; diff --git a/src/bin/rustii/archive/u8.rs b/src/bin/rustii/archive/u8.rs new file mode 100644 index 0000000..8a51675 --- /dev/null +++ b/src/bin/rustii/archive/u8.rs @@ -0,0 +1,44 @@ +// archive/u8.rs from rustii (c) 2025 NinjaCheetah & Contributors +// https://github.com/NinjaCheetah/rustii +// +// Code for the U8 packing/unpacking commands in the rustii CLI. + +use std::{str, fs}; +use std::path::{Path, PathBuf}; +use anyhow::{bail, Context, Result}; +use clap::Subcommand; +use rustii::archive::u8; + +#[derive(Subcommand)] +#[command(arg_required_else_help = true)] +pub enum Commands { + /// Pack a directory into a U8 archive + Pack { + /// The directory to pack into a U8 archive + input: String, + /// The name of the packed U8 archive + output: String, + }, + /// Unpack a U8 archive into a directory + Unpack { + /// The path to the U8 archive to unpack + input: String, + /// The directory to unpack the U8 archive to + output: String, + } +} + +pub fn pack_u8_archive(_input: &str, _output: &str) -> Result<()> { + todo!(); +} + +pub fn unpack_u8_archive(input: &str, output: &str) -> Result<()> { + let in_path = Path::new(input); + if !in_path.exists() { + bail!("Source U8 archive \"{}\" could not be found.", input); + } + let u8_data = u8::U8Archive::from_bytes(&fs::read(in_path)?)?; + println!("{:?}", u8_data); + fs::write(Path::new(output), u8_data.to_bytes()?)?; + Ok(()) +} diff --git a/src/bin/rustii/main.rs b/src/bin/rustii/main.rs index cfd0d79..eedb5b3 100644 --- a/src/bin/rustii/main.rs +++ b/src/bin/rustii/main.rs @@ -44,6 +44,14 @@ enum Commands { #[command(subcommand)] command: archive::lz77::Commands }, + Nus { + #[command(subcommand)] + command: title::nus::Commands + }, + U8 { + #[command(subcommand)] + command: archive::u8::Commands + }, /// Pack/unpack/edit a WAD file Wad { #[command(subcommand)] @@ -68,6 +76,9 @@ fn main() -> Result<()> { Some(Commands::Fakesign { input, output }) => { title::fakesign::fakesign(input, output)? }, + Some(Commands::Info { input }) => { + info::info(input)? + }, Some(Commands::Lz77 { command }) => { match command { archive::lz77::Commands::Compress { input, output } => { @@ -78,8 +89,28 @@ fn main() -> Result<()> { } } }, - Some(Commands::Info { input }) => { - info::info(input)? + Some(Commands::Nus { command }) => { + match command { + title::nus::Commands::Ticket { tid, output } => { + title::nus::download_ticket(tid, output)? + }, + title::nus::Commands::Title { tid, version, output} => { + title::nus::download_title(tid, version, output)? + } + title::nus::Commands::Tmd { tid, version, output} => { + title::nus::download_tmd(tid, version, output)? + } + } + } + Some(Commands::U8 { command }) => { + match command { + archive::u8::Commands::Pack { input, output } => { + archive::u8::pack_u8_archive(input, output)? + }, + archive::u8::Commands::Unpack { input, output } => { + archive::u8::unpack_u8_archive(input, output)? + } + } }, Some(Commands::Wad { command }) => { match command { diff --git a/src/bin/rustii/title/mod.rs b/src/bin/rustii/title/mod.rs index 0650d30..e450f4f 100644 --- a/src/bin/rustii/title/mod.rs +++ b/src/bin/rustii/title/mod.rs @@ -2,4 +2,5 @@ // https://github.com/NinjaCheetah/rustii pub mod fakesign; +pub mod nus; pub mod wad; diff --git a/src/bin/rustii/title/nus.rs b/src/bin/rustii/title/nus.rs new file mode 100644 index 0000000..0fe99db --- /dev/null +++ b/src/bin/rustii/title/nus.rs @@ -0,0 +1,215 @@ +// title/nus.rs from rustii (c) 2025 NinjaCheetah & Contributors +// https://github.com/NinjaCheetah/rustii +// +// Code for NUS-related commands in the rustii CLI. + +use std::{str, fs}; +use std::path::PathBuf; +use anyhow::{bail, Context, Result}; +use clap::{Subcommand, Args}; +use rustii::title::{cert, content, nus, ticket, tmd}; +use rustii::title; + +#[derive(Subcommand)] +#[command(arg_required_else_help = true)] +pub enum Commands { + /// Download a Ticket from the NUS + Ticket { + /// The Title ID that the Ticket is for + tid: String, + /// An optional Ticket name; defaults to .tik + #[arg(short, long)] + output: Option, + }, + /// Download a title from the NUS + Title { + /// The Title ID of the Title to download + tid: String, + /// The version of the Title to download + #[arg(short, long)] + version: Option, + #[command(flatten)] + output: TitleOutputType, + }, + /// Download a TMD from the NUS + Tmd { + /// The Title ID that the TMD is for + tid: String, + /// The version of the TMD to download + #[arg(short, long)] + version: Option, + /// An optional TMD name; defaults to .tmd + #[arg(short, long)] + output: Option, + } +} + +#[derive(Args)] +#[clap(next_help_heading = "Output Format")] +#[group(multiple = false, required = true)] +pub struct TitleOutputType { + /// Download the Title data to the specified output directory + #[arg(short, long)] + output: Option, + /// Download the Title to a WAD file + #[arg(short, long)] + wad: Option, +} + +pub fn download_ticket(tid: &str, output: &Option) -> Result<()> { + println!("Downloading Ticket for title {tid}..."); + if tid.len() != 16 { + bail!("The specified Title ID is invalid!"); + } + let out_path = if output.is_some() { + PathBuf::from(output.clone().unwrap()) + } else { + PathBuf::from(format!("{}.tik", tid)) + }; + let tid: [u8; 8] = hex::decode(tid)?.try_into().unwrap(); + let tik_data = nus::download_ticket(tid, true).with_context(|| "Ticket data could not be downloaded.")?; + fs::write(&out_path, tik_data)?; + println!("Successfully downloaded Ticket to \"{}\"!", out_path.display()); + Ok(()) +} + +fn download_title_dir(title: title::Title, output: String) -> Result<()> { + println!(" - Saving downloaded data..."); + let out_path = PathBuf::from(output); + if out_path.exists() { + if !out_path.is_dir() { + bail!("A file already exists with the specified directory name!"); + } + } else { + fs::create_dir(&out_path).with_context(|| format!("The output directory \"{}\" could not be created.", out_path.display()))?; + } + let tid = hex::encode(title.tmd.title_id); + println!(" - Saving TMD..."); + fs::write(out_path.join(format!("{}.tmd", &tid)), title.tmd.to_bytes()?).with_context(|| format!("Failed to open TMD file \"{}.tmd\" for writing.", tid))?; + println!(" - Saving Ticket..."); + fs::write(out_path.join(format!("{}.tik", &tid)), title.ticket.to_bytes()?).with_context(|| format!("Failed to open Ticket file \"{}.tmd\" for writing.", tid))?; + println!(" - Saving certificate chain..."); + fs::write(out_path.join(format!("{}.cert", &tid)), title.cert_chain.to_bytes()?).with_context(|| format!("Failed to open certificate chain file \"{}.cert\" for writing.", tid))?; + // Iterate over the content files and write them out in encrypted form. + for record in &title.content.content_records { + println!(" - Decrypting and saving content with Content ID {}...", record.content_id); + fs::write(out_path.join(format!("{:08X}.app", record.content_id)), title.get_content_by_cid(record.content_id)?) + .with_context(|| format!("Failed to open content file \"{:08X}.app\" for writing.", record.content_id))?; + } + println!("Successfully downloaded title with Title ID {} to directory \"{}\"!", tid, out_path.display()); + Ok(()) +} + +fn download_title_dir_enc(tmd: tmd::TMD, content_region: content::ContentRegion, cert_chain: cert::CertificateChain, output: String) -> Result<()> { + println!(" - Saving downloaded data..."); + let out_path = PathBuf::from(output); + if out_path.exists() { + if !out_path.is_dir() { + bail!("A file already exists with the specified directory name!"); + } + } else { + fs::create_dir(&out_path).with_context(|| format!("The output directory \"{}\" could not be created.", out_path.display()))?; + } + let tid = hex::encode(tmd.title_id); + println!(" - Saving TMD..."); + fs::write(out_path.join(format!("{}.tmd", &tid)), tmd.to_bytes()?).with_context(|| format!("Failed to open TMD file \"{}.tmd\" for writing.", tid))?; + println!(" - Saving certificate chain..."); + fs::write(out_path.join(format!("{}.cert", &tid)), cert_chain.to_bytes()?).with_context(|| format!("Failed to open certificate chain file \"{}.cert\" for writing.", tid))?; + // Iterate over the content files and write them out in encrypted form. + for record in &content_region.content_records { + println!(" - Saving content with Content ID {}...", record.content_id); + fs::write(out_path.join(format!("{:08X}", record.content_id)), content_region.get_enc_content_by_cid(record.content_id)?) + .with_context(|| format!("Failed to open content file \"{:08X}\" for writing.", record.content_id))?; + } + println!("Successfully downloaded title with Title ID {} to directory \"{}\"!", tid, out_path.display()); + Ok(()) +} + +fn download_title_wad(title: title::Title, output: String) -> Result<()> { + println!(" - Packing WAD..."); + let out_path = PathBuf::from(output).with_extension("wad"); + fs::write(&out_path, title.to_wad().with_context(|| "A WAD could not be packed.")?.to_bytes()?).with_context(|| format!("Could not open WAD file \"{}\" for writing.", out_path.display()))?; + println!("Successfully downloaded title with Title ID {} to WAD file \"{}\"!", hex::encode(title.tmd.title_id), out_path.display()); + Ok(()) +} + +pub fn download_title(tid: &str, version: &Option, output: &TitleOutputType) -> Result<()> { + if tid.len() != 16 { + bail!("The specified Title ID is invalid!"); + } + if version.is_some() { + println!("Downloading title {} v{}, please wait...", tid, version.clone().unwrap()); + } else { + println!("Downloading title {} vLatest, please wait...", tid); + } + let version: Option = if version.is_some() { + Some(version.clone().unwrap().parse().with_context(|| "The specified Title version must be a valid integer!")?) + } else { + None + }; + let tid: [u8; 8] = hex::decode(tid)?.try_into().unwrap(); + println!(" - Downloading and parsing TMD..."); + let tmd = tmd::TMD::from_bytes(&nus::download_tmd(tid, version, true).with_context(|| "TMD data could not be downloaded.")?)?; + println!(" - Downloading and parsing Ticket..."); + let tik_res = &nus::download_ticket(tid, true); + let tik = match tik_res { + Ok(tik) => Some(ticket::Ticket::from_bytes(tik)?), + Err(_) => { + if output.wad.is_some() { + bail!("--wad was specified, but this Title has no common Ticket and cannot be packed into a WAD!"); + } else { + println!(" - No Ticket is available!"); + None + } + } + }; + // Build a vec of contents by iterating over the content records and downloading each one. + let mut contents: Vec> = Vec::new(); + for record in &tmd.content_records { + println!(" - Downloading content {} of {} (Content ID: {}, Size: {} bytes)...", + record.index + 1, &tmd.content_records.len(), record.content_id, record.content_size); + contents.push(nus::download_content(tid, record.content_id, true).with_context(|| format!("Content with Content ID {} could not be downloaded.", record.content_id))?); + println!(" - Done!"); + } + let content_region = content::ContentRegion::from_contents(contents, tmd.content_records.clone())?; + println!(" - Building certificate chain..."); + let cert_chain = cert::CertificateChain::from_bytes(&nus::download_cert_chain(true).with_context(|| "Certificate chain could not be built.")?)?; + if tik.is_some() { + // If we have a Ticket, then build a Title and jump to the output method. + let title = title::Title::from_parts(cert_chain, None, tik.unwrap(), tmd, content_region, None)?; + if output.wad.is_some() { + download_title_wad(title, output.wad.clone().unwrap())?; + } else { + download_title_dir(title, output.output.clone().unwrap())?; + } + } else { + // If we're downloading to a directory and have no Ticket, save the TMD and encrypted + // contents to the directory only. + download_title_dir_enc(tmd, content_region, cert_chain, output.output.clone().unwrap())?; + } + Ok(()) +} + +pub fn download_tmd(tid: &str, version: &Option, output: &Option) -> Result<()> { + let version: Option = if version.is_some() { + Some(version.clone().unwrap().parse().with_context(|| "The specified TMD version must be a valid integer!")?) + } else { + None + }; + println!("Downloading TMD for title {tid}..."); + if tid.len() != 16 { + bail!("The specified Title ID is invalid!"); + } + let out_path = if output.is_some() { + PathBuf::from(output.clone().unwrap()) + } else if version.is_some() { + PathBuf::from(format!("{}.tmd.{}", tid, version.unwrap())) + } else { + PathBuf::from(format!("{}.tmd", tid)) + }; + let tid: [u8; 8] = hex::decode(tid)?.try_into().unwrap(); + let tmd_data = nus::download_tmd(tid, version, true).with_context(|| "TMD data could not be downloaded.")?; + fs::write(&out_path, tmd_data)?; + println!("Successfully downloaded TMD to \"{}\"!", out_path.display()); + Ok(()) +} diff --git a/src/bin/rustii/title/wad.rs b/src/bin/rustii/title/wad.rs index 9895baa..3375f4d 100644 --- a/src/bin/rustii/title/wad.rs +++ b/src/bin/rustii/title/wad.rs @@ -138,7 +138,7 @@ pub fn convert_wad(input: &str, target: &ConvertTargets, output: &Option } title.ticket.title_key = title_key_new; title.fakesign()?; - fs::write(out_path.clone(), title.to_wad()?.to_bytes()?)?; + fs::write(&out_path, title.to_wad()?.to_bytes()?)?; println!("Successfully converted {} WAD to {} WAD \"{}\"!", source, target, out_path.file_name().unwrap().to_str().unwrap()); Ok(()) } @@ -205,7 +205,7 @@ pub fn pack_wad(input: &str, output: &str) -> Result<()> { out_path.set_extension("wad"); } } - fs::write(out_path.clone(), wad.to_bytes()?).with_context(|| format!("Could not open output file \"{}\" for writing.", out_path.display()))?; + fs::write(&out_path, wad.to_bytes()?).with_context(|| format!("Could not open output file \"{}\" for writing.", out_path.display()))?; println!("WAD file packed!"); Ok(()) } diff --git a/src/title/content.rs b/src/title/content.rs index b829ada..5e2b910 100644 --- a/src/title/content.rs +++ b/src/title/content.rs @@ -6,6 +6,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use sha1::{Sha1, Digest}; use thiserror::Error; +use crate::title::content::ContentError::MissingContents; use crate::title::tmd::ContentRecord; use crate::title::crypto; @@ -13,6 +14,8 @@ use crate::title::crypto; pub enum ContentError { #[error("requested index {index} is out of range (must not exceed {max})")] IndexOutOfRange { index: usize, max: usize }, + #[error("expected {required} contents based on content records but found {found}")] + MissingContents { required: usize, found: usize }, #[error("content with requested Content ID {0} could not be found")] CIDNotFound(u32), #[error("content's hash did not match the expected value (was {hash}, expected {expected})")] @@ -70,6 +73,19 @@ impl ContentRegion { contents, }) } + + /// Creates a ContentRegion instance that can be used to parse and edit content stored in a + /// digital Wii title from a vector of contents and the ContentRecords from a TMD. + pub fn from_contents(contents: Vec>, content_records: Vec) -> Result { + if contents.len() != content_records.len() { + return Err(MissingContents { required: content_records.len(), found: contents.len()}); + } + let mut content_region = Self::new(content_records)?; + for i in 0..contents.len() { + content_region.load_enc_content(&contents[i], content_region.content_records[i].index as usize)?; + } + Ok(content_region) + } /// Creates a ContentRegion instance from the ContentRecords of a TMD that contains no actual /// content. This can be used to load existing content from files. @@ -77,9 +93,8 @@ impl ContentRegion { let content_region_size: u64 = content_records.iter().map(|x| (x.content_size + 63) & !63).sum(); let content_region_size = content_region_size as u32; let num_contents = content_records.len() as u16; - let content_start_offsets: Vec = Vec::new(); - let mut contents: Vec> = Vec::new(); - contents.resize(num_contents as usize, Vec::new()); + let content_start_offsets: Vec = vec![0; num_contents as usize]; + let contents: Vec> = vec![Vec::new(); num_contents as usize]; Ok(ContentRegion { content_records, content_region_size, @@ -143,6 +158,16 @@ impl ContentRegion { Err(ContentError::CIDNotFound(cid)) } } + + /// Loads existing content into the specified index of a ContentRegion instance. This content + /// must be encrypted. + pub fn load_enc_content(&mut self, content: &[u8], index: usize) -> Result<(), ContentError> { + if index >= self.content_records.len() { + return Err(ContentError::IndexOutOfRange { index, max: self.content_records.len() - 1 }); + } + self.contents[index] = Vec::from(content); + Ok(()) + } /// Loads existing content into the specified index of a ContentRegion instance. This content /// must be decrypted and needs to match the size and hash listed in the content record at that diff --git a/src/title/mod.rs b/src/title/mod.rs index ac346b5..6071003 100644 --- a/src/title/mod.rs +++ b/src/title/mod.rs @@ -7,6 +7,7 @@ pub mod cert; pub mod commonkeys; pub mod content; pub mod crypto; +pub mod nus; pub mod ticket; pub mod tmd; pub mod versions; @@ -52,15 +53,37 @@ impl Title { let ticket = ticket::Ticket::from_bytes(&wad.ticket()).map_err(TitleError::Ticket)?; let tmd = tmd::TMD::from_bytes(&wad.tmd()).map_err(TitleError::TMD)?; let content = content::ContentRegion::from_bytes(&wad.content(), tmd.content_records.clone()).map_err(TitleError::Content)?; - let title = Title { + Ok(Title { cert_chain, crl: wad.crl(), ticket, tmd, content, meta: wad.meta(), + }) + } + + /// Creates a new Title instance from all of its individual components. + pub fn from_parts(cert_chain: cert::CertificateChain, crl: Option<&[u8]>, ticket: ticket::Ticket, tmd: tmd::TMD, + content: content::ContentRegion, meta: Option<&[u8]>) -> Result { + // Create empty vecs for the CRL and meta areas if we weren't supplied with any, as they're + // optional components. + let crl = match crl { + Some(crl) => crl.to_vec(), + None => Vec::new() }; - Ok(title) + let meta = match meta { + Some(meta) => meta.to_vec(), + None => Vec::new() + }; + Ok(Title { + cert_chain, + crl, + ticket, + tmd, + content, + meta + }) } /// Converts a Title instance into a WAD, which can be used to export the Title back to a file. diff --git a/src/title/nus.rs b/src/title/nus.rs new file mode 100644 index 0000000..be284ab --- /dev/null +++ b/src/title/nus.rs @@ -0,0 +1,143 @@ +// title/nus.rs from rustii (c) 2025 NinjaCheetah & Contributors +// https://github.com/NinjaCheetah/rustii +// +// Implements the functions required for downloading data from the NUS. + +use std::str; +use std::io::Write; +use reqwest; +use thiserror::Error; +use crate::title::{cert, tmd, ticket, content}; +use crate::title; + +use sha1::{Sha1, Digest}; + +const WII_NUS_ENDPOINT: &str = "http://nus.cdn.shop.wii.com/ccs/download/"; +const WII_U_NUS_ENDPOINT: &str = "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/"; + +#[derive(Debug, Error)] +pub enum NUSError { + #[error("the data returned by the NUS is not valid")] + InvalidData, + #[error("the requested Title ID or version could not be found on the NUS")] + NotFound, + #[error("Certificate processing error")] + Certificate(#[from] cert::CertificateError), + #[error("TMD processing error")] + TMD(#[from] tmd::TMDError), + #[error("Ticket processing error")] + Ticket(#[from] ticket::TicketError), + #[error("Content processing error")] + Content(#[from] content::ContentError), + #[error("an error occurred while assembling a Title from the downloaded data")] + Title(#[from] title::TitleError), + #[error("data could not be downloaded from the NUS")] + Request(#[from] reqwest::Error), + #[error("an error occurred writing NUS data")] + IO(#[from] std::io::Error), +} + +/// Downloads the retail certificate chain from the NUS. +pub fn download_cert_chain(wiiu_endpoint: bool) -> Result, NUSError> { + // To build the certificate chain, we need to download both the TMD and Ticket of a title. For + // the sake of simplicity, we'll use the Wii Menu 4.3U because I already found the required TMD + // and Ticket offsets for it. + let endpoint_url = if wiiu_endpoint { + WII_U_NUS_ENDPOINT.to_owned() + } else { + WII_NUS_ENDPOINT.to_owned() + }; + let tmd_url = format!("{}0000000100000002/tmd.513", endpoint_url); + let tik_url = format!("{}0000000100000002/cetk", endpoint_url); + let client = reqwest::blocking::Client::new(); + let tmd = client.get(tmd_url).header(reqwest::header::USER_AGENT, "wii libnup/1.0").send()?.bytes()?; + let tik = client.get(tik_url).header(reqwest::header::USER_AGENT, "wii libnup/1.0").send()?.bytes()?; + // Assemble the certificate chain. + let mut cert_chain: Vec = Vec::new(); + // Certificate Authority data. + cert_chain.write_all(&tik[0x2A4 + 768..])?; + // Certificate Policy (TMD certificate) data. + cert_chain.write_all(&tmd[0x328..0x328 + 768])?; + // XS (Ticket certificate) data. + cert_chain.write_all(&tik[0x2A4..0x2A4 + 768])?; + Ok(cert_chain) +} + +/// Downloads a specified content file from the specified title from the NUS. +pub fn download_content(title_id: [u8; 8], content_id: u32, wiiu_endpoint: bool) -> Result, NUSError> { + // Build the download URL. The structure is download// + let endpoint_url = if wiiu_endpoint { + WII_U_NUS_ENDPOINT.to_owned() + } else { + WII_NUS_ENDPOINT.to_owned() + }; + let content_url = format!("{}{}/{:08X}", endpoint_url, &hex::encode(title_id), content_id); + let client = reqwest::blocking::Client::new(); + let response = client.get(content_url).header(reqwest::header::USER_AGENT, "wii libnup/1.0").send()?; + if !response.status().is_success() { + return Err(NUSError::NotFound); + } + Ok(response.bytes()?.to_vec()) +} + +/// Downloads all contents from the specified title from the NUS. +pub fn download_contents(tmd: &tmd::TMD, wiiu_endpoint: bool) -> Result>, NUSError> { + let content_ids: Vec = tmd.content_records.iter().map(|record| { record.content_id }).collect(); + let mut contents: Vec> = Vec::new(); + for id in content_ids { + contents.push(download_content(tmd.title_id, id, wiiu_endpoint)?); + } + Ok(contents) +} + +/// Downloads the Ticket for a specified Title ID from the NUS, if it's available. +pub fn download_ticket(title_id: [u8; 8], wiiu_endpoint: bool) -> Result, NUSError> { + // Build the download URL. The structure is download//cetk. + let endpoint_url = if wiiu_endpoint { + WII_U_NUS_ENDPOINT.to_owned() + } else { + WII_NUS_ENDPOINT.to_owned() + }; + let tik_url = format!("{}{}/cetk", endpoint_url, &hex::encode(title_id)); + let client = reqwest::blocking::Client::new(); + let response = client.get(tik_url).header(reqwest::header::USER_AGENT, "wii libnup/1.0").send()?; + if !response.status().is_success() { + return Err(NUSError::NotFound); + } + let tik = ticket::Ticket::from_bytes(&response.bytes()?).map_err(|_| NUSError::InvalidData)?; + tik.to_bytes().map_err(|_| NUSError::InvalidData) +} + +/// Downloads an entire title with all of its content from the NUS and returns a Title instance. +pub fn download_title(title_id: [u8; 8], title_version: Option, wiiu_endpoint: bool) -> Result { + // Download the individual components of a title and then build a title from them. + let cert_chain = cert::CertificateChain::from_bytes(&download_cert_chain(wiiu_endpoint)?)?; + let tmd = tmd::TMD::from_bytes(&download_tmd(title_id, title_version, wiiu_endpoint)?)?; + let tik = ticket::Ticket::from_bytes(&download_ticket(title_id, wiiu_endpoint)?)?; + let content_region = content::ContentRegion::from_contents(download_contents(&tmd, wiiu_endpoint)?, tmd.content_records.clone())?; + let title = title::Title::from_parts(cert_chain, None, tik, tmd, content_region, None)?; + Ok(title) +} + +/// Downloads the TMD for a specified Title ID from the NUS. +pub fn download_tmd(title_id: [u8; 8], title_version: Option, wiiu_endpoint: bool) -> Result, NUSError> { + // Build the download URL. The structure is download//tmd for latest and + // download//tmd. for when a specific version is requested. + let endpoint_url = if wiiu_endpoint { + WII_U_NUS_ENDPOINT.to_owned() + } else { + WII_NUS_ENDPOINT.to_owned() + }; + let tmd_url = if title_version.is_some() { + format!("{}{}/tmd.{}", endpoint_url, &hex::encode(title_id), title_version.unwrap()) + } else { + format!("{}{}/tmd", endpoint_url, &hex::encode(title_id)) + }; + let client = reqwest::blocking::Client::new(); + let response = client.get(tmd_url).header(reqwest::header::USER_AGENT, "wii libnup/1.0").send()?; + if !response.status().is_success() { + return Err(NUSError::NotFound); + } + let tmd = tmd::TMD::from_bytes(&response.bytes()?).map_err(|_| NUSError::InvalidData)?; + tmd.to_bytes().map_err(|_| NUSError::InvalidData) +} diff --git a/src/title/tmd.rs b/src/title/tmd.rs index c63d1fb..0559952 100644 --- a/src/title/tmd.rs +++ b/src/title/tmd.rs @@ -50,11 +50,11 @@ impl fmt::Display for TitleType { #[derive(Debug, Clone)] pub enum ContentType { - Normal, - Development, - HashTree, - DLC, - Shared, + Normal = 1, + Development = 2, + HashTree = 3, + DLC = 16385, + Shared = 32769, } impl fmt::Display for ContentType { @@ -70,8 +70,8 @@ impl fmt::Display for ContentType { } pub enum AccessRight { - AHB, - DVDVideo, + AHB = 0, + DVDVideo = 1, } #[derive(Debug, Clone)] @@ -332,10 +332,7 @@ impl TMD { /// Gets whether a specified access right is enabled in a TMD. pub fn check_access_right(&self, right: AccessRight) -> bool { - match right { - AccessRight::AHB => (self.access_rights & (1 << 0)) != 0, - AccessRight::DVDVideo => (self.access_rights & (1 << 1)) != 0, - } + self.access_rights & (1 << right as u8) != 0 } /// Gets the name of the certificate used to sign a TMD as a string.