From afb8d3f925f7ac3aac4e839f2855c48c9890760a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 11 Feb 2022 16:03:06 +0100 Subject: [PATCH] pySim-shell: introduce 'apdu' command for sending raw APDU to card This can be useful when playing around with cards, for example sending commands for which pySim-shell doesn't yet have proper support. Change-Id: Ib504431d26ed2b6f71f77a143ff0a7fb4f5ea02e --- pySim-shell.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pySim-shell.py b/pySim-shell.py index 3b17a75f..a82d56f9 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -673,6 +673,17 @@ class PySimCommands(CommandSet): else: raise ValueError("error: cannot authenticate, no adm-pin!") + apdu_cmd_parser = argparse.ArgumentParser() + apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string') + + @cmd2.with_argparser(apdu_cmd_parser) + def do_apdu(self, opts): + """Send a raw APDU to the card, and print SW + Response. + DANGEROUS: pySim-shell will not know any card state changes, and + not continue to work as expected if you e.g. select a different file.""" + data, sw = self._cmd.card._scc._tp.send_apdu(opts.APDU) + self._cmd.poutput("SW: %s %s, RESP: %s" % (sw, self._cmd.rs.interpret_sw(sw), data)) + @with_default_category('ISO7816 Commands') class Iso7816Commands(CommandSet):