|
|
|
@ -16,7 +16,7 @@
|
|
|
|
|
|
|
|
|
|
import click
|
|
|
|
|
|
|
|
|
|
from .. import debuglink
|
|
|
|
|
from .. import debuglink, mapping, messages, protobuf
|
|
|
|
|
from ..messages import DebugLinkShowTextStyle as S
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -71,3 +71,48 @@ def show_text(connect, icon, color, header, body):
|
|
|
|
|
return debuglink.show_text(
|
|
|
|
|
connect(), header, body_text, icon=icon, icon_color=color
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
|
@click.argument("message_name_or_type")
|
|
|
|
|
@click.argument("hex_data")
|
|
|
|
|
@click.pass_obj
|
|
|
|
|
def send_bytes(connect, message_name_or_type, hex_data):
|
|
|
|
|
"""Send raw bytes to Trezor.
|
|
|
|
|
|
|
|
|
|
Message type and message data must be specified separately, due to how message
|
|
|
|
|
chunking works on the transport level. Message length is calculated and sent
|
|
|
|
|
automatically, and it is currently impossible to explicitly specify invalid length.
|
|
|
|
|
|
|
|
|
|
MESSAGE_NAME_OR_TYPE can either be a number, or a name from the MessageType enum,
|
|
|
|
|
in which case the value of that enum is used.
|
|
|
|
|
"""
|
|
|
|
|
if message_name_or_type.isdigit():
|
|
|
|
|
message_type = int(message_name_or_type)
|
|
|
|
|
else:
|
|
|
|
|
message_type = getattr(messages.MessageType, message_name_or_type)
|
|
|
|
|
|
|
|
|
|
if not isinstance(message_type, int):
|
|
|
|
|
raise click.ClickException("Invalid message type.")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
message_data = bytes.fromhex(hex_data)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise click.ClickException("Invalid hex data.") from e
|
|
|
|
|
|
|
|
|
|
transport = connect(return_transport=True)
|
|
|
|
|
transport.begin_session()
|
|
|
|
|
transport.write(message_type, message_data)
|
|
|
|
|
|
|
|
|
|
response_type, response_data = transport.read()
|
|
|
|
|
transport.end_session()
|
|
|
|
|
|
|
|
|
|
click.echo("Response type: {}".format(response_type))
|
|
|
|
|
click.echo("Response data: {}".format(response_data.hex()))
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
msg = mapping.decode(response_type, response_data)
|
|
|
|
|
click.echo("Parsed message:")
|
|
|
|
|
click.echo(protobuf.format_message(msg))
|
|
|
|
|
except Exception as e:
|
|
|
|
|
click.echo("Could not parse response: {}".format(e))
|
|
|
|
|