From a19e95e6c9c5f0e5f0387f57c3cff49840bb08aa Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 22 Jun 2021 17:46:59 +0200 Subject: [PATCH] [wip] injection: change argument type to bytes --- mitmproxy/addons/proxyserver.py | 10 ++++------ mitmproxy/command.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mitmproxy/addons/proxyserver.py b/mitmproxy/addons/proxyserver.py index f7a60918a..a58e19bcc 100644 --- a/mitmproxy/addons/proxyserver.py +++ b/mitmproxy/addons/proxyserver.py @@ -190,15 +190,14 @@ class Proxyserver: self._connections[event.flow.client_conn.peername].server_event(event) @command.command("inject.websocket") - def inject_websocket(self, flow: Flow, to_client: bool, message: str, is_text: bool = True): + def inject_websocket(self, flow: Flow, to_client: bool, message: bytes, is_text: bool = True): if not isinstance(flow, http.HTTPFlow) or not flow.websocket: ctx.log.warn("Cannot inject WebSocket messages into non-WebSocket flows.") - message_bytes = strutils.escaped_str_to_bytes(message) msg = websocket.WebSocketMessage( Opcode.TEXT if is_text else Opcode.BINARY, not to_client, - message_bytes + message ) event = WebSocketMessageInjected(flow, msg) try: @@ -207,12 +206,11 @@ class Proxyserver: ctx.log.warn(str(e)) @command.command("inject.tcp") - def inject_tcp(self, flow: Flow, to_client: bool, message: str): + def inject_tcp(self, flow: Flow, to_client: bool, message: bytes): if not isinstance(flow, tcp.TCPFlow): ctx.log.warn("Cannot inject TCP messages into non-TCP flows.") - message_bytes = strutils.escaped_str_to_bytes(message) - event = TcpMessageInjected(flow, tcp.TCPMessage(not to_client, message_bytes)) + event = TcpMessageInjected(flow, tcp.TCPMessage(not to_client, message)) try: self.inject_event(event) except ValueError as e: diff --git a/mitmproxy/command.py b/mitmproxy/command.py index 23aed219d..c47c7b740 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -73,7 +73,7 @@ class Command: for name, parameter in self.signature.parameters.items(): t = parameter.annotation if not mitmproxy.types.CommandTypes.get(parameter.annotation, None): - raise exceptions.CommandError(f"Argument {name} has an unknown type ({_empty_as_none(t)}) in {func}.") + raise exceptions.CommandError(f"Argument {name} has an unknown type {t} in {func}.") if self.return_type and not mitmproxy.types.CommandTypes.get(self.return_type, None): raise exceptions.CommandError(f"Return type has an unknown type ({self.return_type}) in {func}.")