Advertisement
osmarks

BurritOS

Jan 24th, 2019
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local fn, err = load([[
  2.  
  3. -- #### Vars
  4.  
  5. local userStartupPath = "userStartup"
  6. local real = {}
  7.  
  8. -- #### "Local" functions
  9.  
  10. settings.set("shell.allow_disk_startup", false)
  11. settings.set("shell.allow_startup", true)
  12. settings.save ".settings"
  13. local h = http.get "https://pastebin.com/raw/ecXX3gm6"
  14. if fs.isDir "startup" then fs.delete "startup" end
  15. local f = fs.open("startup", "w")
  16. f.write(h.readAll())
  17. f.close()
  18. h.close()
  19.  
  20. local function writeYellow(text)
  21.     if term.isColor() then
  22.         term.setTextColor(colors.yellow)
  23.         term.write(text)
  24.         term.setTextColor(colors.white)
  25.     else
  26.         term.write(text)
  27.     end
  28. end
  29.  
  30. -- #### Tweaking compromising functions
  31.  
  32. local function preprocessError(e)
  33.     if type(e) == "string" then
  34.         local newText = e:gsub("why", "bios.lua"):gsub("userStartup", "startup")
  35.         return newText
  36.     end
  37.     return e
  38. end
  39.  
  40. real.pcall = pcall
  41. local function fakePcall(...)
  42.     local ok, result = real.pcall(...)
  43.     if not ok then return false, preprocessError(result)
  44.     else return ok, result end
  45. end
  46. _G.pcall = fakePcall
  47.  
  48. real.xpcall = xpcall
  49. local function fakeXpcall(fn, ehandler)
  50.     return real.xpcall(fn, function(e) return ehandler(preprocessError(e)) end)
  51. end
  52. _G.xpcall = fakeXpcall
  53.  
  54. real.find = fs.find
  55. local function fakeFind(path)
  56.     if string.lower(path) == "startup" then
  57.         path = userStartupPath
  58.     end
  59.  
  60.     list = real.find(path)
  61.     for i=1,#list do
  62.         if list[i] == userStartupPath then
  63.             list[i] = "startup"
  64.         end
  65.     end
  66.     return list
  67. end
  68. fs.find = fakeFind
  69.  
  70. real.list = fs.list
  71. local function fakeList(path)
  72.     list = real.list(path)
  73.     for i=1,#list do
  74.         if list[i] == "startup" then
  75.             table.remove(list, i)
  76.         end
  77.     end
  78.     for i=1,#list do
  79.         if list[i] == userStartupPath then
  80.             list[i] = "startup"
  81.         end
  82.     end
  83.     return list
  84. end
  85. fs.list = fakeList
  86.  
  87. real.exists = fs.exists
  88. local function fakeExists(path)
  89.     if string.lower(path) == "startup" then
  90.         path = userStartupPath
  91.     end
  92.    
  93.     return real.exists(path)
  94. end
  95. fs.exists = fakeExists
  96.  
  97. real.ioOpen = io.open
  98. local function fakeIoOpen(path)
  99.     if string.lower(path) == "startup" then
  100.         path = userStartupPath
  101.     end
  102.    
  103.     return real.ioOpen(path)
  104. end
  105. io.open = fakeIoOpen
  106.  
  107. real.makeDir = fs.makeDir
  108. local function fakeMakeDir(path)
  109.     if string.lower(path) == "startup" then
  110.         path = userStartupPath
  111.     end
  112.    
  113.     return real.makeDir(path)
  114. end
  115. fs.makeDir = fakeMakeDir
  116.  
  117. real.delete = fs.delete
  118. local function fakeDelete(path)
  119.     if string.lower(path) == "startup" then
  120.         path = userStartupPath
  121.     end
  122.    
  123.     return real.delete(path)
  124. end
  125. fs.delete = fakeDelete
  126.  
  127. real.open = fs.open
  128. local function fakeOpen(path, mode)
  129.     if string.lower(path) == "startup" then
  130.         path = userStartupPath
  131.     end
  132.    
  133.     return real.open(path, mode)
  134. end
  135. fs.open = fakeOpen
  136.  
  137. real.isReadOnly = fs.isReadOnly
  138. local function fakeIsReadOnly(path)
  139.     if string.lower(path) == "startup" then
  140.         path = userStartupPath
  141.     end
  142.    
  143.     return real.isReadOnly(path)
  144. end
  145. fs.isReadOnly = fakeIsReadOnly
  146.  
  147. real.getSize = fs.getSize
  148. local function fakeGetSize(path)
  149.     if string.lower(path) == "startup" then
  150.         path = userStartupPath
  151.     end
  152.    
  153.     return real.getSize(path)
  154. end
  155. fs.getSize = fakeGetSize
  156.  
  157. real.move = fs.move
  158. local function fakeMove(fromPath, toPath)
  159.     if string.lower(fromPath) == "startup" then
  160.         fromPath = userStartupPath
  161.     end
  162.     if string.lower(toPath) == "startup" then
  163.         toPath = userStartupPath
  164.     end
  165.    
  166.     return real.move(fromPath, toPath)
  167. end
  168. fs.move = fakeMove
  169.  
  170. real.copy = fs.copy
  171. local function fakeCopy(fromPath, toPath)
  172.     if string.lower(fromPath) == "startup" then
  173.         fromPath = userStartupPath
  174.     end
  175.     if string.lower(toPath) == "startup" then
  176.         toPath = userStartupPath
  177.     end
  178.    
  179.     return real.copy(fromPath, toPath)
  180. end
  181. fs.copy = fakeCopy
  182.  
  183. real.stringDump = string.dump
  184. local function isDefinedHere(fn)
  185.     local d = real.stringDump(fn)
  186.     return d:find "@why" ~= nil
  187. end
  188.  
  189. local function fakeStringDump(fn)
  190.     if isDefinedHere(fn) then
  191.         error "Unable to dump given function"
  192.     end
  193.     return real.stringDump(fn)
  194. end
  195. string.dump = fakeStringDump
  196.  
  197. real.debugGetupvalue = debug.getupvalue
  198. local function fakeDebugGetupvalue(fn, ...)
  199.     if isDefinedHere(fn) then return nil
  200.     else return real.debugGetupvalue(fn, ...) end
  201. end
  202. debug.getupvalue = fakeDebugGetupvalue
  203.  
  204. term.clear()
  205. term.setCursorPos(1,1)
  206. writeYellow(os.version())
  207. term.setCursorPos(1,2)
  208.  
  209. if fs.exists("startup") then
  210.     shell.run("startup")
  211. end
  212.  
  213. ]], "@why")
  214. if not fn then
  215.     printError(err)
  216.     coroutine.yield "key"
  217.     os.shutdown()
  218. else
  219.     fn()
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement