예제 #1
0
QPCSCReader::Result QPCSCReader::transfer( const QByteArray &cmd ) const
{
	static const SCARD_IO_REQUEST T0 = { 1, 8 };
	static const SCARD_IO_REQUEST T1 = { 2, 8 };
	QByteArray data( 255 + 3, 0 );
	DWORD size = data.size();

	qDebug() << "Send:" << cmd.toHex();
	DWORD ret = SCardTransmit( d->card, d->proto == SCARD_PROTOCOL_T0 ? &T0 : &T1,
		LPCBYTE(cmd.constData()), cmd.size(), 0, LPBYTE(data.data()), &size );
	if( ret != SCARD_S_SUCCESS )
	{
		qDebug() << "Err:" << ret;
		return Result();
	}

	Result result( data.mid( size-2, 2 ), data.left( size - 2 ) );
	qDebug() << "Recv:" << result.first.toHex() << result.second.toHex();

	if( result.first.at( 0 ) == 0x61 )
	{
		QByteArray cmd( "\x00\xC0\x00\x00\x00", 5 );
		cmd[4] = data.at( size-1 );
		return transfer( cmd );
	}
	return result;
}
예제 #2
0
QPCSCReader::Result QPCSCReader::transfer( const QByteArray &apdu ) const
{
	static const SCARD_IO_REQUEST T0 = { SCARD_PROTOCOL_T0, sizeof(SCARD_IO_REQUEST) };
	static const SCARD_IO_REQUEST T1 = { SCARD_PROTOCOL_T1, sizeof(SCARD_IO_REQUEST) };
	QByteArray data( 1024, 0 );
	DWORD size = DWORD(data.size());

	qCDebug(APDU).nospace() << 'T' << d->proto - 1 << "> " << apdu.toHex().constData();
	LONG ret = SC(Transmit, d->card, d->proto == SCARD_PROTOCOL_T0 ? &T0 : &T1,
		LPCBYTE(apdu.constData()), DWORD(apdu.size()), nullptr, LPBYTE(data.data()), &size);
	if( ret != SCARD_S_SUCCESS )
		return { QByteArray(), QByteArray(), quint32(ret) };

	Result result = { data.mid(int(size - 2), 2), data.left(int(size - 2)), quint32(ret) };
	qCDebug(APDU).nospace() << 'T' << d->proto - 1 << "< " << result.SW.toHex().constData();
	if(!result.data.isEmpty()) qCDebug(APDU).nospace() << data.left(int(size)).toHex().constData();

	switch(result.SW.at(0))
	{
	case 0x61: // Read more
	{
		QByteArray cmd( "\x00\xC0\x00\x00\x00", 5 );
		cmd[4] = data.at(int(size - 1));
		Result result2 = transfer( cmd );
		result2.data.prepend(result.data);
		return result2;
	}
	case 0x6C: // Excpected lenght
	{
		QByteArray cmd = apdu;
		cmd[4] = result.SW.at(1);
		return transfer(cmd);
	}
	default: return result;
	}
}
예제 #3
0
STDMETHODIMP CEngine::LoadHtml(BSTR html, BSTR baseUrl)
{
  return HTMLayoutLoadHtmlEx(m_hWnd,LPCBYTE(html),SysStringByteLen(html),baseUrl)? S_OK: S_FALSE;
}
예제 #4
0
BOOL KNetConnectPlayer::ProcessPacket( INT nConnectId, LPCBYTE pData, UINT uDataLen )
{
	QCONFIRM_RET_FALSE(nConnectId > 0 && nConnectId <= m_nMaxConnId);
	QCONFIRM_RET_FALSE(pData);

	RxStat(pData, uDataLen);

	INT nPlayerIndex = m_pnConnId2PlayerIndex[nConnectId];
	if (nPlayerIndex == 0)
	{
		// Process Login
		KC2S_LOGIN *pLL = (KC2S_LOGIN* )pData;
		QCONFIRM_RET_FALSE(pLL->byProtocol == emKPLBASE_PTC_C2S_LOGIN && uDataLen == sizeof(KC2S_LOGIN));
		//Q_Printl("pLL->byProtocol="<<pLL->byProtocol <<" uDataLen=" <<uDataLen);
		
		DWORD dwClientIp = 0;
		USHORT uClientPort = 0;
		g_piSocketServer->GetRemoteAddress(nConnectId, dwClientIp, uClientPort);
		Q_Printl("[ClientLogin] from [" << inet_ntoa(*(struct in_addr*)&dwClientIp) << ":" << uClientPort <<
			"] ConnectionToken" << KGuidHelper::GuidToString(pLL->guid) << " pLL->dwTinyTerminal=" << pLL->dwTinyTerminal);

		// 玩家已连接上,未发Login协议前应为0
		QCONFIRM(m_pnConnId2PlayerIndex[nConnectId] == 0);

		QCONFIRM_RET_FALSE(pLL->byGameServerVersion <= KD_PROTOCOL_VERSION &&
			pLL->byGameServerVersion >= KD_PROTOCOL_VERSION_LOWER_LIMIT);

		return OnClientLogin2(pLL->dwRoleId, pLL->guid, nConnectId, pLL->nHidden,pLL->dwTinyTerminal);
	}
	QCONFIRM_RET_FALSE(uDataLen >= sizeof(BYTE) * 2);

	// Check Protocol Size
	INT nPtcSize = KPTC_SIZE::GetSizeC2S(*pData, *(pData + 1));
	if (nPtcSize > 0)
	{
		QCONFIRM_RET_FALSE((UINT)nPtcSize == uDataLen);
	}
	else // 变长
	{
		QCONFIRM_RET_FALSE(uDataLen >= sizeof(BYTE) * 3 && *(LPWORD)(pData + 2) == uDataLen);
	}

	KPlayer* pPlayer = g_cPlayerMgr.GetByIndex(nPlayerIndex);
	QCONFIRM_RET_FALSE(pPlayer);

	// Doing 协议过滤
	if ( KNSBASE_EXT::DoingProtocolFilter[pPlayer->GetMoveState()] &&
		! (*KNSBASE_EXT::DoingProtocolFilter[pPlayer->GetMoveState()])(*pPlayer, pData, uDataLen) )
	{
		QLogPrintf(LOG_ERR, "[%s] Doing为[%d]时禁止发送[PF %u, P %u] 协议被屏蔽",
			pPlayer->GetName(), pPlayer->GetMoveState(), LPCBYTE(pData)[0], LPCBYTE(pData)[1]);
		return TRUE;
	}

	// base协议处理
	if (*pData == 0)
		return g_cPlayerBaseProcess.ProcessProtocol(nPlayerIndex, pData, uDataLen);

	PLAYER_GAME_STATE eGameState = pPlayer->GetGameState();
	if (eGameState != gsPlaying)
	{
		KPTC_HEADER_BASE* pHeader = (KPTC_HEADER_BASE*)pData;

		QLogPrintf(LOG_ERR, "Protocol[%u, %u] blocked, Player[%d][%s] GameState[%d] is not 'gsPlaying'",
			pHeader->byProtocolFamily, pHeader->byProtocol,
			pPlayer->m_dwId, pPlayer->GetName(),
			eGameState);
		
		// 其他状态不接受扩展协议
		return TRUE;
	}

	// 子模块协议处理
	IKModuleInterface* piModule = g_cModuleManager.GetModule(BYTE(*pData) - KD_MAX_BASE_PROTOCOL_HEADER);
	if (!piModule)
	{
		Q_Error("Unrecognized Protocol " << BYTE(*pData) << " " << BYTE(*(pData+ 1)) << " Size " << uDataLen);
		return FALSE;
	}
	piModule->ProcessProtocol(nPlayerIndex, pData, uDataLen);
	return TRUE;
}