コード例 #1
0
ファイル: iccid.py プロジェクト: minghsu/usim_modifier_v3
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        set_content = None
        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.ICCID)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp != None:
            print(self.get_res("original").format(convert_bcd_to_string(read_resp), toHexString(read_resp)))

            if set_content != None and self.is_update_require_adm == uicc.adm_verified:
                original = convert_bcd_to_string(read_resp)
                update_content = set_content + original[len(set_content):]

                if uicc.update_binary(convert_string_to_bcd(update_content)) == ERROR.NONE:
                    print(self.get_res("updated").format(update_content, toHexString(convert_string_to_bcd(update_content))))
                else:
                    print(self.get_res("update_error"))

        else:
            print(self.get_res("read_error"))

        log.debug(self.__class__.__name__, "EXIT")
コード例 #2
0
ファイル: imsi.py プロジェクト: minghsu/usim_modifier_v3
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc_resp: uicc_sel_resp = None
        uicc: uicc = arg_components.modeler.uicc

        set_content = None

        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        # read EF_IMSI
        uicc_resp = uicc.select(UICC_FILE.IMSI)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp == None:
            print(self.get_res("read_error"))
            return

        # RAW IMSI: 08 09 10 10 10 32 54 76 98
        #              -  --------------------
        # Convert 09 10 10 10 32 54 76 98 => 9001010123456789
        # Ignore 1st char, and just use '001010123456789'
        print(
            self.get_res("original").format(
                convert_bcd_to_string(read_resp[1:])[1:],
                toHexString(read_resp)))

        if set_content != None and self.is_update_require_adm == uicc.adm_verified:
            imsi_update_content = read_resp[:]

            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])

            if uicc.update_binary(imsi_update_content) != ERROR.NONE:
                print(self.get_res("update_error"))
                return

            print(
                self.get_res("updated").format(
                    convert_bcd_to_string(imsi_update_content[1:])[1:],
                    toHexString(imsi_update_content)))

        log.debug(self.__class__.__name__, "EXIT")
コード例 #3
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        ID_GID1 = 0
        ID_GID2 = 1
        gid_working_list = [["GID1", UICC_FILE.GID1, None],
                            ["GID2", UICC_FILE.GID2, None]]

        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "gid1":
                gid_working_list[ID_GID1][2] = toBytes(value)
            elif key == "gid2":
                gid_working_list[ID_GID2][2] = toBytes(value)

        for i in range(len(gid_working_list)):
            uicc_resp: uicc_sel_resp = uicc.select(gid_working_list[i][1])
            read_resp = uicc.read_binary(uicc_resp)
            if read_resp != None:
                print(self.get_res("original").format(
                    gid_working_list[i][0], toHexString(read_resp)))

                if gid_working_list[i][2] != None and self.is_update_require_adm == uicc.adm_verified:
                    update_content = read_resp[:]

                    update_len = len(gid_working_list[i][2])
                    if update_len > uicc_resp.length:
                        update_len = uicc_resp.length

                    for j in range(0, update_len):
                        update_content[j] = gid_working_list[i][2][j]

                    if uicc.update_binary(update_content) == ERROR.NONE:
                        print(self.get_res("updated").format(
                            toHexString(update_content)))
                    else:
                        print(self.get_res("update_error").format(
                            gid_working_list[i][0]))
            elif uicc_resp.sw1 == 0x6A and uicc_resp.sw1 == 0x82:
                print(self.get_res("not_exist").format(gid_working_list[i][0]))
            else:
                print(self.get_res("read_error").format(
                    gid_working_list[i][0]))

        log.debug(self.__class__.__name__, "EXIT")
コード例 #4
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        set_content = None
        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.SPN)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp != None:

            # 01 4D 49 4E 47 FF FF FF FF FF FF FF FF FF FF FF FF
            # First byte is 'display condition'
            # 2 to 17 is 'service provider name'
            print(
                self.get_res("original").format(convert_alpha_to_string(
                    read_resp[1:]),
                                                toHexString(read_resp),
                                                width=(uicc_resp.length - 1)))

            if set_content != None and self.is_update_require_adm == uicc.adm_verified:
                update_len = len(set_content)
                if update_len > (uicc_resp.length - 1):
                    update_len = (uicc_resp.length - 1)

                update_content = [0xFF] * uicc_resp.length
                update_content[0] = 0x01
                for i in range(update_len):
                    update_content[i + 1] = ord(set_content[i])

                if uicc.update_binary(update_content) == ERROR.NONE:
                    print(
                        self.get_res("updated").format(
                            convert_alpha_to_string(update_content[1:]),
                            toHexString(update_content),
                            width=(uicc_resp.length - 1)))
                else:
                    print(self.get_res("update_error"))

        else:
            print(self.get_res("read_error"))

        log.debug(self.__class__.__name__, "EXIT")
コード例 #5
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc_resp: uicc_sel_resp = None
        uicc: uicc = arg_components.modeler.uicc

        ori_mnc_length = None
        mnc_length = None
        efad_data_response = None

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

        dict_args = convert_arguments_to_dict(arg_arguments)
        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 and len(set_mcc) not in (0, 3):
            print(self.get_res("invalid_mcc"))
            return
        if update_mnc and len(set_mnc) not in (0, 2, 3):
            print(self.get_res("invalid_mnc"))
            return

        # read mnc length from EF_AD
        uicc_resp = uicc.select(UICC_FILE.AD)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp == None:
            print(self.get_res("read_error"))
            return

        efad_data_response = read_resp[:]  # keep for update mnc length
        ori_mnc_length = mnc_length = read_resp[3]
        # update mnc length to EF_AD if not equal
        if update_mnc and len(set_mnc) != mnc_length:
            mnc_length = len(set_mnc)
            efad_data_response[3] = mnc_length

            if uicc.update_binary(efad_data_response) != ERROR.NONE:
                print(self.get_res("update_error"))
                return

        # read EF_IMSI
        uicc_resp = uicc.select(UICC_FILE.IMSI)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp == None:
            print(self.get_res("read_error"))
            return

        mcc = convert_bcd_to_string(read_resp[1:])[1:4]
        mnc = convert_bcd_to_string(read_resp[1:])[4:4 + ori_mnc_length]
        print(self.get_res("original").format(mcc, mnc))

        if (update_mcc or update_mnc
            ) and self.is_update_require_adm == uicc.adm_verified:
            update_imsi = read_resp[:]

            # prepare 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)

            # prepare 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]))

            if uicc.update_binary(update_imsi) != ERROR.NONE:
                print(self.get_res("update_error"))
                return

            mcc = convert_bcd_to_string(update_imsi[1:])[1:4]
            mnc = convert_bcd_to_string(update_imsi[1:])[4:4 + mnc_length]
            print(self.get_res("updated").format(mcc, mnc))

        log.debug(self.__class__.__name__, "EXIT")