Guest User

Untitled

a guest
Jan 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local tArgs = {...}
  2. local virusDB = {'fs.open((%p.)startup(%p.))', 'os.pullEvent = os.pullEventRaw', 'fs.delete((%p.)scan(%p.))'}
  3. -- Add virus code to virusDB (line above)
  4. percent = 0
  5. if #tArgs < 1 then
  6.  print("Usage:")
  7.  print("scan <program>")
  8.  print("")
  9.  error()
  10. end
  11. path = shell.resolve(tArgs[1])
  12. if fs.exists(path) == false then
  13.  print("File does not exist.")
  14.  error()
  15. end
  16.  
  17. function status(lines)
  18.  add = (100/lines)/#virusDB
  19.  write(math.floor(percent))
  20.  print("%")
  21.  percent = percent + add
  22. end
  23.  
  24.  
  25. function scan(file, string)
  26.  for w in string.gmatch(file, string) do
  27.   return true
  28.  end
  29.  return false
  30. end
  31.  
  32.  
  33. function ready(tempFile)
  34. lines = #tempFile
  35. if #tempFile > 65 then
  36.  quick = true
  37. else
  38.  quick = false
  39. end
  40. for virNum = 1, #virusDB do
  41.  for fileNum = 1, #tempFile do
  42.   term.clear()
  43.   term.setCursorPos(1,1)
  44.   print("Searching for virus #"..virNum.." in "..tArgs[1])
  45.   write("Results: ")
  46.   val = scan(tempFile[fileNum], virusDB[virNum])
  47.   print(val)
  48.   write("Status: ")
  49.   status(lines)
  50.   if val == true then
  51.    print("")
  52.    print("************************")
  53.    print("       Virus Info       ")
  54.    print("")
  55.    print("Virus code: "..virusDB[virNum])
  56.    print("Line number: "..fileNum)
  57.    print("************************")
  58.    print("")
  59.    print("Would you like to delete this program? (Y/N)")
  60.    act, key = os.pullEvent("key")
  61.    if key == 21 then
  62.     path = shell.resolve(tArgs[1])
  63.     fs.delete(path)
  64.     term.clear()
  65.     term.setCursorPos(1,1)
  66.     print("File removed.")
  67.     error()
  68.    end
  69.   end
  70.  if quick == false then
  71.    sleep(.1)
  72.  end
  73.  end
  74. end
  75. end
  76.  
  77. function read(file)
  78.  f = fs.open(file, "r")
  79.  fileData = {}
  80.  nilLine = 0
  81.  repeat
  82.   table.insert(fileData, line)
  83.   line = f.readLine()
  84.   if line == nil then
  85.    nilLine = nilLine + 1
  86.   else
  87.    nilLine = 0
  88.   end
  89.   until nilLine > 1
  90.  f.close()
  91.  ready(fileData)
  92. end
  93.  
  94. read(tArgs[1])
  95. term.clear()
  96. term.setCursorPos(1,1)
  97. print("File scan complete. Scanned "..lines.." lines total.")
  98. if quick == true then
  99.  print("File was scanned in hyper mode to save time.")
  100. end
  101. sleep(2)
  102. os.reboot()
Add Comment
Please, Sign In to add comment