コード例 #1
0
bool WiiSave::loadFromMemory(const Uint8* data, Uint64 length)
{
    if (m_reader == NULL)
        m_reader = new BinaryReader(data, length);
    else
    {
        m_reader->setData(data, length);
    }

    m_reader->setEndianess(Stream::BigEndian);

    m_banner = readBanner();
    if (!m_banner)
    {
        std::cerr << "Invalid banner" << std::endl;
        return false;
    }

    Uint32 bkVer = m_reader->readUInt32();
    bkVer = bkVer;
    if (bkVer != 0x00000070)
    {
        std::cerr << "Invalid BacKup header size: 0x" << std::hex << bkVer << std::endl;
        return false;
    }

    Uint32 bkMagic = m_reader->readUInt32();
    bkMagic = bkMagic;
    if (bkMagic != 0x426B0001)
    {
        std::cerr << "Invalid BacKup header magic: 0x" << std::hex << bkMagic << std::endl;
        return false;
    }

    Uint32 ngId = m_reader->readUInt32();
    ngId = ngId;

    Uint32 numFiles = m_reader->readUInt32();

    /*int fileSize =*/ m_reader->readUInt32();
    m_reader->seek(8); // skip unknown data;

    Uint32 totalSize = m_reader->readUInt32();
    m_reader->seek(64); // Unknown (Most likely padding)
    m_reader->seek(8);
    m_reader->seek(6);
    m_reader->seek(2);
    m_reader->seek(0x10);

    WiiFile* file;
    for (Uint32 i = 0; i < numFiles; ++i)
    {
        file = readFile();
        if (file)
            addFile("/" + file->filename(), file);
    }

    readCerts(totalSize);
    return true;
}
コード例 #2
0
ファイル: PTsshSocket.cpp プロジェクト: VerKnowSys/Syndir
int32
PTsshSocket::connectToServer()
{
	int
		result = PTSSH_SUCCESS;
	bool
		bSS_init = false,
		bSR_init = false;

	CryptoStuff::Cipher 
		*pEncrypt = NULL,
		*pDecrypt = NULL;

	//Set socket options
	setSocketOptions(m_sock);

	//Let's try and connect to the host with our socket
	if ( ::connect(m_sock, (struct sockaddr*)m_pSockAddr, sizeof(struct sockaddr_in)) != 0) {
		close(m_sock);

#ifdef WIN32
		int error = WSAGetLastError();
		PTLOG((LL_error, "Winsock error number %d\n", error));
#endif
		result = PTSSH_ERR_CouldNotConnectToHost;
		goto error;
	}

	/**************************
	* Object init and member var setup
	***************************/
	
	pthread_mutex_lock( &m_isAliveMutex);
		m_bIsSocketAlive = true;
	pthread_mutex_unlock( &m_isAliveMutex);

	//Now set the socket blocking
	if (! setSocketBlocking(m_sock, true)) //Blocking
	{
		result = PTSSH_ERR_CouldNotSetSocketBlocking;
		goto error;
	}

	//Finally, create and startup our socket send and socket recieve threads
	m_pSS = new SocketSend(m_pChannelMgr, m_pActivityMutex, m_pActivity_cv, this, m_sock);
	m_pSR = new SocketRecieve(m_pChannelMgr, m_pActivityMutex, m_pActivity_cv, this, m_sock);
	if ( ! m_pSR || ! m_pSS)
	{
		result = PTSSH_ERR_CouldNotAllocateMemory;
		goto error;
	}

	if ( m_pSS->init() != PTSSH_SUCCESS)
	{
		result = PTSSH_ERR_CouldNotInit_SS;
		goto error;
	}
	bSS_init = true;

	if ( m_pSR->init() != PTSSH_SUCCESS)
	{
		result = PTSSH_ERR_CouldNotInit_SR;
		goto error;
	}
	bSR_init = true;

	/* Now let the SocketRecieve class know about the SocketSend class so that it can tell
	 * it when to go into key exchange mode. */
	m_pSR->setSocketSendPtr( m_pSS);

	/* ...and let the SocketSend class know about the SocketRecieve class so that it can
	 * tell it when keyX mode is finished & when it can use its new cipher object */
	m_pSS->setSocketRecievePtr( m_pSR);

	/* Create our initial Cipher objects. Starting out, they won't have a cipher algorithm,
	so we'll just use them to get things like blocksize and mac size */
	pEncrypt = new CryptoStuff::Cipher();
	if ( ! pEncrypt)
	{
		result = PTSSH_ERR_CouldNotAllocateMemory;
		goto error;
	}
	
	//Give the new cipher to the socketSend class
	m_pSS->setInitialCipher( pEncrypt);
	pEncrypt = NULL; // m_pSS now ownes this

	pDecrypt = new CryptoStuff::Cipher();
	if ( ! pDecrypt)
	{
		result = PTSSH_ERR_CouldNotAllocateMemory;
		goto error;
	}

	//Set the new decryption cipher
	m_pSR->setInitialCipher( pDecrypt);
	pDecrypt = NULL; //m_pSR now ownes this

	/***************************
	* Send/Recieve Banners
	***************************/
	//setV_C, our banner message in our DH object
	m_pCrypto->setV_C( PTSSH_BANNER, (uint32) strlen(PTSSH_BANNER) -2);
	
	//Send our banner 
	if ( rawSocketWrite( PTSSH_BANNER, (uint32) strlen(PTSSH_BANNER)) == PTSSH_SUCCESS)
	{
		char banner[256];
		memset(banner, 0x0, 256);
		//recieve remote banner
		int32 len = readBanner( &m_pRemoteBanner);
		if (len > 0 && m_pRemoteBanner)
		{
			memcpy(banner, m_pRemoteBanner, len); //  <-- dangerous!
			PTLOG((LL_debug1, "Remote banner: %s\n", banner));
		}
		else
		{
			result = PTSSH_ERR_CouldNotGetRemoteBanner;
			goto error;
		}
	}

	/***************************
	* Start the threads!
	***************************/
	if ( ! m_pSS->startThread())
	{
		result = PTSSH_ERR_CouldNotStartSocketSendThread;
		goto error;
	}
	if ( ! m_pSR->startThread())
	{
		result = PTSSH_ERR_CouldNotStartSocketRecieveThread;
		goto error;
	}
	
	return result;

error:
	close (m_sock);
	if ( m_pSS)
	{
		if ( bSS_init && m_pSS->isRunning())
			m_pSS->stopThread();

		delete m_pSS;
		m_pSS = NULL;
	}

	if ( m_pSR)
	{
		if ( bSR_init && m_pSR->isRunning() )
			m_pSR->stopThread();

		delete m_pSR;
		m_pSR = NULL;
	}

	if ( pEncrypt )
	{
		m_pSS->setCipher( NULL);
		delete pEncrypt;
		pEncrypt = NULL;
	}

	if ( pDecrypt )
	{
		m_pSR->setCipher( NULL);
		delete pDecrypt;
		pDecrypt = NULL;
	}

	pthread_mutex_lock( &m_isAliveMutex);
		m_bIsSocketAlive = false;
	pthread_mutex_unlock( &m_isAliveMutex);

	return result;
}