Advertisement
1lann

antivirusv4

Jun 18th, 2012
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.41 KB | None | 0 0
  1. -- (c) COPYRIGHT 2012      --
  2. -- A program made by 1lann --
  3. -- Thanks to: This_is_1984 --
  4. -- and GravityScore        --
  5. function move(dir, option1, option2)
  6. term.setCursorPos(3, 14)
  7. write("                                          ")
  8. if dir == "left" then
  9. b1 = (math.floor(13-(string.len(option1)/2)))-1
  10. b2 = math.floor(37-(string.len(option2)/2))
  11. term.setCursorPos(b1, 14)
  12. term.write(">" .. option1 .. "<")
  13. term.setCursorPos(b2, 14)
  14. term.write(option2)
  15. coroutine.yield()
  16. event, key = os.pullEvent("key")
  17. if key == 205 then
  18. r = move("right", option1, option2)
  19. return r
  20. elseif key ==  28 then
  21. return option1
  22. else
  23. r = move("left", option1, option2)
  24. return r
  25. end
  26. elseif dir == "right" then
  27. b1 = math.floor(13-(string.len(option1)/2))
  28. b2 = (math.floor(37-(string.len(option2)/2)))-1
  29. term.setCursorPos(b1, 14)
  30. term.write(option1)
  31. term.setCursorPos(b2, 14)
  32. term.write(">" .. option2 .. "<")
  33. coroutine.yield()
  34. event, key = os.pullEvent("key")
  35. if key == 203 then
  36. r = move("left", option1, option2)
  37. return r
  38. elseif key ==  28 then
  39. return option2
  40. else
  41. r = move("right", option1, option2)
  42. return r
  43. end
  44. elseif dir == "centre" then
  45. b1 = math.floor(25-(string.len(option1)/2))
  46. term.setCursorPos(b1, 14)
  47. write(">" .. option1 .. "<")
  48. coroutine.yield()
  49. event, key = os.pullEvent("key")
  50. if key == 28 then
  51. return option2
  52. else
  53. r = move("centre", option1, option2)
  54. return r
  55. end
  56. else
  57. error("Not a valid direction")
  58. end
  59. end
  60.  
  61. function prompt(line1, line2, line3, line4, line5, option1, option2)
  62. show(true)
  63. term.clear()
  64. term.setCursorPos(2,2)
  65. write("+----------------------------------------------+")
  66. term.setCursorPos(2,3)
  67. write("|1lann's Rescue Disk (v0.5)                    |")
  68. term.setCursorPos(2,4)
  69. write("+----------------------------------------------+")
  70. for i = 1, 12 do
  71. b = i+4
  72. term.setCursorPos(2, b)
  73. write("|")
  74. term.setCursorPos(49, b)
  75. write("|")
  76. end
  77. term.setCursorPos(2, 17)
  78. write("+----------------------------------------------+")
  79. a1 = math.floor(25-(string.len(line1)/2))
  80. a2 = math.floor(25-(string.len(line2)/2))
  81. a3 = math.floor(25-(string.len(line3)/2))
  82. a4 = math.floor(25-(string.len(line4)/2))
  83. a5 = math.floor(25-(string.len(line5)/2))
  84. term.setCursorPos(a1, 7)
  85. write(line1)
  86. term.setCursorPos(a2, 8)
  87. write(line2)
  88. term.setCursorPos(a3, 9)
  89. write(line3)
  90. term.setCursorPos(a4, 10)
  91. write(line4)
  92. term.setCursorPos(a5, 11)
  93. write(line5)
  94. dir = "left"
  95. if option2 == nil then
  96. dir = "centre"
  97. end
  98. x = move(dir, option1, option2)
  99. term.clear()
  100. term.setCursorPos(1, 1)
  101. show(false)
  102. return x
  103. end
  104.  
  105. function log(log)
  106. f = io.open("/disk/avlog.log", "a")
  107. f:write(log .. "\n")
  108. f:close()
  109. end
  110.  
  111.  
  112. function scandir(ldir)
  113.   local currentdir = ldir
  114.   local cont = {}
  115.   cont = fs.list(currentdir)
  116. if cont[1] == nil then
  117. return
  118. end
  119.  local b = 0
  120.   for i = 1, #cont do
  121. sleep(0.000001)
  122.    b = b+1
  123. i = b
  124. if cont[i] == "disk" and currentdir == "/" then
  125. skip = "true"
  126. elseif cont[i] == "rom" and currentdir == "/" then
  127. skip = "true"
  128. else
  129. skip = "false"
  130. end
  131.     if not fs.isDir(currentdir .. cont[i]) then
  132.       files = files+1
  133.       f = io.open(currentdir .. cont[i], "r")
  134.       local data = f:read("*a")
  135.       f:close()
  136.       for xvirus = 1, #virusdatabase do
  137.       local find = string.find(data, virusdatabase[xvirus], 1, false)
  138.       if find ~= nil then
  139.     fs.delete( "/disk/bad" .. cont[i])
  140.         fs.move(currentdir .. cont[i], "/disk/bad" .. cont[i])
  141.         viruses = viruses+1
  142.         print("Virus \"" .. namedatabase[xvirus] .. "\" found in " .. currentdir .. cont[i])
  143.         log("Virus \"" .. namedatabase[xvirus] .. "\" found in " .. currentdir .. cont[i])
  144.         break
  145. end
  146. end
  147.     elseif skip == "false" then
  148. folders = folders+1
  149.      scandir(currentdir .. cont[i] .. "/")
  150. else
  151.     end
  152.   end
  153. end
  154.  
  155. function namecheck()
  156. filelist = fs.list("/")
  157. names = {"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"}
  158. for b = 1, #filelist do
  159. for i = 1, #names do
  160. if filelist[b] == names[i] then
  161. viruses = viruses+1
  162. files = files+1
  163. print("Virus \"General.Malware\" found in /" .. filelist[b])
  164. log("Virus \"General.Malware\" found in /" .. filelist[b])
  165. fs.delete("/disk/bad" .. filelist[b])
  166. fs.move("/" .. filelist[b], "/disk/bad" .. filelist[b])
  167. else
  168. end
  169. end
  170. end
  171. end
  172.  
  173. function syscheck()
  174. filelist = fs.list("/")
  175. system  = fs.list("/rom/programs")
  176. for b = 1, #filelist do
  177. for i = 1, #system do
  178. if filelist[b] == system[i] then
  179. viruses = viruses+1
  180. files = files+1
  181. print("Virus \"General.Malware\" found in /" .. filelist[b])
  182. log("Virus \"General.Malware\" found in /" .. filelist[b])
  183. fs.delete("/disk/bad" .. filelist[b])
  184. fs.move("/" .. filelist[b], "/disk/bad" .. filelist[b])
  185. else
  186. end
  187. end
  188. end
  189. end
  190.  
  191. function maskscan()
  192. option = prompt(" ", "Right! Now we\'re going to do a", "full virus scan and delete", "all the viruses", " ", "Ok", "Exit")
  193. if option == "Exit" then
  194. prompt(" ", "Alright! Just be careful!", "Please eject the disk", "Press enter to shutdown the computer", " ", "Shutdown")
  195. os.shutdown()
  196. end
  197. log("Start virus scan")
  198. viruses = 0
  199. files = 0
  200. folders = 0
  201. syscheck()
  202. namecheck()
  203. scandir("/")
  204. log("Scanned through " .. files .. " files")
  205. log("Scanned through " .. folders .. " folders")
  206. log("End virus scan")
  207. log(" ")
  208. print("Press any key to continue...")
  209. os.pullEvent("key")
  210. prompt("Scanned through " .. files .. " files and " .. folders .. " folders!", "A total of " .. viruses .. " viruses were found and moved!", "The files were moved on the disk,", "prefixed with \"bad\"", " ", "Ok")
  211. prompt("Horrah! You finished the entire antivirus", "process! \(It\'s that easy!\)", "Please eject the disk", "Press enter to shutdown the computer", " ", "Shutdown")
  212. os.shutdown()
  213. end
  214.  
  215. function restore()
  216. option = prompt(" ", "Uh oh!, You\'re computer is infected!", "Don\'t worry! we can fix this in a sinch", "Do you want to ignore it or restore it", "from the disk?", "Restore", "Ignore")
  217. if option == "Restore" then
  218. f = io.open("/disk/startbackup", "r")
  219. startbackup = f:read("*a")
  220. f:close()
  221. f = io.open("/startup", "r")
  222. startupfile = f:read("*a")
  223. f:close()
  224. f = io.open("/disk/badstartup", "w")
  225. f:write(startupfile)
  226. f:close()
  227. f = io.open("/startup", "w")
  228. f:write(startbackup)
  229. f:close()
  230. prompt("Restored!", "Also, I made a copy of the bad startup", "on the disk called badstartup", "The next step is to perform a", "full antivirus scan", "Continue")
  231. maskscan()
  232. end
  233. maskscan()
  234. end
  235.  
  236. function manual()
  237. prompt("Alright, then I can\'t check your startup", "You\'re going to have to check it yourself", "Hit exit once you\'re done checking", "BTW, editting and hitting save won\'t", "do anything to the actual startup", "Open startup")
  238. f = io.open("/startup", "r")
  239. file = f:read("*a")
  240. f:close()
  241. f = io.open("/disk/tempstartup", "w")
  242. f:write(file)
  243. f:close()
  244. shell.run("/rom/programs/edit", "/disk/tempstartup")
  245. fs.delete("/disk/tempstartup")
  246. option = prompt(" ", " ", "Was that startup file correct?", " ", " ", "Yes", "No")
  247. if option == "Yes" then
  248. f = io.open("/disk/startbackup", "w")
  249. f:write(file)
  250. f:close()
  251. prompt(" ", "Backed up on the disk as \"startbackup\"", "The next step is to perform a", "full antivirus scan", " ", "Continue")
  252. maskscan()
  253. else
  254. restore()
  255. end
  256. end
  257.  
  258. function main()
  259. clock = 0.1
  260. term.clear()
  261. term.setCursorPos(1, 1)
  262. if not fs.exists("/startup") then
  263. f = io.open("/startup", "w")
  264. f:write("\n")
  265. f:close()
  266. end
  267.   if clock > 1 then
  268.     prompt(" ", " ", "This program wasn\'t run on startup!", "Please reboot your computer and try again", " ", "Ok")
  269.   elseif not fs.exists("/disk/startup") then
  270.     prompt(" ", "This program is not ran from a disk", "Please put it on a disk as startup", "and try again"," ", "Ok")
  271.   elseif not fs.isDir("/disk") then
  272.     input = prompt(" ", "A file is obstructing the name \"disk\"", "Would you like to rename it or", "exit the rescue disk?", " ", "Rename", "Exit")
  273.     if input == "Rename" then
  274.       f = io.open("/disk", "r")
  275.       disk = f:read("*a")
  276.       f:close()
  277.       f = io.open("/otherdisk", "w")
  278.       f:write(disk)
  279.       f:close()
  280.       prompt(" ", " ", "Alright, renamed to \"otherdisk\"", "Now we have to reboot the computer", " ", "Reboot")
  281.       os.reboot()
  282.     else
  283.       os.shutdown()
  284.     end
  285. else
  286. if fs.exists("/disk/tempstartup") then fs.delete("/disk/tempstartup") end
  287. shell.run("/rom/programs/http/pastebin", "get", "hLnnpXtZ", "/disk/tempstartup")
  288. f = io.open("/disk/tempstartup", "r")
  289. tempstartup = f:read("*a")
  290. f:close()
  291. f = io.open("/disk/startup", "r")
  292. avstartup = f:read("*a")
  293. f:close()
  294. fs.delete("/disk/tempstartup")
  295. if fs.exists("/disk/database") then fs.delete("/disk/database") end
  296. shell.run("/rom/programs/http/pastebin", "get", "xJhGLZeV", "/disk/database")
  297. f = io.open("/disk/database", "r")
  298. namedatabase = {}
  299. bdatabase = f:read("*l")
  300. while bdatabase ~= nil do
  301. table.insert(namedatabase, bdatabase)
  302. bdatabase = f:read("*l")
  303. bdatabase = f:read("*l")
  304. end
  305. f:close()
  306. f = io.open("/disk/database", "r")
  307. virusdatabase = {}
  308. bdatabase = f:read("*l")
  309. bdatabase = f:read("*l")
  310. while bdatabase ~= nil do
  311. table.insert(virusdatabase, bdatabase)
  312. bdatabase = f:read("*l")
  313. bdatabase = f:read("*l")
  314. end
  315. f:close()
  316. fs.delete("/disk/database")
  317.     option = prompt(" ", "Welcome to 1lann\'s Rescue Disk! \(v0.5\)", "Would you like to continue", "Or go to the terminal?", " ", "Continue", "Terminal")
  318.     if option == "Terminal" then
  319.       term.clear()
  320.       term.setCursorPos(1, 1)
  321.     end
  322. else
  323.   prompt("Uh oh! The rescue disk is infected!", "Please re-install the rescue disk", "and make sure that computer is", "off when you insert the rescue disk", "Press enter to shutdown", "Shutdown")
  324.   os.shutdown()
  325. end
  326. end
  327. terminate = true
  328. end
  329. end
  330.  
  331.  
  332. local stime = false
  333. function show(bool)
  334.   stime = bool
  335. end
  336.  
  337. local running = true
  338. function run(bool)
  339.   running = bool
  340. end
  341.  
  342. terminate = false
  343.  
  344. local function clockFunc()
  345. while running == true do
  346. while stime == true do
  347.   x, y = term.getCursorPos()
  348.   time = textutils.formatTime(os.time())
  349.   term.setCursorPos(41,3)
  350.   write("        ")
  351.   term.setCursorPos(41,3)
  352.   write(time)
  353.   term.setCursorPos(x, y)
  354.   sleep(0.03)
  355. end
  356. sleep(0.03)
  357. end
  358. end
  359.  
  360. while terminate == false do
  361.     parallel.waitForAny(clockFunc, main)
  362. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement