Click here to Skip to main content
15,886,678 members
Articles / Programming Languages / C++

Debugger support for CRC hash values

Rate me:
Please Sign up or sign in to vote.
4.36/5 (6 votes)
4 Mar 2007MIT10 min read 52.7K   421   17  
Using Expression Evaluator to convert a CRC hash value to a string in the debugger.
// The CRC class is a 4 byte CRC value of a string (ignoring case)
// If CRC_STRINGS is defined in the project's settings you can use GetStr to retrieve the text.
// In that case it will check for CRC conflicts (different strings with same CRC).
// The comparison operators compare the CRC value.
// CRC("")=0
//
// Add this to AUTOEXP.DAT
// CRC=$ADDIN(<path to the DLL>\CRCView.dll,CRCView)
//
// Copyright (C) 2005-2006 Pandemic Studios
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _CRC_H
#define _CRC_H

class CRC
{
public:
	// Constructors
	CRC( void )
	{
	}

	CRC( const CRC &x )
	{
		m_Crc=x.m_Crc;
	}

	CRC( const char *string );

	CRC( unsigned long crc )
	{
		m_Crc=crc;
	}

	// Access
	// Resolves the CRC to a string
	const char *GetStr( void ) const;

	unsigned long GetCRC( void ) const
	{
		return m_Crc;
	}

	// Compare
	bool operator==( const CRC &x ) const
	{
		return m_Crc==x.m_Crc;
	}

	bool operator!=( const CRC &x ) const
	{
		return m_Crc!=x.m_Crc;
	}

	bool operator<( const CRC &x ) const
	{
		return m_Crc<x.m_Crc;
	}

	bool operator>( const CRC &x ) const
	{
		return m_Crc>x.m_Crc;
	}

	bool operator<=( const CRC &x ) const
	{
		return m_Crc<=x.m_Crc;
	}

	bool operator>=( const CRC &x ) const
	{
		return m_Crc>=x.m_Crc;
	}

	// Appends a string to the end
	void Append( const char *string );

	// Returns true if it is an empty CRC
	bool IsEmpty( void ) const
	{
		return m_Crc==0;
	}

private:
	unsigned long m_Crc;
};

//Given a data buffer and it's size, calculates the CRC code for it.
unsigned long CalcCRC( const void *buffer, int size, unsigned long crc=0 );

//Given a string, calculates the CRC code for it, ignore case.
unsigned long CalcCRCNoCase( const char *buffer, unsigned long crc=0 );

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
United States United States
Ivo started programming in 1985 on an Apple ][ clone. He graduated from Sofia University, Bulgaria with a MSCS degree. Ivo has been working as a professional programmer for over 12 years, and as a professional game programmer for over 10. He is currently employed in Pandemic Studios, a video game company in Los Angeles, California.

Comments and Discussions