mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
(Broken) Work on new dynamic runtime config system
This commit is contained in:
Generated
+28
-7
@@ -256,6 +256,12 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.82"
|
version = "0.3.82"
|
||||||
@@ -368,6 +374,12 @@ version = "1.0.22"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.228"
|
||||||
@@ -375,6 +387,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -397,6 +410,19 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@@ -463,16 +489,11 @@ dependencies = [
|
|||||||
name = "unshell-lib"
|
name = "unshell-lib"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
|
||||||
"bincode",
|
"bincode",
|
||||||
"block-padding 0.4.1",
|
|
||||||
"cbc",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"getrandom",
|
|
||||||
"hex",
|
|
||||||
"hex-literal",
|
|
||||||
"libloading",
|
"libloading",
|
||||||
"sha2",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"unshell-obfuscate",
|
"unshell-obfuscate",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unshell-config"
|
||||||
|
version = "0.1.0"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "unshell-config"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
Generated
+28
-7
@@ -256,6 +256,12 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.82"
|
version = "0.3.82"
|
||||||
@@ -368,6 +374,12 @@ version = "1.0.22"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.228"
|
||||||
@@ -375,6 +387,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -397,6 +410,19 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@@ -455,16 +481,11 @@ dependencies = [
|
|||||||
name = "unshell-lib"
|
name = "unshell-lib"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
|
||||||
"bincode",
|
"bincode",
|
||||||
"block-padding 0.4.1",
|
|
||||||
"cbc",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"getrandom",
|
|
||||||
"hex",
|
|
||||||
"hex-literal",
|
|
||||||
"libloading",
|
"libloading",
|
||||||
"sha2",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"unshell-obfuscate",
|
"unshell-obfuscate",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
+9
-10
@@ -3,8 +3,15 @@ name = "unshell-lib"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["client", "server"]
|
||||||
|
|
||||||
|
# Components
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
|
||||||
log_debug = []
|
log_debug = []
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Base dependencies
|
# Base dependencies
|
||||||
libloading = {version = "0.8.9"}
|
libloading = {version = "0.8.9"}
|
||||||
@@ -12,13 +19,5 @@ bincode = "2.0.1"
|
|||||||
unshell-obfuscate = {path = "../unshell-obfuscate"}
|
unshell-obfuscate = {path = "../unshell-obfuscate"}
|
||||||
chrono = "0.4.42"
|
chrono = "0.4.42"
|
||||||
|
|
||||||
# Crypt dependencies
|
serde = {version = "1.0.228", features=["derive"]}
|
||||||
aes = "0.8.4"
|
serde_json = "1.0.145"
|
||||||
block-padding = "0.4.1"
|
|
||||||
cbc = "0.1.2"
|
|
||||||
getrandom = "0.3.4"
|
|
||||||
hex = "0.4.3"
|
|
||||||
hex-literal = "1.1.0"
|
|
||||||
sha2 = "0.10.9"
|
|
||||||
|
|
||||||
#
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
mod client_runtime;
|
mod client_runtime;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
|
|
||||||
pub const MODULE_NAME: &'static str = "client";
|
pub const MODULE_NAME: &'static str = "client";
|
||||||
|
|
||||||
// pub use unshell_modules::setup_logger;
|
// pub use unshell_modules::setup_logger;
|
||||||
@@ -10,9 +8,7 @@ pub const MODULE_NAME: &'static str = "client";
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Component,
|
Component,
|
||||||
ModuleRuntime,
|
module::Interface,
|
||||||
client::client_runtime::RuntimeTest,
|
|
||||||
module::{Interface, Manager},
|
|
||||||
module_interface,
|
module_interface,
|
||||||
warn,
|
warn,
|
||||||
// module_interface,
|
// module_interface,
|
||||||
@@ -60,9 +56,9 @@ impl Component for ClientComponent {
|
|||||||
MODULE_NAME
|
MODULE_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>> {
|
// fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>> {
|
||||||
Some(Box::new(RuntimeTest::new(manager)))
|
// Some(Box::new(RuntimeTest::new(manager)))
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn clone_box(&self) -> Box<dyn Component> {
|
fn clone_box(&self) -> Box<dyn Component> {
|
||||||
Box::new(self.clone())
|
Box::new(self.clone())
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
use unshell_obfuscate::obfuscated_symbol;
|
||||||
|
|
||||||
|
use crate::{Component, config::NamedComponent};
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[obfuscated_symbol]
|
||||||
|
pub fn get_components() -> Vec<NamedComponent> {
|
||||||
|
// let mut components: HashMap<&'static str, Box<dyn Component>> = HashMap::new();
|
||||||
|
|
||||||
|
return vec![
|
||||||
|
NamedComponent {name:,crate::client::MODULE_NAME, get_interface: crate::client::get_interface, start_runtime: todo!() },
|
||||||
|
];
|
||||||
|
|
||||||
|
// components
|
||||||
|
|
||||||
|
// vec![
|
||||||
|
// Feature::Client,
|
||||||
|
// #[cfg(feature = "server")]
|
||||||
|
// Feature::Server,
|
||||||
|
// ]
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
// use bincode::{Decode, Encode};
|
||||||
|
// use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
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>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct RuntimeConfig {
|
||||||
|
pub parent_component: &'static str,
|
||||||
|
pub name: &'static str,
|
||||||
|
pub config: HashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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<&'static dyn ModuleRuntime, ModuleError>
|
||||||
|
+ Sync
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Trait that wraps the get_interface<T>() function inside of components
|
||||||
|
pub trait InterfaceWrapper: Send + Sync {
|
||||||
|
fn get_interface<T>() -> Option<T>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
|
}
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
pub mod config;
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
pub mod module;
|
pub mod module;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
|
||||||
|
mod components;
|
||||||
|
pub use components::get_components;
|
||||||
|
|
||||||
mod announcement;
|
mod announcement;
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
@@ -46,7 +50,7 @@ impl fmt::Display for ModuleError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for defining modules that have a runtime.
|
/// Trait for defining modules that have a runtime.
|
||||||
pub trait ModuleRuntime: Send {
|
pub trait ModuleRuntime: Send + Sync {
|
||||||
/// Returns true if the module is running.
|
/// Returns true if the module is running.
|
||||||
/// After returning false, the module will be dropped.
|
/// After returning false, the module will be dropped.
|
||||||
fn is_running(&self) -> bool;
|
fn is_running(&self) -> bool;
|
||||||
@@ -56,7 +60,8 @@ pub trait ModuleRuntime: Send {
|
|||||||
|
|
||||||
pub trait Component {
|
pub trait Component {
|
||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
|
// fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
|
||||||
|
|
||||||
fn get_interface(&self) -> Box<dyn Interface>;
|
fn get_interface(&self) -> Box<dyn Interface>;
|
||||||
fn clone_box(&self) -> Box<dyn Component>;
|
fn clone_box(&self) -> Box<dyn Component>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,81 +7,142 @@ use std::{
|
|||||||
|
|
||||||
use unshell_obfuscate::symbol;
|
use unshell_obfuscate::symbol;
|
||||||
|
|
||||||
use crate::*;
|
use crate::{
|
||||||
|
config::{NamedComponent, PayloadConfig, RuntimeConfig},
|
||||||
|
*,
|
||||||
|
};
|
||||||
use module::Module;
|
use module::Module;
|
||||||
|
|
||||||
// #[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
pub struct Manager {
|
pub struct Manager<'a> {
|
||||||
|
id: &'static str,
|
||||||
|
|
||||||
modules: Vec<Module>,
|
modules: Vec<Module>,
|
||||||
components: HashMap<&'static str, Box<dyn Component>>,
|
|
||||||
|
active_runtimes: Vec<&'a dyn ModuleRuntime>,
|
||||||
|
// runtime_config: Vec<RuntimeConfig>,
|
||||||
|
components: HashMap<String, &'a NamedComponent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
|
// static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
|
||||||
|
|
||||||
impl Manager {
|
impl<'a> Manager<'a> {
|
||||||
|
fn new(id: &'static str, config: &'a Vec<NamedComponent>, modules: Vec<Module>) -> Self {
|
||||||
|
Self {
|
||||||
|
id,
|
||||||
|
|
||||||
|
// config,
|
||||||
|
modules,
|
||||||
|
|
||||||
|
components: config.iter().map(|c| (c.name.to_string(), c)).collect(),
|
||||||
|
|
||||||
|
active_runtimes: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create Manager, and run initilization for each Module
|
/// Create Manager, and run initilization for each Module
|
||||||
#[allow(static_mut_refs)]
|
#[allow(static_mut_refs)]
|
||||||
pub fn run<'a>(modules: Vec<Module>) {
|
pub fn run(config: &'static PayloadConfig, modules: Vec<Module>) {
|
||||||
let this: Self = Self::load_modules(modules);
|
// Construct self
|
||||||
let components = this.components.clone();
|
let this = Self::new(&config.id, &config.components, modules);
|
||||||
|
|
||||||
|
// Load each of the pre-prepared modules
|
||||||
|
// this.load_components();
|
||||||
|
|
||||||
let this = Arc::new(Mutex::new(this));
|
let this = Arc::new(Mutex::new(this));
|
||||||
|
|
||||||
let mut runtimes: Vec<Box<dyn ModuleRuntime>> = Vec::new();
|
Self::start_runtimes(this.clone(), &config.runtime_config);
|
||||||
|
|
||||||
for (_name, component) in components {
|
// let components = this.components.clone();
|
||||||
let module_runtime = component.start_runtime(this.clone());
|
|
||||||
if let Some(module_runtime) = module_runtime {
|
|
||||||
runtimes.push(module_runtime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Self::join(&mut runtimes);
|
// let mut runtimes: Vec<Box<dyn ModuleRuntime>> = Vec::new();
|
||||||
|
|
||||||
|
// for (_name, component) in components {
|
||||||
|
// let module_runtime = component.start_runtime(this.clone());
|
||||||
|
// if let Some(module_runtime) = module_runtime {
|
||||||
|
// runtimes.push(module_runtime);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
Self::join(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_modules<'a>(modules: Vec<Module>) -> Self {
|
// fn load_components(&mut self) {
|
||||||
let module_count = modules.len();
|
// for i in 0..self.modules.len() {
|
||||||
let mut this = Self {
|
// debug!("Importing module {}", i);
|
||||||
modules,
|
// // let this_lock = .unwrap();
|
||||||
components: HashMap::new(),
|
// let component_func = if let Ok(component_func) = self.modules[i]
|
||||||
};
|
// .get_symbol::<fn() -> HashMap<&'static str, Box<dyn Component>>>(
|
||||||
|
// symbol!("get_components").as_bytes(),
|
||||||
|
// ) {
|
||||||
|
// component_func
|
||||||
|
// } else {
|
||||||
|
// warn!("get_components function not found");
|
||||||
|
// continue;
|
||||||
|
// };
|
||||||
|
|
||||||
for i in 0..module_count {
|
// let components = component_func();
|
||||||
debug!("Importing module {}", i);
|
|
||||||
// let this_lock = .unwrap();
|
// let len = components.len();
|
||||||
let component_func = if let Ok(component_func) = this.modules[i]
|
// debug!("[{}] Loaded {} components", i, len);
|
||||||
.get_symbol::<fn() -> HashMap<&'static str, Box<dyn Component>>>(
|
|
||||||
symbol!("get_components").as_bytes(),
|
// self.components.extend(components);
|
||||||
) {
|
// }
|
||||||
component_func
|
// }
|
||||||
} else {
|
|
||||||
warn!("get_components function not found");
|
/// Start each runtime
|
||||||
continue;
|
fn start_runtimes(this: Arc<Mutex<Self>>, runtimes: &'static Vec<RuntimeConfig>) {
|
||||||
|
for runtime in runtimes {
|
||||||
|
let mut this_lock = this.lock().unwrap();
|
||||||
|
|
||||||
|
let component = match this_lock.components.get(runtime.parent_component) {
|
||||||
|
Some(component) => component,
|
||||||
|
None => {
|
||||||
|
warn!(
|
||||||
|
"Could not find component {} which is referenced by runtime {}",
|
||||||
|
runtime.parent_component, runtime.name
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let components = component_func();
|
let runtime = match (*component.start_runtime)(runtime) {
|
||||||
|
Ok(runtime) => runtime,
|
||||||
|
Err(e) => {
|
||||||
|
warn!("Failed to start runtime: {:?}", e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let len = components.len();
|
this_lock.active_runtimes.push(runtime);
|
||||||
debug!("[{}] Loaded {} components", i, len);
|
|
||||||
|
|
||||||
this.components.extend(components);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterateratively loop through all runtimes, until all are finished executing
|
/// Iterateratively loop through all runtimes, until all are finished executing
|
||||||
pub fn join(runtimes: &mut Vec<Box<dyn ModuleRuntime>>) {
|
fn join(this: Arc<Mutex<Self>>) {
|
||||||
// let mut len = runtimes.len().clone();
|
loop {
|
||||||
while runtimes.len() > 0 {
|
let mut this_lock = this.lock().unwrap();
|
||||||
runtimes.retain(|runtime| runtime.is_running());
|
|
||||||
|
|
||||||
thread::sleep(Duration::from_micros(100));
|
if this_lock.active_runtimes.len() <= 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this_lock
|
||||||
|
.active_runtimes
|
||||||
|
.retain(|runtime| runtime.is_running());
|
||||||
|
|
||||||
|
drop(this_lock);
|
||||||
|
|
||||||
|
thread::sleep(Duration::from_millis(500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_component(&self) -> HashMap<&'static str, Box<dyn Component>> {
|
// pub fn get_component(&self) -> HashMap<&'static str, Box<dyn Component>> {
|
||||||
self.components.clone()
|
// self.components.clone()
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub fn get_name(&self) -> &str {
|
||||||
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub extern "C" fn test1234(&self, float: f32) {
|
// pub extern "C" fn test1234(&self, float: f32) {
|
||||||
|
|||||||
Generated
+28
-7
@@ -341,6 +341,12 @@ version = "1.70.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jiff"
|
name = "jiff"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
@@ -498,6 +504,12 @@ version = "1.0.22"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.228"
|
||||||
@@ -505,6 +517,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -527,6 +540,19 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@@ -585,16 +611,11 @@ dependencies = [
|
|||||||
name = "unshell-lib"
|
name = "unshell-lib"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
|
||||||
"bincode",
|
"bincode",
|
||||||
"block-padding 0.4.1",
|
|
||||||
"cbc",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"getrandom",
|
|
||||||
"hex",
|
|
||||||
"hex-literal",
|
|
||||||
"libloading",
|
"libloading",
|
||||||
"sha2",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"unshell-obfuscate",
|
"unshell-obfuscate",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ edition = "2024"
|
|||||||
[features]
|
[features]
|
||||||
obfuscate = ["unshell-obfuscate/obfuscate"]
|
obfuscate = ["unshell-obfuscate/obfuscate"]
|
||||||
log_debug = ["unshell-lib/log_debug"]
|
log_debug = ["unshell-lib/log_debug"]
|
||||||
|
# default = ["obfuscate"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
|
|||||||
@@ -1,11 +1,28 @@
|
|||||||
use unshell_lib::{
|
use unshell_lib::{
|
||||||
ModuleError,
|
ModuleError,
|
||||||
|
config::{PayloadConfig, RuntimeConfig},
|
||||||
module::{Manager, Module},
|
module::{Manager, Module},
|
||||||
};
|
};
|
||||||
|
use unshell_obfuscate::symbol;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate unshell_lib;
|
extern crate unshell_lib;
|
||||||
|
|
||||||
|
static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
|
||||||
|
id: symbol!("Test ID"),
|
||||||
|
components: unshell_lib::get_components(),
|
||||||
|
runtime_config: vec![
|
||||||
|
RuntimeConfig {
|
||||||
|
"client"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// static RUNTIME_CONFIG: PayloadConfig = PayloadConfig {
|
||||||
|
// id: symbol!("Test ID"),
|
||||||
|
// components: Vec::new(),
|
||||||
|
// };
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(not(feature = "obfuscate"))]
|
#[cfg(not(feature = "obfuscate"))]
|
||||||
unshell_lib::logger::PrettyLogger::init();
|
unshell_lib::logger::PrettyLogger::init();
|
||||||
@@ -15,12 +32,13 @@ fn main() {
|
|||||||
match || -> Result<(), ModuleError> {
|
match || -> Result<(), ModuleError> {
|
||||||
let args = std::env::args();
|
let args = std::env::args();
|
||||||
|
|
||||||
let mut modules = Vec::new();
|
// let mut modules = Vec::new();
|
||||||
for arg in args.skip(1) {
|
// for arg in args.skip(1) {
|
||||||
debug!("Loading module: {}", arg);
|
// debug!("Loading module: {}", arg);
|
||||||
modules.push(Module::new(&arg)?)
|
// modules.push(Module::new(&arg)?)
|
||||||
}
|
// }
|
||||||
Manager::run(modules);
|
|
||||||
|
Manager::run(&PAYLOAD_CONFIG, Vec::new());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}() {
|
}() {
|
||||||
|
|||||||
Reference in New Issue
Block a user