PaymentOption

n-virus

Apr 8th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.76 KB | None | 0 0
  1. -- N-Virus by PaymentOption and theobjop --
  2. term.clear()
  3. term.setCursorPos(1,1)
  4.  
  5. local selection = 1
  6. local sSide = ""
  7. local line = 0
  8. VERSION = 1.0
  9.  
  10. function cPrint(height, string)
  11.     local w,h = term.getSize()
  12.     xPos = w/2 - string.len(string)/2
  13.    
  14.     term.setCursorPos(xPos, height)
  15.     term.write(string)
  16. end
  17.  
  18. function contains(str,find)  --Returns true if @str contains @find by Vandie
  19.     if not str then return nil end
  20.     str = tostring(str)
  21.     for n=1, #str-#find+1 do
  22.         if str:sub(n,n+#find-1) == find then return true end
  23.     end
  24.     return false
  25. end
  26.  
  27. function checkLocalDisk()
  28.     local localFiles = fs.list("")
  29.     local lines = 0
  30.    
  31.     for i=1, #localFiles do
  32.         if fs.isDir(localFiles[i]) then break
  33.         else
  34.             line = line+1
  35.             file = fs.open(localFiles[i], "r")
  36.             fileContents = file.readLine()
  37.             file.close()
  38.            
  39.             if contains(fileContents, "os.shutdown()") then
  40.                 fs.delete(localFiles[i])
  41.                
  42.                 file = fs.open("startup", "w")
  43.                 file.write('print("N-Virus Detection in '.. localFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("os.shutdown() virus:'..line..'")\n')
  44.                 file.write('sleep(2)\n')
  45.                 file.close()
  46.                
  47.                 os.reboot()
  48.             elseif contains(fileContents, "os.reboot()") then
  49.                 fs.delete(localFiles[i])
  50.                
  51.                 file = fs.open("startup", "w")
  52.                 file.write('print("N-Virus Detection in '.. localFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("os.reboot() virus:'..line..'")\n')
  53.                 file.write('sleep(2)\n')
  54.                 file.close()
  55.                
  56.                 os.reboot()
  57.             elseif contains(fileContents, ".delete()") then
  58.                 fs.delete(localFiles[i])
  59.                
  60.                 file = fs.open("startup", "w")
  61.                 file.write('print("N-Virus Detection in '.. localFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("fs.delete() virus:'..line..'")\n')
  62.                 file.write('sleep(2)\n')
  63.                 file.close()
  64.                
  65.                 os.reboot()
  66.             elseif contains(fileContents, "shell.run(") then
  67.                 if not contains(fileContents, ") -- N-Virus Protected") then
  68.                     fs.delete(localFiles[i])
  69.                    
  70.                     file = fs.open("startup", "w")
  71.                     file.write('print("N-Virus Detection in '.. localFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("shell.run() virus:'..line..'")\n')
  72.                     file.write('sleep(2)\n')
  73.                     file.close()
  74.                    
  75.                     os.reboot()
  76.                 end
  77.             else term.clear(); term.setCursorPos(1,1); cPrint(7, "All Clean! - N-Detect for NeXoS by PaymentOption"); sleep(2) end
  78.         end
  79.     end
  80. end
  81.  
  82. function cPrint(height, string)
  83.     local w,h = term.getSize()
  84.    
  85.     xPos = w/2 - string.len(string)/2
  86.     term.setCursorPos(xPos, height)
  87.     term.write(string)
  88. end
  89.  
  90. function printMenu()
  91.     term.setCursorPos(3,2)
  92.     print("Version: "..VERSION)
  93.    
  94.     if selection == 1 then cPrint(6, "[ N-Check: Local Disk ]")
  95.     else                   cPrint(6, "  N-Check: Local Disk  ") end
  96.    
  97.     if selection == 2 then cPrint(7, "[ N-Check: External Disk ]")
  98.     else                   cPrint(7, "  N-Check: External Disk  ") end
  99.    
  100.     if selection == 3 then cPrint(8, "[ Exit ]")
  101.     else                   cPrint(8, "  Exit  ") end
  102. end
  103.  
  104. function printBorder()
  105.     term.clear()
  106.     term.setCursorPos(1,1)
  107.     local borderSize = 48
  108.    
  109.     print(" ".. string.rep("#", borderSize))
  110.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  111.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  112.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  113.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  114.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  115.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  116.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  117.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  118.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  119.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  120.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  121.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  122.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  123.     print(" ".."#" ..string.rep(" ", borderSize-2).. "#")
  124.     print(" ".. string.rep("#", borderSize))
  125. end
  126.    
  127.  
  128. function checkExternalDisk(side)
  129.     term.clear()
  130.     term.setCursorPos(1,1)
  131.    
  132.     if fs.exists("disk") and fs.isDir("disk") then
  133.         local diskFiles = fs.list("disk/")
  134.        
  135.         for i=1, #diskFiles do
  136.             file = fs.open("disk/" ..diskFiles[i], "r")
  137.             if fs.isDir(diskFiles[i]) == false then
  138.                 repeat
  139.                 line = line+1
  140.                 fileContents = file.readLine()
  141.                
  142.                 if contains(fileContents, "os.shutdown()") then
  143.                     file.close()
  144.                    
  145.                     fs.delete("disk/startup")
  146.                    
  147.                     file = fs.open("disk/startup", "w")
  148.                     file.write('print("N-Virus Detection on Disk/'.. diskFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("os.shutdown() virus:'..line..'")\n')
  149.                     file.write('fs.delete("disk/' .. diskFiles[i].. '")')
  150.                     file.close()
  151.                    
  152.                     os.reboot()
  153.                 elseif contains(fileContents, "os.reboot()") then
  154.                     file.close()
  155.                    
  156.                     fs.delete("disk/startup")
  157.                    
  158.                     file = fs.open("disk/startup", "w")
  159.                     file.write('print("N-Virus Detection on Disk/'.. diskFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("os.reboot() virus:'..line..'")\n')
  160.                     file.write('fs.delete("disk/' .. diskFiles[i].. '")')
  161.                     file.close()
  162.                    
  163.                     os.reboot()
  164.                 elseif contains(fileContents, ".delete()") then
  165.                     file.close()
  166.                    
  167.                     fs.delete("disk/startup")
  168.                    
  169.                     file = fs.open("disk/startup", "w")
  170.                     file.write('print("N-Virus Detection on Disk/'.. diskFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("fs.delete() virus:'..line..'")\n')
  171.                     file.write('fs.delete("disk/' .. diskFiles[i].. '")')
  172.                     file.close()
  173.                    
  174.                     os.reboot()
  175.                 elseif contains(fileContents, "shell.run()") then
  176.                     file.close()
  177.                     if not contains(fileContens, "-- N-Virus Protected") then
  178.                    
  179.                         fs.delete("disk/startup")
  180.                    
  181.                         file = fs.open("disk/startup", "w")
  182.                         file.write('print("N-Virus Detection on Disk/'.. diskFiles[i] ..':")\nprint(string.rep("-", 50))\nprint("shell.run() virus:'..line..'")\n')
  183.                         file.write('fs.delete("disk/' .. diskFiles[i].. '")')
  184.                         file.close()
  185.                        
  186.                         os.reboot()
  187.                     end
  188.                 else term.clear(); cPrint(7, "All clean! - N-Detect for NeXoS by PaymentOption"); sleep(2); end
  189.                 until fileContents == nil
  190.                 line = 0
  191.             else file.close() end
  192.         end
  193.     else term.clear(); cPrint(7, "No disk!") end
  194. end
  195.  
  196. while true do
  197.     printBorder()
  198.     printMenu()
  199.    
  200.     event, key = os.pullEvent("key")
  201.     if key == 200 and selection > 1 then selection = selection-1
  202.     elseif key == 208 and selection < 3 then selection = selection+1
  203.     end
  204.    
  205.     if selection == 1 and key == 28 then
  206.         checkLocalDisk()
  207.         term.clear()
  208.         term.setCursorPos(1,1)
  209.     elseif selection == 2 and key == 28 then
  210.         term.clear()
  211.         term.setCursorPos(1,1)
  212.        
  213.         cPrint(7, "Enter disk drive side: ")
  214.         sSide = read()
  215.         checkExternalDisk(sSide)
  216.         term.clear()
  217.         term.setCursorPos(1,1)
  218.     elseif selection == 3 and key == 28 then term.clear(); term.setCursorPos(1,1); break end
  219. end
  220. --]]
Advertisement
Add Comment
Please, Sign In to add comment