Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {
- rootButton = {
- text = "root",
- toggle = false,
- isToggled = false,
- x=2,
- y=7,
- id=1,
- action = root,
- },
- unrootButton = {
- text = "unRoot",
- toggle = false,
- isToggled = false,
- x=2,
- y=9,
- id=2,
- action = unroot,
- },
- opt = {
- text = "Options",
- toggle = false,
- isToggled = false,
- x=2,
- y=11,
- id=3,
- action = function() drawOptions() editVar("posS", 1) editVar("selScreen", 2) end,
- },
- exitBtn = {
- text = "Exit",
- toggle = false,
- isToggled = false,
- x=2,
- y=13,
- id=4,
- action = function() if colors then term.setBackgroundColor(colors.black) end term.clear() term.setCursorPos(1, 1) error() end,
- },
- }
- local options = {
- icbBtn = {
- text = "Install Custom Bootloader",
- toggle = true,
- isToggled = false,
- x=2,
- y=7,
- id=1,
- action = function() editVar("cBootloader", not cBootloader) end,
- },
- sbfBtn = {
- text = "Select Bootloader File",
- toggle = false,
- isToggled = cBootloaderPathE,
- x=2,
- y=9,
- id=2,
- action = print(""),
- },
- icsBtn = {
- text = "Install Custom SuperSU",
- toggle = true,
- isToggled = false,
- x=2,
- y=11,
- id=3,
- action = function() editVar("SU", not SU) end,
- },
- ssfBtn = {
- text = "Select SuperSU File",
- toggle = false,
- isToggled = SUPathE,
- x=2,
- y=13,
- id=4,
- action = print(""),
- },
- lblBtn = {
- text = "Lock Bootloader",
- toggle = true,
- isToggled = false,
- x=2,
- y=15,
- id=5,
- action = function() editVar("lBootloader", not lBootloader) end,
- },
- backBtn = {
- text = "Back",
- toggle = false,
- isToggled = false,
- x=2,
- y=17,
- id=6,
- action = function() editVar("posS", 1) editVar("selScreen", 1) qRefresh() end,
- },
- }
- local cBootloader = false
- local cBootloaderPath = ""
- local cBootloaderPathE = false
- local lBootloader = false
- local SU = false
- local SUPath = ""
- local SUPathE = false
- local debug = true
- local posS = 1
- local selScreen = 1
- local w,h = term.getSize()
- local rStatus = "Waiting..."
- local function centerText(text)
- local x,y = term.getSize()
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text)
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- -- Change Functions
- function editVar(var, val)
- if var == "cBootloader" then
- cBootloader = val
- elseif var == "cBootloaderPath" then
- cBootloaderPath = val
- elseif var == "lBootloader" then
- lBootloader = val
- elseif var == "SU" then
- SU = val
- elseif var == "SUPath" then
- SUPath = val
- elseif var == "posS" then
- posS = val
- elseif var == "selScreen" then
- selScreen = val
- elseif var == "rStatus" then
- rStatus = val
- elseif var == "cBootloaderPathE" then
- cBootloaderPathE = val
- elseif var == "SUPathE" then
- SUPathE = val
- end
- end
- function button(x, y, toggled, action, toggle, text)
- term.setCursorPos(x, y)
- term.setTextColor(colors.black)
- if toggled then
- term.setBackgroundColor(colors.green)
- else
- term.setBackgroundColor(colors.red)
- end
- write(" "..text.." ")
- end
- function drawButtons()
- for i, v in pairs(buttons) do
- button(v.x, v.y, v.isToggled, v.action, v.toggle, v.text)
- end
- end
- function buttonStd(x, y, toggled, action, toggle, text, isSel)
- local aCode = "Disabled"
- term.setCursorPos(x, y)
- --term.setTextColor(colors.black)
- if toggled and toggle then
- --term.setBackgroundColor(colors.green)
- aCode = "Enabled"
- elseif not toggled and toggle then
- --term.setBackgroundColor(colors.red)
- aCode = "Disabled"
- else
- aCode = ""
- end
- if isSel then
- write("> [ "..text.." ]".." "..aCode)
- else
- write("[ "..text.." ]".." "..aCode)
- end
- end
- function drawButtonsStd()
- for i, v in pairs(buttons) do
- if v.id == posS then
- buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
- else
- buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
- end
- end
- end
- function drawButtonsOpt()
- for i, v in pairs(options) do
- button(v.x, v.y, v.isToggled, v.action, v.toggle, v.text)
- end
- end
- function drawButtonsOptStd()
- for i, v in pairs(options) do
- if v.id == posS then
- buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
- else
- buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
- end
- end
- end
- function buttonStdPocket(x, y, toggled, action, toggle, text, isSel)
- local aCode = "|N"
- term.setCursorPos(x, y)
- --term.setTextColor(colors.black)
- if toggled and toggle then
- --term.setBackgroundColor(colors.green)
- aCode = "|Y"
- elseif not toggled and toggle then
- --term.setBackgroundColor(colors.red)
- aCode = "|N"
- else
- aCode = ""
- end
- if isSel then
- write("> [ "..text..aCode.." ]")
- else
- write("[ "..text..aCode.." ]")
- end
- end
- function drawButtonsStdPocket()
- for i, v in pairs(buttons) do
- if v.id == posS then
- buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
- else
- buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
- end
- end
- end
- function drawButtonsOptStdPocket()
- for i, v in pairs(options) do
- if v.id == posS then
- buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
- else
- buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
- end
- end
- end
- function drawOptionsAdv()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.setCursorPos(1, 3)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.blue)
- centerText("Fire-Rooter by CCGrimHaxor")
- term.setCursorPos(1, 5)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.setCursorPos(1, h - 2)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clearLine()
- term.setCursorPos(2, 7)
- drawButtonsOpt()
- end
- function drawOptionsStd()
- term.clear()
- term.setCursorPos(1, 3)
- centerText("Fire-Rooter by CCGrimHaxor")
- term.setCursorPos(2, 7)
- drawButtonsOptStd()
- end
- function drawOptionsStdPocket()
- term.clear()
- term.setCursorPos(1, 3)
- centerText("Fire-Rooter by CCGrimHaxor")
- term.setCursorPos(2, 7)
- drawButtonsOptStdPocket()
- end
- function drawOptions()
- if colors and not debug then
- drawOptionsAdv()
- else
- if pocket then
- drawOptionsStdPocket()
- else
- drawOptionsStd()
- end
- end
- end
- function makeGUIAdv()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.setCursorPos(1, 3)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.blue)
- centerText("Fire-Rooter by CCGrimHaxor")
- term.setCursorPos(1, 5)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.setCursorPos(1, h - 2)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clearLine()
- term.setCursorPos(1, h - 2)
- centerText("Status: "..rStatus)
- term.setCursorPos(2, 7)
- drawButtons()
- end
- function makeGUIStd()
- term.clear()
- term.setCursorPos(1, 3)
- centerText("Fire-Rooter by CCGrimHaxor")
- term.setCursorPos(1, h - 2)
- centerText("Status: "..rStatus)
- term.setCursorPos(2, 7)
- drawButtonsStd()
- end
- function makeGUIStdPocket()
- term.clear()
- term.setCursorPos(1, 3)
- centerText("Fire-Rooter by CCGrimHaxor")
- term.setCursorPos(1, h - 2)
- centerText("Status: "..rStatus)
- term.setCursorPos(2, 7)
- drawButtonsStdPocket()
- end
- function qRefresh()
- if colors and not debug then
- makeGUIAdv()
- else
- if pocket then
- makeGUIStdPocket()
- else
- makeGUIStd()
- end
- end
- end
- function setStatus(text)
- rStatus = text
- if colors and not debug then
- term.setCursorPos(1, h - 2)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clearLine()
- end
- term.setCursorPos(1, h - 2)
- centerText("Status: "..text)
- qRefresh()
- end
- function checkFile(file)
- if fs.exists(file) then
- if not fs.exists("/FRBackup") then
- fs.makeDir("/FRBackup")
- else
- fs.delete("/FRBackup")
- fs.makeDir("/FRBackup")
- end
- fs.move(file, "/FRBackup/"..file)
- end
- end
- function downloadFile(code, name)
- checkFile(name)
- local response = http.get("http://api.turtlescripts.com/getFileRAW/"..code)
- if response then
- local text = response.readAll()
- response.close()
- local file = fs.open(name, "w")
- file.write(text)
- file.close()
- else
- error("Error: HTTP not enabled or invalid file!")
- end
- end
- function eventHandler()
- while true do
- local e = {os.pullEvent()}
- if e[1] == "mouse_click" then
- if not debug then
- if colors then
- if e[2] == 1 then
- if selScreen == 1 then
- for i,v in pairs(buttons) do
- if e[3] >= v.x and e[3] <= (v.x + string.len(v.text) + 2) and e[4] == v.y then
- v.action()
- if v.toggle then
- v.isToggled = not v.isToggled
- makeGUIAdv()
- end
- end
- end
- elseif selScreen == 2 then
- for i,v in pairs(options) do
- if e[3] >= v.x and e[3] <= (v.x + string.len(v.text) + 2) and e[4] == v.y then
- v.action()
- if v.toggle then
- v.isToggled = not v.isToggled
- drawOptions()
- end
- end
- end
- end
- end
- end
- end
- elseif e[1] == "key" and (debug or not colors) then
- if selScreen == 1 then
- if e[2] == 208 then
- if posS ~= tablelength(buttons) then
- posS = posS + 1
- else
- posS = 1
- end
- elseif e[2] == 200 then
- if posS ~= 1 then
- posS = posS - 1
- else
- posS = tablelength(buttons)
- end
- elseif e[2] == 28 then
- for i,v in pairs(buttons) do
- if v.id == posS then
- v.action()
- if v.toggle then
- v.isToggled = not v.isToggled
- end
- end
- end
- end
- if pocket then
- makeGUIStdPocket()
- else
- makeGUIStd()
- end
- elseif selScreen == 2 then
- if e[2] == 208 then
- if posS ~= tablelength(options) then
- posS = posS + 1
- else
- posS = 1
- end
- elseif e[2] == 200 then
- if posS ~= 1 then
- posS = posS - 1
- else
- posS = tablelength(options)
- end
- elseif e[2] == 28 then
- for i,v in pairs(options) do
- if v.id == posS then
- v.action()
- if v.toggle then
- v.isToggled = not v.isToggled
- end
- end
- end
- end
- if pocket then
- drawOptions()
- else
- drawOptions()
- end
- end
- elseif e[1] == "terminate" then
- term.clear()
- term.setCursorPos(1, 1)
- return
- end
- end
- end
- function root()
- if type(hasRoot) == "function" or hasRoot ~= nil then
- error("You are already rooted!")
- end
- setStatus("Adding files...")
- fs.makeDir("/.SANDBOX") -- Somewhere to put sandboxed items
- fs.makeDir("/.SANDBOX/ROM") -- Sandboxed ROM(deletes on restart)
- fs.makeDir("/.SANDBOX/SANDBOX") -- Sandboxed Files(delets on restart)
- fs.makeDir("/.SANDBOX/FILES") -- Basic Files
- fs.makeDir("/.ROOT") -- Somewhere to put all the important items
- fs.makeDir("/.ROOT/ROM") -- This contains all the files to allow the root to exist
- fs.makeDir("/.ROM") -- This is where your modified rom files will go
- sleep(1)
- setStatus("Downloading...")
- downloadFile("gjdiep", "/startup")
- downloadFile("gjdieo", "/bios.lua")
- downloadFile("gjdieq", "/.ROOT/ROM/shell")
- downloadFile("gjdier", "/.ROOT/ROM/startup")
- downloadFile("gjdif5", "/.ROOT/Injector")
- if cBootloader then
- downloadFile("gjdieu", "/.ROOT/BootLoader")
- end
- if SU then
- downloadFile("gjdiev", "/.ROOT/SU")
- end
- sleep(2)
- setStatus("Rooting...")
- local rootFile = fs.open("/.ROOT/rooted")
- rootFile.writeLine("Device Rooted!")
- rootFile.close()
- sleep(2)
- os.reboot()
- end
- function backupSandbox()
- if fs.exists("/.SANDBOX/FILES") then
- for i,v in pairs(fs.list("/.SANDBOX/FILES")) do
- checkFile(v)
- fs.copy("/.SANDBOX/FILES/"..v, v)
- end
- end
- end
- function unroot()
- if type(hasRoot) ~= "function" or hasRoot == nil then
- error("You are not rooted!")
- end
- setStatus("Requesting Root...")
- root.getRoot()
- sleep(1)
- setStatus("UnRooting...")
- fs.delete("/.ROOT/rooted")
- sleep(1)
- setStatus("Backing up files...")
- backupSandbox()
- sleep(1)
- setStatus("Removing files...")
- fs.delete("/.SANDBOX")
- fs.delete("/.ROOT")
- fs.delete("/.ROM")
- fs.delete("/startup")
- fs.delete("/bios.lua")
- for i,v in pairs(fs.list("/FRBackup")) do
- fs.copy("/FRBackup/"..v, v)
- end
- sleep(2)
- setStatus("UnRooted!")
- sleep(1)
- os.reboot()
- end
- if colors and not debug then
- makeGUIAdv()
- else
- if pocket then
- makeGUIStdPocket()
- else
- makeGUIStd()
- end
- end
- eventHandler()
Add Comment
Please, Sign In to add comment