aboutsummaryrefslogtreecommitdiffstats
path: root/pySim
diff options
context:
space:
mode:
authorSebastian Viviani <guilly@gmail.com>2020-04-17 16:42:09 +0100
committerguilly@gmail.com <guilly@gmail.com>2020-06-03 14:36:42 +0000
commit0e9f93fdd613ec53b9123335bc6f1ed71b8a06b6 (patch)
tree17124582512ae64a0f7d846aee1a26d03d693346 /pySim
parent0dc8f6921707d1d59cbfe2c5841ff479632c5edc (diff)
commands.py: fix read_binary for lengths > 256
fixed commit with commented changes Change-Id: Ie9c61caa1412606254b44a3a24f26ad44950e73a
Diffstat (limited to 'pySim')
-rw-r--r--pySim/commands.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/pySim/commands.py b/pySim/commands.py
index e077289..7288b19 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -119,8 +119,17 @@ class SimCardCommands(object):
return (None, None)
if length is None:
length = self.__len(r) - offset
- pdu = self.cla_byte + 'b0%04x%02x' % (offset, (min(256, length) & 0xff))
- return self._tp.send_apdu(pdu)
+ total_data = ''
+ while offset < length:
+ chunk_len = min(255, length-offset)
+ pdu = self.cla_byte + 'b0%04x%02x' % (offset, chunk_len)
+ data,sw = self._tp.send_apdu(pdu)
+ if sw == '9000':
+ total_data += data
+ offset += chunk_len
+ else:
+ raise ValueError('Failed to read (offset %d)' % (offset))
+ return total_data, sw
def update_binary(self, ef, data, offset=0, verify=False):
self.select_file(ef)