View difference between Paste ID: AEDjVVd3 and Jn48zZjG
SHOW: | | - or go back to the newest paste.
1
--#--
2
dev = false
3
defaultPath = nil
4-
WaitTime = 15
4+
WaitTime = 0
5
ID = nil
6
profanity = false
7
8
--==--==--==--==--==--==--==--==--==--
9
function cp(str) --FBI, its not what you think it is
10
  local x, y = term.getSize()
11
  local cx, cy = term.getCursorPos()
12
  local l = #str
13
  term.setCursorPos((x/2)-(l/2), cy)
14
  print(str)
15
end
16
17
function halt()
18
  os.pullEvent("HALT")
19
end
20
21
function fuck(err, act)
22
  term.setCursorPos(1,1)
23
  term.setBackgroundColor(colors.white)
24
  term.clear()
25
  term.setTextColor(colors.black)
26
  if profanity then cp("Fuck, it broke") else cp("It broke") end
27
  print("\r\n")
28
  if err == nil then cp("Thats all I know") end
29
  if err ~= nil then print(err) end
30
  if act == "reboot" then os.reboot() else halt() end
31
end
32
33-
local counter = 0
33+
34-
function LoadCFG()
34+
35-
	if fs.exists(".bcfg") then
35+
36-
		local f = fs.open(".bcfg", 'r')
36+
37-
		local d = f.readAll()
37+
38-
		f.close()
38+
39-
		
39+
40-
		ion = textutils.unserialize(d)
40+
41-
		for k, v in pairs(ion) do
41+
42-
			if dev then print(tostring(k) .. " = " .. tostring(v)) end
42+
43-
			if k == 'SecureBootFile' then 
43+
44-
     if SecureBoot == nil then enableSecureBoot(v) end
44+
45-
   else
45+
46-
     ls = loadstring(k .. " = " .. tostring(v))
46+
47-
	  		setfenv(ls, getfenv())
47+
48-
		  	ls()
48+
49-
   end				
49+
50-
		end
50+
51-
		if dev then sleep(.5) end
51+
52-
	end
52+
53
function exec(file)
54
  local f = fs.open(file, 'r')
