diff options
Diffstat (limited to 'solter.py')
-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())) |