コード例 #1
0
ファイル: iccid.py プロジェクト: minghsu/usim_modifier
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")

        ret_content = "Can't read the content from EF_ICCID!"
        raw_format = False
        update_iccid = False
        set_content = ""

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "format" and value.lower() == "raw":
                raw_format = True
            elif key == "set":
                set_content = value
                update_iccid = True

        # select EF_ICCID
        response, sw1, sw2 = select_file_in_mf(
            arg_connection, USIM_FILE_ID.ICCID.value)

        if sw1 == 0x90:
            data_length = get_data_length(response)
            response, sw1, sw2 = arg_connection.read_binary(data_length)

            if update_iccid:
                original = convert_bcd_to_string(response)
                update_content = set_content + original[len(set_content):]

                response, sw1, sw2 = arg_connection.update_binary(
                    convert_string_to_bcd(update_content))
                if sw1 == 0x90:
                    ret_content = "ICCID: Updated to '%s'" % (update_content)
                else:
                    ret_content = "Can't update the new content to EF_ICCID!"
            else:
                if raw_format:
                    ret_content = "ICCID: " + toHexString(response)
                else:
                    ret_content = "ICCID: " + convert_bcd_to_string(response)

        return ret_content
コード例 #2
0
    def __get_iccid(self, arg_connection):
        self.__logging.debug("__get_iccid")

        # select EF_ICCID
        response, sw1, sw2 = select_file_in_mf(arg_connection,
                                               USIM_FILE_ID.ICCID.value)

        if sw1 == 0x90:
            data_length = get_data_length(response)
            response, sw1, sw2 = arg_connection.read_binary(data_length)
            return convert_bcd_to_string(response)

        return None
コード例 #3
0
ファイル: pin_cache.py プロジェクト: minghsu/usim_modifier
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")

        if not os.path.exists(DEF_SECURITY_CACHE_FOLDER):
            os.makedirs(DEF_SECURITY_CACHE_FOLDER)

        ret_content = "Unexpected error!!"

        adm_code = None
        pin1_code = None

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "adm":
                adm_code = value
            elif key == "pin1":
                pin1_code = value

        if (adm_code == None or pin1_code == None or len(adm_code) != 16
                or len(pin1_code) < 4 or len(pin1_code) > 8):
            ret_content = "Invalid PIN1/ADM code, operation terminated!!"
        else:
            response, sw1, sw2 = select_file_in_mf(arg_connection,
                                                   USIM_FILE_ID.ICCID.value)
            if sw1 == 0x90:
                data_length = get_data_length(response)
                response, sw1, sw2 = arg_connection.read_binary(data_length)

                iccid = convert_bcd_to_string(response)

                try:
                    security_node = etree.Element("security")
                    adm_node = etree.SubElement(security_node, "adm")
                    adm_node.text = adm_code
                    pin1_node = etree.SubElement(security_node, "pin1")
                    pin1_node.text = pin1_code
                    xmltree = etree.ElementTree(security_node)
                    xmltree.write(DEF_SECURITY_CACHE_FOLDER + os.sep + iccid +
                                  ".xml",
                                  pretty_print=True,
                                  xml_declaration=True,
                                  encoding='utf-8')
                    ret_content = "The " + iccid + ".xml file stored success."
                except:
                    ret_content = "Can't store " + iccid + ".xml file, operation terminated!"

        return ret_content
