From 7d9c6583efe8c6f5cb9f49718b85bef332915b7d Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 6 Aug 2024 20:01:24 +0200 Subject: [PATCH] pySim.cards: Make file_exists() check for activated/deactivated The Card.file_exists() method is only called by legacy pySim-{read,prog} when it wants to determine if it can read/write a file. Therefore it actually doesn't only want to know if the file exists, but also if it's not deactivated. Change-Id: I73bd1ab3780e475c96a10cd5dbdd45b829c67335 Closes: OS#6530 --- pySim/cards.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pySim/cards.py b/pySim/cards.py index 802c9213..65aef982 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -23,7 +23,7 @@ # from typing import Optional, Tuple -from pySim.ts_102_221 import EF_DIR +from pySim.ts_102_221 import EF_DIR, CardProfileUICC from pySim.ts_51_011 import DF_GSM from pySim.utils import * @@ -54,10 +54,17 @@ class CardBase: print("warning: erasing is not supported for specified card type!") def file_exists(self, fid: Path) -> bool: + """Determine if the file exists (and is not deactivated).""" res_arr = self._scc.try_select_path(fid) for res in res_arr: if res[1] != '9000': return False + try: + d = CardProfileUICC.decode_select_response(res_arr[-1][0]) + if d.get('life_cycle_status_integer', 'operational_activated') != 'operational_activated': + return False + except: + pass return True def read_aids(self) -> List[Hexstr]: