From cbb8c02d25668b561c5c74f3b59271ad8c6fc4c4 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 16 Dec 2022 16:57:16 +0100 Subject: [PATCH] pySim-prog: make dry-run more realistic The process_card function has a dry-run mode where one can test parameters without actually writing to the card. However, the dry-run feature also does not perform read operations and connects to the card reader at a different point in time. Lets be more accurate here and perform all operations a normal programming cycle would perform but without calling the card.program() method. Change-Id: I3653bada1ad26bcf75109a935105273ee9d1525c --- pySim-prog.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/pySim-prog.py b/pySim-prog.py index 1ea1425a..dbf1148e 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -718,22 +718,21 @@ def save_batch(opts): def process_card(opts, first, ch): + # Connect transport + ch.get(first) + + # Get card + card = card_detect(opts.type, scc) + if card is None: + print("No card detected!") + return -1 + + # Probe only + if opts.probe: + return 0 + + # Erase if requested (not in dry run mode!) if opts.dry_run is False: - # Connect transport - ch.get(first) - - if opts.dry_run is False: - # Get card - card = card_detect(opts.type, scc) - if card is None: - print("No card detected!") - return -1 - - # Probe only - if opts.probe: - return 0 - - # Erase if requested if opts.erase: print("Formatting ...") card.erase() @@ -746,15 +745,9 @@ def process_card(opts, first, ch): imsi = None iccid = None if opts.read_iccid: - if opts.dry_run: - # Connect transport - ch.get(False) (res, _) = scc.read_binary(['3f00', '2fe2'], length=10) iccid = dec_iccid(res) elif opts.read_imsi: - if opts.dry_run: - # Connect transport - ch.get(False) (res, _) = scc.read_binary(EF['IMSI']) imsi = swap_nibbles(res)[3:] else: