aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2021-11-10 17:36:26 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2021-11-19 13:21:32 +0100
commit825b56411585dc2b5cb27bd647e5f10431456166 (patch)
treef80b63f3dfd3a00a377ec4965c0d0df3c7f1da80
parentf1fc619b2dc7d45e4986d3508f0e3bed3a9768ee (diff)
pySim-shell: export command: guess number of records when not specified
The select response of an UICC will always return the number of records of a file. However, older SIM will not include the number of records in the select response. In those cases, simply guess the number of records by reading until the first invalid record is hit. Change-Id: Ib480797d881b9ec607ec6a86b73d452449f8cf87 Related: OS#5274
-rwxr-xr-xpySim-shell.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index 0519ec4..8e8a1a6 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -517,10 +517,28 @@ class PySimCommands(CommandSet):
result = self._cmd.rs.read_binary()
self._cmd.poutput("update_binary " + str(result[0]))
elif structure == 'cyclic' or structure == 'linear_fixed':
- num_of_rec = fd['num_of_rec']
- for r in range(1, num_of_rec + 1):
- result = self._cmd.rs.read_record(r)
- self._cmd.poutput("update_record %d %s" % (r, str(result[0])))
+ # Use number of records specified in select response
+ if 'num_of_rec' in fd:
+ num_of_rec = fd['num_of_rec']
+ for r in range(1, num_of_rec + 1):
+ result = self._cmd.rs.read_record(r)
+ self._cmd.poutput("update_record %d %s" % (r, str(result[0])))
+ # When the select response does not return the number of records, read until we hit the
+ # first record that cannot be read.
+ else:
+ r = 1
+ while True:
+ try:
+ result = self._cmd.rs.read_record(r)
+ except SwMatchError as e:
+ # We are past the last valid record - stop
+ if e.sw_actual == "9402":
+ break
+ # Some other problem occurred
+ else:
+ raise e
+ self._cmd.poutput("update_record %d %s" % (r, str(result[0])))
+ r = r + 1
elif structure == 'ber_tlv':
tags = self._cmd.rs.retrieve_tags()
for t in tags: