Sirshark10

Simulate2

Jun 19th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if not fs.exists("/EmuRom") then
  2.   fs.copy("/rom","/EmuRom")
  3.   fs.copy("/rom/programs/http/pastebin","/EmuRom/programs")
  4. end
  5.  
  6. local args = {...}
  7. local ID,root
  8.  
  9. if args[1] then
  10.   ID = tonumber(args[1])
  11.   root = ("/"..ID)
  12. else
  13.   return -- exits program :P
  14. end
  15.  
  16. oldID = os.getComputerID()
  17. oldPath = shell.path()
  18. OldGID = os.getComputerID
  19. if type(ID) ~= "number" then
  20.   print("Please use proper arguments, EX: Simulate <ID>")
  21.   return
  22. end
  23.  
  24. function os.getComputerID()
  25.   return ID
  26. end
  27.  
  28. if not fs.exists("/"..ID) then
  29.   fs.makeDir("/"..ID)
  30. end
  31.  
  32. shell.setPath("/EmuRom/programs:/EmuRom/programs/advanced:/EmuRom/programs/rednet:/EmuRom/programs/fun:/EmuRom/programs/fun/advanced:/Emurom/Programs/http")
  33. shell.setDir(root)
  34. local oldSet = shell.setDir
  35. local resolve = shell.resolve
  36. local oldRun = shell.run
  37.  
  38. function exit()
  39.   shell.setDir = oldSet
  40.   shell.run = oldRun
  41. end
  42.  
  43. function shell.setDir(toDir)
  44.   --shell.setDir = oldSet
  45.   local absolute = resolve(toDir)
  46.   local lastc = fs.getName(absolute)
  47.   if absolute == "/" or absolute:match("(.+/)") ~= ID then
  48.     printError("Attempt to leave sandbox")
  49.     return
  50.   end
  51.   --[[if lastc=="root" or lastc=="EmuRom" then
  52.     printError("Attempt to leave sandbox")
  53.     return
  54.   end]]--
  55.   return oldSet(toDir)
  56. end
  57.  
  58. function shell.run(prog,...)
  59.   if shell.resolveProgram(prog) == shell.resolveProgram("shell") or shell.resolveProgram(prog) == shell.resolveProgram("/rom/programs/shell") then
  60.   printError("Attempt to leave sandbox")
  61.   return
  62.   end
  63.   return oldRun(prog,...)
  64. end
Add Comment
Please, Sign In to add comment