pickar

Untitled

Mar 31st, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.67 KB | None | 0 0
  1. local buttons = {
  2.     rootButton = {
  3.         text = "root",
  4.         toggle = false,
  5.         isToggled = false,
  6.         x=2,
  7.         y=7,
  8.         id=1,
  9.         action = root,
  10.     },
  11.     unrootButton = {
  12.         text = "unRoot",
  13.         toggle = false,
  14.         isToggled = false,
  15.         x=2,
  16.         y=9,
  17.         id=2,
  18.         action = unroot,
  19.     },
  20.     opt = {
  21.         text = "Options",
  22.         toggle = false,
  23.         isToggled = false,
  24.         x=2,
  25.         y=11,
  26.         id=3,
  27.         action = function() drawOptions() editVar("posS", 1) editVar("selScreen", 2) end,
  28.     },
  29.     exitBtn = {
  30.         text = "Exit",
  31.         toggle = false,
  32.         isToggled = false,
  33.         x=2,
  34.         y=13,
  35.         id=4,
  36.         action = function() if colors then term.setBackgroundColor(colors.black) end term.clear() term.setCursorPos(1, 1) error() end,
  37.     },
  38. }
  39. local options = {
  40.     icbBtn = {
  41.         text = "Install Custom Bootloader",
  42.         toggle = true,
  43.         isToggled = false,
  44.         x=2,
  45.         y=7,
  46.         id=1,
  47.         action = function() editVar("cBootloader", not cBootloader) end,
  48.     },
  49.     sbfBtn = {
  50.         text = "Select Bootloader File",
  51.         toggle = false,
  52.         isToggled = cBootloaderPathE,
  53.         x=2,
  54.         y=9,
  55.         id=2,
  56.         action = print(""),
  57.     },
  58.     icsBtn = {
  59.         text = "Install Custom SuperSU",
  60.         toggle = true,
  61.         isToggled = false,
  62.         x=2,
  63.         y=11,
  64.         id=3,
  65.         action = function() editVar("SU", not SU) end,
  66.     },
  67.     ssfBtn = {
  68.         text = "Select SuperSU File",
  69.         toggle = false,
  70.         isToggled = SUPathE,
  71.         x=2,
  72.         y=13,
  73.         id=4,
  74.         action = print(""),
  75.     },
  76.     lblBtn = {
  77.         text = "Lock Bootloader",
  78.         toggle = true,
  79.         isToggled = false,
  80.         x=2,
  81.         y=15,
  82.         id=5,
  83.         action = function() editVar("lBootloader", not lBootloader) end,
  84.     },
  85.     backBtn = {
  86.         text = "Back",
  87.         toggle = false,
  88.         isToggled = false,
  89.         x=2,
  90.         y=17,
  91.         id=6,
  92.         action = function() editVar("posS", 1) editVar("selScreen", 1) qRefresh() end,
  93.     },
  94. }
  95. local cBootloader = false
  96. local cBootloaderPath = ""
  97. local cBootloaderPathE = false
  98. local lBootloader = false
  99. local SU = false
  100. local SUPath = ""
  101. local SUPathE = false
  102. local debug = true
  103. local posS = 1
  104. local selScreen = 1
  105. local w,h = term.getSize()
  106. local rStatus = "Waiting..."
  107.  
  108. local function centerText(text)
  109.     local x,y = term.getSize()
  110.     local x2,y2 = term.getCursorPos()
  111.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  112.     write(text)
  113. end
  114.  
  115. function tablelength(T)
  116.     local count = 0
  117.     for _ in pairs(T) do count = count + 1 end
  118.     return count
  119. end
  120.  
  121. -- Change Functions
  122. function editVar(var, val)
  123.     if var == "cBootloader" then
  124.         cBootloader = val
  125.     elseif var == "cBootloaderPath" then
  126.         cBootloaderPath = val
  127.     elseif var == "lBootloader" then
  128.         lBootloader = val
  129.     elseif var == "SU" then
  130.         SU = val
  131.     elseif var == "SUPath" then
  132.         SUPath = val
  133.     elseif var == "posS" then
  134.         posS = val
  135.     elseif var == "selScreen" then
  136.         selScreen = val
  137.     elseif var == "rStatus" then
  138.         rStatus = val
  139.     elseif var == "cBootloaderPathE" then
  140.         cBootloaderPathE = val
  141.     elseif var == "SUPathE" then
  142.         SUPathE = val
  143.     end
  144. end
  145.  
  146. function button(x, y, toggled, action, toggle, text)
  147.     term.setCursorPos(x, y)
  148.     term.setTextColor(colors.black)
  149.     if toggled then
  150.         term.setBackgroundColor(colors.green)
  151.     else
  152.         term.setBackgroundColor(colors.red)
  153.     end
  154.     write(" "..text.." ")
  155. end
  156.  
  157. function drawButtons()
  158.     for i, v in pairs(buttons) do
  159.         button(v.x, v.y, v.isToggled, v.action, v.toggle, v.text)
  160.     end
  161. end
  162.  
  163. function buttonStd(x, y, toggled, action, toggle, text, isSel)
  164.     local aCode = "Disabled"
  165.     term.setCursorPos(x, y)
  166.     --term.setTextColor(colors.black)
  167.     if toggled and toggle then
  168.         --term.setBackgroundColor(colors.green)
  169.         aCode = "Enabled"
  170.     elseif not toggled and toggle then
  171.         --term.setBackgroundColor(colors.red)
  172.         aCode = "Disabled"
  173.     else
  174.         aCode = ""
  175.     end
  176.     if isSel then
  177.         write("> [ "..text.." ]".."  "..aCode)
  178.     else
  179.         write("[ "..text.." ]".."  "..aCode)
  180.     end
  181. end
  182.  
  183. function drawButtonsStd()
  184.     for i, v in pairs(buttons) do
  185.         if v.id == posS then
  186.             buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
  187.         else
  188.             buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
  189.         end
  190.     end
  191. end
  192.  
  193. function drawButtonsOpt()
  194.     for i, v in pairs(options) do
  195.         button(v.x, v.y, v.isToggled, v.action, v.toggle, v.text)
  196.     end
  197. end
  198.  
  199. function drawButtonsOptStd()
  200.     for i, v in pairs(options) do
  201.         if v.id == posS then
  202.             buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
  203.         else
  204.             buttonStd(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
  205.         end
  206.     end
  207. end
  208.  
  209. function buttonStdPocket(x, y, toggled, action, toggle, text, isSel)
  210.     local aCode = "|N"
  211.     term.setCursorPos(x, y)
  212.     --term.setTextColor(colors.black)
  213.     if toggled and toggle then
  214.         --term.setBackgroundColor(colors.green)
  215.         aCode = "|Y"
  216.     elseif not toggled and toggle then
  217.         --term.setBackgroundColor(colors.red)
  218.         aCode = "|N"
  219.     else
  220.         aCode = ""
  221.     end
  222.     if isSel then
  223.         write("> [ "..text..aCode.." ]")
  224.     else
  225.         write("[ "..text..aCode.." ]")
  226.     end
  227. end
  228.  
  229. function drawButtonsStdPocket()
  230.     for i, v in pairs(buttons) do
  231.         if v.id == posS then
  232.             buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
  233.         else
  234.             buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
  235.         end
  236.     end
  237. end
  238.  
  239. function drawButtonsOptStdPocket()
  240.     for i, v in pairs(options) do
  241.         if v.id == posS then
  242.             buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, true)
  243.         else
  244.             buttonStdPocket(v.x, v.y, v.isToggled, v.action, v.toggle, v.text, false)
  245.         end
  246.     end
  247. end
  248.  
  249.  
  250. function drawOptionsAdv()
  251.     term.setCursorPos(1, 1)
  252.     term.setBackgroundColor(colors.blue)
  253.     term.clear()
  254.     term.setCursorPos(1, 1)
  255.     term.setBackgroundColor(colors.black)
  256.     term.clearLine()
  257.     term.setCursorPos(1, 3)
  258.     term.setTextColor(colors.red)
  259.     term.setBackgroundColor(colors.blue)
  260.     centerText("Fire-Rooter by CCGrimHaxor")
  261.     term.setCursorPos(1, 5)
  262.     term.setBackgroundColor(colors.black)
  263.     term.clearLine()
  264.     term.setCursorPos(1, h - 2)
  265.     term.setBackgroundColor(colors.blue)
  266.     term.setTextColor(colors.white)
  267.     term.clearLine()
  268.     term.setCursorPos(2, 7)
  269.     drawButtonsOpt()
  270. end
  271.  
  272. function drawOptionsStd()
  273.     term.clear()
  274.     term.setCursorPos(1, 3)
  275.     centerText("Fire-Rooter by CCGrimHaxor")
  276.     term.setCursorPos(2, 7)
  277.     drawButtonsOptStd()
  278. end
  279.  
  280. function drawOptionsStdPocket()
  281.     term.clear()
  282.     term.setCursorPos(1, 3)
  283.     centerText("Fire-Rooter by CCGrimHaxor")
  284.     term.setCursorPos(2, 7)
  285.     drawButtonsOptStdPocket()
  286. end
  287.  
  288. function drawOptions()
  289.     if colors and not debug then
  290.         drawOptionsAdv()
  291.     else
  292.         if pocket then
  293.             drawOptionsStdPocket()
  294.         else
  295.             drawOptionsStd()
  296.         end
  297.     end
  298. end
  299.  
  300. function makeGUIAdv()
  301.     term.setCursorPos(1, 1)
  302.     term.setBackgroundColor(colors.blue)
  303.     term.clear()
  304.     term.setCursorPos(1, 1)
  305.     term.setBackgroundColor(colors.black)
  306.     term.clearLine()
  307.     term.setCursorPos(1, 3)
  308.     term.setTextColor(colors.red)
  309.     term.setBackgroundColor(colors.blue)
  310.     centerText("Fire-Rooter by CCGrimHaxor")
  311.     term.setCursorPos(1, 5)
  312.     term.setBackgroundColor(colors.black)
  313.     term.clearLine()
  314.     term.setCursorPos(1, h - 2)
  315.     term.setBackgroundColor(colors.blue)
  316.     term.setTextColor(colors.white)
  317.     term.clearLine()
  318.     term.setCursorPos(1, h - 2)
  319.     centerText("Status: "..rStatus)
  320.     term.setCursorPos(2, 7)
  321.     drawButtons()
  322. end
  323.  
  324. function makeGUIStd()
  325.     term.clear()
  326.     term.setCursorPos(1, 3)
  327.     centerText("Fire-Rooter by CCGrimHaxor")
  328.     term.setCursorPos(1, h - 2)
  329.     centerText("Status: "..rStatus)
  330.     term.setCursorPos(2, 7)
  331.     drawButtonsStd()
  332. end
  333.  
  334. function makeGUIStdPocket()
  335.     term.clear()
  336.     term.setCursorPos(1, 3)
  337.     centerText("Fire-Rooter by CCGrimHaxor")
  338.     term.setCursorPos(1, h - 2)
  339.     centerText("Status: "..rStatus)
  340.     term.setCursorPos(2, 7)
  341.     drawButtonsStdPocket()
  342. end
  343.  
  344. function qRefresh()
  345.     if colors and not debug then
  346.         makeGUIAdv()
  347.     else
  348.         if pocket then
  349.             makeGUIStdPocket()
  350.         else
  351.             makeGUIStd()
  352.         end
  353.     end
  354. end
  355.  
  356. function setStatus(text)
  357.     rStatus = text
  358.     if colors and not debug then
  359.         term.setCursorPos(1, h - 2)
  360.         term.setBackgroundColor(colors.blue)
  361.         term.setTextColor(colors.white)
  362.         term.clearLine()
  363.     end
  364.     term.setCursorPos(1, h - 2)
  365.     centerText("Status: "..text)
  366.     qRefresh()
  367. end
  368.  
  369. function checkFile(file)
  370.     if fs.exists(file) then
  371.         if not fs.exists("/FRBackup") then
  372.             fs.makeDir("/FRBackup")
  373.         else
  374.             fs.delete("/FRBackup")
  375.             fs.makeDir("/FRBackup")
  376.         end
  377.         fs.move(file, "/FRBackup/"..file)
  378.     end
  379. end
  380.  
  381. function downloadFile(code, name)
  382.     checkFile(name)
  383.     local response = http.get("http://api.turtlescripts.com/getFileRAW/"..code)
  384.     if response then
  385.         local text = response.readAll()
  386.         response.close()
  387.  
  388.         local file = fs.open(name, "w")
  389.         file.write(text)
  390.         file.close()
  391.     else
  392.         error("Error: HTTP not enabled or invalid file!")
  393.     end
  394. end
  395.  
  396. function eventHandler()
  397.     while true do
  398.         local e = {os.pullEvent()}
  399.         if e[1] == "mouse_click" then
  400.             if not debug then
  401.                 if colors then
  402.                     if e[2] == 1 then
  403.                         if selScreen == 1 then
  404.                             for i,v in pairs(buttons) do
  405.                                 if e[3] >= v.x and e[3] <= (v.x + string.len(v.text) + 2) and e[4] == v.y then
  406.                                     v.action()
  407.                                     if v.toggle then
  408.                                         v.isToggled = not v.isToggled
  409.                                         makeGUIAdv()
  410.                                     end
  411.                                 end
  412.                             end
  413.                         elseif selScreen == 2 then
  414.                             for i,v in pairs(options) do
  415.                                 if e[3] >= v.x and e[3] <= (v.x + string.len(v.text) + 2) and e[4] == v.y then
  416.                                     v.action()
  417.                                     if v.toggle then
  418.                                         v.isToggled = not v.isToggled
  419.                                         drawOptions()
  420.                                     end
  421.                                 end
  422.                             end
  423.                         end
  424.                     end
  425.                 end
  426.             end
  427.         elseif e[1] == "key" and (debug or not colors) then
  428.             if selScreen == 1 then
  429.                 if e[2] == 208 then
  430.                     if posS ~= tablelength(buttons) then
  431.                         posS = posS + 1
  432.                     else
  433.                         posS = 1
  434.                     end
  435.                 elseif e[2] == 200 then
  436.                     if posS ~= 1 then
  437.                         posS = posS - 1
  438.                     else
  439.                         posS = tablelength(buttons)
  440.                     end
  441.                 elseif e[2] == 28 then
  442.                     for i,v in pairs(buttons) do
  443.                         if v.id == posS then
  444.                             v.action()
  445.                             if v.toggle then
  446.                                 v.isToggled = not v.isToggled
  447.                             end
  448.                         end
  449.                     end
  450.                 end
  451.                 if pocket then
  452.                     makeGUIStdPocket()
  453.                 else
  454.                     makeGUIStd()
  455.                 end
  456.             elseif selScreen == 2 then
  457.                 if e[2] == 208 then
  458.                     if posS ~= tablelength(options) then
  459.                         posS = posS + 1
  460.                     else
  461.                         posS = 1
  462.                     end
  463.                 elseif e[2] == 200 then
  464.                     if posS ~= 1 then
  465.                         posS = posS - 1
  466.                     else
  467.                         posS = tablelength(options)
  468.                     end
  469.                 elseif e[2] == 28 then
  470.                     for i,v in pairs(options) do
  471.                         if v.id == posS then
  472.                             v.action()
  473.                             if v.toggle then
  474.                                 v.isToggled = not v.isToggled
  475.                             end
  476.                         end
  477.                     end
  478.                 end
  479.                 if pocket then
  480.                     drawOptions()
  481.                 else
  482.                     drawOptions()
  483.                 end
  484.             end
  485.         elseif e[1] == "terminate" then
  486.             term.clear()
  487.             term.setCursorPos(1, 1)
  488.             return
  489.         end
  490.     end
  491. end
  492.  
  493. function root()
  494.     if type(hasRoot) == "function" or hasRoot ~= nil then
  495.         error("You are already rooted!")
  496.     end
  497.     setStatus("Adding files...")
  498.     fs.makeDir("/.SANDBOX") -- Somewhere to put sandboxed items
  499.     fs.makeDir("/.SANDBOX/ROM") -- Sandboxed ROM(deletes on restart)
  500.     fs.makeDir("/.SANDBOX/SANDBOX") -- Sandboxed Files(delets on restart)
  501.     fs.makeDir("/.SANDBOX/FILES") -- Basic Files
  502.     fs.makeDir("/.ROOT") -- Somewhere to put all the important items
  503.     fs.makeDir("/.ROOT/ROM") -- This contains all the files to allow the root to exist
  504.     fs.makeDir("/.ROM") -- This is where your modified rom files will go
  505.     sleep(1)
  506.     setStatus("Downloading...")
  507.     downloadFile("gjdiep", "/startup")
  508.     downloadFile("gjdieo", "/bios.lua")
  509.     downloadFile("gjdieq", "/.ROOT/ROM/shell")
  510.     downloadFile("gjdier", "/.ROOT/ROM/startup")
  511.     downloadFile("gjdif5", "/.ROOT/Injector")
  512.     if cBootloader then
  513.         downloadFile("gjdieu", "/.ROOT/BootLoader")
  514.     end
  515.     if SU then
  516.         downloadFile("gjdiev", "/.ROOT/SU")
  517.     end
  518.     sleep(2)
  519.     setStatus("Rooting...")
  520.     local rootFile = fs.open("/.ROOT/rooted")
  521.     rootFile.writeLine("Device Rooted!")
  522.     rootFile.close()
  523.     sleep(2)
  524.     os.reboot()
  525. end
  526.  
  527. function backupSandbox()
  528.     if fs.exists("/.SANDBOX/FILES") then
  529.         for i,v in pairs(fs.list("/.SANDBOX/FILES")) do
  530.             checkFile(v)
  531.             fs.copy("/.SANDBOX/FILES/"..v, v)
  532.         end
  533.     end
  534. end
  535.  
  536. function unroot()
  537.     if type(hasRoot) ~= "function" or hasRoot == nil then
  538.         error("You are not rooted!")
  539.     end
  540.     setStatus("Requesting Root...")
  541.     root.getRoot()
  542.     sleep(1)
  543.     setStatus("UnRooting...")
  544.     fs.delete("/.ROOT/rooted")
  545.     sleep(1)
  546.     setStatus("Backing up files...")
  547.     backupSandbox()
  548.     sleep(1)
  549.     setStatus("Removing files...")
  550.     fs.delete("/.SANDBOX")
  551.     fs.delete("/.ROOT")
  552.     fs.delete("/.ROM")
  553.     fs.delete("/startup")
  554.     fs.delete("/bios.lua")
  555.     for i,v in pairs(fs.list("/FRBackup")) do
  556.         fs.copy("/FRBackup/"..v, v)
  557.     end
  558.     sleep(2)
  559.     setStatus("UnRooted!")
  560.     sleep(1)
  561.     os.reboot()
  562. end
  563.  
  564. if colors and not debug then
  565.     makeGUIAdv()
  566. else
  567.     if pocket then
  568.         makeGUIStdPocket()
  569.     else
  570.         makeGUIStd()
  571.     end
  572. end
  573. eventHandler()
Add Comment
Please, Sign In to add comment