From a4e68f0d752d81ee2aa2c0943326bd519ada13fc Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 14 Oct 2020 00:30:18 +0200 Subject: Also allows to send data through the socket Signed-off-by: Olivier Gayot --- solter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'solter.py') diff --git a/solter.py b/solter.py index 7c85833..10e9bb6 100755 --- a/solter.py +++ b/solter.py @@ -17,6 +17,8 @@ TCP_KEEPIDLE = 4 TCP_KEEPINTVL = 5 TCP_KEEPCNT = 6 +MSG_NOSIGNAL = 0x4000 + def _get_commands_enable_disable_keepalive(sockfd: int, enable: bool, **kwargs): """ Return GDB instructions to enable or disable keepalive on a given socket """ @@ -37,6 +39,13 @@ def _get_commands_change_tcp_option(sockfd: int, value: int, param: int, **kwarg "set $rsp += sizeof(int)", ) +def get_commands_send_data(sockfd: int, data: str, **kwargs): + """ Return GDB instructions to send raw data through a socket """ + if '"' in data or "\n" in data: + raise ValueError("Double-quotes and newlines are not supported") + + return [f'call (int)send({sockfd}, "{data}", {len(data)}, {MSG_NOSIGNAL})'] + def get_commands_enable_keepalive(**kwargs): """ Return GDB commands to enable keepalive on a given socket """ @@ -123,4 +132,11 @@ if __name__ == "__main__": subparser.add_argument("value", type=int) subparser.set_defaults(command=get_commands_change_keepalive_count) + # Send data + subparser = subparsers.add_parser("send-data", aliases=["send"], + help="Send data through the socket") + + subparser.add_argument("data", help="Raw data") + subparser.set_defaults(command=get_commands_send_data) + main(vars(parser.parse_args())) -- cgit v1.2.3