forked from StrafesNET/map-tool
v1 POC (proof of concept)
This commit is contained in:
parent
9e482891ba
commit
4c1632c0b6
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -360,6 +360,8 @@ name = "strafesnet-scanner"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rbx_binary",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection_database",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -7,3 +7,5 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rbx_binary = "0.7.1"
|
||||
rbx_dom_weak = "2.5.0"
|
||||
rbx_reflection_database = "0.2.7"
|
||||
|
65
src/main.rs
65
src/main.rs
@ -1,3 +1,64 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
fn class_is_a(class: &str, superclass: &str) -> bool {
|
||||
if class==superclass {
|
||||
return true
|
||||
}
|
||||
let class_descriptor=rbx_reflection_database::get().classes.get(class);
|
||||
if let Some(descriptor) = &class_descriptor {
|
||||
if let Some(class_super) = &descriptor.superclass {
|
||||
return class_is_a(&class_super, superclass)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn recursive_collect_scripts(scripts: &mut std::vec::Vec<String>,dom: &rbx_dom_weak::WeakDom, instance: &rbx_dom_weak::Instance){
|
||||
for &referent in instance.children() {
|
||||
let c = dom.get_by_ref(referent).unwrap();
|
||||
if class_is_a(c.class.as_str(), "LuaSourceContainer") {
|
||||
if let Some(rbx_dom_weak::types::Variant::String(s)) = c.properties.get("Source") {
|
||||
scripts.push(s.clone());
|
||||
}
|
||||
}
|
||||
recursive_collect_scripts(scripts,dom,c);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Using buffered I/O is recommended with rbx_binary
|
||||
let input = std::io::BufReader::new(std::fs::File::open("map.rbxm")?);
|
||||
|
||||
let dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
//Construct allowed scripts
|
||||
let mut allowed = std::collections::HashSet::<String>::new();
|
||||
for entry in std::fs::read_dir("allowed")? {
|
||||
allowed.insert(std::fs::read_to_string(entry?.path())?);
|
||||
}
|
||||
|
||||
let mut scripts = std::vec::Vec::<String>::new();
|
||||
recursive_collect_scripts(&mut scripts, &dom, dom.root());
|
||||
|
||||
//check scribb
|
||||
let mut any_failed=false;
|
||||
for (i,script) in scripts.iter().enumerate() {
|
||||
if allowed.contains(script) {
|
||||
println!("pass");
|
||||
}else{
|
||||
println!("fail");
|
||||
any_failed=true;
|
||||
std::fs::write(format!("blocked/{}.lua",i),script)?;
|
||||
}
|
||||
}
|
||||
if any_failed {
|
||||
println!("One or more scripts are not allowed.");
|
||||
return Ok(())//everything is not ok but idk how to return an error LMAO
|
||||
}
|
||||
println!("All scripts passed!");
|
||||
// std::process::Command::new("rbxcompiler")
|
||||
// .arg("--compile=false")
|
||||
// .arg("--group=6980477")
|
||||
// .arg("--asset=5692139100")
|
||||
// .arg("--input=map.rbxm")
|
||||
// .spawn()?;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user