commands: fix update_binary() with non-zero offset

In Icc240d5c8c04198640eb118565ea99f10ba27466 we introduced support for
writing files > 255 bytes by splitting the write into multiple chunks.

However, at the same time, that commit broke support for writing data at
non-zero offsets.  Unfortunately, this is used extensively within
pySim-prog e.g. for writing K + OP/OPc data to sysmoISIM-SJA2 and sysmoUSIM-SJS1
cards.

This commit fixes the related problem.

Change-Id: Ie1aeaab29701946233ed73db3331039690d695da
Fixes: Icc240d5c8c04198640eb118565ea99f10ba27466
Closes: OS#5254
This commit is contained in:
Harald Welte 2021-10-14 19:13:08 +02:00
parent 4c1dca04a5
commit 80901d6d39
1 changed files with 2 additions and 2 deletions

View File

@ -172,11 +172,11 @@ class SimCardCommands(object):
self.select_path(ef)
total_data = ''
total_sw = "9000"
chunk_offset = offset
chunk_offset = 0
while chunk_offset < data_length:
chunk_len = min(255, data_length - chunk_offset)
# chunk_offset is bytes, but data slicing is hex chars, so we need to multiply by 2
pdu = self.cla_byte + 'd6%04x%02x' % (chunk_offset, chunk_len) + data[chunk_offset*2 : (chunk_offset+chunk_len)*2]
pdu = self.cla_byte + 'd6%04x%02x' % (offset + chunk_offset, chunk_len) + data[chunk_offset*2 : (chunk_offset+chunk_len)*2]
chunk_data, chunk_sw = self._tp.send_apdu(pdu)
if chunk_sw == total_sw:
total_data += chunk_data