diff --git a/handlers.py b/handlers.py index 0f6a6c4..6a9d620 100644 --- a/handlers.py +++ b/handlers.py @@ -22,6 +22,7 @@ import socket import queue import enum import abc +import sys from typing import Any, Optional from construct import Container @@ -123,6 +124,33 @@ class DbgMuxConnHandler(DbgMuxFrameHandler): ''' Called on connection termination ''' +class DbgMuxConnInteractiveTerminal(DbgMuxConnHandler): + def __init__(self, *args, **kw): + self.attached: bool = False + super().__init__(*args) + + def attach(self): + self.attached = True + while True: + try: + line = input() + if self.conn_state == ConnState.Established: + self.send_data(bytes(line, 'ascii')) + except (KeyboardInterrupt, EOFError) as e: + break + self.attached = False + + def _handle_data(self, data: bytes) -> None: + if self.attached: + sys.stdout.write(data.decode('ascii')) + + def _handle_establish(self) -> None: + pass + + def _handle_terminate(self) -> None: + pass + + class DbgMuxConnUdpBridge(DbgMuxConnHandler): DGRAM_MAX_LEN: int = 1024