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
This commit is contained in:
Philipp Maier 2022-12-16 16:57:16 +01:00
parent 0a8d9f05b8
commit cbb8c02d25
1 changed files with 14 additions and 21 deletions

View File

@ -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: