diff --git a/src/runtime/builtins.rs b/src/runtime/builtins.rs index 035a6e7..fe5abbf 100644 --- a/src/runtime/builtins.rs +++ b/src/runtime/builtins.rs @@ -57,6 +57,24 @@ pub fn lua_write(_: &Lua, (addr, data): (usize, Vec)) -> Result, Option) +) -> Result, Error> { + let window = pattern.len(); + let first_only = first.unwrap_or(false); + let mut matches = vec![]; + + for i in 0..(size-window) { + let slice = unsafe { std::slice::from_raw_parts((start + i) as *const u8, window) }; + if slice == pattern { + matches.push(start + i); + if first_only { break; } + } + } + + Ok(matches) +} + pub fn lua_procmaps(lua: &Lua, ret: Option) -> Result { let mut out = String::new(); let maps = get_process_maps(std::process::id() as i32) diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 56e8cfb..8892427 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -26,6 +26,7 @@ pub fn register_builtin_fn(lua: &Lua, console: broadcast::Sender) -> Res lua.globals().set("hexdump", lua.create_function(lua_hexdump)?)?; lua.globals().set("read", lua.create_function(lua_read)?)?; lua.globals().set("write", lua.create_function(lua_write)?)?; + lua.globals().set("find", lua.create_function(lua_find)?)?; lua.globals().set("procmaps", lua.create_function(lua_procmaps)?)?; lua.globals().set("exit", lua.create_function(lua_exit)?)?; lua.globals().set("mmap", lua.create_function(lua_mmap)?)?;