aboutsummaryrefslogtreecommitdiffstats
path: root/pySim/commands.py
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2022-06-02 14:45:41 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2022-06-03 10:26:58 +0200
commit40ea4a4a1cf7612d71e3a0364305ed9d517caa80 (patch)
tree1a8008f3cee9fdd7dd0723a14e7ca640fe0d972b /pySim/commands.py
parentf16ac6acf8f08c2ac1be06312e225ec7f6262bdf (diff)
commands: add ".." notation to expand hexstrings
When updating files and records there are sometimes huge portions that are just 0xff. Mostly this is at the end of a file or record that is not completely used. Lets add a notation to tell PySim-shell how to fill those sections. Change-Id: Iedd7887bf7d706878f4a3beca8dbea456404610b
Diffstat (limited to 'pySim/commands.py')
-rw-r--r--pySim/commands.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/pySim/commands.py b/pySim/commands.py
index a959851..7b50677 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -23,7 +23,7 @@
from construct import *
from pySim.construct import LV
-from pySim.utils import rpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize
+from pySim.utils import rpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize, expand_hex
from pySim.exceptions import SwMatchError
@@ -190,6 +190,10 @@ class SimCardCommands(object):
offset : byte offset in file from which to start writing
verify : Whether or not to verify data after write
"""
+
+ file_len = self.binary_size(ef)
+ data = expand_hex(data, file_len)
+
data_length = len(data) // 2
# Save write cycles by reading+comparing before write
@@ -255,16 +259,17 @@ class SimCardCommands(object):
verify : verify data by re-reading the record
conserve : read record and compare it with data, skip write on match
"""
+
res = self.select_path(ef)
+ rec_length = self.__record_len(res)
+ data = expand_hex(data, rec_length)
if force_len:
# enforce the record length by the actual length of the given data input
rec_length = len(data) // 2
else:
- # determine the record length from the select response of the file and pad
- # the input data with 0xFF if necessary. In cases where the input data
- # exceed we throw an exception.
- rec_length = self.__record_len(res)
+ # make sure the input data is padded to the record length using 0xFF.
+ # In cases where the input data exceed we throw an exception.
if (len(data) // 2 > rec_length):
raise ValueError('Data length exceeds record length (expected max %d, got %d)' % (
rec_length, len(data) // 2))