Bug #6385 » 76e18254499aff27dea07c93e14eb7f74426240f.patch
pySim/utils.py | ||
---|---|---|
422 | 422 | |
423 | 423 |
def dec_imsi(ef: Hexstr) -> Optional[str]: |
424 | 424 |
"""Converts an EF value to the IMSI string representation""" |
425 |
if len(ef) < 4: |
|
426 |
return None |
|
427 |
l = int(ef[0:2], 16) * 2 # Length of the IMSI string |
|
428 |
l = l - 1 # Encoded length byte includes oe nibble |
|
429 |
swapped = swap_nibbles(ef[2:]).rstrip('f') |
|
430 |
if len(swapped) < 1: |
|
431 |
return None |
|
432 |
oe = (int(swapped[0]) >> 3) & 1 # Odd (1) / Even (0) |
|
433 |
if not oe: |
|
434 |
# if even, only half of last byte was used |
|
435 |
l = l-1 |
|
436 |
if l != len(swapped) - 1: |
|
425 |
try: |
|
426 |
if len(ef) < 4: |
|
427 |
return None |
|
428 |
l = int(ef[0:2], 16) * 2 # Length of the IMSI string |
|
429 |
l = l - 1 # Encoded length byte includes oe nibble |
|
430 |
swapped = swap_nibbles(ef[2:]).rstrip('f') |
|
431 |
if len(swapped) < 1: |
|
432 |
return None |
|
433 |
oe = (int(swapped[0]) >> 3) & 1 # Odd (1) / Even (0) |
|
434 |
if not oe: |
|
435 |
# if even, only half of last byte was used |
|
436 |
l = l-1 |
|
437 |
if l != len(swapped) - 1: |
|
438 |
return None |
|
439 |
imsi = swapped[1:] |
|
440 |
return imsi |
|
441 |
except ValueError as err: |
|
442 |
# print("IMSI is present but malformed") |
|
437 | 443 |
return None |
438 |
imsi = swapped[1:] |
|
439 |
return imsi |
|
440 | 444 | |
441 | 445 | |
442 | 446 |
def dec_iccid(ef: Hexstr) -> str: |