Fix many python3 compatibility problems
It's 2020, and I'm actually rather shocked to find that this code was not python3 compatbile a long time ago...
This commit is contained in:
parent
77d68b84b3
commit
76c74c93d5
|
@ -217,9 +217,9 @@ def decode_BCD(data=[]):
|
||||||
# 2nd digit (4 MSB), can be padding (e.g. 0xF)
|
# 2nd digit (4 MSB), can be padding (e.g. 0xF)
|
||||||
if (B>>4) < 10: string += str(B>>4)
|
if (B>>4) < 10: string += str(B>>4)
|
||||||
if len(string) <= 0:
|
if len(string) <= 0:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def compute_luhn(digit_str=''):
|
def compute_luhn(digit_str=''):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -67,7 +67,7 @@ class Common():
|
||||||
opts, args = getopt.getopt(argv, COMMON_GETOPTS + getopts,
|
opts, args = getopt.getopt(argv, COMMON_GETOPTS + getopts,
|
||||||
COMMON_GETOPTS_LONG + getopts_long)
|
COMMON_GETOPTS_LONG + getopts_long)
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print " * Error: Invalid commandline options"
|
print(" * Error: Invalid commandline options")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# Set flags for common options
|
# Set flags for common options
|
||||||
|
@ -114,8 +114,8 @@ class Common():
|
||||||
|
|
||||||
# Check for ADM1 key
|
# Check for ADM1 key
|
||||||
if not self.adm1:
|
if not self.adm1:
|
||||||
print " * Error: adm1 parameter missing -- exiting..."
|
print(" * Error: adm1 parameter missing -- exiting...")
|
||||||
print ""
|
print("")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Set flags for specific options
|
# Set flags for specific options
|
||||||
|
@ -213,4 +213,4 @@ class Common():
|
||||||
if self.show_aid:
|
if self.show_aid:
|
||||||
self.sim.show_aid()
|
self.sim.show_aid()
|
||||||
|
|
||||||
print "Done!"
|
print("Done!")
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Card_res_apdu():
|
||||||
# convert Benoit Michau style result to sysmocom style result
|
# convert Benoit Michau style result to sysmocom style result
|
||||||
def from_mich(self, mich):
|
def from_mich(self, mich):
|
||||||
self.apdu = mich[3]
|
self.apdu = mich[3]
|
||||||
self.sw = [ mich[2][0], mich[2][1] ]
|
self.sw = [ mich[2][0], mich[2][1] ]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
dump = ""
|
dump = ""
|
||||||
|
@ -204,4 +204,4 @@ class Simcard():
|
||||||
def update_record(self, data, rec_no = 0):
|
def update_record(self, data, rec_no = 0):
|
||||||
res = Card_res_apdu()
|
res = Card_res_apdu()
|
||||||
res.from_mich(self.card.UPDATE_RECORD(rec_no, GSM_SIM_INS_UPDATE_RECORD_ABS, data))
|
res.from_mich(self.card.UPDATE_RECORD(rec_no, GSM_SIM_INS_UPDATE_RECORD_ABS, data))
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -347,7 +347,7 @@ class SYSMO_ISIMSJA2_FILE_EF_USIM_SQN:
|
||||||
# we automatically set the value to the correct length
|
# we automatically set the value to the correct length
|
||||||
ind_size_bits_calculated = int(math.log((len(content) - 14) / 6, 2))
|
ind_size_bits_calculated = int(math.log((len(content) - 14) / 6, 2))
|
||||||
if ind_size_bits_calculated != self.ind_size_bits:
|
if ind_size_bits_calculated != self.ind_size_bits:
|
||||||
print " Warning: SQN Parameter ind_size_bits is set to " + str(self.ind_size_bits) + ", resetting it to " + str(ind_size_bits_calculated) + "!"
|
print(" Warning: SQN Parameter ind_size_bits is set to " + str(self.ind_size_bits) + ", resetting it to " + str(ind_size_bits_calculated) + "!")
|
||||||
self.ind_size_bits = ind_size_bits_calculated
|
self.ind_size_bits = ind_size_bits_calculated
|
||||||
|
|
||||||
self.reset() #ensure freshness data is correctly reset
|
self.reset() #ensure freshness data is correctly reset
|
||||||
|
@ -452,11 +452,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
# Try card model #1
|
# Try card model #1
|
||||||
try:
|
try:
|
||||||
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9"
|
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9"
|
||||||
print "Trying to find card with ATR: " + atr
|
print("Trying to find card with ATR: " + atr)
|
||||||
Sysmo_usim.__init__(self, atr)
|
Sysmo_usim.__init__(self, atr)
|
||||||
card_detected = True
|
card_detected = True
|
||||||
except:
|
except:
|
||||||
print " * Card not detected!"
|
print(" * Card not detected!")
|
||||||
|
|
||||||
if card_detected == True:
|
if card_detected == True:
|
||||||
return
|
return
|
||||||
|
@ -465,11 +465,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
# Try card model #2
|
# Try card model #2
|
||||||
try:
|
try:
|
||||||
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 31 33 02 51 B2"
|
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 31 33 02 51 B2"
|
||||||
print "Trying to find card with ATR: " + atr
|
print("Trying to find card with ATR: " + atr)
|
||||||
Sysmo_usim.__init__(self, atr)
|
Sysmo_usim.__init__(self, atr)
|
||||||
card_detected = True
|
card_detected = True
|
||||||
except:
|
except:
|
||||||
print " * Card not detected!"
|
print(" * Card not detected!")
|
||||||
|
|
||||||
if card_detected == True:
|
if card_detected == True:
|
||||||
return
|
return
|
||||||
|
@ -477,11 +477,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
# Try card model #3 (sysmoTSIM)
|
# Try card model #3 (sysmoTSIM)
|
||||||
try:
|
try:
|
||||||
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 52 75 31 04 51 D5"
|
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 52 75 31 04 51 D5"
|
||||||
print "Trying to find card with ATR: " + atr
|
print("Trying to find card with ATR: " + atr)
|
||||||
Sysmo_usim.__init__(self, atr)
|
Sysmo_usim.__init__(self, atr)
|
||||||
card_detected = True
|
card_detected = True
|
||||||
except:
|
except:
|
||||||
print " * Card not detected!"
|
print(" * Card not detected!")
|
||||||
|
|
||||||
if card_detected == True:
|
if card_detected == True:
|
||||||
return
|
return
|
||||||
|
@ -522,7 +522,7 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
|
|
||||||
print(" * New Milenage Parameters for (EF.MILENAGE_CFG):")
|
print(" * New Milenage Parameters for (EF.MILENAGE_CFG):")
|
||||||
ef_milenage_cfg = SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(params_swapped)
|
ef_milenage_cfg = SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(params_swapped)
|
||||||
print str(ef_milenage_cfg)
|
print(str(ef_milenage_cfg))
|
||||||
|
|
||||||
print(" * Programming...")
|
print(" * Programming...")
|
||||||
# Note: The milenage configuration file in ADF_USIM and
|
# Note: The milenage configuration file in ADF_USIM and
|
||||||
|
@ -573,42 +573,42 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
# DF_SYSTEM/EF_SIM_AUTH_KEY:
|
# DF_SYSTEM/EF_SIM_AUTH_KEY:
|
||||||
self.__select_ef_sim_auth_key()
|
self.__select_ef_sim_auth_key()
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * DF_SYSTEM/EF_SIM_AUTH_KEY:"
|
print(" * DF_SYSTEM/EF_SIM_AUTH_KEY:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_SIM_AUTH_KEY(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_SIM_AUTH_KEY(res.apdu))
|
||||||
|
|
||||||
# ADF_USIM/EF_USIM_AUTH_KEY_2G:
|
# ADF_USIM/EF_USIM_AUTH_KEY_2G:
|
||||||
self.__select_xsim_auth_key(isim = False, _2G = True)
|
self.__select_xsim_auth_key(isim = False, _2G = True)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_USIM/EF_USIM_AUTH_KEY_2G:"
|
print(" * ADF_USIM/EF_USIM_AUTH_KEY_2G:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu))
|
||||||
|
|
||||||
if self.sim.has_isim:
|
if self.sim.has_isim:
|
||||||
# ADF_ISIM/EF_ISIM_AUTH_KEY_2G:
|
# ADF_ISIM/EF_ISIM_AUTH_KEY_2G:
|
||||||
self.__select_xsim_auth_key(isim = True, _2G = True)
|
self.__select_xsim_auth_key(isim = True, _2G = True)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_ISIM/EF_ISIM_AUTH_KEY_2G:"
|
print(" * ADF_ISIM/EF_ISIM_AUTH_KEY_2G:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu))
|
||||||
|
|
||||||
# ADF_USIM/EF_USIM_AUTH_KEY:
|
# ADF_USIM/EF_USIM_AUTH_KEY:
|
||||||
self.__select_xsim_auth_key(isim = False, _2G = False)
|
self.__select_xsim_auth_key(isim = False, _2G = False)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_USIM/EF_USIM_AUTH_KEY:"
|
print(" * ADF_USIM/EF_USIM_AUTH_KEY:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu))
|
||||||
|
|
||||||
if self.sim.has_isim:
|
if self.sim.has_isim:
|
||||||
# ADF_ISIM/EF_ISIM_AUTH_KEY:
|
# ADF_ISIM/EF_ISIM_AUTH_KEY:
|
||||||
self.__select_xsim_auth_key(isim = True, _2G = False)
|
self.__select_xsim_auth_key(isim = True, _2G = False)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_ISIM/EF_ISIM_AUTH_KEY:"
|
print(" * ADF_ISIM/EF_ISIM_AUTH_KEY:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu))
|
||||||
|
|
||||||
# ADF_USIM/EF_MILENAGE_CFG:
|
# ADF_USIM/EF_MILENAGE_CFG:
|
||||||
self.sim.select(GSM_SIM_MF)
|
self.sim.select(GSM_SIM_MF)
|
||||||
self.sim.card.SELECT_ADF_USIM()
|
self.sim.card.SELECT_ADF_USIM()
|
||||||
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
|
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_USIM/EF_MILENAGE_CFG:"
|
print(" * ADF_USIM/EF_MILENAGE_CFG:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu))
|
||||||
|
|
||||||
if self.sim.has_isim:
|
if self.sim.has_isim:
|
||||||
# ADF_ISIM/EF_MILENAGE_CFG:
|
# ADF_ISIM/EF_MILENAGE_CFG:
|
||||||
|
@ -616,16 +616,16 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
self.sim.card.SELECT_ADF_ISIM()
|
self.sim.card.SELECT_ADF_ISIM()
|
||||||
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
|
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_ISIM/EF_MILENAGE_CFG:"
|
print(" * ADF_ISIM/EF_MILENAGE_CFG:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu))
|
||||||
|
|
||||||
# ADF_USIM/EF_USIM_SQN:
|
# ADF_USIM/EF_USIM_SQN:
|
||||||
self.sim.select(GSM_SIM_MF)
|
self.sim.select(GSM_SIM_MF)
|
||||||
self.sim.card.SELECT_ADF_USIM()
|
self.sim.card.SELECT_ADF_USIM()
|
||||||
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_USIM/EF_USIM_SQN:"
|
print(" * ADF_USIM/EF_USIM_SQN:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
|
||||||
|
|
||||||
if self.sim.has_isim:
|
if self.sim.has_isim:
|
||||||
# ADF_USIM/EF_ISIM_SQN:
|
# ADF_USIM/EF_ISIM_SQN:
|
||||||
|
@ -633,8 +633,8 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
self.sim.card.SELECT_ADF_ISIM()
|
self.sim.card.SELECT_ADF_ISIM()
|
||||||
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print " * ADF_ISIM/EF_ISIM_SQN:"
|
print(" * ADF_ISIM/EF_ISIM_SQN:")
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
|
||||||
|
|
||||||
|
|
||||||
# Show current KI value
|
# Show current KI value
|
||||||
|
@ -822,7 +822,7 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
self.sim.card.SELECT_ADF_USIM()
|
self.sim.card.SELECT_ADF_USIM()
|
||||||
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
|
||||||
|
|
||||||
if self.sim.has_isim:
|
if self.sim.has_isim:
|
||||||
print(" * Current SQN Configuration for ADF_ISIM:")
|
print(" * Current SQN Configuration for ADF_ISIM:")
|
||||||
|
@ -830,7 +830,7 @@ class Sysmo_isim_sja2(Sysmo_usim):
|
||||||
self.sim.card.SELECT_ADF_ISIM()
|
self.sim.card.SELECT_ADF_ISIM()
|
||||||
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
|
||||||
res = self._read_binary(self.sim.filelen)
|
res = self._read_binary(self.sim.filelen)
|
||||||
print SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu)
|
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Sysmo_usim:
|
||||||
|
|
||||||
# Initalize card (select master file)
|
# Initalize card (select master file)
|
||||||
def _init(self):
|
def _init(self):
|
||||||
print " * Initalizing..."
|
print(" * Initalizing...")
|
||||||
self.sim.select(GSM_SIM_MF)
|
self.sim.select(GSM_SIM_MF)
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,12 +204,12 @@ class Sysmo_usim:
|
||||||
self._init()
|
self._init()
|
||||||
self.sim.card.get_AID()
|
self.sim.card.get_AID()
|
||||||
AID = self.sim.card.AID
|
AID = self.sim.card.AID
|
||||||
for a in AID:
|
for a in AID:
|
||||||
if a[0:7] == [0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02]:
|
if a[0:7] == [0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02]:
|
||||||
appstr = "USIM"
|
appstr = "USIM"
|
||||||
elif a[0:7] == [0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04]:
|
elif a[0:7] == [0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04]:
|
||||||
appstr = "ISIM"
|
appstr = "ISIM"
|
||||||
else:
|
else:
|
||||||
appstr = "(unknown)"
|
appstr = "(unknown)"
|
||||||
print " AID: " + hexdump(a[0:5]) + " " + hexdump(a[5:7]) + " " + hexdump(a[7:]) + " ==> " + appstr
|
print(" AID: " + hexdump(a[0:5]) + " " + hexdump(a[5:7]) + " " + hexdump(a[7:]) + " ==> " + appstr)
|
||||||
print ""
|
print("")
|
||||||
|
|
|
@ -340,7 +340,7 @@ class Sysmo_usim_sjs1(Sysmo_usim):
|
||||||
ef_mlngc = SYSMO_USIMSJS1_FILE_EF_MLNGC(res.apdu)
|
ef_mlngc = SYSMO_USIMSJS1_FILE_EF_MLNGC(res.apdu)
|
||||||
|
|
||||||
print(" * Current Milenage Parameters in (EF.MLNGC):")
|
print(" * Current Milenage Parameters in (EF.MLNGC):")
|
||||||
print str(ef_mlngc)
|
print(str(ef_mlngc))
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ class Sysmo_usim_sjs1(Sysmo_usim):
|
||||||
|
|
||||||
print(" * New Milenage Parameters for (EF.MLNGC):")
|
print(" * New Milenage Parameters for (EF.MLNGC):")
|
||||||
ef_mlngc = SYSMO_USIMSJS1_FILE_EF_MLNGC(params)
|
ef_mlngc = SYSMO_USIMSJS1_FILE_EF_MLNGC(params)
|
||||||
print str(ef_mlngc)
|
print(str(ef_mlngc))
|
||||||
|
|
||||||
self.sim.select(SYSMO_USIMSJS1_DF_AUTH)
|
self.sim.select(SYSMO_USIMSJS1_DF_AUTH)
|
||||||
self.sim.select(SYSMO_USIMSJS1_EF_MLNGC)
|
self.sim.select(SYSMO_USIMSJS1_EF_MLNGC)
|
||||||
|
@ -400,7 +400,7 @@ class Sysmo_usim_sjs1(Sysmo_usim):
|
||||||
res = self._read_binary(15, offset = 0)
|
res = self._read_binary(15, offset = 0)
|
||||||
ef_sqnc = SYSMO_USIMSJS1_FILE_EF_SQNC(res.apdu)
|
ef_sqnc = SYSMO_USIMSJS1_FILE_EF_SQNC(res.apdu)
|
||||||
print(" * Current SQN Configuration:")
|
print(" * Current SQN Configuration:")
|
||||||
print str(ef_sqnc)
|
print(str(ef_sqnc))
|
||||||
|
|
||||||
# SQN Array
|
# SQN Array
|
||||||
ind_pow = 2**ef_sqnc.ind_size_bits
|
ind_pow = 2**ef_sqnc.ind_size_bits
|
||||||
|
@ -408,7 +408,7 @@ class Sysmo_usim_sjs1(Sysmo_usim):
|
||||||
res = self._read_binary(ind_pow*6, offset=0)
|
res = self._read_binary(ind_pow*6, offset=0)
|
||||||
ef_sqna = SYSMO_USIMSJS1_FILE_EF_SQNA(res.apdu)
|
ef_sqna = SYSMO_USIMSJS1_FILE_EF_SQNA(res.apdu)
|
||||||
print(" * Current SQN Array:")
|
print(" * Current SQN Array:")
|
||||||
print str(ef_sqna)
|
print(str(ef_sqna))
|
||||||
|
|
||||||
auth_ctr = self.__get_auth_counter()
|
auth_ctr = self.__get_auth_counter()
|
||||||
print("* Authentication Counter: %s" % auth_ctr)
|
print("* Authentication Counter: %s" % auth_ctr)
|
||||||
|
|
Loading…
Reference in New Issue