Sirshark10

Simulate

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