lua - ROBLOX sandboxing -
i new sandboxing in lua, , learn how filter stuff :getchildren() or :kick().
this have far:
function safegetchildren(obj) local objs = {} _,v in pairs(obj) if not v.name:match("^^") table.insert(objs, v.name) end end return objs end function safeclearallchildren(obj) if obj:isa("player") or obj:isa("players") or obj:isa("workspace") or obj:isa("serverscriptservice") or obj:isa("lighting") or obj:isa("replicatedstorage") or obj:isa("startergui") return error("cannot clear object!"); else obj:clearallchildren(); end end function saferemoveobject(obj) local name = obj.name:lower(); if obj:isa("player") or name == "remoteevents" or obj.parent == "remoteevents" or obj.parent == "replicatedstorage" or obj.parent == "startergui" or obj.parent == "serverscriptservice" or obj.parent == "tinysb" return error("cannot destroy object!"); else obj:destroy(); end end local globals = { -- globals workspace = workspace, print = print, error = error, table = table, pairs = pairs, game = game, string = string, _g = _g, getfenv = getfenv, loadstring = loadstring, ipairs = ipairs, next = next, os = os, pcall = pcall, rawequal = rawequal, rawget = rawget, rawset = rawset, select = select, setfenv = setfenv, setmetatable = setmetatable, tonumber = tonumber, tostring = tostring, type = type, unpack = unpack, _version = _version, xpcall = xpcall, collectgarbage = collectgarbage, assert = assert, gcinfo = gcinfo, coroutine = coroutine, string = string, table = table, math = math, delay = delay, loadlibrary = loadlibrary, printidentity = printidentity, spawn = spawn, tick = tick, time = time, usersettings = usersettings, version = version, wait = wait, warn = warn, ypcall = ypcall, pluginmanager = pluginmanager, loadrobloxlibrary = loadrobloxlibrary, settings = settings, stats = stats, -- functions ["require"] = function(...) return error("cannot require object (api disabled)"); end, ["getchildren"] = function(...) return safegetchildren(...); end, ['children'] = function(...) return safegetchildren(...); end, ['clearallchildren'] = function(...) return safeclearallchildren(...); end, ['destroy'] = function(...) return saferemoveobject(...); end, ['remove'] = function(...) return saferemoveobject(...); end, ['kick'] = function(...) return saferemoveobject(...); end, ['saveplace'] = function(...) return error("cannot save place (api disabled)"); end } setfenv(1, globals) table.foreach(workspace:getchildren(), print)
i made in few hours things :getchildren() aren't filtered in environment. if can me explanation on each part of code required help.
you're setting safe wrapper under name 'getchildren' in new environment. later, when testing, you're calling 'getchildren', taken 'workspace' table, , not global variable in new environment.
replacing function in global environment doesn't mean replacing functions same name in tables/objects. work, object must call function current global environment, , not function internal tables or lexical closures.
Comments
Post a Comment