From 80901d6d39fd05b923c48145147c47f0ad5252ca Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 14 Oct 2021 19:13:08 +0200 Subject: [PATCH] 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 --- pySim/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pySim/commands.py b/pySim/commands.py index eb8217d5..cd2b5b3a 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -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