From c32e939c99e8ba916fd0303efe7227f0e868281a Mon Sep 17 00:00:00 2001 From: Alexis Grojean Date: Thu, 12 Oct 2023 17:52:17 +0200 Subject: [PATCH] Add 'dump' option to ledgerctl CLI delete command. --- ledgerwallet/ledgerctl.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ledgerwallet/ledgerctl.py b/ledgerwallet/ledgerctl.py index 0478ec5..c1c9c5e 100644 --- a/ledgerwallet/ledgerctl.py +++ b/ledgerwallet/ledgerctl.py @@ -88,7 +88,7 @@ def get_private_key() -> bytes: return private_key -def get_file_device(target_id, output_file): +def get_file_device(output_file, target_id=0x33000004): try: return LedgerClient(FileDevice(target_id, out=output_file)) except NoLedgerDeviceException as exception: @@ -199,7 +199,7 @@ def install_app(get_client, manifest: AppManifest, force, dump): click.echo("Unable to open file {} for dump.".format(dump)) sys.exit(1) click.echo("Dumping APDU installation file to {}".format(dump)) - client = get_file_device(app_manifest.target_id, dump_file) + client = get_file_device(dump_file, app_manifest.target_id) else: client = get_client() if force: @@ -235,14 +235,31 @@ def install_remote_app(get_client, app_path, key_path, url, key): help="Delete using application hash instead of application name", is_flag=True, ) +@click.option( + "-d", + "--dump", + help="Dump APDU delete command file.", + is_flag=False, + flag_value="out_delete.apdu", +) @click.pass_obj -def delete_app(get_client, app, by_hash): +def delete_app(get_client, app, by_hash, dump): + client = get_client() if by_hash: data = bytes.fromhex(app) else: data = app + + if dump: + try: + dump_file = open(dump, "w") + except OSError: + click.echo("Unable to open file {} for dump.".format(dump)) + sys.exit(1) + click.echo("Dumping APDU delete command file to {}".format(dump)) + client = get_file_device(dump_file) try: - get_client().delete_app(data) + client.delete_app(data) except CommException as e: if e.sw == 0x6985: click.echo("Operation has been canceled by the user.")