<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/26204">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pySim-shell: guess number of records when not specified<br><br>The select response of an UICC will always return the number of records<br>of a file. However, older SIM will not include the number of records in<br>the select response. In those cases, simply guess the number of records<br>by reading until the first empty record is hit. This works because<br>unused records are still initialized with 'fffff....', so an empty record<br>will clearly mark the end of the file.<br><br>Related: OS#5274<br>Change-Id: Ib480797d881b9ec607ec6a86b73d452449f8cf87<br>---<br>M pySim-shell.py<br>1 file changed, 17 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/04/26204/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim-shell.py b/pySim-shell.py</span><br><span>index 72ed213..db72d2d 100755</span><br><span>--- a/pySim-shell.py</span><br><span>+++ b/pySim-shell.py</span><br><span>@@ -516,10 +516,23 @@</span><br><span>                              result = self._cmd.rs.read_binary()</span><br><span>                          self._cmd.poutput("update_binary " + str(result[0]))</span><br><span>                       elif structure == 'cyclic' or structure == 'linear_fixed':</span><br><span style="color: hsl(0, 100%, 40%);">-                              num_of_rec = fd['num_of_rec']</span><br><span style="color: hsl(0, 100%, 40%);">-                           for r in range(1, num_of_rec + 1):</span><br><span style="color: hsl(0, 100%, 40%);">-                                      result = self._cmd.rs.read_record(r)</span><br><span style="color: hsl(0, 100%, 40%);">-                                    self._cmd.poutput("update_record %d %s" % (r, str(result[0])))</span><br><span style="color: hsl(120, 100%, 40%);">+                              # Use number of records specified in select response</span><br><span style="color: hsl(120, 100%, 40%);">+                          if 'num_of_rec' in fd:</span><br><span style="color: hsl(120, 100%, 40%);">+                                        num_of_rec = fd['num_of_rec']</span><br><span style="color: hsl(120, 100%, 40%);">+                                 for r in range(1, num_of_rec + 1):</span><br><span style="color: hsl(120, 100%, 40%);">+                                            result = self._cmd.rs.read_record(r)</span><br><span style="color: hsl(120, 100%, 40%);">+                                          self._cmd.poutput("update_record %d %s" % (r, str(result[0])))</span><br><span style="color: hsl(120, 100%, 40%);">+                              # When the select response does not return the number of records, read until we hit the</span><br><span style="color: hsl(120, 100%, 40%);">+                               # first empty record.</span><br><span style="color: hsl(120, 100%, 40%);">+                         else:</span><br><span style="color: hsl(120, 100%, 40%);">+                                 r = 1</span><br><span style="color: hsl(120, 100%, 40%);">+                                 while True:</span><br><span style="color: hsl(120, 100%, 40%);">+                                           result = self._cmd.rs.read_record(r)</span><br><span style="color: hsl(120, 100%, 40%);">+                                          if len(result[0]) > 0:</span><br><span style="color: hsl(120, 100%, 40%);">+                                                     self._cmd.poutput("update_record %d %s" % (r, str(result[0])))</span><br><span style="color: hsl(120, 100%, 40%);">+                                                      r = r + 1</span><br><span style="color: hsl(120, 100%, 40%);">+                                             else:</span><br><span style="color: hsl(120, 100%, 40%);">+                                                 break</span><br><span>                        elif structure == 'ber_tlv':</span><br><span>                                 tags = self._cmd.rs.retrieve_tags()</span><br><span>                          for t in tags:</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/26204">change 26204</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/26204"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ib480797d881b9ec607ec6a86b73d452449f8cf87 </div>
<div style="display:none"> Gerrit-Change-Number: 26204 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>