Advertisement
Chickenbreadlp

Syscrypt_Setup

May 16th, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.09 KB | None | 0 0
  1. --[[
  2.     MIT License
  3.  
  4.     Copyright © 2016 Chickenbreadlp
  5.  
  6.     Permission is hereby granted, free of charge, to any person obtaining a copy
  7.     of this software and associated documentation files (the "Software"), to deal
  8.     in the Software without restriction, including without limitation the rights
  9.     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.     copies of the Software, and to permit persons to whom the Software is
  11.     furnished to do so, subject to the following conditions:
  12.  
  13.     The above copyright notice and this permission notice shall be included in all
  14.     copies or substantial portions of the Software.
  15.  
  16.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.     SOFTWARE.
  23. ]]
  24.  
  25. local function get(branch, file)
  26.     local response = http.get(
  27.         "https://raw.githubusercontent.com/Chickenbreadlp/ReboOSt/"..branch.."/"..textutils.urlEncode( file )
  28.     )
  29.  
  30.     if response then
  31.         local sResponse = response.readAll()
  32.         response.close()
  33.         return sResponse
  34.     else
  35.     end
  36. end
  37. local function download(branch, filename, sFile)
  38.     local sPath = shell.resolve( sFile )
  39.     if fs.exists( sPath ) then
  40.         return
  41.     end
  42.  
  43.     -- GET the contents from pastebin
  44.     local res = get(branch, filename)
  45.     if res then
  46.         local file = fs.open( sPath, "w" )
  47.         file.write( res )
  48.         file.close()
  49.     end
  50. end
  51.  
  52. local x = 1
  53. local y = {}
  54. local z = {}
  55. local syscrypt_pass = ""
  56.  
  57. local function FirstCrypt(dir)
  58.  if x == 1 then
  59.   x = 0
  60.   math.randomseed(tonumber(syscrypt_pass, 36))
  61.   for i=1, 16 do
  62.    y[i] = math.random(0, 0xFF)
  63.    z[i] = math.random(0, 0xFF)
  64.   end
  65.   math.randomseed(math.random())
  66.   local file = fs.open("/.syscrypt/reference_key", "w")
  67.   file.writeLine('syscrypt_key = "'..hash.sha256(syscrypt_pass)..'"')
  68.   file.close()
  69.  end
  70.  if dir == nil then dir = "" end
  71.  local ListFiles = fs.list(dir)
  72.  for _, file in ipairs(ListFiles) do
  73.   if fs.isDir(dir..file) then
  74.    if file ~= "rom" and file ~= ".syscrypt" then
  75.     if fs.exists("/ReboOSt") and login == true then
  76.      if file ~= ".SyscryptSetup" then
  77.       FirstCrypt(dir.."/"..file.."/")
  78.      end
  79.     else
  80.      FirstCrypt(dir.."/"..file.."/")
  81.     end
  82.    end
  83.   else
  84.    if file == "startup" then
  85.    else
  86.     local prog = fs.open(dir.."/"..file, "rb")
  87.     local progData = {}
  88.     local progbyte = prog.read()
  89.     repeat
  90.      table.insert(progData, progbyte)
  91.      progbyte = prog.read()
  92.     until progbyte == nil
  93.     prog.close()
  94.     progData = ccaes.encrypt_bytestream(progData, y, z)
  95.     local prog = fs.open(dir.."/"..file, "wb")
  96.     for i=1, #progData do
  97.      prog.write(progData[i])
  98.     end
  99.     prog.close()
  100.     sleep(0.01)
  101.    end
  102.   end
  103.  end
  104. end
  105.  
  106. if fs.exists("/.syscrypt") then
  107.  error("Syscrypt is already installed on this pc")
  108. else
  109.  term.setTextColor(colors.yellow)
  110.  print("Please enter your password")
  111.  term.setTextColor(1)
  112.  write("Password: ")
  113.  syscrypt_pass = read("*")
  114.  
  115.  if syscrypt_pass == "" then
  116.   error("No Password provided")
  117.  else
  118.  
  119.   if fs.exists("/ReboOSt") and login == true then
  120.    if fs.exists("/User/.SyscryptSetup/..meta") then
  121.     fs.delete("/User/.SyscryptSetup/..meta")
  122.    end
  123.    fs.makeDir("/User/.SyscryptSetup")
  124.    fs.copy("/User/"..UserName.."/..meta", "/User/.SyscryptSetup/..meta")
  125.    UserName = ".SyscryptSetup"
  126.   end
  127.  
  128.   fs.makeDir("/.syscrypt")
  129.   shell.run("pastebin", "get", "rCYDnCxn", "/.syscrypt/ccaes")
  130.   download("release", "ReboOSt/APIs/encryption", "/.syscrypt/hash")
  131.   os.loadAPI("/.syscrypt/ccaes")
  132.   os.loadAPI("/.syscrypt/hash")
  133.   syscrypt_pass = hash.sha256(syscrypt_pass)
  134.   FirstCrypt()
  135.   if fs.exists("/startup") then
  136.    fs.move("/startup", "/.syscrypt/boot")
  137.   end
  138.   shell.run("pastebin", "get", "s3PazEbG", "startup")
  139.   os.reboot()
  140.  end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement