コード例 #1
0
ファイル: cards.py プロジェクト: fiserto1/simreadGUI
 def _e_imsi(self, imsi):
     """Converts a string imsi into the value of the EF"""
     l = (len(imsi) + 1) // 2  # Required bytes
     oe = len(imsi) & 1  # Odd (1) / Even (0)
     ei = '%02x' % l + swap_nibbles(
         lpad('%01x%s' % ((oe << 3) | 1, imsi), 16))
     return ei
コード例 #2
0
ファイル: dev.py プロジェクト: RaceList/openlibrary
 def input_user_name(self, default=''):
     if not self.edition:
         raise quit()
     name = raw_input('\nreview author? [%s] ' % default) or default
     self.user = db.get_thing(utils.lpad(name, 'user/'), 
                              db.get_type('type/user'))
     if not self.user:
         print '\nreview author not found.'
         self.safety_lock('create a dummy user \'%s\'?' % name)
         self.user = create_dummy_user(name, password='******')
         print '\nok.'
     else:
         print '\nuser %s found.' % self.user
コード例 #3
0
 def input_user_name(self, default=''):
     if not self.edition:
         raise quit()
     name = raw_input('\nreview author? [%s] ' % default) or default
     self.user = db.get_thing(utils.lpad(name, 'user/'),
                              db.get_type('type/user'))
     if not self.user:
         print('\nreview author not found.')
         self.safety_lock('create a dummy user \'%s\'?' % name)
         self.user = create_dummy_user(name, password='******')
         print('\nok.')
     else:
         print('\nuser %s found.' % self.user)
コード例 #4
0
ファイル: cards.py プロジェクト: fiserto1/simreadGUI
    def program(self, p):
        # Home PLMN
        r = self._scc.select_file(['3f00', '7f20', '6f30'])
        tl = int(r[-1][4:8], 16)

        hplmn = self._e_plmn(p['mcc'], p['mnc'])
        self._scc.update_binary('6f30', hplmn + 'ff' * (tl - 3))

        # Get total number of entries and entry size
        rec_cnt, rec_len = self._get_infos()

        # Set first entry
        entry = (
            '81' +  #  1b  Status: Valid & Active
            rpad(b2h(p['name'][0:14]), 28) +  # 14b  Entry Name
            self._e_iccid(p['iccid']) +  # 10b  ICCID
            self._e_imsi(p['imsi']) +  #  9b  IMSI_len + id_type(9) + IMSI
            p['ki'] +  # 16b  Ki
            lpad(p['smsp'], 80)  # 40b  SMSP (padded with ff if needed)
        )
        self._scc.update_record('000c', 1, entry)
コード例 #5
0
ファイル: cards.py プロジェクト: fiserto1/simreadGUI
    def program(self, p):
        # We don't really know yet what ADM PIN 4 is about
        #self._scc.verify_chv(4, h2b("4444444444444444"))

        # Authenticate using ADM PIN 5
        self._scc.verify_chv(5, h2b("4444444444444444"))

        # EF.ICCID
        r = self._scc.select_file(['3f00', '2fe2'])
        data, sw = self._scc.update_binary('2fe2', self._e_iccid(p['iccid']))

        # EF.IMSI
        r = self._scc.select_file(['3f00', '7f20', '6f07'])
        data, sw = self._scc.update_binary('6f07', self._e_imsi(p['imsi']))

        # EF.ACC
        #r = self._scc.select_file(['3f00', '7f20', '6f78'])
        #self._scc.update_binary('6f78', self._e_imsi(p['imsi'])

        # EF.SMSP
        r = self._scc.select_file(['3f00', '7f10', '6f42'])
        data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))

        # Set the Ki using proprietary command
        pdu = '80d4020010' + p['ki']
        data, sw = self._scc._tp.send_apdu(pdu)

        # EF.HPLMN
        r = self._scc.select_file(['3f00', '7f20', '6f30'])
        size = int(r[-1][4:8], 16)
        hplmn = self._e_plmn(p['mcc'], p['mnc'])
        self._scc.update_binary('6f30', hplmn + 'ff' * (size - 3))

        # EF.SPN (Service Provider Name)
        r = self._scc.select_file(['3f00', '7f20', '6f30'])
        size = int(r[-1][4:8], 16)
コード例 #6
0
ファイル: cards.py プロジェクト: fiserto1/simreadGUI
 def _e_plmn(self, mcc, mnc):
     """Converts integer MCC/MNC into 6 bytes for EF"""
     return swap_nibbles(lpad('%d' % mcc, 3) + lpad('%d' % mnc, 3))
コード例 #7
0
async def cmd_gac(ctx):

	bot = ctx.bot
	args = ctx.args
	config = ctx.config

	ctx.alt = bot.options.parse_alt(args)
	lang = bot.options.parse_lang(ctx, args)

	selected_players, error = bot.options.parse_players(ctx, args)

	if error:
		return error

	if not selected_players:
		return bot.errors.not_ally_code_specified(ctx)

	if args:
		return bot.errors.unknown_parameters(args)

	fields = []
	ally_codes = [ x.ally_code for x in selected_players ]
	players = await bot.client.players(ally_codes=ally_codes)
	if not players:
		return bot.errors.ally_codes_not_found(ally_codes)

	players = { x['allyCode']: x for x in players }

	result = {}
	history = {}

	for player in selected_players:

		jplayer = players[player.ally_code]
		max_len = max(len(jplayer['name']), 8)

		key = 'Players'
		if key not in result:
			result[key] = []
		result[key].append(lpad(jplayer['name'], max_len))

		pstats = jplayer['stats']
		for key, real_key in wanted_stats.items():

			if real_key not in result:
				result[real_key] = []

			value = get_stat(pstats, key)
			result[real_key].append(lpad(value, max_len))

		i = 1
		for entry in reversed(jplayer['grandArena']):

			if 'eliteDivision' not in entry:
				entry['eliteDivision'] = False

			for key, real_key in wanted_info.items():
				the_real_key = real_key + str(i)
				if the_real_key not in history:
					history[the_real_key] = []

				if key not in entry:
					entry[key] = 0

				value = str(entry[key])

				if the_real_key.startswith('Season ID'):
					value = parse_season(entry[key])

				elif key.startswith('division'):
					value = get_division(entry[key])

				elif key.startswith('elite'):
					value = get_elite(entry[key])

				elif key.startswith('eventInstanceId'):
					value = get_season_date(entry[key])

				history[the_real_key].append(lpad(value, max_len))

			i += 1

	lines = []

	names = result.pop('Players')
	lines.append('__**Players**__')
	lines.append('`|%s|`' % '|'.join(names))
	lines.append('')

	lines.append('__**General Statistics**__')
	for key, values in result.items():
		display = '|'.join(values)
		if key == 'Players':
			lines.append('`|%s|`' % display)
			lines.append(config['separator'])
		else:
			lines.append('`|%s|`__**%s**__' % (display, key))

	for i in range(1, 4):

		season_id = 'Season ID%d' % i
		if season_id not in history:
			continue

		seasons = history.pop(season_id)
		dates = history.pop('Date%d' % i)

		title = '__**Season %s**__ (*%s*)' % (seasons[0], dates[0].strip())
		lines.append('')
		lines.append(title)

		for key, values in history.items():
			if not key.endswith(str(i)):
				continue

			display = '|'.join(values)
			lines.append('`|%s|`__**%s**__' % (display, key.replace(str(i), '')))

	lines.append('')

	return [{
		'title': 'GAC Stats',
		'description': '\n'.join(lines),
	}]