55-
--sha256 adapted from: http://www.computercraft.info/forums2/index.php?/topic/8169-sha-256-in-pure-lua/
55+
56-
--usage a5(msg)
56+
57-
local a=2^32;local b=a-1;local function c(d)local mt={}local e=setmetatable({},mt)function mt:__index(f)local g=d(f)e[f]=g;return g end;return e end;local function h(e,i)local function j(k,l)local m,o=0,1;while k~=0 and l~=0 do local p,q=k%i,l%i;m=m+e[p][q]*o;k=(k-p)/i;l=(l-q)/i;o=o*i end;m=m+(k+l)*o;return m end;return j end;local function r(e)local s=h(e,2^1)local t=c(function(k)return c(function(l)return s(k,l)end)end)return h(t,2^e.n or 1)end;local u=r({[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0},n=4})local function v(k,l,w,...)local x=nil;if l then k=k%a;l=l%a;x=u(k,l)if w then x=v(x,w,...)end;return x elseif k then return k%a else return 0 end end;local function y(k,l,w,...)local x;if l then k=k%a;l=l%a;x=(k+l-u(k,l))/2;if w then x=bit32_band(x,w,...)end;return x elseif k then return k%a else return b end end;local function z(A)return(-1-A)%a end;local function B(k,C)if C<0 then return lshift(k,-C)end;return math.floor(k%2^32/2^C)end;local function D(A,C)if C>31 or C<-31 then return 0 end;return B(A%a,C)end;local function lshift(k,C)if C<0 then return D(k,-C)end;return k*2^C%2^32 end;local function E(A,C)A=A%a;C=C%32;local F=y(A,2^C-1)return D(A,C)+lshift(F,32-C)end;local f={0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2}local function G(H)return string.gsub(H,".",function(w)return string.format("%02x",string.byte(w))end)end;local function I(J,n)local H=""for K=1,n do local L=J%256;H=string.char(L)..H;J=(J-L)/256 end;return H end;local function M(H,K)local n=0;for K=K,K+3 do n=n*256+string.byte(H,K)end;return n end;local function N(O,P)local Q=64-(P+9)%64;P=I(8*P,8)O=O.."\128"..string.rep("\0",Q)..P;assert(#O%64==0)return O end;local function R(S)S[1]=0x6a09e667;S[2]=0xbb67ae85;S[3]=0x3c6ef372;S[4]=0xa54ff53a;S[5]=0x510e527f;S[6]=0x9b05688c;S[7]=0x1f83d9ab;S[8]=0x5be0cd19;return S end;local function T(O,K,S)local U={}for V=1,16 do U[V]=M(O,K+(V-1)*4)end;for V=17,64 do local g=U[V-15]local W=v(E(g,7),E(g,18),D(g,3))g=U[V-2]U[V]=U[V-16]+W+U[V-7]+v(E(g,17),E(g,19),D(g,10))end;local k,l,w,X,Y,d,Z,_=S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[8]for K=1,64 do local W=v(E(k,2),E(k,13),E(k,22))local a0=v(y(k,l),y(k,w),y(l,w))local a1=W+a0;local a2=v(E(Y,6),E(Y,11),E(Y,25))local a3=v(y(Y,d),y(z(Y),Z))local a4=_+a2+a3+f[K]+U[K]_,Z,d,Y,X,w,l,k=Z,d,Y,X+a4,w,l,k,a4+a1 end;S[1]=y(S[1]+k)S[2]=y(S[2]+l)S[3]=y(S[3]+w)S[4]=y(S[4]+X)S[5]=y(S[5]+Y)S[6]=y(S[6]+d)S[7]=y(S[7]+Z)S[8]=y(S[8]+_)end;local function a5(O)O=N(O,#O)local S=R({})for K=1,#O,64 do T(O,K,S)end;return G(I(S[1],4)..I(S[2],4)..I(S[3],4)..I(S[4],4)..I(S[5],4)..I(S[6],4)..I(S[7],4)..I(S[8],4))end
57+
58
  setfenv(c, getfenv())
59-
local function generateKey(strin)
59+
60-
  local key = '"' .. tostring(a5(strin)) .. '"'
60+
61-
  return key
61+
62
    term.setBackgroundColor(colors.black)
63
    cfill(colors.black)
64-
function enableSecureBoot(file)
64+
65-
  local buffer = fs.open(file, 'r')
65+
66-
  local dump = buffer.readAll()
66+
67-
  --print(dump)
67+
68-
  buffer.close()
68+
69-
  print("Generating Key")
69+
70-
  SecureBootKey = generateKey(dump)
70+
71-
  print("Generated Key")
71+
72-
  --Rewriting startup
72+
73-
  print("Rewriting startup")
73+
74-
  buffer = fs.open('startup', 'r')
74+
75-
  dump = buffer.readAll()
75+
76-
  buffer.close()
76+
77-
  fs.delete("startup")
77+
  if fs.exists("/boot/os") ~= true then
78
    term.setTextColor(colors.red)
79-
  buffer = fs.open('startup', 'w')
79+
    fuck('No Bootable Medium Found')
80-
  buffer.write("--#-- \n")
80+
81-
  buffer.write('local SecureBoot = \'' .. file .. "' \n")
81+
82-
  buffer.write('local SecureBootKey = ' .. SecureBootKey .. " \n")
82+
83-
  buffer.write(dump)
83+
84-
  buffer.close()    
84+
    local chosen = '/boot/os'
85-
  print("Rewrote Startup")
85+
86-
  return 200
86+
87
    if k == "Continue" then
88
      exec(chosen)
89-
function checkSecureBoot(boot)
89+
90-
  local function protect()
90+
91-
    if SecureBootKey == nil then return true end
91+
92-
    local buffer = fs.open(boot, 'r')
92+
93-
    local dump = buffer.readAll()
93+
94-
    buffer.close()
94+
95
      print("WARNING: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING VERY NASTY, PLEASE REBOOT AND MAKE SURE THAT", string.upper(chosen), "HAS NOT BEEN TAMPERED WITH.")
96-
    local key = generateKey(dump)
96+
97-
    if key == '"' .. SecureBootKey .. '"' and boot == SecureBoot then return true end
97+
98-
    if key ~= '"' .. SecureBootKey .. '"' then term.setTextColour(colors.red) print("Secure Boot: Key Not Recognized, This is not the key for " .. SecureBoot) term.setTextColour(colors.black) return false end 
98+
99-
    if boot ~= SecureBoot then term.setTextColour(colors.red) print("Secure Boot: File not recognized") term.setTextColour(colors.black) return false end 
99+
100-
  end    
100+
101-
  o, e = pcall(protect)
101+
102-
  if not o then fuck(e, 'reboot') end
102+
103-
  return e
103+
104
function menu()
105
  term.clear()
106-
--sha256 algorithm adapted from http://www.computercraft.info/forums2/index.php?/topic/8169-sha-256-in-pure-lua/
106+
107-
local a=2^32;local b=a-1;local function c(d)local mt={}local e=setmetatable({},mt)function mt:__index(f)local g=d(f)e[f]=g;return g end;return e end;local function h(e,i)local function j(k,l)local m,o=0,1;while k~=0 and l~=0 do local p,q=k%i,l%i;m=m+e[p][q]*o;k=(k-p)/i;l=(l-q)/i;o=o*i end;m=m+(k+l)*o;return m end;return j end;local function r(e)local s=h(e,2^1)local t=c(function(k)return c(function(l)return s(k,l)end)end)return h(t,2^e.n or 1)end;local u=r({[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0},n=4})local function v(k,l,w,...)local x=nil;if l then k=k%a;l=l%a;x=u(k,l)if w then x=v(x,w,...)end;return x elseif k then return k%a else return 0 end end;local function y(k,l,w,...)local x;if l then k=k%a;l=l%a;x=(k+l-u(k,l))/2;if w then x=bit32_band(x,w,...)end;return x elseif k then return k%a else return b end end;local function z(A)return(-1-A)%a end;local function B(k,C)if C<0 then return lshift(k,-C)end;return math.floor(k%2^32/2^C)end;local function D(A,C)if C>31 or C<-31 then return 0 end;return B(A%a,C)end;local function lshift(k,C)if C<0 then return D(k,-C)end;return k*2^C%2^32 end;local function E(A,C)A=A%a;C=C%32;local F=y(A,2^C-1)return D(A,C)+lshift(F,32-C)end;local f={0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2}local function G(H)return string.gsub(H,".",function(w)return string.format("%02x",string.byte(w))end)end;local function I(J,n)local H=""for K=1,n do local L=J%256;H=string.char(L)..H;J=(J-L)/256 end;return H end;local function M(H,K)local n=0;for K=K,K+3 do n=n*256+string.byte(H,K)end;return n end;local function N(O,P)local Q=64-(P+9)%64;P=I(8*P,8)O=O.."\128"..string.rep("\0",Q)..P;assert(#O%64==0)return O end;local function R(S)S[1]=0x6a09e667;S[2]=0xbb67ae85;S[3]=0x3c6ef372;S[4]=0xa54ff53a;S[5]=0x510e527f;S[6]=0x9b05688c;S[7]=0x1f83d9ab;S[8]=0x5be0cd19;return S end;local function T(O,K,S)local U={}for V=1,16 do U[V]=M(O,K+(V-1)*4)end;for V=17,64 do local g=U[V-15]local W=v(E(g,7),E(g,18),D(g,3))g=U[V-2]U[V]=U[V-16]+W+U[V-7]+v(E(g,17),E(g,19),D(g,10))end;local k,l,w,X,Y,d,Z,_=S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[8]for K=1,64 do local W=v(E(k,2),E(k,13),E(k,22))local a0=v(y(k,l),y(k,w),y(l,w))local a1=W+a0;local a2=v(E(Y,6),E(Y,11),E(Y,25))local a3=v(y(Y,d),y(z(Y),Z))local a4=_+a2+a3+f[K]+U[K]_,Z,d,Y,X,w,l,k=Z,d,Y,X+a4,w,l,k,a4+a1 end;S[1]=y(S[1]+k)S[2]=y(S[2]+l)S[3]=y(S[3]+w)S[4]=y(S[4]+X)S[5]=y(S[5]+Y)S[6]=y(S[6]+d)S[7]=y(S[7]+Z)S[8]=y(S[8]+_)end;local function a5(O)O=N(O,#O)local S=R({})for K=1,#O,64 do T(O,K,S)end;return G(I(S[1],4)..I(S[2],4)..I(S[3],4)..I(S[4],4)..I(S[5],4)..I(S[6],4)..I(S[7],4)..I(S[8],4))end
107+
108
  term.setTextColor(colors.white)
109-
function ViewInsert()
109+
110-
	if fs.exists("/Views") ~= true then fs.makeDir("/Views") end
110+
111-
	if fs.exists("/Views/main.view") ~= true then
111+
112-
		local f = fs.open("/Views/main.view", 'w')
112+
113-
		local payload = [[{
113+
114-
    Children={
114+
115-
      {
115+
116-
        X=1,
116+
117-
		Width="100%",
117+
118-
        Y=2,
118+
119-
        Name="HelloLabel",
119+
120-
        Type="Label",
120+
121-
        Text="Bootloader Setup",
121+
122-
		Align="Center",	
122+
123-
      },
123+
124-
      {
124+
125-
        X=2,
125+
126-
        Y=4,
126+
127-
        Name="DebugMode",
127+
128-
        Type="Button",
128+
129-
        Text="Debug Mode: Disabled",
129+
130-
      },
130+
131-
      {
131+
132-
        X="1",
132+
133-
        Y="100%",
133+
134-
	Align = "Right",
134+
135-
        Name="Save",
135+
136-
        Type="Button",
136+
137-
        Text="Save",
137+
138-
      },
138+
139-
      {
139+
140-
      	X=2,
140+
141-
      	Y=6,
141+
142-
     	Width=22,
142+
143-
	Type="TextBox",
143+
144-
	Name="DPath",
144+
145-
      	Placeholder="Default Path",
145+
146-
      	Active=false
146+
147-
      },
147+
148-
      {
148+
149-
        X=2,
149+
150-
        Y=8,
150+
151-
        Width=22,
151+
152-
        Type="TextBox",
152+
153-
        Name="WaitT",
153+
154-
        Placeholder="Wait Time",
154+
155-
        Active=false,
155+
156-
      },
156+
157-
      {
157+
158-
        X="88%",
158+
159-
        Y="100%",
159+
160-
	Align = "Left",
160+
161-
        Name="Reboot",
161+
162-
        Type="Button",
162+
163-
        Text="Reboot",
163+
164-
      },
164+
165-
    },
165+
166-
    BackgroundColour='white'
166+
167-
} ]]
167+
168-
		f.write(payload)
168+
169-
		f.close()
169+
170-
	end
170+
171
172
    local b = boot()
173-
function startup()
173+
174-
  if fs.exists('startup') then
174+
175-
    local f = fs.open('startup', 'r')
175+
176-
    local ck = f.readLine()
176+
177-
    debug(ck)
177+
178-
    if ck ~= "--#--" then
178+
179-
      --to preserve existing startup, uncomment
179+
180-
      --fs.move('startup', 'startup.boot')
180+
181-
    end 
181+
182
--launch a shell
183-
  local f = fs.open(shell.getRunningProgram(), 'r')
183+
184-
  local ck = f.readLine()
184+
185
end
186-
  local f = fs.open(shell.getRunningProgram(), 'r')
186+
187-
  if ck == "--#--" then
187+
188-
    debug('sgrp = --#--')
188+