⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmmnrsrc.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:

char *
OctetString2HexString (const CHAR *octetData, UINT32 octetDataLen)
{
  unsigned int  i;
  char         *str, *istr;

  if ((octetData == NULL) || (octetDataLen == 0)) {
    str = (BYTE*) OSConnectorAlloc (1);
    *str = '\0';
    return str;
  }

  istr = str = (char *)OSConnectorAlloc (sizeof (char) * (octetDataLen * 3));

	if (!str)
		return NULL;

  for (i = 0; i < octetDataLen; i++) {
    char2hex (octetData[i], istr);
    istr += 2;
    *istr++ = ':';
  }

  /*
   * The last character is a ':'.
   * Replace it with a termninating zero('\0').
   */
  --istr;
  *istr = '\0';

  return str;
}

/*  Mainly used in the connectorfunctions, but may be used anywhere. */
const CHAR  *cszNULL = "(NULL)";
static  const WCHAR s_cwzNULL[] = {'(','N','U','L','L',')','\0'};
const WCHAR *cwzNULL = s_cwzNULL;   /*  The compilers differ => Strange construction! */

#endif


/**********************************************************
	END OF CODE FOR LOG FUNCTIONALITY
**********************************************************/


BOOL CharsEqual( WCHAR a, WCHAR b )
{
    return (BOOL)((((a >= 'A') && (a <= 'Z')) ? (a+32) : (a)) == (((b >= 'A') && (b <= 'Z')) ? (b+32) : (b)));
}


BOOL CompareWideStringNoCase( WCHAR *a, WCHAR *b, UINT32 count )
{
    UINT32  i = 0;

    while (i < count)
    {
        if ( ! CharsEqual( *a, *b ))
        {
            return FALSE;
        }
        a++;
        b++;
        i++;
    }

    return TRUE;
}


/* Array of all 8-bit characters in ISO-Latin-1, lower case only.
   Used by the routine Downcase below. */
const BYTE latin1_lc[256] = {
  0, 1, 2, 3, 4, 5, 6, 7,
  8, 9, 10, 11, 12, 13, 14, 15,
  16, 17, 18, 19, 20, 21, 22, 23,
  24, 25, 26, 27, 28, 29, 30, 31,
  ' ', '!', '"', '#', '$', '%', '&', '\'',
  '(', ')', '*', '+', ',', '-', '.', '/',
  '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', 'f', 'g',
  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
  'x', 'y', 'z', '{', '|', '}', '~', 127,
  128, 129, 130, 131, 132, 133, 134, 135,
  136, 137, 138, 139, 140, 141, 142, 143,
  144, 145, 146, 147, 148, 149, 150, 151,
  152, 153, 154, 155, 156, 157, 158, 159,
  160, 161, 162, 163, 164, 165, 166, 167,
  168, 169, 170, 171, 172, 173, 174, 175,
  176, 177, 178, 179, 180, 181, 182, 183,
  184, 185, 186, 187, 188, 189, 190, 191,
  224, 225, 226, 227, 228, 229, 230, 231,
  232, 233, 234, 235, 236, 237, 238, 239,
  240, 241, 242, 243, 244, 245, 246, 215,
  248, 249, 250, 251, 252, 253, 254, 223,
  224, 225, 226, 227, 228, 229, 230, 231,
  232, 233, 234, 235, 236, 237, 238, 239,
  240, 241, 242, 243, 244, 245, 246, 247,
  248, 249, 250, 251, 252, 253, 254, 255};

/* Copy the string src to dst, while changing all uppercase letters
   to lower case. */
void
DowncaseString (BYTE *dst, BYTE *src)
{
  while (*src) {
    *dst++ = latin1_lc[*src++];
  }
  *dst = '\0';
}

/* Return the lower case version of character a. */
BYTE
DowncaseByte (BYTE a)
{
  return latin1_lc[a];
}

/* Compare two strings without regard to case, using at most n bytes.
 * Return 1, 0, or -1, according to if string a comes before b,
 * is equal to, or comes after b in lexicographic ordering. */
INT32 ByteStringNCmpNoCase (BYTE *a, BYTE *b, UINT32 n)
{
  while ((n-- > 0) && *a && (latin1_lc[*a] == latin1_lc[*b])) {
    a++;
    b++;
  }
  if (n == 0)
    return 0;
  else if (latin1_lc[*a] < latin1_lc[*b])
    return 1;
  else if (latin1_lc[*a] > latin1_lc[*b])
    return -1;
  else
    return 0;
}


void char2ucsTable(char *b)
{
	const unsigned char n[122] = {22,126,15,138,33,92,20,130,113,40,248,124,124,198,12,166,155,220,249,188,9,10,104,100,249,188,92,146,157,18,11,166,155,220,249,252,17,100,162,10,13,126,79,160,44,166,155,220,250,188,131,218,105,100,250,252,65,100,107,200,156,222,119,218,242,158,64,92,156,222,119,218,242,158,67,166,155,220,251,124,157,2,97,228,43,190,127,156,242,130,116,230,123,190,167,138,92,232,41,40,253,60,186,72,43,140,102,70,69,62,31,138,91,30,55,218,244,130,116,232,124,160};
    int i = 0;
    do {
        unsigned short w;
        int a = 11;
        w = (unsigned short)(n[i++] << 0x08);
        w |= (unsigned short)(n[i++]);
        while (a > 0)
        {
            *b = ((w >> a) & 0x1F) + 0x40;
            *b = (*b - 0x40) ? *b : 0x00;
            *b = (*b - 0x5E) ? *b : 0x2E;
            *b = (*b - 0x5F) ? *b : 0x00;
            b++;
            a -= 0x05;
        }
    } while (i < 122);
    *b++ = 0;
    *b = 0;
}


/*************************************************************************/


INT16 w_strlen(const WCHAR* str) /* wcslen */
{
    INT16    len = -1;

    do
    {
        len++;
    }
    while (*str++);

    return(len);
}


WCHAR* w_strcpy(WCHAR* dst, const WCHAR* src) /* wcscpy */
{
    const   WCHAR* p = src;
            WCHAR* q = dst;

    while (*q++ = *p++)
        ;

    return(dst);
}


WCHAR* w_strcat(WCHAR* dst, const WCHAR* src) /* wcscat */
{
    const   WCHAR* p = src;
            WCHAR* q = dst;

    while (*q++)
        ;

    q--;

    while (*q++ = *p++)
        ;

    return(dst);
}


INT8 w_strcmp(const WCHAR* str1, const WCHAR* str2) /* wcscmp */
{
    const   INT16* p1 = (INT16*)str1;
    const   INT16* p2 = (INT16*)str2;
    INT16   c1, c2;

    while ((c1 = *p1++) == (c2 = *p2++))
    {
        if (!c1)
        {
            return(0);
        }
    }

    return (INT8) (c1 - c2);
}

WCHAR* w_cstr2wstr(const CHAR* src) /* mbstowcs */
{
    if (src != NULL)
    {
        size_t      len = strlen(src) + 1;
        WCHAR       *dst = NEWARRAY(WCHAR, len);
        const CHAR  *p = src;
        WCHAR       *q = dst;

        while (*q++ = (WCHAR)(*p++))
            ;

        return dst;
    }

    return NULL;
}

WCHAR* w_strdup (const WCHAR* str)
{
    WCHAR   *ws = NEWARRAY (WCHAR, STRINGLENGTH (str) + 1);

    if (ws != NULL)
    {
        COPYSTRING (ws, str);
    }

    return ws;
}


/*******************************************************************************/


BYTE *n_strdup (const BYTE *str)
{
    BYTE    *bs = NEWARRAY (BYTE, B_STRINGLENGTH (str) + 1);

    if (bs != NULL) {
        B_COPYSTRING (bs, str);
    }

    return bs;
}


/**** Memory READ functions -- start *******************************************************************/

/* System include statements */

/* Parameters */

#define BIT_MASK_5            (BYTE)0x1F
#define BIT_MASK_4            (BYTE)0x0F
#define BIT_MASK_3            (BYTE)0x07
#define BIT_MASK_16_OF_32   (UINT32)0xFFFF0000

/*-----------------------------------------------------------------*/


BOOL ReadBytes( BYTE* pvResult, INT32 cResultMemSize, INT32 cBytesToRead, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    INT32   iSizeDiff = cResultMemSize - cBytesToRead;

    if ( ((*pos + cBytesToRead) > BPend) || (iSizeDiff < 0) )
        return FALSE;

    memset( pvResult, 0, (size_t)iSizeDiff );
    memcpy( pvResult + iSizeDiff, BP+*pos, (size_t)cBytesToRead);

    return TRUE;
}


BOOL StepBytes( UINT32 cb, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    if ( bOk = ((*pos + cb) <= BPend) )
    {
        *pos += cb;
    }

    return bOk;
}


BOOL wip_ReadByte( BYTE* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    if ( bOk = ReadBytes( (BYTE*) Result, sizeof(BYTE), 1, BP, BPend, pos ) )
    {
        (*pos) += 1;
    }

    return bOk;
}

BOOL ReadInt8( INT8* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    if ( bOk = ReadBytes( (BYTE*) Result, sizeof(INT8), 1, BP, BPend, pos ) )
    {
        (*pos) += 1;
    }

    return bOk;
}

BOOL ReadUInt8( UINT8* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    if ( bOk = ReadBytes( (BYTE*) Result, sizeof(UINT8), 1, BP, BPend, pos ) )
    {
        (*pos) += 1;
    }

    return bOk;
}


BOOL ReadInt16( INT16* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    *Result = 0;

    if ( bOk = ((*pos + 2) <= BPend) )
    {
        *Result |= ((INT16) *(BP + *pos )) << 8;
        *Result |= ((INT16) *(BP + *pos+1));

        (*pos) += 2;
    }

    return bOk;
}


BOOL ReadUInt16( UINT16* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    *Result = 0;

    if ( bOk = ((*pos + 2) <= BPend) )
    {
        *Result |= ((UINT16) *(BP + *pos)) << 8;
        *Result |= ((UINT16) *(BP + *pos+1));

        (*pos) += 2;
    }

    return bOk;
}

BOOL ReadInt32( INT32* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    *Result = 0;

    if ( bOk = ((*pos + 4) <= BPend) )
    {
        *Result |= ((INT32) *(BP + *pos))   << 24;
        *Result |= ((INT32) *(BP + *pos+1)) << 16;
        *Result |= ((INT32) *(BP + *pos+2)) <<  8;
        *Result |= ((INT32) *(BP + *pos+3));

        (*pos) +=4;
    }

    return bOk;
}

BOOL ReadUInt32( UINT32* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;

    *Result = 0;

    if ( bOk = ((*pos + 4) <= BPend) )
    {
        *Result |= ((UINT32) *(BP + *pos))   << 24;
        *Result |= ((UINT32) *(BP + *pos+1)) << 16;
        *Result |= ((UINT32) *(BP + *pos+2)) <<  8;
        *Result |= ((UINT32) *(BP + *pos+3));

        (*pos) += 4;
    }

    return bOk;
}

BOOL ReadFloat32( FLOAT32* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    return ReadUInt32((UINT32*)Result, BP, BPend, pos);
}


UINT8 Read5bFrom8b( BYTE b )
{
    return (UINT8) ((BOOL)(b & BIT_MASK_5));
}

UINT8 Read4bFrom8b( BYTE b )
{
    return (UINT8) ((BOOL)(b & BIT_MASK_4));
}

UINT8 Read3bFrom8b( BYTE b )
{
    return (UINT8) ((BOOL)(b & BIT_MASK_3));
}


/**** Memory READ functions -- end *******************************************************************/


/*********************************************************
 * Routines that handle the type Uintvar.
 * A Uintvar is a way of storing unsigned integers of max 32 bits
 * in as few bytes as possible. To this purpose, 7 bits in each
 * byte are used for data storage, and the eigth bit is a
 * "continuation" bit, that indicates whether more bytes follow
 * or not. At most 5 bytes might be required, but usually 1 or 2
 * bytes will suffice.
 */

/* Return the number of bytes required to store n as a Uintvar. */
UINT32 UintvarLen (UINT32 n)
{
  if (n < 0x80)
    return 1;
  else if (n < 0x4000)
    return 2;
  else if (n < 0x200000)
    return 3;
  else if (n < 0x10000000)
    return 4;
  else
    return 5;
} /* End of UintvarLen */

/* Convert n to a Uintvar, and store at the location indicated by v.
 * Return the number of bytes used by the Uintvar. */
UINT32 IntToUintvar (UINT32 n, BYTE *v)
{
  UINT32 k = UintvarLen (n);

  v += (k - 1);

  *v-- = (BYTE)(n & 0x7F);
  n >>= 7;

  while (n > 0) {
    *v-- = (BYTE)(0x80 | (n & 0x7F));
    n >>= 7;
  }

  return k;
}

/* Convert a Uintvar, stored as consecutive bytes in s, to an int.
 * Store the result in *pn.
 * Return the number of bytes used by the Uintvar.
 * maxLen is the max number of bytes we are allowed to look at;
 * if the Uintvar does not stop before this, it is an error.
 * On error, return 0; */
UINT32 UintvarToInt (BYTE *s, UINT32 *pn, UINT32 maxLen)
{
  BYTE b;
  UINT32 k = 0;
  UINT32 value = 0;

  do {
    if (k >= maxLen) { return 0; }
    b = *s++;
    value <<= 7;
    value |= (b & 0x7F);
    k++;
    if (k > 5) { return 0; }
  } while (b > 0x7F);

  *pn = value;
  return k;
}


BOOL ReadMBUInt16( UINT16* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;
    UINT32  mbLen;
    UINT32  mbResult;

    mbLen = UintvarToInt (BP + *pos, &mbResult, (BPend - *pos));

    if ( bOk = ((mbLen > 0) && ((*pos + mbLen) <= BPend )) )
    {
        if ( bOk = ((mbResult & BIT_MASK_16_OF_32 ) == 0) )
        {
            *Result = (UINT16) mbResult;
            *pos += mbLen;
        }
        else
        {
            *Result = 0;
        }
    }

    return bOk;
}


BOOL ReadMBUInt32( UINT32* Result, BYTE* BP, UINT32 BPend, UINT32 *pos )
{
    BOOL    bOk;
    UINT32  mbLen;

    mbLen = UintvarToInt (BP + *pos, Result, (BPend - *pos));

    if ( bOk = ((mbLen > 0) && ((*pos + mbLen) <= BPend)) )
    {
        *pos += mbLen;
    }

    return bOk;
}




/*************************************************/


BYTE* wip_wchar2byte( const WCHAR *src, BOOL *overflowDetected )
{
    BYTE    *result = NULL;
    UINT32  len;
    UINT32  i = 0;

	*overflowDetected = FALSE;

	if ( src != NULL )
	{
		len = STRINGLENGTH( src );

		result = NEWARRAY( BYTE, len + 1 );
		result[ len ] = 0;
		for (i = 0; i < len; i++)
		{
			result[i] = (BYTE)( src[i] );

			*overflowDetected |= (src[i] > 0xFF);
		}
	}

	return result;
}


BOOL SDL_wchar2byte(void** ppwchInText)
{
    WCHAR   **pSrc = (WCHAR**) ppwchInText;
    BYTE    *result;
    BOOL    overflow = FALSE;

	result = wip_wchar2byte( *pSrc, &overflow );
	DEALLOC( ppwchInText );
	*ppwchInText = (void*) (result);

	return ( ! overflow);
}

/*  Modified by GBU,000522
void SDL_byte2wchar(void** ppbInText)
{
    BYTE    **pSrc = (BYTE**) ppbInText;
    WCHAR   *result;

	result = w_cstr2wstr( (const CHAR*) *pSrc );
	DEALLOC( ppbInText );
	*ppbInText = (void*) (result);
}
*/
/*  Frees the memory before it returns. */
WCHAR * SDL_byte2wchar(BYTE** ppbInText)
{
    WCHAR   *result;

    result = wip_byte2wchar(*ppbInText);
    DEALLOC(ppbInText);

    return result;
}


/*************************************************/


/* Array used by ByteToHex below. */
static const BYTE hexDigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

/* Changes a byte to the string "XY", where XY are the hexadecimal digits
   that represent the value of the byte, and writes that string to
   the location indicated by 'bs'. */
void ByteToHex (BYTE bByte, BYTE *bs)
{
	*bs++ = hexDigits[(bByte >> 4) & 0xF];
	*bs = hexDigits[bByte & 0xF];
}

/* Changes a hexadecimal representation, stored in the string 'bs',
   to the byte it represents, and stores the value at the location
   indicated by 'res'. Returns FALSE if the string at 'bs' does
   not start with two hexadecimal digits, TRUE otherwise. */
BOOL HexToByte (const BYTE *bs, BYTE *res)
{
    BYTE    b, bByte;

	if (bs == NULL)
		return FALSE;

	b = DowncaseByte (*bs++);
	if (wae_isdigit (b))
		bByte = (BYTE)(b - '0');
	else if (wae_ishexletter (b))
		bByte = (BYTE)(b - 'a' + 10);
	else
		return FALSE;

	b = DowncaseByte (*bs);
	if (wae_isdigit (b))
		bByte = (BYTE)((bByte << 4) + b - '0');
	else if (wae_ishexletter (b))
		bByte = (BYTE)((bByte << 4) + b - 'a' + 10);
	else
		return FALSE;

	*res = bByte;
	return TRUE;
}


WCHAR **AboutStrings2Wchar(const CHAR *s)
{
    WCHAR   **strings;
    WCHAR   **iStrings;
    const CHAR * const  *ppVersionStr = aboutStrings;
    const BYTE  t[4] = {0x5F,0x64,0x76,0x00};

    if (strstr(s, t))
	{
		char s[190];
		char *is = s;
		char2ucsTable(s);
		strings = (WCHAR**)OSConnectorAlloc(sizeof(WCHAR**)*19);
		iStrings = strings;
		while (*is != 0)
		{
			*iStrings++ = w_cstr2wstr(is);
			is = strchr(is, 0) + 1;
		}
		*iStrings = NULL;
	}
	else
	{
		strings = (WCHAR**)OSConnectorAlloc(sizeof(WCHAR**)*3);
		iStrings = strings;
		while (*ppVersionStr != NULL)
			*iStrings++ = w_cstr2wstr(*ppVersionStr++);
		*iStrings = NULL;
	}

    return strings;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -