static void process_file(const char *filename)
{
	int i;
	FILE *fp;
	if (!(fp = fopen(filename, "rb"))) {
		fprintf(stderr, "! %s : %s\n", filename, strerror(errno));
		return;
	}
	fseek(fp, 0, SEEK_END);
	long size = ftell(fp);
	rewind(fp);

	printf("file name : %s, file size : %ld, CRC32: ", filename, size);
	unsigned char *buf = (unsigned char *) malloc(size);
	if (buf == NULL) {
		fprintf(stderr, "%s:%d: malloc failed\n", __FUNCTION__, __LINE__);
		exit(EXIT_FAILURE);
	}
	long count = fread(buf, 1, size, fp);
	assert(count == size);

	CRC32_t crc;
	CRC32_Init(&crc);
	CRC32_Update(&crc, buf, count);
	unsigned char crc_out[4];
	CRC32_Final(crc_out, crc);
	for (i = 0; i < 4; i++) {
		printf("%02x ", crc_out[i]);
	}
	printf("\n");
	fclose(fp);
}
unsigned int CSentence::ComputeDataCheckSum()
{
#if PHONEME_EDITOR
	int i;
	int c;
	CRC32_t crc;
	CRC32_Init( &crc );

	// Checksum the text
	CRC32_ProcessBuffer( &crc, GetText(), Q_strlen( GetText() ) );
	// Checsum words and phonemes
	c = m_Words.Count();
	for ( i = 0; i < c; ++i )
	{
		CWordTag *word = m_Words[ i ];
		unsigned int wordCheckSum = word->ComputeDataCheckSum();
		CRC32_ProcessBuffer( &crc, &wordCheckSum, sizeof( unsigned int ) );
	}

	// Checksum emphasis data
	c = m_EmphasisSamples.Count();
	for ( i = 0; i < c; ++i )
	{
		CRC32_ProcessBuffer( &crc, &m_EmphasisSamples[ i ].time, sizeof( float ) );
		CRC32_ProcessBuffer( &crc, &m_EmphasisSamples[ i ].value, sizeof( float ) );
	}

	CRC32_Final( &crc );

	return ( unsigned int )crc;
#else
	Assert( 0 );
	return 0;
#endif
}
unsigned int CWordTag::ComputeDataCheckSum()
{
	int i;
	int c;
	CRC32_t crc;
	CRC32_Init( &crc );

	// Checksum the text
	if ( m_pszWord != NULL )
	{
		CRC32_ProcessBuffer( &crc, m_pszWord, Q_strlen( m_pszWord ) );
	}
	// Checksum phonemes
	c = m_Phonemes.Count();
	for ( i = 0; i < c; ++i )
	{
		CPhonemeTag *phoneme = m_Phonemes[ i ];
		unsigned int phonemeCheckSum = phoneme->ComputeDataCheckSum();
		CRC32_ProcessBuffer( &crc, &phonemeCheckSum, sizeof( unsigned int ) );
	}
	// Checksum timestamps
	CRC32_ProcessBuffer( &crc, &m_flStartTime, sizeof( float ) );
	CRC32_ProcessBuffer( &crc, &m_flEndTime, sizeof( float ) );

	CRC32_Final( &crc );

	return ( unsigned int )crc;
}
/*
====================
COM_BlockSequenceCRCByte

For proxy protecting
Turns the passed data into a 
single byte block CRC based on current network sequence number.
====================
*/
byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
{
	CRC32_t crc;
	byte *p;
	byte chkb[60 + 4];

	if (sequence < 0)
		Sys_Error("sequence < 0, in COM_BlockSequenceCRCByte\n");

	p = (byte *)pulCRCTable + (sequence % (NUM_BYTES * sizeof(CRC32_t) - 4));

	// Use up to the first 60 bytes of data and a 4 byte value from the 
	//  CRC lookup table (divided into the sequence)

	if (length > 60)
		length = 60;
	
	memcpy (chkb, base, length);

	chkb[length+0] = p[0];
	chkb[length+1] = p[1];
	chkb[length+2] = p[2];
	chkb[length+3] = p[3];

	length += 4;

	// Compute a crc based on the buffer.
	CRC32_Init(&crc);
	CRC32_ProcessBuffer(&crc, chkb, length);
	CRC32_Final(&crc);
	
	// Chop down to byte size
	return (byte)(crc & 0xFF);
}
Beispiel #5
0
	inline CRC32_t CRC32_ProcessSingleBuffer( const void *p , int len ) {
		CRC32_t crc;

		CRC32_Init( &crc );
		CRC32_ProcessBuffer( &crc , p , len );
		CRC32_Final( &crc );

		return crc;
	}
//-----------------------------------------------------------------------------
// Purpose: Playback sound file that contains phonemes
// Input  : *actor - 
//			*parameters - 
//-----------------------------------------------------------------------------
void C_SceneEntity::DispatchStartSpeak( CChoreoScene *scene, C_BaseFlex *actor, CChoreoEvent *event, soundlevel_t iSoundlevel )
{
	// Emit sound
	if ( IsClientOnly() && actor )
	{
		CSingleUserRecipientFilter filter( C_BasePlayer::GetLocalPlayer() );

		float time_in_past = m_flCurrentTime - event->GetStartTime() ;
		float soundtime = gpGlobals->curtime - time_in_past;

		EmitSound_t es;
		es.m_nChannel = CHAN_VOICE;
		es.m_flVolume = 1;
		es.m_SoundLevel = iSoundlevel;
		es.m_flSoundTime = soundtime;

		// No CC since we do it manually
		// FIXME:  This will  change
		es.m_bEmitCloseCaption = false;
		es.m_pSoundName = event->GetParameters();

		EmitSound( filter, actor->entindex(), es );
		actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );

		// Close captioning only on master token no matter what...
		if ( event->GetCloseCaptionType() == CChoreoEvent::CC_MASTER )
		{
			char tok[ CChoreoEvent::MAX_CCTOKEN_STRING ];
			bool validtoken = event->GetPlaybackCloseCaptionToken( tok, sizeof( tok ) );
			if ( validtoken )
			{
				CRC32_t tokenCRC;
				CRC32_Init( &tokenCRC );

				char lowercase[ 256 ];
				Q_strncpy( lowercase, tok, sizeof( lowercase ) );
				Q_strlower( lowercase );

				CRC32_ProcessBuffer( &tokenCRC, lowercase, Q_strlen( lowercase ) );
				CRC32_Final( &tokenCRC );

				float endtime = event->GetLastSlaveEndTime();
				float durationShort = event->GetDuration();
				float durationLong = endtime - event->GetStartTime();
				float duration = MAX( durationShort, durationLong );

				CHudCloseCaption *hudCloseCaption = GET_HUDELEMENT( CHudCloseCaption );
				if ( hudCloseCaption )
				{
					hudCloseCaption->ProcessCaption( lowercase, duration );
				}
			}

		}
	}
}
//-----------------------------------------------------------------------------
// Create binary compiled version of VCD. Stores to a dictionary for later
// post processing
//-----------------------------------------------------------------------------
bool CreateTargetFile_VCD( const char *pSourceName, const char *pTargetName, bool bWriteToZip, bool bLittleEndian )
{
	CUtlBuffer sourceBuf;
	if ( !scriptlib->ReadFileToBuffer( pSourceName, sourceBuf ) )
	{
		return false;
	}

	CRC32_t crcSource;
	CRC32_Init( &crcSource );
	CRC32_ProcessBuffer( &crcSource, sourceBuf.Base(), sourceBuf.TellMaxPut() );
	CRC32_Final( &crcSource );

	ParseFromMemory( (char *)sourceBuf.Base(), sourceBuf.TellMaxPut() );

	CChoreoScene *pChoreoScene = ChoreoLoadScene( pSourceName, NULL, &g_SceneTokenProcessor, Msg );
	if ( !pChoreoScene )
	{
		return false;
	}

	int iScene = g_SceneFiles.AddToTail();

	g_SceneFiles[iScene].fileName.Set( pSourceName );

	// Walk all events looking for SPEAK events
	CChoreoEvent *pEvent;
	for ( int i = 0; i < pChoreoScene->GetNumEvents(); ++i )
	{
		pEvent = pChoreoScene->GetEvent( i );
		FindSoundsInEvent( pEvent, g_SceneFiles[iScene].soundList );
	}

	// calc duration
	g_SceneFiles[iScene].msecs = (unsigned int)( pChoreoScene->FindStopTime() * 1000.0f + 0.5f );

	// compile to binary buffer
	g_SceneFiles[iScene].compiledBuffer.SetBigEndian( !bLittleEndian );
	pChoreoScene->SaveToBinaryBuffer( g_SceneFiles[iScene].compiledBuffer, crcSource, &g_ChoreoStringPool );

	unsigned int compressedSize;
	unsigned char *pCompressedBuffer = LZMA_Compress( (unsigned char *)g_SceneFiles[iScene].compiledBuffer.Base(), g_SceneFiles[iScene].compiledBuffer.TellMaxPut(), &compressedSize );
	if ( pCompressedBuffer )
	{
		// replace the compiled buffer with the compressed version
		g_SceneFiles[iScene].compiledBuffer.Purge();
		g_SceneFiles[iScene].compiledBuffer.EnsureCapacity( compressedSize );
		g_SceneFiles[iScene].compiledBuffer.Put( pCompressedBuffer, compressedSize );
		free( pCompressedBuffer );
	}

	delete pChoreoScene;

	return true;
}
static int sevenzip_decrypt(unsigned char *derived_key, unsigned char *data)
{
	unsigned char out[cur_salt->length];
	AES_KEY akey;
	unsigned char iv[16];
	union {
		unsigned char crcc[4];
		unsigned int crci;
	} _crc_out;
	unsigned char *crc_out = _crc_out.crcc;
	unsigned int ccrc;
	CRC32_t crc;
	int i;
	int nbytes, margin;
	memcpy(iv, cur_salt->iv, 16);

	if(AES_set_decrypt_key(derived_key, 256, &akey) < 0) {
		fprintf(stderr, "AES_set_decrypt_key failed in crypt!\n");
	}
	AES_cbc_encrypt(cur_salt->data, out, cur_salt->length, &akey, iv, AES_DECRYPT);

	/* various verifications tests */

	// test 0, padding check, bad hack :-(
	margin = nbytes = cur_salt->length - cur_salt->unpacksize;
	i = cur_salt->length - 1;
	while (nbytes > 0) {
		if (out[i] != 0)
			return -1;
		nbytes--;
		i--;
	}
	if (margin > 7) {
		// printf("valid padding test ;-)\n");
		// print_hex(out, cur_salt->length);
		return 0;
	}

	// test 1, CRC test
	CRC32_Init(&crc);
	CRC32_Update(&crc, out, cur_salt->unpacksize);
	CRC32_Final(crc_out, crc);
	ccrc =  _crc_out.crci; // computed CRC
	if (ccrc == cur_salt->crc)
		return 0;  // XXX don't be too eager!

	// XXX test 2, "well-formed folder" test
	if (validFolder(out)) {
		printf("validFolder check ;-)\n");
		return 0;
	}

	return -1;
}
Beispiel #9
0
static void charset_checksum_header(struct charset_header *header)
{
	CRC32_Update(&checksum, header->version, sizeof(header->version));
	CRC32_Update(&checksum, &header->min, 1);
	CRC32_Update(&checksum, &header->max, 1);
	CRC32_Update(&checksum, &header->length, 1);
	CRC32_Update(&checksum, &header->count, 1);
	CRC32_Update(&checksum, header->offsets, sizeof(header->offsets));
	CRC32_Update(&checksum, header->order, sizeof(header->order));
	CRC32_Final(header->check, checksum);
}
//-----------------------------------------------------------------------------
// Purpose: Helper function get get determinisitc random values for shared/prediction code
// Input  : seedvalue - 
//			*module - 
//			line - 
// Output : static int
//-----------------------------------------------------------------------------
static int SeedFileLineHash( int seedvalue, const char *sharedname, int additionalSeed )
{
	CRC32_t retval;

	CRC32_Init( &retval );

	CRC32_ProcessBuffer( &retval, (void *)&seedvalue, sizeof( int ) );
	CRC32_ProcessBuffer( &retval, (void *)&additionalSeed, sizeof( int ) );
	CRC32_ProcessBuffer( &retval, (void *)sharedname, Q_strlen( sharedname ) );
	
	CRC32_Final( &retval );

	return (int)( retval );
}
CRC32_t CShaderDLLVerification::Function1( unsigned char *pData )
{
	pData += SHADER_DLL_VERIFY_DATA_PTR_OFFSET;
	g_pLastInputData = (unsigned char*)pData;

	void *pVerifyPtr1 = &g_Blah;
	
	CRC32_t testCRC;
	CRC32_Init( &testCRC );
	CRC32_ProcessBuffer( &testCRC, pData, SHADER_DLL_VERIFY_DATA_LEN1 );
	CRC32_ProcessBuffer( &testCRC, &g_hDLLInst, 4 );
	CRC32_ProcessBuffer( &testCRC, &pVerifyPtr1, 4 );
	CRC32_Final( &testCRC );

	return testCRC;
}
//-----------------------------------------------------------------------------
// Purpose: Computes the crc for all sendtables for the data sent in the class/table definitions
// Output : CRC32_t
//-----------------------------------------------------------------------------
CRC32_t SendTable_ComputeCRC()
{
	CRC32_t result;
	CRC32_Init( &result );

	// walk the tables and checksum them
	int c = g_SendTables.Count();
	for ( int i = 0 ; i < c; i++ )
	{
		SendTable *st = g_SendTables[ i ];
		result = SendTable_CRCTable( result, st );
	}


	CRC32_Final( &result );

	return result;
}
Beispiel #13
0
unsigned short UTIL_GetAchievementEventMask( void )
{
	CRC32_t mapCRC;
	CRC32_Init( &mapCRC );

	char lowercase[ 256 ];
#ifdef CLIENT_DLL
	Q_FileBase( engine->GetLevelName(), lowercase, sizeof( lowercase ) );
#else
	Q_strncpy( lowercase, STRING( gpGlobals->mapname ), sizeof( lowercase ) );
#endif
	Q_strlower( lowercase );

	CRC32_ProcessBuffer( &mapCRC, lowercase, Q_strlen( lowercase ) );
	CRC32_Final( &mapCRC );

	return ( mapCRC & 0xFFFF );
}
Beispiel #14
0
unsigned int CPhonemeTag::ComputeDataCheckSum()
{
	CRC32_t crc;
	CRC32_Init( &crc );

	// Checksum the text
	CRC32_ProcessBuffer( &crc, m_szPhoneme, Q_strlen( m_szPhoneme ) );
	int phonemeCode = GetPhonemeCode();
	CRC32_ProcessBuffer( &crc, &phonemeCode, sizeof( int ) );

	// Checksum timestamps
	float startTime = GetStartTime();
	float endTime = GetEndTime();
	CRC32_ProcessBuffer( &crc, &startTime, sizeof( float ) );
	CRC32_ProcessBuffer( &crc, &endTime, sizeof( float ) );

	CRC32_Final( &crc );

	return ( unsigned int )crc;
}
Beispiel #15
0
		CRC32_t GetChecksum( void ) const {
			CRC32_t crc;
			CRC32_Init( &crc );

			CRC32_ProcessBuffer( &crc, &command_number, sizeof( command_number ) );
			CRC32_ProcessBuffer( &crc, &tick_count, sizeof( tick_count ) );
			CRC32_ProcessBuffer( &crc, &viewangles, sizeof( viewangles ) );
			CRC32_ProcessBuffer( &crc, &aimdirection, sizeof( aimdirection ) );
			CRC32_ProcessBuffer( &crc, &forwardmove, sizeof( forwardmove ) );
			CRC32_ProcessBuffer( &crc, &sidemove, sizeof( sidemove ) );
			CRC32_ProcessBuffer( &crc, &upmove, sizeof( upmove ) );
			CRC32_ProcessBuffer( &crc, &buttons, sizeof( buttons ) );
			CRC32_ProcessBuffer( &crc, &impulse, sizeof( impulse ) );
			CRC32_ProcessBuffer( &crc, &weaponselect, sizeof( weaponselect ) );
			CRC32_ProcessBuffer( &crc, &weaponsubtype, sizeof( weaponsubtype ) );
			CRC32_ProcessBuffer( &crc, &random_seed, sizeof( random_seed ) );
			CRC32_ProcessBuffer( &crc, &mousedx, sizeof( mousedx ) );
			CRC32_ProcessBuffer( &crc, &mousedy, sizeof( mousedy ) );

			CRC32_Final( &crc );
			return crc;
		}
unsigned int CSoundCombiner::ComputeChecksum()
{
	CRC32_t crc;
	CRC32_Init( &crc );
	
	int c = m_Work.Count();
	for ( int i = 0; i < c; ++i )
	{
		CombinerWork *curitem = m_Work[ i ];
		unsigned int chk = curitem->sentence.ComputeDataCheckSum();

	//	Msg( "  %i -> sentence %u, startoffset %f fn %s\n",
	//		i, chk, curitem->entry->startoffset, curitem->entry->wavefile );

		CRC32_ProcessBuffer( &crc, &chk, sizeof( unsigned long ) );
		CRC32_ProcessBuffer( &crc, &curitem->entry->startoffset, sizeof( float ) );
		CRC32_ProcessBuffer( &crc, curitem->entry->wavefile, Q_strlen( curitem->entry->wavefile ) );
	}

	CRC32_Final( &crc );
	return ( unsigned int )crc;
}
//-----------------------------------------------------------------------------
// Purpose: Calcs CRC of all stat data
//-----------------------------------------------------------------------------
int CTFStatPanel::CalcCRC( int iSteamID )
{
	CRC32_t crc;
	CRC32_Init( &crc );
	
	// make a CRC of stat data
	CRC32_ProcessBuffer( &crc, &iSteamID, sizeof( iSteamID ) );

	for ( int iClass = TF_FIRST_NORMAL_CLASS; iClass <= TF_LAST_NORMAL_CLASS; iClass++ )
	{
		// add each class' data to the CRC
		ClassStats_t &classStats = GetClassStats( iClass );
		CRC32_ProcessBuffer( &crc, &classStats, sizeof( classStats ) );
		// since the class data structure is highly guessable from the file, add one other thing to make the CRC hard to hack w/o code disassembly
		int iObfuscate = iClass * iClass;
		CRC32_ProcessBuffer( &crc, &iObfuscate, sizeof( iObfuscate ) );	
	}

	CRC32_Final( &crc );

	return (int) ( crc & 0x7FFFFFFF );
}
CRC32_t IFaceposerModels::CFacePoserModel::GetBitmapCRC( int sequence )
{
	CStudioHdr *hdr = m_pModel ? m_pModel->GetStudioHdr() : NULL;
	if ( !hdr )
		return (CRC32_t)-1;

	if ( sequence < 0 || sequence >= hdr->GetNumSeq() )
		return (CRC32_t)-1;

	mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( sequence );

	CRC32_t crc;
	CRC32_Init( &crc );

	// For sequences, we'll checsum a bit of data

	CRC32_ProcessBuffer( &crc, (void *)seqdesc.pszLabel(), Q_strlen( seqdesc.pszLabel() ) );
	CRC32_ProcessBuffer( &crc, (void *)seqdesc.pszActivityName(), Q_strlen( seqdesc.pszActivityName() ) );
	CRC32_ProcessBuffer( &crc, (void *)&seqdesc.flags, sizeof( seqdesc.flags ) );
	//CRC32_ProcessBuffer( &crc, (void *)&seqdesc.numevents, sizeof( seqdesc.numevents ) );
	CRC32_ProcessBuffer( &crc, (void *)&seqdesc.numblends, sizeof( seqdesc.numblends ) );
	CRC32_ProcessBuffer( &crc, (void *)seqdesc.groupsize, sizeof( seqdesc.groupsize ) );

	KeyValues *seqKeyValues = new KeyValues("");
	if ( seqKeyValues->LoadFromBuffer( m_pModel->GetFileName( ), m_pModel->GetKeyValueText( sequence ) ) )
	{
		// Yuck, but I need it in a contiguous block of memory... oh well...
		CUtlBuffer buf;
		seqKeyValues->RecursiveSaveToFile( buf, 0 );
		CRC32_ProcessBuffer( &crc, ( void * )buf.Base(), buf.TellPut() );
	}

	seqKeyValues->deleteThis();

	CRC32_Final( &crc );

	return crc;
}
Beispiel #19
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *classname - 
//			*module - 
//			line - 
// Output : static int
//-----------------------------------------------------------------------------
static int ClassFileLineHash( const char *classname, const char *module, int line )
{
	CRC32_t retval;

	CRC32_Init( &retval );

	char tempbuffer[ 512 ];
	
	// ACK, have to go lower case due to issues with .dsp having different cases of drive
	//  letters, etc.!!!
	Q_strncpy( tempbuffer, classname, sizeof( tempbuffer ) );
	Q_strlower( tempbuffer );
	CRC32_ProcessBuffer( &retval, (void *)tempbuffer, Q_strlen( tempbuffer ) );
	
	Q_strncpy( tempbuffer, module, sizeof( tempbuffer ) );
	Q_strlower( tempbuffer );
	CRC32_ProcessBuffer( &retval, (void *)tempbuffer, Q_strlen( tempbuffer ) );
	
	CRC32_ProcessBuffer( &retval, (void *)&line, sizeof( int ) );

	CRC32_Final( &retval );

	return (int)retval;
}