www.pudn.com > He4Hook215b6.rar > krnlstdlib.cpp


#include "krnlstdlib.h" 
 
LONG CompareStringN(PCHAR lpszString1, PCHAR lpszString2, BOOLEAN bCaseInsensitive, ULONG dwLen) 
{ 
  LONG    nRet; 
  STRING  String1, String2; 
  ULONG   dwLen1, dwLen2; 
  CHAR    cSym1, cSym2; 
 
  dwLen1 = strlen(lpszString1); 
  dwLen2 = strlen(lpszString2); 
  if (dwLen < dwLen1) 
  { 
    cSym1 = lpszString1[dwLen]; 
    lpszString1[dwLen] = 0; 
  } 
 
  if (dwLen < dwLen2) 
  { 
    cSym2 = lpszString2[dwLen]; 
    lpszString2[dwLen] = 0; 
  } 
 
  RtlInitString(&String1, lpszString1); 
  RtlInitString(&String2, lpszString2); 
 
  if (dwLen < dwLen1) 
    lpszString1[dwLen] = cSym1; 
  if (dwLen < dwLen2) 
    lpszString2[dwLen] = cSym2; 
 
  nRet = RtlCompareString(&String1, &String2, bCaseInsensitive); 
 
  return nRet; 
} 
 
LONG CompareString(PCHAR lpszString1, PCHAR lpszString2, BOOLEAN bCaseInsensitive) 
{ 
  LONG    nRet; 
  STRING  String1, String2; 
 
  RtlInitString(&String1, lpszString1); 
  RtlInitString(&String2, lpszString2); 
  nRet = RtlCompareString(&String1, &String2, bCaseInsensitive); 
 
  return nRet; 
} 
 
LONG CompareStringW(PWSTR lpszString1, PWSTR lpszString2, BOOLEAN bCaseInsensitive) 
{ 
  LONG    nRet; 
  UNICODE_STRING  String1, String2; 
 
  RtlInitUnicodeString(&String1, lpszString1); 
  RtlInitUnicodeString(&String2, lpszString2); 
  nRet = RtlCompareUnicodeString(&String1, &String2, bCaseInsensitive); 
 
  return nRet; 
} 
 
VOID ConvertToUpper(PCHAR Dest, PCHAR Source, ULONG Len) 
{ 
  ULONG   i; 
   
  for (i = 0; i < Len; ++i) 
  { 
    if (Source[i] >= 'a' && Source[i] <= 'z') 
    { 
      Dest[i] = Source[i] - 'a' + 'A'; 
    } 
    else 
    { 
      Dest[i] = Source[i]; 
    } 
  } 
} 
 
VOID ConvertToUpperW(PWSTR Dest, PWSTR Source, ULONG Len) 
{ 
  ULONG   i; 
   
  for (i = 0; i < Len; ++i) 
  { 
    if (Source[i] >= L'a' && Source[i] <= L'z') 
    { 
      Dest[i] = Source[i] - L'a' + L'A'; 
    } 
    else 
    { 
      Dest[i] = Source[i]; 
    } 
  } 
} 
 
PCHAR strncatZ(PCHAR dest, PCHAR source, int length) 
{        
  int     origlen = strlen(dest); 
 
  strncpy(dest+origlen, source, length); 
  dest[origlen+length] = 0; 
  return(dest); 
} 
 
int __strcmpi(char *lpszString1, char *lpszString2) 
{ 
  return strcmp(_strlow(lpszString1), _strlow(lpszString2)); 
} 
 
char *_strlow(char *lpszString) 
{ 
  int i, nSize = strlen(lpszString); 
 
  for (i=0; i