Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- -------- Rescue Disk
- -- -------- Made by 1lann, GravityScore
- -- -------- With Thanks To this_is_1984
- -- -------- Variables
- -- Version
- local antivirusVersion = "1.0"
- -- Dropbox URLs
- local antivirusURL = "http://dl.dropbox.com/u/97263369/antivirus/antivirus-stable.lua"
- local databaseURL = "http://dl.dropbox.com/u/97263369/antivirus/database.txt"
- -- Locations
- local antivirusLocation = "/" .. shell.getRunningProgram()
- local mountPath = "/disk"
- local databaseLocation = "/.rescue-disk-database"
- -- Clock Variables
- local clockRunning = true
- local clockVisible = true
- local toTerminal = false
- -- -------- Prompt Software
- function prompt(list, dir)
- -- Functions
- local function drawArrows(word, x, y)
- term.setCursorPos(x, y)
- write("[")
- term.setCursorPos(x + 1 + string.len(word), y)
- write("]")
- end
- local function removeArrows(word, x, y)
- term.setCursorPos(x, y)
- write(" ")
- term.setCursorPos(x + 1 + string.len(word), y)
- write(" ")
- end
- -- Variables
- local curSel = 1
- local c1 = 200
- local c2 = 208
- if dir == "horizontal" then c1 = 203 c2 = 205 end
- -- Draw
- for i = 1, #list do
- if list[i][2] == -1 then
- local w, h = term.getSize()
- list[i][2] = math.ceil(w/2 - list[i][1]:len()/2)
- end
- term.setCursorPos(list[i][2], list[i][3])
- write(list[i][1])
- end
- drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
- -- Selection
- while not(exitApp) do
- local event, key = os.pullEvent("key")
- removeArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
- if key == c1 then
- if curSel ~= 1 then curSel = curSel - 1 end
- elseif key == c2 then
- if curSel ~= #list then curSel = curSel + 1 end
- elseif key == 28 then
- return list[curSel][1]
- end
- drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
- end
- end
- -- -------- Drawing
- local function centerPrint(text)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- term.setCursorPos(math.ceil((w + 1)/2 - text:len()/2), y)
- print(text)
- end
- local function centerWrite(text)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- term.setCursorPos(math.ceil((w + 1)/2 - text:len()/2), y)
- write(text)
- end
- local function clearPage()
- local title = "Rescue Disk " .. antivirusVersion
- -- Title
- term.clear()
- term.setCursorPos(2, 1)
- write(title)
- -- Line
- local w, h = term.getSize()
- term.setCursorPos(1, 1)
- write(string.rep("-", w))
- print(" ")
- end
- -- -------- Updating
- local database = {}
- local function getDropbox(url, loc)
- sleep(0.01)
- while not(exitApp) do
- http.request(url)
- sleep(0.0000000001)
- while not(exitApp) do
- local event, _, response = os.pullEvent()
- if event == "http_failure" then
- return "false"
- elseif event == "http_success" and response ~= nil then
- local text = response:readAll()
- local f = io.open(loc, "w")
- sleep(0.01)
- f:write(text)
- sleep(0.01)
- f:close()
- response:close()
- return "true"
- end
- end
- end
- end
- local function updateClient()
- local updateLocation = "/.rescue-disk-update"
- fs.delete(updateLocation)
- getDropbox(antivirusURL, updateLocation)
- local f1 = io.open(updateLocation, "r")
- local f2 = io.open(antivirusLocation, "r")
- local update = f1:read("*a")
- local current = f2:read("*a")
- f1:close()
- f2:close()
- if current ~= update then
- fs.delete(antivirusLocation)
- fs.move(updateLocation, antivirusLocation)
- shell.run(antivirusLocation)
- error()
- else
- fs.delete(updateLocation)
- end
- end
- local function getDatabase()
- fs.delete(databaseLocation)
- getDropbox(databaseURL, databaseLocation)
- local f = io.open(databaseLocation)
- local lines = {}
- local a = f:read("*l")
- while a ~= nil do
- table.insert(lines, a)
- a = f:read("*l")
- end
- f:close()
- database = {}
- local curItem = {}
- local t = "name"
- for k, v in pairs(lines) do
- if t == "name" then
- curItem.name = v:gsub("^%s*(.-)%s*$", "%1")
- t = "definition"
- elseif t == "definition" then
- curItem.definition = v
- table.insert(database, curItem)
- t = "name"
- end
- end
- fs.delete(databaseLocation)
- end
- -- -------- Validation
- local function runOnStartup()
- -- Check for startup
- local name = fs.getName(antivirusLocation)
- if name ~= "startup" then
- clearPage()
- print(" ")
- centerPrint("Uh Oh!")
- print("\n\n")
- centerPrint("The Rescue Disk Wasn't Run On Startup!")
- print(" ")
- centerPrint("Please Rename The Rescue Disk To 'startup'")
- centerPrint("And Make Sure It's Run From A Disk")
- local opt = prompt({{"Shutdown", -1, 14}, {"Exit To Terminal", -1, 16}}, "vertical")
- if opt == "Exit To Terminal" then
- toTerminal = true
- end
- return false
- end
- -- Check Run On Disk
- local mPaths = {}
- for _, v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "drive" then
- table.insert(mPaths, disk.getMountPath(v))
- end
- end
- local onDisk = false
- for _, v in pairs(mPaths) do
- if antivirusLocation == "/" .. v .. "/startup" then
- onDisk = true
- mountPath = "/" .. v
- end
- end
- if not(onDisk) then
- clearPage()
- print(" ")
- centerPrint("Uh Oh!")
- print("\n\n")
- centerPrint("The Rescue Disk Wasn't Run From A Disk!")
- print(" ")
- centerPrint("Please Make Sure The Rescue Disk Is Named")
- centerPrint("'startup', And Is Run From A Disk")
- local opt = prompt({{"Shutdown", -1, 14}, {"Exit To Terminal", -1, 16}}, "vertical")
- if opt == "Exit To Terminal" then
- toTerminal = true
- end
- return false
- end
- return true
- end
- -- -------- Clock
- local function runClock()
- while clockRunning do
- if clockVisible then
- local prevx, prevy = term.getCursorPos()
- local w, h = term.getSize()
- local time = textutils.formatTime(os.time())
- term.setCursorPos(w - 10, 1)
- write(string.rep(" ", 10))
- term.setCursorPos(w - time:len() - 1, 1)
- write(time)
- term.setCursorPos(prevx, prevy)
- end
- sleep(0.06)
- end
- end
- -- -------- Scanning
- local viruses = {}
- local function log(...)
- local a = {...}
- for k, v in pairs(a) do
- term.setCursorPos(1, 9 + k)
- term.clearLine()
- centerWrite(v)
- end
- sleep(0.05)
- end
- local function scanRomPrograms()
- local root = fs.list("/")
- local sys = fs.list("/rom/programs")
- for a = 1, #root do
- for b = 1, #sys do
- if root[a] == sys[b] then
- log("General.Malware Found In", "/" .. root[a])
- local c = {}
- c.type = "General.Malware"
- c.location = "/" .. root[a]
- table.insert(viruses, c)
- end
- end
- end
- end
- local function scanRomAPIs()
- local root = fs.list("/")
- local sys = {"cp", "dir", "ls", "mv", "rm", "computer", "http", "secret", "turtle", "bit",
- "colors", "colours", "gps", "help", "io", "parallel", "rednet", "term", "textutils", "vector",
- "os", "math", "fs", "coroutine", "parallel", "peripheral", "rs", "redstone", "shell", "string",
- "table", "term", "adventure", "hello", "worm", "pastebin", "alongtimeago", "dance", "excavate",
- "go", "tunnel", "turn"}
- for a = 1, #root do
- for b = 1, #sys do
- if root[a] == sys[b] then
- log("General.Malware Found In", "/" .. root[a])
- local c = {}
- c.type = "General.Malware"
- c.location = "/" .. root[a]
- table.insert(viruses, c)
- end
- end
- end
- end
- local function scanDirectory(dir)
- local curDir = dir
- local cont = fs.list(curDir)
- if cont[1] == nil then
- return
- end
- local skip = false
- for i = 1, #cont do
- sleep(0.000001)
- if (cont[i] == "disk" and curDir == "/") or (cont[i] == "rom" and curDir == "/") then
- skip = true
- else
- skip = false
- end
- if not(fs.isDir(curDir .. cont[i])) then
- local f = io.open(curDir .. cont[i], "r")
- local data = f:read("*a")
- f:close()
- for x = 1, #database do
- if string.find(data, database[x].definition) ~= nil then
- log(database[x].name .. " Found In", curDir .. cont[i])
- break
- end
- end
- elseif skip == false then
- scanDirectory(curDir .. cont[i] .. "/")
- end
- end
- end
- -- -------- Main
- local function performScan()
- clearPage()
- print("\n")
- centerPrint("Complete Virus Scan")
- print(" ")
- centerPrint("This Will Search Through")
- centerPrint("All Your Computer's Files,")
- centerPrint("And Check If Any Are Viruses.")
- print(" ")
- centerPrint("Beware! Most Viruses Will Have")
- centerPrint("Already Deleted Most Of Your")
- centerPrint("Computer's Files.")
- local w, h = term.getSize()
- local opt = prompt({{"Continue", math.floor(w/4 - string.len("Continue")/2), 16},
- {"Exit To Terminal", math.ceil(w/4 - string.len("Exit To Terminal")/2 + w/2), 16}},
- "horizontal")
- if opt == "Continue" then
- clearPage()
- print("\n\n\n\n")
- centerPrint("Scanning For Viruses...")
- sleep(0.25)
- scanRomPrograms()
- scanRomAPIs()
- scanDirectory("/")
- clearPage()
- print("\n")
- centerPrint("Done!")
- if #viruses == 0 then
- print("\n\n\n")
- centerPrint("No Viruses Were Found!")
- prompt({{"Continue", -1, 14}}, "vertical")
- else
- local opt1 = prompt({{"Delete All Viruses", -1, 9}, {"Move Viruses To Disk", -1, 11}},
- "vertical")
- if opt1 == "Delete All Viruses" then
- for _, v in pairs(viruses) do
- fs.delete(v.location)
- end
- elseif opt1 == "Move Viruses To Disk" then
- if not(fs.exists(mountPath .. "/viruses")) then fs.makeDir(mountPath .. "/viruses") end
- for _, v in pairs(viruses) do
- fs.delete(mountPath .. "/viruses/" .. fs.getName(v.location))
- fs.move(v.location, mountPath .. "/viruses/" .. fs.getName(v.location))
- end
- end
- end
- clearPage()
- print("\n")
- centerPrint("Horrah!")
- print(" ")
- centerPrint("Your Computer Is Now Completely")
- centerPrint("Free Of Viruses!")
- print(" ")
- centerPrint("Enjoy!")
- prompt({{"Shutdown", -1, 15}}, "vertical")
- return nil
- elseif opt == "Exit To Terminal" then
- toTerminal = true
- return
- end
- end
- local function main()
- clearPage()
- print("\n")
- centerPrint("Welcome To Rescue Disk " .. antivirusVersion)
- print(" ")
- centerPrint("Made by 1lann and GravityScore")
- local opt = prompt({{"Continue To Terminal", -1, 12}, {"Perform Virus Scan", -1, 14}}, "vertical")
- if opt == "Continue To Terminal" then
- toTerminal = true
- return
- elseif opt == "Perform Virus Scan" then
- performScan()
- end
- end
- -- -------- Startup
- local function startup()
- -- Splash screen
- term.clear()
- term.setCursorPos(1, 4)
- centerPrint(" ____ ")
- centerPrint(" / __ \\ ___ _____ _____ __ __ ___ ")
- centerPrint(" / /_/ // _ \\ / ___// ___// / / // _ \\")
- centerPrint(" / _, _// __//__ // /__ / /_/ // __/")
- centerPrint(" /_/ |_| \\___//____/ \\___/ \\__,_/ \\___/ ")
- centerPrint(" ____ __ ")
- centerPrint(" / __ \\ __ _____ / /__ ")
- centerPrint(" / / / // // ___// //_/ ")
- centerPrint(" / /_/ // //__ // ,< ")
- centerPrint(" /_____//_//____//_/|_| ")
- -- Updating
- term.setCursorPos(1, 18)
- term.clearLine()
- centerWrite("Updating Rescue Disk...")
- updateClient()
- -- Run on startup
- local cont = runOnStartup()
- if not(cont) then
- if toTerminal == false then
- term.clear()
- term.setCursorPos(1, 1)
- os.shutdown()
- else
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint("Thank You For Using Rescue Disk v" .. antivirusVersion)
- centerPrint("Made By GravityScore and 1lann")
- error()
- end
- end
- -- Database
- term.clearLine()
- centerWrite("Loading Database...")
- getDatabase()
- -- Start
- parallel.waitForAny(main, runClock)
- -- Exit
- if toTerminal == true then
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint("Thank You For Using Rescue Disk v" .. antivirusVersion)
- centerPrint("Made By GravityScore and 1lann")
- else
- term.clear()
- term.setCursorPos(1, 1)
- os.shutdown()
- end
- end
- -- Run
- startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement