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

View File

@@ -718,11 +718,9 @@ def save_batch(opts):
def process_card(opts, first, ch): def process_card(opts, first, ch):
if opts.dry_run is False:
# Connect transport # Connect transport
ch.get(first) ch.get(first)
if opts.dry_run is False:
# Get card # Get card
card = card_detect(opts.type, scc) card = card_detect(opts.type, scc)
if card is None: if card is None:
@@ -733,7 +731,8 @@ def process_card(opts, first, ch):
if opts.probe: if opts.probe:
return 0 return 0
# Erase if requested # Erase if requested (not in dry run mode!)
if opts.dry_run is False:
if opts.erase: if opts.erase:
print("Formatting ...") print("Formatting ...")
card.erase() card.erase()
@@ -746,15 +745,9 @@ def process_card(opts, first, ch):
imsi = None imsi = None
iccid = None iccid = None
if opts.read_iccid: if opts.read_iccid:
if opts.dry_run:
# Connect transport
ch.get(False)
(res, _) = scc.read_binary(['3f00', '2fe2'], length=10) (res, _) = scc.read_binary(['3f00', '2fe2'], length=10)
iccid = dec_iccid(res) iccid = dec_iccid(res)
elif opts.read_imsi: elif opts.read_imsi:
if opts.dry_run:
# Connect transport
ch.get(False)
(res, _) = scc.read_binary(EF['IMSI']) (res, _) = scc.read_binary(EF['IMSI'])
imsi = swap_nibbles(res)[3:] imsi = swap_nibbles(res)[3:]
else: else: