diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-10-14 00:30:18 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-10-14 00:30:18 +0200 |
commit | a4e68f0d752d81ee2aa2c0943326bd519ada13fc (patch) | |
tree | 36492812f22dda8a345481b30313ecdadc6c7f41 | |
parent | a246d3771cf930b8ed4b91f67a6a1639b7ce8827 (diff) |
Also allows to send data through the socket
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rwxr-xr-x | solter.py | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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())) |