From 7f9f64ac2a239659b99a52809669e300bd20f75b Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Mon, 11 May 2020 21:28:52 +0200 Subject: cards: reset uninitalized EF.AD The contents of EF.AD me be uninitalized (all bytes set to 0xff). If this is the case reset all bytes of the file to 0x00 and continue the update of EF.AD with this value. Change-Id: I57cf53e0c540469f11b6d85bd3daf3f9e14c237e --- pySim/cards.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pySim/cards.py b/pySim/cards.py index f469cae..1c0add0 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -148,8 +148,13 @@ class Card(object): if mnclen > 3: raise RuntimeError('unable to calculate proper mnclen') - data = self._scc.read_binary(EF['AD'], length=None, offset=0) - content = data[0][0:6] + "%02X" % mnclen + data, sw = self._scc.read_binary(EF['AD'], length=None, offset=0) + + # Reset contents to EF.AD in case the file is uninintalized + if data.lower() == "ffffffff": + data = "00000000" + + content = data[0:6] + "%02X" % mnclen data, sw = self._scc.update_binary(EF['AD'], content) return sw -- cgit v1.2.3