mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Move manager into it's own project
This commit is contained in:
Generated
+14
-2
@@ -164,9 +164,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"unshell-lib",
|
||||
"unshell-manager",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
@@ -662,13 +663,24 @@ dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"libc",
|
||||
"libloading",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-manager"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"libc",
|
||||
"libloading",
|
||||
"rand",
|
||||
"unshell-lib",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-obfuscate"
|
||||
version = "0.0.0"
|
||||
|
||||
@@ -2,19 +2,19 @@ cargo-features = ["trim-paths", "panic-immediate-abort"]
|
||||
|
||||
[package]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[features]
|
||||
log_debug = ["unshell-lib/log_debug"]
|
||||
obfuscate = ["unshell-lib/obfuscate", "unshell-obfuscate/obfuscate"]
|
||||
log_debug = ["unshell-lib/log_debug", "unshell-manager/obfuscate"]
|
||||
obfuscate = ["unshell-lib/obfuscate", "unshell-obfuscate/obfuscate", "unshell-manager/obfuscate"]
|
||||
|
||||
[dependencies]
|
||||
unshell-lib = {path = "../../unshell-lib", default-featues = false}
|
||||
unshell-obfuscate = {path = "../../unshell-obfuscate", default-featues = false}
|
||||
unshell-manager = {path = "../../unshell-manager", default-featues = false}
|
||||
|
||||
[profile.release]
|
||||
strip = true # Strip symbols from the binary
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cargo clean
|
||||
# cargo clean
|
||||
|
||||
OBFUSCATION_KEY=abc123abc \
|
||||
cargo build --release
|
||||
|
||||
@@ -8,15 +8,13 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use unshell_lib::{
|
||||
config::RuntimeConfig,
|
||||
module::Manager,
|
||||
network::{Stream, TcpStream},
|
||||
*,
|
||||
};
|
||||
use unshell_lib::{ModuleError, Result, config::RuntimeConfig, debug, error, info};
|
||||
// use unshell_modules::{Manager, ModuleRuntime};
|
||||
|
||||
use unshell_lib::ModuleRuntime;
|
||||
use unshell_manager::{
|
||||
Manager, ModuleRuntime,
|
||||
network::{Stream, TcpStream},
|
||||
};
|
||||
|
||||
pub struct ClientRuntime {
|
||||
config: &'static RuntimeConfig,
|
||||
@@ -25,7 +23,7 @@ pub struct ClientRuntime {
|
||||
}
|
||||
|
||||
impl ClientRuntime {
|
||||
pub fn new(config: &'static RuntimeConfig) -> Result<ClientRuntime, ModuleError> {
|
||||
pub fn new(config: &'static RuntimeConfig) -> Result<ClientRuntime> {
|
||||
let join_signal = Arc::new(AtomicBool::new(false));
|
||||
|
||||
Ok(Self {
|
||||
@@ -66,7 +64,7 @@ impl ModuleRuntime for ClientRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
fn init(&mut self, manager: Arc<Mutex<Manager>>) -> Result<(), ModuleError> {
|
||||
fn init(&mut self, manager: Arc<Mutex<Manager>>) -> Result<()> {
|
||||
let host = match self.config.config.get("host") {
|
||||
Some(host) => host,
|
||||
None => {
|
||||
|
||||
@@ -6,13 +6,13 @@ use std::any::TypeId;
|
||||
|
||||
use unshell_lib::{
|
||||
ModuleError,
|
||||
ModuleRuntime,
|
||||
// client::client_runtime::ClientRuntime,
|
||||
config::{InterfaceWrapper, NamedComponent, RuntimeConfig},
|
||||
module_interface,
|
||||
warn, // module_interface,
|
||||
config::RuntimeConfig,
|
||||
warn, // module_interface
|
||||
};
|
||||
|
||||
use unshell_manager::{InterfaceWrapper, ModuleRuntime, NamedComponent, module_interface};
|
||||
|
||||
use crate::client_runtime::ClientRuntime;
|
||||
|
||||
pub use unshell_lib::logger::setup_logger;
|
||||
|
||||
Generated
-720
@@ -1,720 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cipher",
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
|
||||
dependencies = [
|
||||
"bincode_derive",
|
||||
"serde",
|
||||
"unty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode_derive"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
|
||||
dependencies = [
|
||||
"virtue",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d28ed5f5f65056148fd25e1a596b5b6d9e772270abf9a9085d7cbfbf26c563"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
||||
|
||||
[[package]]
|
||||
name = "cbc"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[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 = "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"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasip2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hex-literal"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1"
|
||||
|
||||
[[package]]
|
||||
name = "hybrid-array"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f471e0a81b2f90ffc0cb2f951ae04da57de8baa46fa99112b062a5173a5088d0"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
||||
dependencies = [
|
||||
"block-padding 0.3.3",
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[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.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.177"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.145"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unshell-breakout-module"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"unshell-lib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-crypt"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"block-padding 0.4.1",
|
||||
"cbc",
|
||||
"getrandom",
|
||||
"hex",
|
||||
"hex-literal",
|
||||
"regex",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-lib"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"libc",
|
||||
"libloading",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-obfuscate"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"unshell-crypt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unty"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "virtue"
|
||||
version = "0.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.1+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.59.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43fa6694ed34d6e57407afbccdeecfa268c470a7d2a5b0cf49ce9fcc345afb90"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c640b22cd9817fae95be82f0d2f90b11f7605f6c319d16705c459b27ac2cbc26"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
@@ -1,32 +0,0 @@
|
||||
cargo-features = ["trim-paths"]
|
||||
|
||||
[package]
|
||||
name = "unshell-breakout-module"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[features]
|
||||
default = ["client", "server", "log_debug"]
|
||||
|
||||
client = ["unshell-lib/client"]
|
||||
server = ["unshell-lib/server"]
|
||||
|
||||
log_debug = ["unshell-lib/log_debug"]
|
||||
obfuscate = ["unshell-lib/obfuscate"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
unshell-lib = {path = "../unshell-lib", default-featues = false}
|
||||
|
||||
|
||||
[profile.release]
|
||||
strip = true # Strip symbols from the binary
|
||||
opt-level = "s" # Optimize for size
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
debug = false
|
||||
trim-paths = "all"
|
||||
@@ -1,2 +0,0 @@
|
||||
# unshell-breakout-module
|
||||
Project that contains the code to construct a module
|
||||
@@ -1,8 +0,0 @@
|
||||
OBFUSCATION_KEY=abc123abc \
|
||||
RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" \
|
||||
cargo +nightly build \
|
||||
-Z build-std=std,panic_abort \
|
||||
-Z build-std-features="optimize_for_size" \
|
||||
--profile release $@
|
||||
|
||||
# upx ./target/release/libunshell_module_test.so
|
||||
@@ -1,4 +0,0 @@
|
||||
// Behold! The world's most sophisticated shared library! (it has no code)
|
||||
#![no_main]
|
||||
|
||||
pub use unshell_lib::get_components;
|
||||
@@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "unshell-cli"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
unshell-lib = {path = "../unshell-lib", features=["log_debug"]}
|
||||
unshell-obfuscate = {path = "../unshell-obfuscate"}
|
||||
unshell-crypt = {path = "../unshell-crypt"}
|
||||
# lazy_static = "1.5.0"
|
||||
static_init = "1.0.4"
|
||||
@@ -1,2 +0,0 @@
|
||||
# unshell-cli
|
||||
Command-line interface for unshell
|
||||
@@ -1,6 +0,0 @@
|
||||
RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" cargo +nightly run \
|
||||
-Z build-std=std,panic_abort \
|
||||
-Z build-std-features="optimize_for_size" \
|
||||
--profile release $@
|
||||
|
||||
# upx ./target/release/libunshell_module_test.so
|
||||
@@ -1,94 +0,0 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::{Write, stdin, stdout},
|
||||
};
|
||||
|
||||
use static_init::dynamic;
|
||||
use unshell_lib::{
|
||||
config::{PayloadConfig, RuntimeConfig},
|
||||
module::Manager,
|
||||
};
|
||||
use unshell_obfuscate::{obs, symbol};
|
||||
|
||||
#[dynamic]
|
||||
static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
|
||||
id: symbol!("Test ID"),
|
||||
components: unshell_lib::get_components(),
|
||||
runtime_config: vec![],
|
||||
};
|
||||
|
||||
use std::alloc::{Layout, alloc};
|
||||
use std::ptr;
|
||||
|
||||
fn leak<T>(value: T) -> &'static mut T {
|
||||
unsafe {
|
||||
let layout = Layout::new::<T>();
|
||||
let ptr = alloc(layout) as *mut T;
|
||||
ptr::write(ptr, value);
|
||||
&mut *ptr
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
unshell_lib::logger::PrettyLogger::init();
|
||||
|
||||
let manager = Manager::start(&PAYLOAD_CONFIG, Vec::new());
|
||||
|
||||
let runtime = leak(RuntimeConfig {
|
||||
parent_component: symbol!("server").to_string(),
|
||||
name: symbol!("server runtime").to_string(),
|
||||
config: HashMap::from([(symbol!("host").to_string(), obs!("localhost:1234"))]),
|
||||
});
|
||||
|
||||
Manager::add_runtime(manager.clone(), runtime)?;
|
||||
|
||||
// Manager::st
|
||||
|
||||
// Manager::join(manager);
|
||||
|
||||
loop {
|
||||
print!("> ");
|
||||
stdout().flush().expect("Failed to flush stdout");
|
||||
let mut input = String::new();
|
||||
stdin().read_line(&mut input).expect("Failed to read line");
|
||||
|
||||
let args = input.trim().split(" ").collect::<Vec<&str>>();
|
||||
|
||||
match args[0] {
|
||||
"" => {}
|
||||
"c" => {
|
||||
println!(
|
||||
"Current connections: {}",
|
||||
manager.lock().unwrap().connections.len()
|
||||
)
|
||||
}
|
||||
"test" => {
|
||||
if let Some(arg) = args.get(1) {
|
||||
println!("Test with argument: {}", arg);
|
||||
|
||||
manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.broadcast(unshell_lib::Announcement::TestAnnouncement(arg.to_string()))?;
|
||||
|
||||
// serverruntime
|
||||
// .send(&Announcement::TestAnnouncement(arg.to_string()))
|
||||
// .unwrap();
|
||||
} else {
|
||||
println!("Test without argument");
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
println!("Invalid Command: '{}'", args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// println!("{:?}", args);
|
||||
}
|
||||
|
||||
// serverruntime.send(&Announcement::GetRuntimes)?;
|
||||
|
||||
// let response = serverruntime.
|
||||
|
||||
// Ok(())
|
||||
}
|
||||
Generated
-11
@@ -317,16 +317,6 @@ version = "0.2.177"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.14"
|
||||
@@ -654,7 +644,6 @@ dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"libc",
|
||||
"libloading",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -16,7 +16,7 @@ obfuscate = ["unshell-obfuscate/obfuscate"]
|
||||
|
||||
[dependencies]
|
||||
# Base dependencies
|
||||
libloading = {version = "0.8.9"}
|
||||
# libloading = {version = "0.8.9"}
|
||||
bincode = "2.0.1"
|
||||
unshell-obfuscate = {path = "../unshell-obfuscate"}
|
||||
chrono = "0.4.42"
|
||||
|
||||
@@ -1,25 +1,4 @@
|
||||
use std::{collections::HashMap, fmt::Debug};
|
||||
|
||||
// use bincode::{Decode, Encode};
|
||||
// use serde::{Deserialize, Serialize};
|
||||
|
||||
// use bincode::{Decode, Encode};
|
||||
|
||||
use crate::{ModuleError, ModuleRuntime};
|
||||
|
||||
// /// Payload config that is instantiated
|
||||
// #[derive(Serialize, Deserialize)]
|
||||
// pub struct Config {
|
||||
// pub id: String,
|
||||
// pub key: String,
|
||||
// pub components: Vec<String>,
|
||||
// }
|
||||
|
||||
pub struct PayloadConfig {
|
||||
pub id: &'static str,
|
||||
pub components: Vec<NamedComponent>,
|
||||
pub runtime_config: Vec<RuntimeConfig>,
|
||||
}
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RuntimeConfig {
|
||||
@@ -27,41 +6,3 @@ pub struct RuntimeConfig {
|
||||
pub name: String,
|
||||
pub config: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NamedComponent {
|
||||
pub name: &'static str,
|
||||
|
||||
// + Sync + Sync + Sync + Sync + Sync + Sync + Sync + Sync
|
||||
pub get_interface: &'static (dyn Fn() -> Option<&'static (dyn InterfaceWrapper + Sync)> + Sync),
|
||||
pub start_runtime: &'static (
|
||||
dyn Fn(&'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime>, ModuleError>
|
||||
+ Sync
|
||||
),
|
||||
}
|
||||
|
||||
impl Debug for NamedComponent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("NamedComponent")
|
||||
.field("name", &self.name)
|
||||
// .field("get_interface", &self.get_interface)
|
||||
// .field("start_runtime", &self.start_runtime)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait that wraps the get_interface<T>() function inside of components
|
||||
pub trait InterfaceWrapper: Send + Sync {
|
||||
fn get_interface<T: 'static>(&self) -> Option<T>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
// impl<T: 'static> InterfaceWrapper for T {
|
||||
// default fn get_interface<T>() -> Option<T>
|
||||
// where
|
||||
// Self: Sized,
|
||||
// {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
|
||||
+3
-19
@@ -2,23 +2,18 @@
|
||||
|
||||
pub mod config;
|
||||
pub mod logger;
|
||||
pub mod module;
|
||||
pub mod network;
|
||||
|
||||
mod announcement;
|
||||
use std::{
|
||||
fmt::{self, Debug},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use std::fmt::{self, Debug};
|
||||
|
||||
pub use announcement::Announcement;
|
||||
|
||||
use crate::module::Manager;
|
||||
pub type Result<T> = std::result::Result<T, ModuleError>;
|
||||
|
||||
///Generic error type for module-related operations.
|
||||
#[derive(Debug)]
|
||||
pub enum ModuleError {
|
||||
LibLoadingError(libloading::Error),
|
||||
LibLoadingError(String),
|
||||
// LogError(log::SetLoggerError),
|
||||
LinkError(String),
|
||||
CryptError(String),
|
||||
@@ -45,17 +40,6 @@ impl fmt::Display for ModuleError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for defining modules that have a runtime.
|
||||
pub trait ModuleRuntime: Send + Sync {
|
||||
fn init(&mut self, manager: Arc<Mutex<Manager>>) -> Result<(), ModuleError>;
|
||||
|
||||
/// Returns true if the module is running.
|
||||
/// After returning false, the module will be dropped.
|
||||
fn is_running(&self) -> bool;
|
||||
/// Consumes the module, implementation should kill whatever is running.
|
||||
fn kill(self: Box<Self>);
|
||||
}
|
||||
|
||||
// pub trait Component {
|
||||
// fn name(&self) -> &'static str;
|
||||
// // fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
|
||||
|
||||
+57
-54
@@ -89,18 +89,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d28ed5f5f65056148fd25e1a596b5b6d9e772270abf9a9085d7cbfbf26c563"
|
||||
checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.0"
|
||||
version = "3.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
||||
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
|
||||
|
||||
[[package]]
|
||||
name = "cbc"
|
||||
@@ -113,9 +113,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.45"
|
||||
version = "1.2.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe"
|
||||
checksum = "9f50d563227a1c37cc0a263f64eca3334388c01c5e4c4861a9def205c614383c"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
@@ -194,9 +194,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
@@ -214,15 +214,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.9"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
@@ -297,15 +297,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
checksum = "7ee5b5339afb4c41626dde77b7a611bd4f2c202b897852b4bcf5d03eddc61010"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.82"
|
||||
version = "0.3.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65"
|
||||
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
@@ -313,9 +313,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.177"
|
||||
version = "0.2.178"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
@@ -338,9 +338,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.28"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -494,9 +494,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
checksum = "62049b2877bf12821e8f9ad256ee38fdc31db7387ec2d3b3f403024de2034aea"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
@@ -531,7 +531,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -611,9 +611,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.110"
|
||||
version = "2.0.111"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
|
||||
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -632,22 +632,12 @@ version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unshell-cli"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"static_init",
|
||||
"unshell-crypt",
|
||||
"unshell-lib",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-crypt"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"block-padding 0.4.1",
|
||||
"block-padding 0.4.2",
|
||||
"cbc",
|
||||
"getrandom",
|
||||
"hex",
|
||||
@@ -664,20 +654,33 @@ dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"libc",
|
||||
"libloading",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-manager"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"libc",
|
||||
"libloading",
|
||||
"rand",
|
||||
"unshell-lib",
|
||||
"unshell-obfuscate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell-obfuscate"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
"rand",
|
||||
"static_init",
|
||||
"syn 2.0.111",
|
||||
"unshell-crypt",
|
||||
]
|
||||
|
||||
@@ -710,9 +713,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60"
|
||||
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -723,9 +726,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2"
|
||||
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -733,22 +736,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc"
|
||||
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
"syn 2.0.111",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76"
|
||||
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -796,7 +799,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -807,7 +810,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -842,20 +845,20 @@ checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.30"
|
||||
version = "0.8.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ea879c944afe8a2b25fef16bb4ba234f47c694565e97383b36f3a878219065c"
|
||||
checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.30"
|
||||
version = "0.8.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf955aa904d6040f70dc8e9384444cb1030aed272ba3cb09bbc4ab9e7c1f34f5"
|
||||
checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "unshell-manager"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
obfuscate = ["unshell-obfuscate/obfuscate"]
|
||||
log = ["unshell-lib/log"]
|
||||
log_debug = ["unshell-lib/log_debug"]
|
||||
|
||||
client = ["unshell-lib/client"]
|
||||
server = ["unshell-lib/server"]
|
||||
|
||||
[dependencies]
|
||||
unshell-lib = {path = "../unshell-lib", default-features = false}
|
||||
unshell-obfuscate = {path = "../unshell-obfuscate", default-features = false}
|
||||
|
||||
bincode = "2.0.1"
|
||||
libc = "0.2.178"
|
||||
libloading = "0.8.9"
|
||||
rand = "0.9.2"
|
||||
@@ -0,0 +1,39 @@
|
||||
// use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
use unshell_lib::Result;
|
||||
use unshell_lib::config::RuntimeConfig;
|
||||
|
||||
use crate::ModuleRuntime;
|
||||
|
||||
pub struct PayloadConfig {
|
||||
pub id: &'static str,
|
||||
pub components: Vec<NamedComponent>,
|
||||
pub runtime_config: Vec<RuntimeConfig>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NamedComponent {
|
||||
pub name: &'static str,
|
||||
|
||||
// + Sync + Sync + Sync + Sync + Sync + Sync + Sync + Sync
|
||||
pub get_interface: &'static (dyn Fn() -> Option<&'static (dyn InterfaceWrapper + Sync)> + Sync),
|
||||
pub start_runtime:
|
||||
&'static (dyn Fn(&'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime>> + Sync),
|
||||
}
|
||||
|
||||
impl Debug for NamedComponent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("NamedComponent")
|
||||
.field("name", &self.name)
|
||||
// .field("get_interface", &self.get_interface)
|
||||
// .field("start_runtime", &self.start_runtime)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait that wraps the get_interface<T>() function inside of components
|
||||
pub trait InterfaceWrapper: Send + Sync {
|
||||
fn get_interface<T: 'static>(&self) -> Option<T>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
mod manager;
|
||||
mod module;
|
||||
mod module_interface;
|
||||
pub mod network;
|
||||
mod proc_load;
|
||||
|
||||
pub mod interface;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub use manager::Manager;
|
||||
pub use module::Module;
|
||||
|
||||
pub use interface::{InterfaceWrapper, NamedComponent};
|
||||
|
||||
extern crate unshell_lib;
|
||||
use unshell_lib::Result;
|
||||
|
||||
/// Trait for defining modules that have a runtime.
|
||||
pub trait ModuleRuntime: Send + Sync {
|
||||
fn init(&mut self, manager: Arc<Mutex<Manager>>) -> Result<()>;
|
||||
|
||||
/// Returns true if the module is running.
|
||||
/// After returning false, the module will be dropped.
|
||||
fn is_running(&self) -> bool;
|
||||
/// Consumes the module, implementation should kill whatever is running.
|
||||
fn kill(self: Box<Self>);
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use crate::{Announcement, module::Manager};
|
||||
use crate::Manager;
|
||||
use unshell_lib::Announcement;
|
||||
|
||||
impl Manager {
|
||||
pub fn recv_announcement(&mut self, announcement: &Announcement) {
|
||||
+6
-2
@@ -1,4 +1,8 @@
|
||||
use crate::{Announcement, ModuleError, module::Manager, network::Stream};
|
||||
use unshell_lib::{Announcement, Result};
|
||||
|
||||
use crate::network::Stream;
|
||||
|
||||
use crate::Manager;
|
||||
|
||||
impl Manager {
|
||||
pub fn add_connection(&mut self, connection: Box<dyn Stream<Announcement>>) {
|
||||
@@ -23,7 +27,7 @@ impl Manager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn broadcast(&mut self, announcement: Announcement) -> Result<(), ModuleError> {
|
||||
pub fn broadcast(&mut self, announcement: Announcement) -> Result<()> {
|
||||
for connection in &mut self.connections {
|
||||
connection.write(announcement.clone())?;
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
mod announcement;
|
||||
mod connection;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
@@ -5,14 +8,16 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::{NamedComponent, PayloadConfig, RuntimeConfig},
|
||||
network::Stream,
|
||||
*,
|
||||
};
|
||||
use module::Module;
|
||||
use unshell_lib::{Announcement, Result, config::RuntimeConfig, debug, warn};
|
||||
use unshell_obfuscate::symbol;
|
||||
|
||||
use crate::{
|
||||
ModuleRuntime,
|
||||
interface::{NamedComponent, PayloadConfig},
|
||||
module::Module,
|
||||
network::Stream,
|
||||
};
|
||||
|
||||
// #[derive(Debug)]
|
||||
pub struct Manager {
|
||||
id: &'static str,
|
||||
@@ -175,10 +180,7 @@ impl Manager {
|
||||
this_lock.active_runtimes.push(runtime);
|
||||
}
|
||||
|
||||
pub fn add_runtime(
|
||||
this: Arc<Mutex<Self>>,
|
||||
runtime: &'static RuntimeConfig,
|
||||
) -> Result<(), ModuleError> {
|
||||
pub fn add_runtime(this: Arc<Mutex<Self>>, runtime: &'static RuntimeConfig) -> Result<()> {
|
||||
Self::create_runtime(this.clone(), runtime);
|
||||
|
||||
this.lock()
|
||||
@@ -1,22 +1,25 @@
|
||||
use libloading::{Library, Symbol};
|
||||
use unshell_lib::{
|
||||
ModuleError, Result,
|
||||
logger::{self, SetupLogger, logger},
|
||||
warn,
|
||||
};
|
||||
|
||||
use crate::module::proc_load::memfd_create_dlopen;
|
||||
use crate::{ModuleError, logger::SetupLogger, logger::logger};
|
||||
|
||||
use crate::*;
|
||||
use crate::proc_load::memfd_create_dlopen;
|
||||
|
||||
pub struct Module {
|
||||
lib: Library,
|
||||
}
|
||||
|
||||
impl Module {
|
||||
pub fn new(path: &str) -> Result<Self, ModuleError> {
|
||||
let lib = unsafe { Library::new(&path) }.map_err(|e| ModuleError::LibLoadingError(e))?;
|
||||
pub fn new(path: &str) -> Result<Self> {
|
||||
let lib = unsafe { Library::new(&path) }
|
||||
.map_err(|e| ModuleError::LibLoadingError(e.to_string()))?;
|
||||
|
||||
let this = Self { lib };
|
||||
|
||||
if let Ok(setup_logger) = this.get_symbol::<SetupLogger>(b"setup_logger") {
|
||||
setup_logger(logger());
|
||||
setup_logger(logger::logger());
|
||||
} else {
|
||||
warn!("setup_logger not found");
|
||||
}
|
||||
@@ -26,7 +29,7 @@ impl Module {
|
||||
|
||||
// TODO: Implement actual reflective ELF loading (possibly even custom format)
|
||||
// Look at https://github.com/weizhiao/rust-elfloader
|
||||
pub fn new_bytes(bytes: &[u8]) -> Result<Self, ModuleError> {
|
||||
pub fn new_bytes(bytes: &[u8]) -> Result<Self> {
|
||||
let lib =
|
||||
memfd_create_dlopen(bytes).map_err(|e| ModuleError::Error(e.to_string().into()))?;
|
||||
|
||||
@@ -40,7 +43,7 @@ impl Module {
|
||||
|
||||
Ok(this)
|
||||
}
|
||||
pub fn get_symbol<T>(&self, symbol: &[u8]) -> Result<Symbol<'_, T>, ModuleError> {
|
||||
pub fn get_symbol<T>(&self, symbol: &[u8]) -> Result<Symbol<'_, T>> {
|
||||
let symbol = unsafe { self.lib.get::<T>(symbol) }
|
||||
.map_err(|e| ModuleError::LinkError(format!("Failed to load symbol: {}", e)))?;
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
mod manager;
|
||||
mod manager_announcement;
|
||||
mod manager_connection;
|
||||
|
||||
mod module;
|
||||
|
||||
mod proc_load;
|
||||
|
||||
// use std::any::Any;
|
||||
|
||||
// pub use logger::setup_logger;
|
||||
pub use manager::Manager;
|
||||
pub use module::Module;
|
||||
|
||||
/// "Module Interface" helper macro that creates a struct with function pointers
|
||||
/// Useful for defining and requiring modules' functions accross FFI boundry.
|
||||
#[macro_export]
|
||||
@@ -1,10 +1,9 @@
|
||||
// mod connection;
|
||||
mod tcp_stream;
|
||||
|
||||
pub use tcp_stream::TcpStream;
|
||||
|
||||
// pub use connection::Connection;
|
||||
|
||||
use crate::ModuleError;
|
||||
use unshell_lib::ModuleError;
|
||||
|
||||
/// This is the data transmission type
|
||||
pub trait Stream<T>: Send + Sync {
|
||||
@@ -7,7 +7,9 @@ use std::{
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{Announcement, ModuleError, debug, network::Stream};
|
||||
use unshell_lib::{Announcement, ModuleError, Result, debug};
|
||||
|
||||
use crate::network::Stream;
|
||||
|
||||
pub struct TcpStream(Arc<AtomicBool>, net::TcpStream);
|
||||
|
||||
@@ -96,7 +98,7 @@ impl Stream<Announcement> for TcpStream {
|
||||
ret
|
||||
}
|
||||
|
||||
fn write(&mut self, announcement: Announcement) -> Result<(), crate::ModuleError> {
|
||||
fn write(&mut self, announcement: Announcement) -> Result<()> {
|
||||
let bytes = announcement.encode();
|
||||
|
||||
// Write length of bytes
|
||||
@@ -115,7 +117,7 @@ impl Stream<Announcement> for TcpStream {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn try_clone(&self) -> Result<Box<dyn Stream<Announcement> + Send + Sync>, crate::ModuleError> {
|
||||
fn try_clone(&self) -> Result<Box<dyn Stream<Announcement> + Send + Sync>> {
|
||||
Ok(Box::new(Self(
|
||||
self.0.clone(),
|
||||
self.1
|
||||
@@ -1,27 +1,30 @@
|
||||
// Load a shared object by saving bytes to a filesystem in /proc
|
||||
|
||||
use std::{error::Error, ffi::CString, io}; // 0.8
|
||||
use std::{ffi::CString, io};
|
||||
|
||||
use libloading::Library;
|
||||
|
||||
use crate::debug;
|
||||
use unshell_lib::{ModuleError, Result, warn};
|
||||
|
||||
// The `memfd_create` syscall flags (MFD_CLOEXEC is common and good practice)
|
||||
const MFD_CLOEXEC: u32 = 0x0001;
|
||||
const MFD_ALLOW_SEALING: u32 = 0x0002;
|
||||
|
||||
pub fn memfd_create_dlopen(payload: &[u8]) -> Result<Library, Box<dyn Error>> {
|
||||
pub fn memfd_create_dlopen(payload: &[u8]) -> Result<Library> {
|
||||
use rand::distr::{Alphanumeric, SampleString};
|
||||
|
||||
let string = Alphanumeric.sample_string(&mut rand::rng(), 16);
|
||||
|
||||
// 1. Create the anonymous in-memory file descriptor using the raw syscall
|
||||
let c_name = CString::new(string).expect("CString conversion failed");
|
||||
let c_name = CString::new(string)
|
||||
.map_err(|e| ModuleError::LibLoadingError(format!("CString conversion failed: {e:?}")))?;
|
||||
|
||||
let fd = unsafe { libc::memfd_create(c_name.as_ptr(), MFD_CLOEXEC | MFD_ALLOW_SEALING) };
|
||||
|
||||
if fd < 0 {
|
||||
return Err(io::Error::last_os_error().to_string().into());
|
||||
return Err(ModuleError::LibLoadingError(format!(
|
||||
"IO Error {:?}",
|
||||
io::Error::last_os_error().to_string()
|
||||
)));
|
||||
}
|
||||
|
||||
// 2. Write the payload bytes to the in-memory file
|
||||
@@ -33,7 +36,9 @@ pub fn memfd_create_dlopen(payload: &[u8]) -> Result<Library, Box<dyn Error>> {
|
||||
unsafe {
|
||||
libc::close(fd);
|
||||
}
|
||||
return Err("Failed to write full payload to memfd".into());
|
||||
return Err(ModuleError::LibLoadingError(
|
||||
"Failed to write full payload to memfd".into(),
|
||||
));
|
||||
}
|
||||
|
||||
// Optional: Seal the file to prevent modification, common for security/integrity
|
||||
@@ -41,7 +46,7 @@ pub fn memfd_create_dlopen(payload: &[u8]) -> Result<Library, Box<dyn Error>> {
|
||||
let seals = libc::F_SEAL_GROW | libc::F_SEAL_SHRINK | libc::F_SEAL_WRITE;
|
||||
if unsafe { libc::fcntl(fd, libc::F_ADD_SEALS, seals) } == -1 {
|
||||
// Log a warning but continue if sealing fails (e.g., due to permissions)
|
||||
debug!(
|
||||
warn!(
|
||||
"memfd_create_dlopen: Failed to apply seals. Error: {}",
|
||||
io::Error::last_os_error()
|
||||
);
|
||||
@@ -52,5 +57,8 @@ pub fn memfd_create_dlopen(payload: &[u8]) -> Result<Library, Box<dyn Error>> {
|
||||
let dl_path = format!("/proc/self/fd/{}", fd);
|
||||
|
||||
// 4. Use dlopen (via libloading) on the virtual path
|
||||
Ok(unsafe { Library::new(&dl_path)? })
|
||||
Ok(unsafe {
|
||||
Library::new(&dl_path)
|
||||
.map_err(|e| ModuleError::LibLoadingError(format!("Failed to import library: {}", e)))?
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user