Posted 04 January 2015 - 09:28 PM
So this is a tool i simply wrote because I wanted to see if I could make it work :)/>
It is not very big as you can see:
So what is this doing ?
It takes either a function or a path to a file and runs it with the given restrictions.
The only function you have to call is :
It will then run your function(or file) and as soon as theres a function that is blocked by the user it will call the function passed through the third argument( if no argument is given it will error at the first occurance of a blocked function with "blocked function!")
Uhm well yeah thats it ^^.
A small example:
Now if your function contains something like os.shutdown or setmetatable(blah) it would print "A blocked function was called !" instead of actually shutting the computer down for example !
If there are any bugs i will try to fix them ! :)/>
Pastebin:
Ingame:
Hope you like it :D/> !
Kouksi44
It is not very big as you can see:
Spoiler
local function iTable(cpTable,newTable,func)
for k,v in pairs(cpTable) do
if type(v)=="table" then
newTable[k]={}
iTable(v,newTable[k],func)
else
newTable[k]=func
end
end
return newTable
end
local function blocked()
error("Blocked function!",2)
end
local function getFunc(f)
if fs.exists(f) then
fu=fs.open(f,"r")
funct=fu.readAll()
fu.close()
funct=loadstring(funct)
return funct
else
end
end
function setEnvironment(sfunc,blockedFuncs,bFunc)
if sfunc==nil then
error("Must be 2 arguments")
end
bErr=bFunc or blocked
if type(sfunc)=="string" then
func=getFunc(sfunc)
elseif type(sfunc)=="function" then
func=sfunc
end
local env=setmetatable({},{__index=_G})
local nBlocked=iTable(blockedFuncs,env,bErr)
setfenv(func,nBlocked)
func()
end
So what is this doing ?
It takes either a function or a path to a file and runs it with the given restrictions.
The only function you have to call is :
setEnvironment(functionYouWantToSandbox,TableOfBlockedFunctions,AlternativeFunctionForBlockedOnes)
It will then run your function(or file) and as soon as theres a function that is blocked by the user it will call the function passed through the third argument( if no argument is given it will error at the first occurance of a blocked function with "blocked function!")
Uhm well yeah thats it ^^.
A small example:
blockedFuncs={ os={shutdown=true,reboot=true},setfenv=true,setmetatable=true,shell={run=true}}
setEnvironment(yourFunc,blockedFuncs,function() print("A blocked function was called !") end)
Now if your function contains something like os.shutdown or setmetatable(blah) it would print "A blocked function was called !" instead of actually shutting the computer down for example !
If there are any bugs i will try to fix them ! :)/>
Pastebin:
http://pastebin.com/2f2qSe4i
Ingame:
pastebin get 2f2qSe4i sandbox
Hope you like it :D/> !
Kouksi44
Edited on 04 January 2015 - 08:34 PM