mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
[wip] injection: change argument type to bytes
This commit is contained in:
parent
1858564b91
commit
a19e95e6c9
@ -190,15 +190,14 @@ class Proxyserver:
|
|||||||
self._connections[event.flow.client_conn.peername].server_event(event)
|
self._connections[event.flow.client_conn.peername].server_event(event)
|
||||||
|
|
||||||
@command.command("inject.websocket")
|
@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:
|
if not isinstance(flow, http.HTTPFlow) or not flow.websocket:
|
||||||
ctx.log.warn("Cannot inject WebSocket messages into non-WebSocket flows.")
|
ctx.log.warn("Cannot inject WebSocket messages into non-WebSocket flows.")
|
||||||
|
|
||||||
message_bytes = strutils.escaped_str_to_bytes(message)
|
|
||||||
msg = websocket.WebSocketMessage(
|
msg = websocket.WebSocketMessage(
|
||||||
Opcode.TEXT if is_text else Opcode.BINARY,
|
Opcode.TEXT if is_text else Opcode.BINARY,
|
||||||
not to_client,
|
not to_client,
|
||||||
message_bytes
|
message
|
||||||
)
|
)
|
||||||
event = WebSocketMessageInjected(flow, msg)
|
event = WebSocketMessageInjected(flow, msg)
|
||||||
try:
|
try:
|
||||||
@ -207,12 +206,11 @@ class Proxyserver:
|
|||||||
ctx.log.warn(str(e))
|
ctx.log.warn(str(e))
|
||||||
|
|
||||||
@command.command("inject.tcp")
|
@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):
|
if not isinstance(flow, tcp.TCPFlow):
|
||||||
ctx.log.warn("Cannot inject TCP messages into non-TCP flows.")
|
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))
|
||||||
event = TcpMessageInjected(flow, tcp.TCPMessage(not to_client, message_bytes))
|
|
||||||
try:
|
try:
|
||||||
self.inject_event(event)
|
self.inject_event(event)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
@ -73,7 +73,7 @@ class Command:
|
|||||||
for name, parameter in self.signature.parameters.items():
|
for name, parameter in self.signature.parameters.items():
|
||||||
t = parameter.annotation
|
t = parameter.annotation
|
||||||
if not mitmproxy.types.CommandTypes.get(parameter.annotation, None):
|
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):
|
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}.")
|
raise exceptions.CommandError(f"Return type has an unknown type ({self.return_type}) in {func}.")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user