コード例 #4
0
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")

        ret_content = "Can't retrive the MCC/MNC value!"
        mnc_length = None
        efad_data_response = None

        set_mcc = ""
        set_mnc = ""
        update_mcc = False
        update_mnc = False

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "mcc":
                set_mcc = value
                update_mcc = True
            elif key == "mnc":
                set_mnc = value
                update_mnc = True

        # Check the length of MCC/MNC
        if update_mcc:
            if len(set_mcc) not in (0, 3):
                return "Invalid the length of MCC!"
        if update_mnc:
            if len(set_mnc) not in (0, 2, 3):
                return "Invalid the length of MNC!"

        # select EF_AD to get the length of mnc
        response, sw1, sw2 = select_file_in_adf(arg_connection,
                                                USIM_FILE_ID.AD.value)
        if sw1 == 0x90:
            data_length = get_data_length(response)
            response, sw1, sw2 = arg_connection.read_binary(data_length)
            if sw1 == 0x90:
                efad_data_response = response[:]  # keep for update mnc length
                mnc_length = response[3]

        # select EF_IMSI
        if mnc_length != None:
            response, sw1, sw2 = select_file_in_adf(arg_connection,
                                                    USIM_FILE_ID.IMSI.value)
            if sw1 == 0x90:
                data_length = get_data_length(response)
                response, sw1, sw2 = arg_connection.read_binary(data_length)

                if update_mcc or update_mnc:
                    update_imsi = response[:]

                    # MCC
                    if update_mcc and (len(set_mcc) == 3):
                        update_imsi[1] = (update_imsi[1]
                                          & 0x0F) + (int(set_mcc[0]) << 4)
                        update_imsi[2] = (update_imsi[2] & 0xF0) + (int(
                            set_mcc[1]))
                        update_imsi[2] = (update_imsi[2]
                                          & 0x0F) + (int(set_mcc[2]) << 4)

                    # MNC
                    if update_mnc and (len(set_mnc) >= 2):
                        update_imsi[3] = (update_imsi[3] & 0xF0) + (int(
                            set_mnc[0]))
                        update_imsi[3] = (update_imsi[3]
                                          & 0x0F) + (int(set_mnc[1]) << 4)

                        if len(set_mnc) == 3:
                            update_imsi[4] = (update_imsi[4] & 0xF0) + (int(
                                set_mnc[2]))

                    response, sw1, sw2 = arg_connection.update_binary(
                        update_imsi)
                    if sw1 == 0x90:
                        if update_mnc:
                            response, sw1, sw2 = select_file_in_adf(
                                arg_connection, USIM_FILE_ID.AD.value)
                            mnc_length = len(set_mnc)
                            efad_data_response[3] = mnc_length
                            response, sw1, sw2 = arg_connection.update_binary(
                                efad_data_response)
                            if sw1 == 0x90:
                                ret_content = "Can't update the length of MNC!"

                        mcc = convert_bcd_to_string(update_imsi[1:])[1:4]
                        mnc = convert_bcd_to_string(
                            update_imsi[1:])[4:4 + mnc_length]
                        ret_content = "MCC/MNC: %s/%s" % (mcc, mnc)
                    else:
                        ret_content = "Can't update the new MCC/MNC to EF_IMSI!"

                else:
                    if sw1 == 0x90:
                        mcc = convert_bcd_to_string(response[1:])[1:4]
                        mnc = convert_bcd_to_string(response[1:])[4:4 +
                                                                  mnc_length]
                        ret_content = "MCC/MNC: %s/%s" % (mcc, mnc)

        return ret_content
コード例 #5
0
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")

        ret_content = "Can't read the content from EF_IMSI!"
        raw_format = False
        set_content = ""
        update_imsi = False

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "format" and value.lower() == "raw":
                raw_format = True
            elif key == "set":
                set_content = value
                update_imsi = True

        # select EF_IMSI
        response, sw1, sw2 = select_file_in_adf(arg_connection,
                                                USIM_FILE_ID.IMSI.value)

        if sw1 == 0x90:
            data_length = get_data_length(response)
            response, sw1, sw2 = arg_connection.read_binary(data_length)

            if sw1 == 0x90:
                if update_imsi:
                    imsi_update_content = response[:]

                    for i in range(len(set_content)):
                        if i == 15:
                            break
                        Idx_of_PayLoad = int(((i + 1) / 2) + 1)
                        Mod_Value = (i % 2)

                        if Mod_Value == 0:
                            imsi_update_content[Idx_of_PayLoad] = (
                                imsi_update_content[Idx_of_PayLoad]
                                & 0x0F) + (int(set_content[i]) << 4)
                        else:
                            imsi_update_content[Idx_of_PayLoad] = (
                                imsi_update_content[Idx_of_PayLoad]
                                & 0xF0) + int(set_content[i])

                    response, sw1, sw2 = arg_connection.update_binary(
                        imsi_update_content)
                    if sw1 == 0x90:
                        ret_content = ("IMSI: Updated to '" +
                                       convert_bcd_to_string(
                                           imsi_update_content[1:])[1:] +
                                       ("'"))
                    else:
                        ret_content = "Can't update the new content to EF_IMSI!"

                else:
                    if raw_format:
                        ret_content = "IMSI: " + toHexString(response)
                    else:
                        ret_content = ("IMSI: " +
                                       convert_bcd_to_string(response[1:])[1:])

        return ret_content