Advertisement
jesusthekiller

LuaOS Cheaty Startup

Jun 21st, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. -- LuaOS STARTUP IS _startup
  2.  
  3. --[[
  4.     Author of original code: NeverCast
  5. ]]--
  6.  
  7. --[[
  8.     Project info:
  9.    
  10.     Name: LuaOS
  11.     Creator: Jesusthekiller
  12.     Language: Lua (CC)
  13.     Website: None
  14.     License: GNU GPL
  15.         License file can be fount at www.jesusthekiller.com/license-gpl.html
  16.  
  17.     Version: 1.0
  18. ]]--
  19.  
  20. --[[
  21.     Changelog:
  22.       1.0:
  23.         Initial Release
  24.     1.1:
  25.         Cheaty distro release
  26. ]]--
  27.  
  28. --[[
  29.     LICENSE:
  30.    
  31.     LuaOS
  32.     Copyright (c) 2013 Jesusthekiller
  33.  
  34.     This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  35.  
  36.     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  37.  
  38.     See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  39. ]]--
  40.  
  41. if not fs.exists("uos") then
  42.     shell.run("pastebin", "get", "eFcg8T1E", "uos")
  43. end
  44.  
  45. if os.myEnv then
  46.     return
  47. end
  48.  
  49. local prevState = {}
  50.  
  51. table.size = function(tbl)
  52.     local count = 0
  53.     for _,__ in pairs(tbl) do
  54.         count = count + 1
  55.     end
  56.     return count
  57. end
  58.  
  59. local function getParentShell()
  60.   local at=0
  61.   while true do
  62.     at=at+1
  63.     local ok,env = pcall(function() return getfenv(at) end)
  64.     if not ok then break end
  65.     if table.size(env) == 1 then
  66.           local i,v = next(env) -- Grab first
  67.           if i == "shell" then
  68.             return v
  69.           end
  70.     end  
  71.   end
  72.   return nil
  73. end
  74.  
  75. local function recover()
  76.     -- Set flag
  77.     os.myEnv = true
  78.     -- Put back the trampled environment
  79.     os.startTimer = prevState.startTimer
  80.     os.shutdown = prevState.shutdown
  81.     os.pullEvent = prevState.pullEvent
  82.     --
  83.    
  84.     prevState = nil
  85.     -- start rednet
  86.     os.unloadAPI("rednet")
  87.     os.loadAPI("rednet")
  88.    
  89.     -- start uos shell
  90.     os.run({}, "uos")
  91. end
  92.  
  93. os.stage = {}
  94.  
  95. local function setStage(stage)
  96.     os.stage.currentStage = stage
  97. end
  98.  
  99. local function getStage()
  100.     return os.stage.currentStage
  101. end
  102.  
  103. local function _os_pullEvent(_filter)
  104.     _filter = _filter or ""
  105.     if _filter == "key" then
  106.         setStage("bioswait")
  107.         return "key", 0
  108.     elseif _filter == "timer" then
  109.         setStage("shutdown")
  110.         return "timer", 0
  111.     end
  112. end
  113.  
  114. local function _replSleep(dur)
  115.     local timer = prevState.startTimer( dur )
  116.     repeat
  117.         local sEvent, param = prevState.pullEvent( "timer" )
  118.     until param == timer
  119. end
  120.  
  121. local function _os_shutdown()
  122.     if getStage() == "shutdown" then
  123.         setStage("jstincse")
  124.     elseif getStage() == "bioswait" then
  125.         setStage("biosexit")
  126.     end
  127.     if getStage() == "biosexit" then
  128.         recover()
  129.     end
  130. end
  131.  
  132. local function _os_startTimer(seconds)
  133.     return 0
  134. end
  135.  
  136. local function inject()
  137.     prevState.startTimer = os.startTimer
  138.     prevState.shutdown = os.shutdown
  139.     prevState.pullEvent = os.pullEvent
  140.     os.shutdown = _os_shutdown
  141.     os.pullEvent = _os_pullEvent
  142.     os.startTimer = _os_startTimer
  143.     setStage("injected")
  144.     local shellImpl = getParentShell()
  145.     shellImpl.exit()
  146. end
  147.  
  148. inject()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement