📄 hxinfcod.cpp
字号:
if (nBitLenActual==nBitLen)
{
bRetVal = this->DecodeObj(Buffer, nBitLen, pObj);
}
delete [] Buffer;
return bRetVal;
}
/////////////////////////////////////////////////////////////////////
BOOL CHXInfoDecoder::HexDecodeObj(const char* szHex, IHXStreamableObj* pObj)
{
if (szHex)
{
return this->HexDecodeObj(szHex,strlen(szHex),pObj);
}
return(FALSE);
}
/////////////////////////////////////////////////////////////////////
BOOL CHXInfoDecoder::HexDecodeObj(const char* szHex, UINT32 nHexLen, IHXStreamableObj* pObj)
{
UINT32 nBitLen = nHexLen>>1; // unhexed length is 1/2 of hex'd length
UCHAR* Buffer=new UCHAR[nBitLen];
HX_ASSERT(Buffer!=NULL);
if (Buffer==NULL) return(FALSE);
UINT32 nBitLenActual = CHXInfoDecoder::SetFromHex(szHex, Buffer, nHexLen);
BOOL bRetVal = FALSE;
if (nBitLenActual==nBitLen)
{
bRetVal = this->DecodeObj(Buffer,nBitLen,pObj);
}
delete [] Buffer;
return bRetVal;
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadObj(IHXStreamableObj* pObj)
{
UINT32 nLen=this->GetOffset();
if (pObj->ReadObjFromBits(this)==HXR_OK)
return this->GetOffset()-nLen;
#if 0
// reading object
this->Seek(nLen);
#endif
return(0);
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadUCHAR(UCHAR& nValue)
{
UCHAR temp;
memcpy(&temp, m_Buffer+m_nOffset, sizeof(temp)); /* Flawfinder: ignore */
nValue = temp;
m_nOffset += sizeof(temp);
return sizeof(temp);
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadUINT16(UINT16& nValue)
{
UINT16 temp16;
memcpy(&temp16, m_Buffer+m_nOffset, sizeof(temp16)); /* Flawfinder: ignore */
nValue = WToHost(temp16);
m_nOffset += sizeof(temp16);
return sizeof(temp16);
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadUINT32(UINT32& nValue)
{
UINT32 temp32;
memcpy(&temp32, m_Buffer+m_nOffset, sizeof(temp32)); /* Flawfinder: ignore */
nValue = DwToHost(temp32);
m_nOffset += sizeof(temp32);
return sizeof(temp32);
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadString(CHXString& strValue)
{
UINT32 FieldLen = *(m_Buffer+m_nOffset++);
char* pBuffer = strValue.GetBuffer((int)FieldLen);
memcpy(pBuffer, m_Buffer+m_nOffset, (int)FieldLen); /* Flawfinder: ignore */
pBuffer[FieldLen] = '\0';
strValue.ReleaseBuffer();
m_nOffset += FieldLen;
return FieldLen+1;
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadAndAllocCString(char*& pszValue)
{
UINT32 FieldLen = *(m_Buffer+m_nOffset++);
pszValue = new char[FieldLen+1];
memcpy(pszValue, m_Buffer+m_nOffset, (int)FieldLen); /* Flawfinder: ignore */
pszValue[FieldLen] = '\0';
m_nOffset += FieldLen;
return FieldLen+1;
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadLargeString(CHXString& strValue)
{
UINT16 FieldLen = 0;
UINT32 nSize = ReadUINT16(FieldLen);
char* pBuffer = strValue.GetBuffer(FieldLen);
memcpy(pBuffer, m_Buffer+m_nOffset, FieldLen); /* Flawfinder: ignore */
pBuffer[FieldLen] = '\0';
strValue.ReleaseBuffer();
m_nOffset += FieldLen;
return nSize+FieldLen;
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadAndAllocLargeCString(char*& pszValue)
{
UINT16 FieldLen = 0;
UINT32 nSize = ReadUINT16(FieldLen);
pszValue = new char[FieldLen+1];
memcpy(pszValue, m_Buffer+m_nOffset, FieldLen); /* Flawfinder: ignore */
pszValue[FieldLen] = '\0';
m_nOffset += FieldLen;
return nSize+FieldLen;
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadBuffer(char* szBuffer, UINT32 nSize)
{
memcpy(szBuffer, m_Buffer+m_nOffset, (int)nSize); /* Flawfinder: ignore */
m_nOffset += nSize;
return nSize;
}
#if 0
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(UINT32) CHXInfoDecoder::ReadUTCTime(UTCTimeRep& TimeRep)
{
UINT32 time, nSize;
nSize = ReadUINT32(time);
TimeRep.SetUTCTime(time);
return(nSize);
}
#endif
/////////////////////////////////////////////////////////////////////
STDMETHODIMP CHXInfoDecoder::Seek(UINT32 nPos)
{
if (nPos<=m_nDecodedLen)
{
m_nOffset = nPos;
}
return(HXR_OK);
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP CHXInfoDecoder::SkipForward(UINT32 nAmount)
{
m_nOffset += nAmount;
if (m_nOffset>m_nDecodedLen)
{
m_nOffset = m_nDecodedLen;
}
return(HXR_OK);
}
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(BOOL) CHXInfoDecoder::IsEndOfData()
{
if (m_nDecodedLen<Perplex_ALIGNMENT)
{
return(TRUE);
}
if (m_nOffset>(m_nDecodedLen-Perplex_ALIGNMENT))
return(TRUE);
else
return(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// FromHexNibble()
//
// Purpose:
//
//
// Parameters:
//
// char hexChar
// Character representing a hex encoding of a nibble.
//
// Return:
//
// UCHAR
// Actual value of the nibble encoded by hexChar.
//
UCHAR CHXInfoDecoder::FromHexNibble(char hexChar)
{
UCHAR value = 0;
if (hexChar >= '0' && hexChar <= '9')
{
value = hexChar - '0';
}
else if (hexChar >= 'A' && hexChar <= 'F')
{
value = hexChar - 'A' + 10;
}
else if (hexChar >= 'a' && hexChar <= 'f')
{
value = hexChar - 'a' + 10;
}
#ifdef _DEBUG
else
{
// Bad hex character!
HX_ASSERT(FALSE);
}
#endif
return value;
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// HXClientLicense::SetFromHex()
//
// Purpose:
//
// Sets items of the license key from a hexidecimal encoding of the
// license key bits.
//
// Parameters:
//
// const char* hex
// Pointer to a buffer that contains a hexidecimal encoding of the
// license key.
//
// UCHAR* Bits
// Pointer to a buffer that will be filled on output with a bitwise
// decoding of the license key.
//
// UINT32 nSize
// Size of the hex string on input
//
// Return:
//
// int
// Size in bytes of decoded size!
//
// Note:
//
// Hex representations of the License Key consist of the
// representation of the bits in human readable form in a
// HEX encoding. This basically uses a pointer to a memory
// buffer of charcters encoded as hex representing the bits.
// Valid characters are 0-9,A-F. Buffers out will be upper
// case letters, buffers in will be converted to upper case.
//
// These char's are hex encoding. They are never DBCS, the only
// valid characters are 0-9,A-F
//
UINT32 CHXInfoDecoder::SetFromHex(const char* hex, UCHAR* Bits, UINT32 nSize)
{
UINT32 ndxBits;
UINT32 ndxHex = 0;
UCHAR nibble1;
UCHAR nibble2;
UCHAR byte;
for (ndxBits = 0; ndxHex < nSize; ndxBits++)
{
nibble1 = FromHexNibble(hex[ndxHex]);
nibble1 = nibble1 << 4;
ndxHex++;
nibble2 = FromHexNibble(hex[ndxHex]);
byte = nibble1 | nibble2;
ndxHex++;
Bits[ndxBits] = byte;
}
return ndxBits;
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// ToHexNibble()
//
// Purpose:
//
// Converts a nibble into the appropriate character for Hex encoding.
//
// Parameters:
//
// UCHAR hexValue
// Value of the nibble.
//
// Return:
//
// char
// Character representing the hex encoding of the nibble.
//
char CHXInfoEncoder::ToHexNibble(UCHAR hexValue)
{
char hexChar = '0';
if (hexValue <= 0x9)
{
hexChar = '0' + hexValue;
}
else if (hexValue >= 0xA && hexValue <= 0xF)
{
hexChar = 'A' + (hexValue - 10);
}
#ifdef _DEBUG
else
{
// Bad hex character!
HX_ASSERT(FALSE);
}
#endif
return hexChar;
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// DumpToHex()
//
// Purpose:
//
// Formats the license key in human readable hexadecimal encoding.
//
// Parameters:
//
// char* hex
// Pointer to buffer to be filled with hexadecimal encoding of
// license key
//
// Return:
//
// None.
//
void CHXInfoEncoder::DumpToHex(char* hex, UCHAR* Bits, UINT32 nSize)
{
UINT32 ndxBits;
UINT32 ndxHex = 0;
UCHAR nibble1;
UCHAR nibble2;
UCHAR byte;
for (ndxBits = 0; ndxBits < nSize; ndxBits++)
{
byte = Bits[ndxBits];
nibble1 = (byte & 0xF0) >> 4;
nibble2 = (byte & 0x0F);
hex[ndxHex] = ToHexNibble(nibble1);
ndxHex++;
hex[ndxHex] = ToHexNibble(nibble2);
ndxHex++;
}
hex[ndxHex] = '\0';
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// MapFromPerplex()
//
// Purpose:
//
// Converts appropriate characters for Perplex encoding into a ULONG32.
//
#ifdef _WIN16
extern char* zPerplexChars;
#else
// A copy of this is kept in in pnmisc\pub\win\pnmisc16.h. If you change
// this (which is very unlikely), then be sure to change it there.
static const char zPerplexChars[] =
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
'E'
};
static const char zDePerplexMap[] =
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,
0,36,37,38,39,40,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
#endif /* _WIN16 */
UCHAR CHXInfoDecoder::MapFromPerplex(char Perplex)
{
return zDePerplexMap[Perplex];
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// MapToPerplex()
//
// Purpose:
//
// Converts a digit ordinal to the Perplex digit...
//
char CHXInfoEncoder::MapToPerplex(UCHAR Perplex)
{
#ifdef _DEBUG
#ifndef _WIN16
// On win16, zPerplexChars is a char *, rather than an array, so this
// doesn't work.
int size_zPerplexChars = sizeof(zPerplexChars);
int size_zPerplexChars0 = sizeof(zPerplexChars[0]);
HX_ASSERT(Perplex < size_zPerplexChars/size_zPerplexChars0);
#endif
#endif
return zPerplexChars[Perplex];
}
/////////////////////////////////////////////////////////////////////////////
//
// Function:
//
// FromPerplex()
//
// Purpose:
//
// Converts appropriate characters for Perplex encoding into a ULONG32.
//
ULONG32 CHXInfoDecoder::FromPerplex(const char* Perplex)
{
ULONG32 value = 0;
ULONG32 PerplexBase = 1;
for (int n = 0; n < Perplex_PER_ULONG32; n++)
{
value += MapFromPerplex(Perplex[n]) * PerplexBase;
PerplexBase *= Perplex_BASE;
}
// Convert to local byte order!
value = DwToHost(value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -