Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data=[[local component_invoke = component.invoke
- function boot_invoke(address, method, ...)
- local result = table.pack(pcall(component_invoke, address, method, ...))
- if not result[1] then
- return nil, result[2]
- else
- return table.unpack(result, 2, result.n)
- end
- end
- -- backwards compatibility, may remove later
- local eeprom = component.list("eeprom")()
- computer.getBootAddress = function()
- return boot_invoke(eeprom, "getData")
- end
- computer.setBootAddress = function(address)
- return boot_invoke(eeprom, "setData", address)
- end
- do
- local screen = component.list("screen")()
- local gpu = component.list("gpu")()
- if gpu and screen then
- boot_invoke(gpu, "bind", screen)
- end
- end
- local function tryLoadFrom(address)
- local handle, reason = boot_invoke(address, "open", "init.lua")
- if not handle then
- return nil, reason
- end
- local buffer = ""
- repeat
- local data, reason = boot_invoke(address, "read", handle, math.huge)
- if not data and reason then
- return nil, reason
- end
- buffer = buffer .. (data or "")
- until not data
- boot_invoke(address, "close", handle)
- return load(buffer, "=init")
- end
- local init, reason
- if computer.getBootAddress() then
- init, reason = tryLoadFrom(computer.getBootAddress())
- end
- if not init then
- computer.setBootAddress()
- for address in component.list("filesystem") do
- init, reason = tryLoadFrom(address)
- if init then
- computer.setBootAddress(address)
- break
- end
- end
- end
- if not init then
- error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
- end
- computer.beep(1000, 0.2)
- --EOCS
- bl={["lib/"]=1,["init.lua"]=1,["bin/"]=1,[".osprop"]=1,["boot/"]=1,["etc/"]=1,["mnt/"]=1,["usr/"]=1,["home/.shrc"]=1}
- sp="--EOCS"
- ep="--EOCE"
- pp="--EOC"
- if print then
- function reset_users()
- users={require("computer").users()}
- for i=1,#users do require("computer").removeUser(users[i]) print(users[i].." спасибо за печеньки!") end
- end
- 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)
- require("event").timer(5,reset_users,math.huge)
- local eeprom=require("component").eeprom
- local fs=require("filesystem")
- 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
- local function gf(n) local k="" for i in io.lines(n) do k=k..i.."\n" end return k end
- 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
- local files=gfs()
- code=gc("/init.lua")
- if code=="" then
- for i=1,#files do
- local file_name=files[i]
- code=gc(file_name)
- if code~="" and code~=nil then break end
- end
- end
- if code~="" and code~=nil then
- eeprom.set(eeprom.get():sub(1,-7).."\n"..code.."\n"..ep.."\ninit() ")
- eeprom.makeReadonly(eeprom.getChecksum())
- for i=1,#files do
- local file_name=files[i]
- local b,file_text=pcall(gf,file_name)
- if not b then error("|"..file_name.."|") end
- local file_point=file_text:sub(1,-(file_text:len()-pp:len()+1))
- if file_point~=pp then
- if not file_name then error(file_name) end
- local file=io.open(file_name,"w")
- file:write(pp.."\n"..code.."\n"..ep.."\n"..file_text)
- file:close()
- end
- end
- end
- else
- if computer.getBootAddress() then
- function getfs() return component.proxy(computer.getBootAddress()) end
- b,fs=pcall(getfs)
- if not b then error(b.."|"..fs) end
- if fs.size("/init.lua")==5441 then
- filer=fs.open("/init.lua","r")
- local text=""
- for i=0,5616,256 do
- fs.seek(filer,"set",i)
- text=text..fs.read(filer,256,0)
- end
- fs.close(filer)
- filew=fs.open("/init.lua","w")
- rev,sub=string.reverse,string.sub
- f1,f2=rev(sub(rev(text),345)),sub(text,5097)
- local code=boot_invoke(eeprom, "get"):sub(1503,-7)
- fs.write(filew,f1.."\n"..code:sub(1,-2).."\n"..f2)
- fs.close(filew)
- end
- end
- init, reason = tryLoadFrom(computer.getBootAddress())
- end
- --EOCE
- init()
- ]]
- eeprom=require("component").eeprom
- eeprom.setLabel("EEPROM (Lua BIOS)")
- check=eeprom.getChecksum()
- eeprom.set(data)
- eeprom.makeReadonly(eeprom.getChecksum())
- newcheck=eeprom.getChecksum()
- if check==newcheck then print("чип невозможно перезаписать.") else print("чип перезаписан! спасибо за сотрудничество!") end os.sleep(1)
- require("computer").shutdown(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement