mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Convert to no_std, add request type
This commit is contained in:
Generated
+187
-3
@@ -92,6 +92,35 @@ version = "3.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
|
||||
|
||||
[[package]]
|
||||
name = "bytecheck"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0caa33a2c0edca0419d15ac723dff03f1956f7978329b1e3b5fdaaaed9d3ca8b"
|
||||
dependencies = [
|
||||
"bytecheck_derive",
|
||||
"ptr_meta",
|
||||
"rancor",
|
||||
"simdutf8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytecheck_derive"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89385e82b5d1821d2219e0b095efa2cc1f246cbf99080f3be46a1a85c0d392d9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||
|
||||
[[package]]
|
||||
name = "cbc"
|
||||
version = "0.1.2"
|
||||
@@ -202,6 +231,12 @@ dependencies = [
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.8"
|
||||
@@ -230,6 +265,12 @@ dependencies = [
|
||||
"wasip2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
@@ -275,6 +316,16 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.1.4"
|
||||
@@ -328,6 +379,26 @@ version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "munge"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e17401f259eba956ca16491461b6e8f72913a0a114e39736ce404410f915a0c"
|
||||
dependencies = [
|
||||
"munge_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "munge_macro"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4568f25ccbd45ab5d5603dc34318c1ec56b117531781260002151b8530a9f931"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@@ -384,6 +455,26 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b9a0cf95a1196af61d4f1cbdab967179516d9a4a4312af1f31948f8f6224a79"
|
||||
dependencies = [
|
||||
"ptr_meta_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta_derive"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7347867d0a7e1208d93b46767be83e2b8f978c3dad35f775ac8d8847551d6fe1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.44"
|
||||
@@ -399,6 +490,15 @@ version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "rancor"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a063ea72381527c2a0561da9c80000ef822bdd7c3241b1cc1b12100e3df081ee"
|
||||
dependencies = [
|
||||
"ptr_meta",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.2"
|
||||
@@ -466,12 +566,57 @@ version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
|
||||
|
||||
[[package]]
|
||||
name = "rend"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cadadef317c2f20755a64d7fdc48f9e7178ee6b0e1f7fce33fa60f1d68a276e6"
|
||||
dependencies = [
|
||||
"bytecheck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a30e631b7f4a03dee9056b8ef6982e8ba371dd5bedb74d3ec86df4499132c70"
|
||||
dependencies = [
|
||||
"bytecheck",
|
||||
"bytes",
|
||||
"hashbrown",
|
||||
"indexmap",
|
||||
"munge",
|
||||
"ptr_meta",
|
||||
"rancor",
|
||||
"rend",
|
||||
"rkyv_derive",
|
||||
"tinyvec",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv_derive"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8100bb34c0a1d0f907143db3149e6b4eea3c33b9ee8b189720168e818303986f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "sc"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
@@ -485,7 +630,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -538,6 +682,12 @@ version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "simdutf8"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.1"
|
||||
@@ -594,6 +744,21 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.19.0"
|
||||
@@ -606,15 +771,24 @@ version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unix-print"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c50e1866b3de196f1329f6a805771eee750651c83bbebd5dff159e5f033cc16f"
|
||||
dependencies = [
|
||||
"sc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unshell"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"rkyv",
|
||||
"static_init",
|
||||
"unix-print",
|
||||
"ush-obfuscate",
|
||||
]
|
||||
|
||||
@@ -642,6 +816,16 @@ dependencies = [
|
||||
"unshell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a68d3c8f01c0cfa54a75291d83601161799e4a89a39e0929f4b0354d88757a37"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
|
||||
+7
-2
@@ -36,13 +36,18 @@ obfuscate_ref = ["ush-obfuscate/obfuscate_ref"]
|
||||
|
||||
[dependencies]
|
||||
chrono = { workspace = true, optional = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
# serde = { workspace = true }
|
||||
# serde_json = { workspace = true }
|
||||
|
||||
crossbeam-channel = "0.5.15"
|
||||
|
||||
ush-obfuscate = { path = "./ush-obfuscate" }
|
||||
static_init.workspace = true
|
||||
|
||||
rkyv = "0.8.15"
|
||||
|
||||
unix-print = {version = "0.1.0" }
|
||||
|
||||
# unshell-crypt = {path = "./unshell-crypt"}
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
+4
-1
@@ -1,8 +1,11 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub mod logger;
|
||||
pub mod tree;
|
||||
|
||||
// Re-exports
|
||||
pub use serde_json::{Value, json};
|
||||
// pub use serde_json::{Value, json};
|
||||
pub use ush_obfuscate as obfuscate;
|
||||
|
||||
+6
-6
@@ -7,15 +7,15 @@ mod log_disabled;
|
||||
|
||||
mod pretty_logger;
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::String;
|
||||
pub use pretty_logger::PrettyLogger;
|
||||
pub use pretty_logger::log;
|
||||
|
||||
pub static mut IS_DEFAULT_LOGGER: bool = true;
|
||||
static mut LOGGER: &dyn Logger = &DefaultLogger;
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug)]
|
||||
pub enum LogLevel {
|
||||
Debug,
|
||||
Info,
|
||||
@@ -23,12 +23,12 @@ pub enum LogLevel {
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug)]
|
||||
pub struct Record {
|
||||
log_level: LogLevel,
|
||||
location: Option<String>,
|
||||
// line: u32,
|
||||
time: Option<SystemTime>,
|
||||
time: Option<u64>,
|
||||
message: String,
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn set_logger(logger: &'static dyn Logger) {
|
||||
pub fn add_record(
|
||||
log_level: LogLevel,
|
||||
location: Option<String>,
|
||||
time: Option<SystemTime>,
|
||||
time: Option<u64>,
|
||||
message: String,
|
||||
) {
|
||||
logger().log(Record {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use alloc::{boxed::Box, format};
|
||||
|
||||
use crate::logger::{LogLevel, Logger, Record};
|
||||
|
||||
pub struct PrettyLogger {
|
||||
@@ -31,7 +33,7 @@ pub fn log(message: &Record) {
|
||||
(None, None) => {
|
||||
static WHITE: &str = "\x1b[97m";
|
||||
|
||||
println!("{} {WHITE}{}", log_level, message.message,);
|
||||
unix_print::unix_println!("{} {WHITE}{}", log_level, message.message);
|
||||
}
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
@@ -45,9 +47,12 @@ pub fn log(message: &Record) {
|
||||
static TIME_COLOR: &str = "\x1b[36m";
|
||||
static GREY: &str = "\x1b[90m";
|
||||
|
||||
println!(
|
||||
unix_print::unix_println!(
|
||||
"{OFF_WHITE}[{TIME_COLOR}{}{OFF_WHITE}] {} {WHITE}{} {GREY}{}{WHITE}",
|
||||
date, log_level, message.message, location
|
||||
date,
|
||||
log_level,
|
||||
message.message,
|
||||
location
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// use std::collections::VecDeque;
|
||||
|
||||
use alloc::{collections::vec_deque::VecDeque, string::String, vec::Vec};
|
||||
use rkyv::{Archive, Deserialize, Serialize};
|
||||
|
||||
#[derive(Archive, Deserialize, Serialize)]
|
||||
#[rkyv(compare(PartialEq), derive(Debug))]
|
||||
pub struct TreeRequest {
|
||||
// The exact path that this packet should be heading down to
|
||||
destination_path: VecDeque<String>,
|
||||
// The list of previous paths that this packet came from
|
||||
// This is the destination path added in reverse order
|
||||
source_path: VecDeque<String>,
|
||||
|
||||
request_type: TreeRequestType,
|
||||
|
||||
// The data type of the payload, to determine how to deserialize and interpret it on the other side
|
||||
// This is equivalent to HTTP's content-type header
|
||||
content_type: String,
|
||||
|
||||
// The payload of the packet
|
||||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Archive, Deserialize, Serialize)]
|
||||
#[rkyv(compare(PartialEq), derive(Debug))]
|
||||
pub enum TreeRequestType {
|
||||
Return = 0,
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Submit = 3,
|
||||
|
||||
ListBranches = 10,
|
||||
|
||||
// CreateField = 3,
|
||||
// DeleteField = 4,
|
||||
UnnamedError = 100,
|
||||
NoBranchError = 101,
|
||||
ProtocolError = 102,
|
||||
ExecutionError = 103,
|
||||
}
|
||||
+2
-78
@@ -1,81 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
mod message;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
mod log;
|
||||
pub mod symbols;
|
||||
|
||||
pub trait TreeElement {
|
||||
// fn get_children(&self) -> HashMap<TreeType, TreeType>;
|
||||
fn get_type(&self) -> Value;
|
||||
fn send_message(&mut self, target: Value, message: Value) -> Value;
|
||||
}
|
||||
|
||||
pub struct Tree {
|
||||
elements: HashMap<String, Box<dyn TreeElement>>,
|
||||
}
|
||||
|
||||
impl Tree {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
elements: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_element(&mut self, name: String, element: Box<dyn TreeElement>) {
|
||||
self.elements.insert(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeElement for Tree {
|
||||
fn get_type(&self) -> Value {
|
||||
json!(symbols::TYPE_TREE)
|
||||
}
|
||||
|
||||
// fn send_message_child(&mut self, element: Value, message: TreeMessage) -> TreeMessage {
|
||||
// let name = if let TreeType::String(name) = element {
|
||||
// name
|
||||
// } else {
|
||||
// return TreeMessage::Error(ModuleError::InvalidType);
|
||||
// };
|
||||
|
||||
// if let Some(element) = self.elements.get_mut(&name) {
|
||||
// element.send_message(message)
|
||||
// } else {
|
||||
// TreeMessage::Error(ModuleError::TreeNotExist)
|
||||
// }
|
||||
// }
|
||||
|
||||
fn send_message(&mut self, target: Value, message: Value) -> Value {
|
||||
match target {
|
||||
Value::Null => {
|
||||
if let Some(message) = message.as_str() {
|
||||
match message {
|
||||
"GetChildren" => {
|
||||
let children = self
|
||||
.elements
|
||||
.iter()
|
||||
.map(|c| (Value::String(c.0.clone()), c.1.get_type()))
|
||||
.into_iter()
|
||||
.collect::<HashMap<Value, Value>>();
|
||||
|
||||
json!(children)
|
||||
}
|
||||
|
||||
_ => Value::String("UnsupportedMethod".to_owned()),
|
||||
}
|
||||
} else {
|
||||
Value::String("UnsupportedMethod".to_owned())
|
||||
}
|
||||
}
|
||||
Value::String(target) => {
|
||||
if let Some(child) = self.elements.get_mut(&target) {
|
||||
child.send_message(Value::Null, message)
|
||||
} else {
|
||||
Value::String("UnsupportedMethod".to_owned())
|
||||
}
|
||||
}
|
||||
_ => Value::String("UnsupportedMethod".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct Tree {}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#![macro_use]
|
||||
extern crate unshell;
|
||||
|
||||
use unshell::{info, obfuscate::sym, tree::Tree};
|
||||
use unshell::{info, logger::PrettyLogger};
|
||||
|
||||
fn main() {
|
||||
// PrettyLogger::init();
|
||||
PrettyLogger::init();
|
||||
|
||||
let mut manager = Tree::new();
|
||||
manager.init_logger();
|
||||
// let mut manager = Tree::new();
|
||||
// manager.init_logger();
|
||||
|
||||
println!("{}", sym!("TEST"));
|
||||
// println!("{}", sym!("TEST"));
|
||||
|
||||
info!("Test thing!");
|
||||
info!("Test thing!");
|
||||
// info!("Test thing!");
|
||||
|
||||
// loop {
|
||||
// if test123(&mut manager) {
|
||||
|
||||
Reference in New Issue
Block a user