From 8a23d5b71b8adec369e9e7c5cdda0963cc60d67e Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 23 Oct 2023 12:06:16 +0200 Subject: [PATCH 1/3] Issue #12: Add command to unzip osb files --- Cargo.lock | 300 ++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 10 ++ libs/deob/Cargo.toml | 7 + libs/deob/build.rs | 31 +++++ libs/deob/src/deob.c | 37 ++++++ libs/deob/src/deob.h | 43 +++++++ libs/deob/src/lib.rs | 38 ++++++ src/cli.rs | 3 + src/main.rs | 7 + src/unzip_osb.rs | 132 +++++++++++++++++++ 10 files changed, 588 insertions(+), 20 deletions(-) create mode 100644 libs/deob/Cargo.toml create mode 100644 libs/deob/build.rs create mode 100644 libs/deob/src/deob.c create mode 100644 libs/deob/src/deob.h create mode 100644 libs/deob/src/lib.rs create mode 100644 src/unzip_osb.rs diff --git a/Cargo.lock b/Cargo.lock index f2bf174..f700288 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aes" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "anstyle" version = "1.0.4" @@ -25,9 +36,9 @@ checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", @@ -49,6 +60,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bitflags" version = "1.3.2" @@ -57,9 +74,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" @@ -70,18 +87,46 @@ dependencies = [ "generic-array", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +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.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ + "jobserver", "libc", ] @@ -91,6 +136,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "clap" version = "4.4.6" @@ -152,14 +207,38 @@ dependencies = [ ] [[package]] -name = "cpufeatures" -version = "0.2.9" +name = "constant_time_eq" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cpufeatures" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" 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.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,6 +249,22 @@ dependencies = [ "typenum", ] +[[package]] +name = "deob" +version = "0.1.0" +dependencies = [ + "cc", +] + +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] + [[package]] name = "dialoguer" version = "0.11.0" @@ -191,6 +286,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -221,6 +317,16 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -239,9 +345,9 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -255,6 +361,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "indexmap" version = "2.0.2" @@ -265,12 +380,30 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + [[package]] name = "itoa" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jobserver" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +dependencies = [ + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -320,11 +453,36 @@ dependencies = [ "clap", "clap_complete", "console", + "deob", "dialoguer", "quick-xml", "serde", "serde_yaml", "sha256", + "zip", +] + +[[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]] @@ -333,6 +491,18 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.69" @@ -361,6 +531,12 @@ 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 = "redox_syscall" version = "0.3.5" @@ -378,11 +554,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.18" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -397,18 +573,18 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", @@ -428,6 +604,17 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.8" @@ -458,6 +645,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "syn" version = "2.0.38" @@ -484,24 +677,42 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "time" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +dependencies = [ + "deranged", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + [[package]] name = "tokio" version = "1.33.0" @@ -680,3 +891,52 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2", + "sha1", + "time", + "zstd", +] + +[[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.9+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 012f2cc..d4cc6de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,9 @@ readme = "README.md" build = "build.rs" +[workspace] +members = ["libs/deob"] + [dependencies] clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false } serde = { version = "1.0", features = ["derive"] } @@ -18,6 +21,13 @@ console = "0.15" sha256 = "1.4" dialoguer = "0.11" +deob = { path = "./libs/deob", optional = true } +zip = { version = "0.6", optional = true } + +[features] +# Requires env var OSB_KEY to be present at build time +unzip-osb = ["dep:deob", "dep:zip"] + [build-dependencies] clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false } clap_complete = "4.4" diff --git a/libs/deob/Cargo.toml b/libs/deob/Cargo.toml new file mode 100644 index 0000000..b5882e6 --- /dev/null +++ b/libs/deob/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "deob" +version = "0.1.0" +edition = "2021" + +[build-dependencies] +cc = "1.0" diff --git a/libs/deob/build.rs b/libs/deob/build.rs new file mode 100644 index 0000000..4c8c430 --- /dev/null +++ b/libs/deob/build.rs @@ -0,0 +1,31 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +use std::io::Error; + +fn main() -> Result<(), Error> { + cc::Build::new().file("src/deob.c").compile("deob"); + println!("cargo:rerun-if-changed=src/deob.c"); + Ok(()) +} diff --git a/libs/deob/src/deob.c b/libs/deob/src/deob.c new file mode 100644 index 0000000..78252ec --- /dev/null +++ b/libs/deob/src/deob.c @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "deob.h" + +void deob(char * in) { + const long long s[2] = { S0, S1 }; + char d[] = "OSTAR.password$OSB"; + for (size_t i = 0; i < DL; i++) d[i] = (CS)[i]; + size_t l = strlen(in) / 2; + for (size_t i = 0; i < l; i++) { + for (size_t j = 0; j < DL; j++) { DLT(0); DLT(1); } + DLS(i); + } + INZ(l); +} diff --git a/libs/deob/src/deob.h b/libs/deob/src/deob.h new file mode 100644 index 0000000..877795b --- /dev/null +++ b/libs/deob/src/deob.h @@ -0,0 +1,43 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef OSC_VARIANT_DEOB_H +#define OSC_VARIANT_DEOB_H + +#include +#include +#include + +#define S0 8373972096940928081 +#define S1 7378413942531504450 +#define CS (char*)&s +#define DL sizeof(d) / sizeof(d[0]) - 2 +#define I2 i*2 +#define INZ(var) in[var] = 0 +#define DLS(idx) in[idx] = (d[DL+1]<<4)|d[DL] +#define DLT(idx) d[DL+idx] = (in[I2+idx] == d[j]) ? (char)j : d[DL+idx] + +void deob(char * in); + +#endif //OSC_VARIANT_DEOB_H diff --git a/libs/deob/src/lib.rs b/libs/deob/src/lib.rs new file mode 100644 index 0000000..64f704f --- /dev/null +++ b/libs/deob/src/lib.rs @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +use std::ffi::{c_char, CStr, CString}; + +#[link(name = "deob")] +extern "C" { + fn deob(key: *const c_char); +} + +pub fn deobfuscate(s: &str) -> String { + let key = CString::new(s).unwrap_or_default().into_raw(); + unsafe { + deob(key); + String::from_utf8_lossy(CStr::from_ptr(key).to_bytes()).to_string() + } +} diff --git a/src/cli.rs b/src/cli.rs index db1a4d9..932bc3a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -101,4 +101,7 @@ pub enum SubCommand { #[arg(long = "strict", help = "Strikter Vergleich des Inhalts")] strict: bool, }, + #[cfg(feature = "unzip-osb")] + #[command(about = "Entpackt eine OSB-Datei")] + UnzipOsb { file: String }, } diff --git a/src/main.rs b/src/main.rs index 8ae217c..e3a4dbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,8 @@ use crate::profile::Profile; mod cli; mod model; mod profile; +#[cfg(feature = "unzip-osb")] +mod unzip_osb; enum FileError { Reading(String, String), @@ -255,6 +257,11 @@ fn main() -> Result<(), Box> { } }; } + #[cfg(feature = "unzip-osb")] + SubCommand::UnzipOsb { file } => { + use crate::unzip_osb::unzip_osb; + unzip_osb(file.as_str()) + } }; Ok(()) diff --git a/src/unzip_osb.rs b/src/unzip_osb.rs new file mode 100644 index 0000000..676fea1 --- /dev/null +++ b/src/unzip_osb.rs @@ -0,0 +1,132 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +use console::style; +use deob::deobfuscate; +use std::{fs, io}; + +macro_rules! started { + ( $o:expr ) => { + println!("{: <6}{}", style("[..]").cyan(), $o); + }; +} + +macro_rules! ok { + ( $o:expr ) => { + use console::Term; + let _ = Term::stdout().move_cursor_up(1); + println!("{: <6}{}", style("[OK]").green(), $o); + }; +} + +macro_rules! error { + ( $o:expr, $e:expr ) => { + use console::Term; + let _ = Term::stdout().move_cursor_up(1); + println!("{: <6}{} - Error: {}", style("[ERR]").red(), $o, $e); + }; +} + +pub fn unzip_osb(path: &str) { + println!("Entpacke OSB-Datei {}\n", style(path).yellow()); + + let pw = deobfuscate(env!("OSB_KEY").trim()); + + let file = match fs::File::open(path) { + Ok(file) => file, + Err(err) => { + println!( + "{: <6}Abbruch! - Kann Datei nicht entpacken: {}", + style("[ERR]").red(), + err + ); + return; + } + }; + + let mut archive = match zip::ZipArchive::new(file) { + Ok(file) => file, + Err(err) => { + println!( + "{: <6}Abbruch! - Kann Datei nicht entpacken: {}", + style("[ERR]").red(), + err + ); + return; + } + }; + + for i in 0..archive.len() { + let mut file = if let Ok(Ok(file)) = archive.by_index_decrypt(i, pw.as_bytes()) { + file + } else { + println!( + "{: <6}Abbruch! - Kann Datei nicht entpacken", + style("[ERR]").red() + ); + return; + }; + + let outpath = match file.enclosed_name() { + Some(path) => path.to_owned(), + None => continue, + }; + + started!(outpath.display()); + + if !file.is_dir() { + if let Some(p) = outpath.parent() { + if !p.exists() { + fs::create_dir_all(p).unwrap(); + } + } + let mut outfile = match fs::File::create(&outpath) { + Ok(file) => file, + Err(err) => { + error!(outpath.display(), err); + continue; + } + }; + match io::copy(&mut file, &mut outfile) { + Ok(_) => {} + Err(err) => { + error!(outpath.display(), err); + continue; + } + } + ok!(outpath.display()); + } else { + if !outpath.exists() { + match fs::create_dir_all(&outpath) { + Ok(_) => {} + Err(err) => { + error!(outpath.display(), err); + continue; + } + } + } + ok!(outpath.display()); + } + } +} From 8c11c6d891aed9c0e98f7626a1b6f71600968b2f Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 23 Oct 2023 12:12:38 +0200 Subject: [PATCH 2/3] Issue #12: Added information about subcommand unzip-os --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5e5a87a..a938e81 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ unvollständigen Ausgabedateien zu erzeugen. Die folgenden Unterbefehle sind verfügbar -#### `sha256sum` +#### Unterbefehl `sha256sum` Das Berechnen der SHA256 Prüfsumme ist mit dem Unterbefehl `sha256sum` auch unter Windows einfach möglich und erzeugt eine Ausgabe analog dem Befehl auf Linux-Systemen: @@ -27,7 +27,7 @@ und erzeugt eine Ausgabe analog dem Befehl auf Linux-Systemen: osc-variant sha256sum meine-beispieldatei.osc ``` -#### `list` +#### Unterbefehl `list` Zum Auflisten der Inhalte einer Datei wird folgender Befehl verwendet: @@ -37,7 +37,7 @@ osc-variant list meine-beispieldatei.osc Mit der Option `--filter` kann die Ausgabe eingeschränkt werden. -#### `tree` +#### Unterbefehl `tree` Zum Auflisten der Inhalte mit allen Abhängigkeiten, z.B. Daten- und Merkmalskataloge und bei Formularen wird der Befehl `tree` verwendet: @@ -59,7 +59,7 @@ Achtung! Dies erzeugt eine sehr umfangreiche Ausgabe. Mit der Option `--filter` kann auch hier die Ausgabe eingeschränkt werden. -#### `diff` +#### Unterbefehl `diff` Zum Vergleich zweier OSC-Dateien wird der Unterbefehl `diff` verwendet. Der optionale Parameter `--strict` vergleicht auch den Inhalt der OSC-Datei. @@ -75,7 +75,7 @@ bzw. osc-variant diff meine-beispieldatei.osc andere-beispieldatei.osc --strict ``` -#### `modify` +#### Unterbefehl `modify` Zum Anpassen des Inhalts einer Datei: @@ -91,6 +91,14 @@ Ohne Profildatei wird die Datei lediglich eingelesen, Leerzeichen am Ende eines Ohne eine Angabe der Ausgabedatei wird auf die Standardausgabe ausgegeben. +#### Unterbefehl `unzip-osb` + +Ab Version 0.6.0 ist die Anwendung zudem in der Lage, die für eine Aktualisierung der OS-Bibliothek genutzten OSB-Dateien zu entpacken: + +``` +osc-variant unzip-osb OSBIB-6.10.osb +``` + #### Kompakte Ausgabe OSC-Dateien sind XML-Dateien. Diese Anwendung ermöglicht optional die Ausgabe als kompaktere XML-Datei ohne Zeilenumbrüche. From f5dc366488ee504d29ed0167830c7b8afded4bc8 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 23 Oct 2023 12:44:40 +0200 Subject: [PATCH 3/3] Issue #12: Compile with feature unzip-osb in make file --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ad7a351..d76618d 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,11 @@ binary-all: win-binary-x86_64 linux-binary-x86_64 .PHONY: win-binary-x86_64 win-binary-x86_64: - cargo build --release --target=x86_64-pc-windows-gnu + cargo build --release --target=x86_64-pc-windows-gnu --features unzip-osb .PHONY: linux-binary-x86_64 linux-binary-x86_64: - cargo build --release --target=x86_64-unknown-linux-gnu + cargo build --release --target=x86_64-unknown-linux-gnu --features unzip-osb .PHONY: install install: