Advertisement
kovakovi2000

CC: External Shell

Feb 12th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. os.loadAPI("rnc2")
  2. os.loadAPI("ldb2")
  3.  
  4. local prg = shell.getRunningProgram()
  5. local label = os.getComputerLabel()
  6. if label == nil then
  7.     return
  8. end
  9.  
  10. function string.starts(String,Start)
  11.     return string.sub(String,1,string.len(Start))==Start
  12. end
  13.  
  14. local function isempty(s)
  15.   return s == nil or s == ''
  16. end
  17.  
  18. function string.split (inputstr, sep)
  19.         if sep == nil then
  20.                 sep = "%s"
  21.         end
  22.         local t={}
  23.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  24.                 table.insert(t, str)
  25.         end
  26.         return t
  27. end
  28.  
  29. rnc2.setTimeOut(prg, 99)
  30. rnc2.setPort(prg, 600)
  31. rnc2.setIdenty(prg, 100)
  32.  
  33. while true do
  34.     rnc2.setIdenty(100)
  35.     local res = rnc2.resive(prg)
  36.     if not isempty(res) and string.starts(res, label .. " ") then
  37.         res = string.sub(res,string.len(label) + 2,string.len(res))
  38.         print("resived message:\"" .. res .. "\"")
  39.         rnc2.setIdenty(prg, 101)
  40.         rnc2.send(prg,label .. "> Command resived!")
  41.         rnc2.setIdenty(prg, 100)
  42.        
  43.         if not shell.run(res) then
  44.             local temp = string.split(res, " ")
  45.             tempsize = table.getn(temp)
  46.             local inside = ""
  47.             for i = 1, tempsize do
  48.                 inside = inside .. '"' .. temp[i] ..'"'
  49.                 if i ~= tempsize then
  50.                     inside = inside .. ","
  51.                 end
  52.             end
  53.             func = loadstring("shell.run(".. inside ..")")
  54.             setfenv(func, getfenv())
  55.             func()
  56.         end
  57.     end
  58. end
  59. print("magic")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement