From 37662691e21ee897a897d1272595565535f3a72b Mon Sep 17 00:00:00 2001 From: rhpidfyre Date: Sun, 29 Dec 2024 03:09:13 -0500 Subject: [PATCH] sandboxing goes after variables now --- Cargo.lock | 242 ++++++++++++++++++------------------------------- Cargo.toml | 3 +- src/luau/vm.rs | 23 +++-- src/shell.rs | 24 ++--- 4 files changed, 112 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b999e0..5f3f4fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,8 +52,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3aa954171903797d5623e047d9ab69d91b493657917bdfb8c2c80ecaf9cdb6f4" dependencies = [ "color-print-proc-macro", - "lazy_static", - "terminfo", ] [[package]] @@ -62,7 +60,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692186b5ebe54007e45a59aea47ece9eb4108e141326c304cdc91699a7118a22" dependencies = [ - "nom 7.1.3", + "nom", "proc-macro2", "quote", "syn", @@ -89,22 +87,27 @@ dependencies = [ ] [[package]] -name = "dirs" -version = "4.0.0" +name = "crossterm" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" dependencies = [ - "dirs-sys", + "bitflags", + "crossterm_winapi", + "mio", + "parking_lot", + "rustix", + "signal-hook", + "signal-hook-mio", + "winapi", ] [[package]] -name = "dirs-sys" -version = "0.3.7" +name = "crossterm_winapi" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" dependencies = [ - "libc", - "redox_users", "winapi", ] @@ -115,20 +118,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] -name = "fnv" -version = "1.0.7" +name = "errno" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ - "cfg-if", "libc", - "wasi", + "windows-sys 0.59.0", ] [[package]] @@ -137,7 +133,7 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -150,12 +146,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.169" @@ -168,9 +158,10 @@ version = "0.1.0" dependencies = [ "color-print", "const_format", + "crossterm", "home", "mlua", - "thiserror 2.0.9", + "thiserror", "uzers", "whoami", ] @@ -186,14 +177,10 @@ dependencies = [ ] [[package]] -name = "libredox" -version = "0.1.3" +name = "linux-raw-sys" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags", - "libc", -] +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -232,6 +219,18 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.52.0", +] + [[package]] name = "mlua" version = "0.10.2" @@ -259,16 +258,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "nom" -version = "5.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08959a387a676302eebf4ddbcbc611da04285579f76f88ee0506c63b1a61dd4b" -dependencies = [ - "memchr", - "version_check", -] - [[package]] name = "nom" version = "7.1.3" @@ -317,44 +306,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "phf" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" -dependencies = [ - "phf_shared", - "rand", -] - -[[package]] -name = "phf_shared" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" -dependencies = [ - "siphasher", -] - [[package]] name = "pkg-config" version = "0.3.31" @@ -379,21 +330,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" - [[package]] name = "redox_syscall" version = "0.5.8" @@ -403,23 +339,25 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom", - "libredox", - "thiserror 1.0.69", -] - [[package]] name = "rustc-hash" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" +[[package]] +name = "rustix" +version = "0.38.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -453,10 +391,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] -name = "siphasher" -version = "0.3.11" +name = "signal-hook" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] [[package]] name = "smallvec" @@ -475,46 +437,13 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "terminfo" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da31aef70da0f6352dbcb462683eb4dd2bfad01cf3fc96cf204547b9a839a585" -dependencies = [ - "dirs", - "fnv", - "nom 5.1.3", - "phf", - "phf_codegen", -] - -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" dependencies = [ - "thiserror-impl 2.0.9", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "thiserror-impl", ] [[package]] @@ -550,12 +479,6 @@ dependencies = [ "log", ] -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -665,6 +588,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index a283a9d..665d50d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,9 @@ version = "0.1.0" edition = "2021" [dependencies] -color-print = { version = "0.3.7", features = ["terminfo"] } +color-print = "0.3.7" const_format = "0.2.33" +crossterm = "0.28.1" home = "0.5.9" mlua = { version = "0.10.0", features = ["luau-jit"] } thiserror = "2.0.9" diff --git a/src/luau/vm.rs b/src/luau/vm.rs index d942132..85f4d9b 100644 --- a/src/luau/vm.rs +++ b/src/luau/vm.rs @@ -1,3 +1,4 @@ +use crate::VERSION; use mlua::{ Lua as Luau, Result as lResult, @@ -15,7 +16,7 @@ where } fn luau_error(err: mlua::Error) -> Option { - cprintln!("====\n{err}\n===="); + cprintln!("====\n[!] {err}\n===="); None } @@ -36,6 +37,7 @@ fn luau_out(luau_args: MultiValue) -> String { trait Globals { fn print(&self) -> lResult<()>; fn printraw(&self) -> lResult<()>; + fn version(&self) -> lResult<()>; } impl Globals for Vm { fn print(&self) -> lResult<()> { @@ -50,24 +52,25 @@ impl Globals for Vm { Ok(()) })?) } + fn version(&self) -> lResult<()> { + let luau_info = self.0.globals().get::("_VERSION")?; + self.0.globals().set("_VERSION", format!("{}, liblambdashell {}", luau_info, VERSION)) + } } pub struct Vm(Luau); impl Vm { - pub fn new() -> Option { - let spawn_luau = || -> lResult { - let instance = Luau::new(); - instance.sandbox(true)?; - instance.globals().set("getfenv", mlua::Nil)?; - instance.globals().set("setfenv", mlua::Nil)?; - Ok(instance) - }; - spawn_luau().map_or_else(|e| display_none(e), |l| Some(Self(l))) + pub fn new() -> Self { + Self(Luau::new()) } fn set_shell_globals(&self) -> mlua::Result<()> { self.print()?; self.printraw()?; + self.version()?; + self.0.globals().set("getfenv", mlua::Nil)?; + self.0.globals().set("setfenv", mlua::Nil)?; + self.0.sandbox(true)?; Ok(()) } diff --git a/src/shell.rs b/src/shell.rs index b278d74..1f0d0c1 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -15,7 +15,7 @@ trait ShellLuauVm { } impl ShellLuauVm for LambdaShell { fn shell_vm_exec(&self, source: String) { - vm::Vm::new().map(|vm| vm.exec(source)); + vm::Vm::new().exec(source); } } @@ -36,21 +36,17 @@ impl LambdaShell { } } - fn input(&mut self) { - let mut input = String::new(); - io::stdin().read_line(&mut input).map_or_else(|read_error| println!("{read_error}"), |_size| { - let trimmed_input = input.trim(); - match trimmed_input { - //special casey - "exit" => self.terminating = true, - _ => self.storage.command_exit_status = commands::Command::new(trimmed_input.to_owned()).exec() - }; - }) - } - pub fn wait(&mut self) -> Result<(), io::Error> { io::Write::flush(&mut io::stdout()).map_or_else(|flush_error| Err(flush_error), |()| { - self.input(); + let mut input = String::new(); + io::stdin().read_line(&mut input).map_or_else(|read_error| println!("{read_error}"), |_size| { + let trimmed_input = input.trim(); + match trimmed_input { + //special casey + "exit" => self.terminating = true, + _ => self.storage.command_exit_status = commands::Command::new(trimmed_input.to_owned()).exec() + }; + }); Ok(()) }) }