Esempio n. 1
0
// helper functions
BOOL CMP3Info::GetNextFrameHeader(HANDLE hFile, MP3FRAMEHEADER* pHeader, int nPassBytes)
{
	memset(pHeader,0,sizeof(*pHeader));
	if (nPassBytes > 0)
		SetFilePointer(hFile,nPassBytes,NULL,FILE_CURRENT);

	int n = 0;
	BOOL bReadOK;
	DWORD dwNumBytesRead;
	do
	{
		bReadOK = ReadFile(hFile,pHeader,4,&dwNumBytesRead,NULL);
		ChangeEndian(pHeader,4); // convert from big-endian to little-endian

		// only search in 10kb
		if (!bReadOK || dwNumBytesRead != 4 ||
			pHeader->framesync == 0x7FF || ++n > 10000)
			break;

		SetFilePointer(hFile,-3,NULL,FILE_CURRENT);
	}
	while (1);

	return (pHeader->framesync == 0x7FF);
}
Esempio n. 2
0
uint32_t NormalUart::Send(uint32_t *Data, uint32_t Length)
{
	SendHeader(&mH);
	for (uint32_t i = 0; i < Length; ++i){
		SendInt(&mH,Data[i]);
	}
	ChangeEndian(Data,Length*sizeof(uint32_t));
	crcInit();
	crc checksum = crcFast((unsigned char*)Data,Length*sizeof(uint32_t));
	//ChangeEndian(&checksum,1);
	SendInt(&mH,checksum);
	return Length;
}
Esempio n. 3
0
	// Decode pIntput into pOutput.  Input length in lSize.  Input buffer and
	// output buffer can be the same, but be sure buffer length is even MOD8.
void CBlowFish::Decode (BYTE * pInput, BYTE * pOutput, DWORD lSize)
{
	DWORD 	lCount ;
	BYTE	*pi, *po ;
	int		i ;
	int		SameDest = (pInput == pOutput ? 1 : 0) ;

#ifdef ORDER_ABCD
	//force data to little endian form
  BYTE *pszStart = pOutput;
  ChangeEndian(pszStart, lSize);
#endif

	for (lCount = 0 ; lCount < lSize ; lCount += 8)
	{
		if (SameDest)	// if encoded data is being written into input buffer
		{
	 	 	Blowfish_decipher ((DWORD *) pInput, (DWORD *) (pInput + 4));
		 	pInput += 8 ;
		}
		else 			// output buffer not equal to input buffer
		{               // so copy input to output before decoding
	 		pi = pInput ;
	 		po = pOutput ;
	 		for (i = 0 ; i < 8 ; i++)
	 			*po++ = *pi++ ;
	 	 	Blowfish_decipher ((DWORD *) pOutput, (DWORD *) (pOutput + 4));
		 	pInput += 8 ;
		 	pOutput += 8 ;
		}
	}

#ifdef ORDER_ABCD
	// change back to the big endian form
  ChangeEndian(pszStart, lSize);
#endif
}
Esempio n. 4
0
	// Encode pIntput into pOutput.  Input length in lSize.  Returned value
	// is length of output which will be even MOD 8 bytes.  Input buffer and
	// output buffer can be the same, but be sure buffer length is even MOD8.
DWORD CBlowFish::Encode (BYTE * pInput, BYTE * pOutput, DWORD lSize)
{
	DWORD 	lCount, lOutSize, lGoodBytes;
	BYTE	*pi, *po;
	int		i, j;
	int		SameDest = (pInput == pOutput ? 1 : 0);

	lOutSize = GetOutputLength (lSize);

#ifdef ORDER_ABCD
	//force data to little endian form
  BYTE *pszStart = pOutput;
  ChangeEndian(pOutput, lOutSize);
#endif

	for (lCount = 0; lCount < lOutSize; lCount += 8)
	{
		if (SameDest)	// if encoded data is being written into input buffer
		{
		 	if (lCount < lSize - 7)	// if not dealing with uneven bytes at end
		 	{
		 	 	Blowfish_encipher ((DWORD *) pInput, (DWORD *) (pInput + 4)) ;
		 	}
		 	else		// pad end of data with null bytes to complete encryption
		 	{
				po = pInput + lSize;	// point at byte past the end of actual data
				j = (int) (lOutSize - lSize);	// number of bytes to set to null
				for (i = 0; i < j; i++)
					*po++ = 0;
		 	 	Blowfish_encipher ((DWORD *) pInput, (DWORD *) (pInput + 4)) ;
		 	}
		 	pInput += 8;
		}
		else 			// output buffer not equal to input buffer, so must copy
		{               // input to output buffer prior to encrypting
		 	if (lCount < lSize - 7)	// if not dealing with uneven bytes at end
		 	{
		 		pi = pInput;
		 		po = pOutput;
		 		for (i = 0 ; i < 8 ; i++)				// copy bytes to output
		 			*po++ = *pi++;
		 	 	Blowfish_encipher ((DWORD *) pOutput, (DWORD *) (pOutput + 4)); // now encrypt them
		 	}
		 	else		// pad end of data with null bytes to complete encryption
		 	{
		 		lGoodBytes = lSize - lCount;	// number of remaining data bytes
		 		po = pOutput;
		 		for (i = 0; i < (int) lGoodBytes ; i++)
		 			*po++ = *pInput++;
		 		for (j = i; j < 8; j++)
		 			*po++ = 0;
		 	 	Blowfish_encipher ((DWORD *) pOutput, (DWORD *) (pOutput + 4));
		 	}
		 	pInput += 8;
		 	pOutput += 8;
		}
	}

#ifdef ORDER_ABCD
	// change back to the big endian form
  ChangeEndian(pszStart, lOutSize);
#endif

	return lOutSize;
}