TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Common.cpp File Reference
#include "../CascLib.h"
#include "../CascCommon.h"
+ Include dependency graph for Common.cpp:

Macros

#define __CASCLIB_SELF__
 
#define STKSIZ   (8*sizeof(void*) - 2)
 
#define SWAP_ENTRIES(index1, index2)
 

Functions

int GetLastError ()
 
void SetLastError (int nError)
 
void CopyString (char *szTarget, const char *szSource, size_t cchLength)
 
void CopyString (wchar_t *szTarget, const char *szSource, size_t cchLength)
 
void CopyString (char *szTarget, const wchar_t *szSource, size_t cchLength)
 
char * CascNewStr (const char *szString, size_t nCharsToReserve)
 
wchar_t * CascNewStr (const wchar_t *szString, size_t nCharsToReserve)
 
TCHARCascNewStrFromAnsi (const char *szBegin, const char *szEnd)
 
TCHARCombinePath (const TCHAR *szDirectory, const TCHAR *szSubDir)
 
TCHARCombinePathAndString (const TCHAR *szPath, const char *szString, size_t nLength)
 
size_t NormalizeFileName (const unsigned char *NormTable, char *szNormName, const char *szFileName, size_t cchMaxChars)
 
size_t NormalizeFileName_UpperBkSlash (char *szNormName, const char *szFileName, size_t cchMaxChars)
 
size_t NormalizeFileName_LowerSlash (char *szNormName, const char *szFileName, size_t cchMaxChars)
 
ULONGLONG CalcFileNameHash (const char *szFileName)
 
int ConvertDigitToInt32 (const TCHAR *szString, PDWORD PtrValue)
 
int ConvertStringToInt08 (const char *szString, PDWORD PtrValue)
 
int ConvertStringToInt32 (const TCHAR *szString, size_t nMaxDigits, PDWORD PtrValue)
 
int ConvertStringToBinary (const char *szString, size_t nMaxDigits, LPBYTE pbBinary)
 
char * StringFromBinary (LPBYTE pbBinary, size_t cbBinary, char *szBuffer)
 
char * StringFromMD5 (LPBYTE md5, char *szBuffer)
 
const wchar_t * GetPlainFileName (const wchar_t *szFileName)
 
const char * GetPlainFileName (const char *szFileName)
 
bool CheckWildCard (const char *szString, const char *szWildCard)
 
bool IsValidMD5 (LPBYTE pbMd5)
 
bool VerifyDataBlockHash (void *pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5)
 
void CalculateDataBlockHash (void *pvDataBlock, DWORD cbDataBlock, LPBYTE md5_hash)
 
void qsort_pointer_array (void **base, size_t num, int(*compare)(const void *, const void *, const void *), const void *context)
 

Variables

unsigned char AsciiToLowerTable_Slash [256]
 
unsigned char AsciiToUpperTable_BkSlash [256]
 
unsigned char IntToHexChar [] = "0123456789abcdef"
 
static int nLastError = ERROR_SUCCESS
 

Macro Definition Documentation

#define __CASCLIB_SELF__
#define STKSIZ   (8*sizeof(void*) - 2)
#define SWAP_ENTRIES (   index1,
  index2 
)
Value:
{ \
temp = base[index1]; \
base[index1] = base[index2]; \
base[index2] = temp; \
}

Function Documentation

ULONGLONG CalcFileNameHash ( const char *  szFileName)
261 {
262  char szNormName[MAX_PATH+1];
263  uint32_t dwHashHigh = 0;
264  uint32_t dwHashLow = 0;
265  size_t nLength;
266 
267  // Normalize the file name - convert to uppercase, slashes to backslashes
268  nLength = NormalizeFileName_UpperBkSlash(szNormName, szFileName, MAX_PATH);
269 
270  // Calculate the HASH value of the normalized file name
271  hashlittle2(szNormName, nLength, &dwHashHigh, &dwHashLow);
272  return ((ULONGLONG)dwHashHigh << 0x20) | dwHashLow;
273 }
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
unsigned long long ULONGLONG
Definition: CascPort.h:144
#define MAX_PATH
Definition: CascPort.h:160
unsigned int uint32_t
Definition: stdint.h:80
size_t NormalizeFileName_UpperBkSlash(char *szNormName, const char *szFileName, size_t cchMaxChars)
Definition: Common.cpp:250

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CalculateDataBlockHash ( void *  pvDataBlock,
DWORD  cbDataBlock,
LPBYTE  md5_hash 
)
513 {
514  hash_state md5_state;
515 
516  md5_init(&md5_state);
517  md5_process(&md5_state, (unsigned char *)pvDataBlock, cbDataBlock);
518  md5_done(&md5_state, md5_hash);
519 }
static void md5_process(md5_state_t *pms, const md5_byte_t *data)
Definition: Crypto_md5.cpp:220
static void md5_init(md5_state_t *pms)
Definition: Crypto_md5.cpp:401
Definition: tomcrypt_hash.h:105

+ Here is the call graph for this function:

char* CascNewStr ( const char *  szString,
size_t  nCharsToReserve 
)
103 {
104  char * szNewString = NULL;
105  size_t nLength;
106 
107  if(szString != NULL)
108  {
109  nLength = strlen(szString);
110  szNewString = CASC_ALLOC(char, nLength + nCharsToReserve + 1);
111  if(szNewString != NULL)
112  {
113  memcpy(szNewString, szString, nLength);
114  szNewString[nLength] = 0;
115  }
116  }
117 
118  return szNewString;
119 }
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

wchar_t* CascNewStr ( const wchar_t *  szString,
size_t  nCharsToReserve 
)
122 {
123  wchar_t * szNewString = NULL;
124  size_t nLength;
125 
126  if(szString != NULL)
127  {
128  nLength = wcslen(szString);
129  szNewString = CASC_ALLOC(wchar_t, nLength + nCharsToReserve + 1);
130  if(szNewString != NULL)
131  {
132  memcpy(szNewString, szString, nLength * sizeof(wchar_t));
133  szNewString[nLength] = 0;
134  }
135  }
136 
137  return szNewString;
138 }
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
arena_t NULL
Definition: jemalloc_internal.h:624
TCHAR* CascNewStrFromAnsi ( const char *  szBegin,
const char *  szEnd 
)
141 {
142  TCHAR * szNewString = NULL;
143 
144  // Only if the entry is valid
145  if(szBegin != NULL && szEnd > szBegin)
146  {
147  // Allocate and copy the string
148  szNewString = CASC_ALLOC(TCHAR, (szEnd - szBegin + 1));
149  if(szNewString != NULL)
150  CopyString(szNewString, szBegin, (szEnd - szBegin));
151  }
152 
153  // Return the string
154  return szNewString;
155 }
void CopyString(char *szTarget, const char *szSource, size_t cchLength)
Definition: Common.cpp:84
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CheckWildCard ( const char *  szString,
const char *  szWildCard 
)
427 {
428  const char * szWildCardPtr;
429 
430  for(;;)
431  {
432  // If there is '?' in the wildcard, we skip one char
433  while(szWildCard[0] == '?')
434  {
435  if(szString[0] == 0)
436  return false;
437 
438  szWildCard++;
439  szString++;
440  }
441 
442  // Handle '*'
443  szWildCardPtr = szWildCard;
444  if(szWildCardPtr[0] != 0)
445  {
446  if(szWildCardPtr[0] == '*')
447  {
448  szWildCardPtr++;
449 
450  if(szWildCardPtr[0] == '*')
451  continue;
452 
453  if(szWildCardPtr[0] == 0)
454  return true;
455 
456  if(AsciiToUpperTable_BkSlash[szWildCardPtr[0]] == AsciiToUpperTable_BkSlash[szString[0]])
457  {
458  if(CheckWildCard(szString, szWildCardPtr))
459  return true;
460  }
461  }
462  else
463  {
464  if(AsciiToUpperTable_BkSlash[szWildCardPtr[0]] != AsciiToUpperTable_BkSlash[szString[0]])
465  return false;
466 
467  szWildCard = szWildCardPtr + 1;
468  }
469 
470  if(szString[0] == 0)
471  return false;
472  szString++;
473  }
474  else
475  {
476  return (szString[0] == 0) ? true : false;
477  }
478  }
479 }
bool CheckWildCard(const char *szString, const char *szWildCard)
Definition: Common.cpp:426
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TCHAR* CombinePath ( const TCHAR szDirectory,
const TCHAR szSubDir 
)
158 {
159  TCHAR * szFullPath = NULL;
160  TCHAR * szPathPtr;
161  size_t nLength1 = 0;
162  size_t nLength2 = 0;
163 
164  // Calculate lengths of each part
165  if(szDirectory != NULL)
166  {
167  // Get the length of the directory
168  nLength1 = _tcslen(szDirectory);
169 
170  // Cut all ending backslashes
171  while(nLength1 > 0 && szDirectory[nLength1 - 1] == _T(PATH_SEPARATOR))
172  nLength1--;
173  }
174 
175  if(szSubDir != NULL)
176  {
177  // Cut all leading backslashes
178  while(szSubDir[0] == _T(PATH_SEPARATOR))
179  szSubDir++;
180 
181  // Get the length of the subdir
182  nLength2 = _tcslen(szSubDir);
183 
184  // Cut all ending backslashes
185  while(nLength2 > 0 && szSubDir[nLength2 - 1] == _T(PATH_SEPARATOR))
186  nLength2--;
187  }
188 
189  // Allocate space for the full path
190  szFullPath = szPathPtr = CASC_ALLOC(TCHAR, nLength1 + nLength2 + 2);
191  if(szFullPath != NULL)
192  {
193  // Copy the directory
194  if(szDirectory != NULL && nLength1 != 0)
195  {
196  memcpy(szPathPtr, szDirectory, (nLength1 * sizeof(TCHAR)));
197  szPathPtr += nLength1;
198  }
199 
200  // Copy the sub-directory
201  if(szSubDir != NULL && nLength2 != 0)
202  {
203  // Append backslash to the previous one
204  if(szPathPtr > szFullPath)
205  *szPathPtr++ = _T(PATH_SEPARATOR);
206 
207  // Copy the string
208  memcpy(szPathPtr, szSubDir, (nLength2 * sizeof(TCHAR)));
209  szPathPtr += nLength2;
210  }
211 
212  // Terminate the string
213  szPathPtr[0] = 0;
214  }
215 
216  return szFullPath;
217 }
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
#define PATH_SEPARATOR
Definition: CascPort.h:115
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148
#define _T(x)
Definition: CascPort.h:171
#define _tcslen
Definition: CascPort.h:172

+ Here is the caller graph for this function:

TCHAR* CombinePathAndString ( const TCHAR szPath,
const char *  szString,
size_t  nLength 
)
220 {
221  TCHAR * szFullPath = NULL;
222  TCHAR * szSubDir;
223 
224  // Create the subdir string
225  szSubDir = CASC_ALLOC(TCHAR, nLength + 1);
226  if(szSubDir != NULL)
227  {
228  CopyString(szSubDir, szString, nLength);
229  szFullPath = CombinePath(szPath, szSubDir);
230  CASC_FREE(szSubDir);
231  }
232 
233  return szFullPath;
234 }
void CopyString(char *szTarget, const char *szSource, size_t cchLength)
Definition: Common.cpp:84
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
TCHAR * CombinePath(const TCHAR *szDirectory, const TCHAR *szSubDir)
Definition: Common.cpp:157

+ Here is the call graph for this function:

int ConvertDigitToInt32 ( const TCHAR szString,
PDWORD  PtrValue 
)
276 {
277  BYTE Digit;
278 
279  Digit = (BYTE)(AsciiToUpperTable_BkSlash[szString[0]] - _T('0'));
280  if(Digit > 9)
281  Digit -= 'A' - '9' - 1;
282 
283  PtrValue[0] = Digit;
284  return (Digit > 0x0F) ? ERROR_BAD_FORMAT : ERROR_SUCCESS;
285 }
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
#define _T(x)
Definition: CascPort.h:171
#define ERROR_BAD_FORMAT
Definition: CascPort.h:214
unsigned char BYTE
Definition: CascPort.h:136
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the caller graph for this function:

int ConvertStringToBinary ( const char *  szString,
size_t  nMaxDigits,
LPBYTE  pbBinary 
)
342 {
343  const char * szStringEnd = szString + nMaxDigits;
344  DWORD dwCounter = 0;
345  BYTE DigitValue;
346  BYTE ByteValue = 0;
347 
348  // Convert the string
349  while(szString < szStringEnd)
350  {
351  // Retrieve the digit converted to hexa
352  DigitValue = (BYTE)(AsciiToUpperTable_BkSlash[szString[0]] - '0');
353  if(DigitValue > 9)
354  DigitValue -= 'A' - '9' - 1;
355  if(DigitValue > 0x0F)
356  return ERROR_BAD_FORMAT;
357 
358  // Insert the digit to the binary buffer
359  ByteValue = (ByteValue << 0x04) | DigitValue;
360  dwCounter++;
361 
362  // If we reached the second digit, it means that we need
363  // to flush the byte value and move on
364  if((dwCounter & 0x01) == 0)
365  *pbBinary++ = ByteValue;
366  szString++;
367  }
368 
369  return ERROR_SUCCESS;
370 }
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
unsigned int DWORD
Definition: CascPort.h:139
#define ERROR_BAD_FORMAT
Definition: CascPort.h:214
unsigned char BYTE
Definition: CascPort.h:136
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the caller graph for this function:

int ConvertStringToInt08 ( const char *  szString,
PDWORD  PtrValue 
)
288 {
289  BYTE DigitOne = AsciiToUpperTable_BkSlash[szString[0]] - '0';
290  BYTE DigitTwo = AsciiToUpperTable_BkSlash[szString[1]] - '0';
291 
292  // Fix the digits
293  if(DigitOne > 9)
294  DigitOne -= 'A' - '9' - 1;
295  if(DigitTwo > 9)
296  DigitTwo -= 'A' - '9' - 1;
297 
298  // Combine them into a value
299  PtrValue[0] = (DigitOne << 0x04) | DigitTwo;
300  return (DigitOne <= 0x0F && DigitTwo <= 0x0F) ? ERROR_SUCCESS : ERROR_BAD_FORMAT;
301 }
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
#define ERROR_BAD_FORMAT
Definition: CascPort.h:214
unsigned char BYTE
Definition: CascPort.h:136
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the caller graph for this function:

int ConvertStringToInt32 ( const TCHAR szString,
size_t  nMaxDigits,
PDWORD  PtrValue 
)
304 {
305  // The number of digits must be even
306  assert((nMaxDigits & 0x01) == 0);
307  assert(nMaxDigits <= 8);
308 
309  // Prepare the variables
310  PtrValue[0] = 0;
311  nMaxDigits >>= 1;
312 
313  // Convert the string up to the number of digits
314  for(size_t i = 0; i < nMaxDigits; i++)
315  {
316  BYTE DigitOne;
317  BYTE DigitTwo;
318 
319  DigitOne = (BYTE)(AsciiToUpperTable_BkSlash[szString[0]] - _T('0'));
320  if(DigitOne > 9)
321  DigitOne -= 'A' - '9' - 1;
322 
323  DigitTwo = (BYTE)(AsciiToUpperTable_BkSlash[szString[1]] - _T('0'));
324  if(DigitTwo > 9)
325  DigitTwo -= 'A' - '9' - 1;
326 
327  if(DigitOne > 0x0F || DigitTwo > 0x0F)
328  return ERROR_BAD_FORMAT;
329 
330  PtrValue[0] = (PtrValue[0] << 0x08) | (DigitOne << 0x04) | DigitTwo;
331  szString += 2;
332  }
333 
334  return ERROR_SUCCESS;
335 }
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
#define _T(x)
Definition: CascPort.h:171
#define ERROR_BAD_FORMAT
Definition: CascPort.h:214
unsigned char BYTE
Definition: CascPort.h:136
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the caller graph for this function:

void CopyString ( char *  szTarget,
const char *  szSource,
size_t  cchLength 
)
85 {
86  memcpy(szTarget, szSource, cchLength);
87  szTarget[cchLength] = 0;
88 }

+ Here is the caller graph for this function:

void CopyString ( wchar_t *  szTarget,
const char *  szSource,
size_t  cchLength 
)
91 {
92  mbstowcs(szTarget, szSource, cchLength);
93  szTarget[cchLength] = 0;
94 }
void CopyString ( char *  szTarget,
const wchar_t *  szSource,
size_t  cchLength 
)
97 {
98  wcstombs(szTarget, szSource, cchLength);
99  szTarget[cchLength] = 0;
100 }
int GetLastError ( )
71 {
72  return nLastError;
73 }
static int nLastError
Definition: Common.cpp:68

+ Here is the caller graph for this function:

const wchar_t* GetPlainFileName ( const wchar_t *  szFileName)
399 {
400  const wchar_t * szPlainName = szFileName;
401 
402  while(*szFileName != 0)
403  {
404  if(*szFileName == '\\' || *szFileName == '/')
405  szPlainName = szFileName + 1;
406  szFileName++;
407  }
408 
409  return szPlainName;
410 }

+ Here is the caller graph for this function:

const char* GetPlainFileName ( const char *  szFileName)
413 {
414  const char * szPlainName = szFileName;
415 
416  while(*szFileName != 0)
417  {
418  if(*szFileName == '\\' || *szFileName == '/')
419  szPlainName = szFileName + 1;
420  szFileName++;
421  }
422 
423  return szPlainName;
424 }
bool IsValidMD5 ( LPBYTE  pbMd5)
485 {
486  BYTE BitSummary = 0;
487 
488  // The MD5 is considered invalid of it is zeroed
489  BitSummary |= pbMd5[0x00] | pbMd5[0x01] | pbMd5[0x02] | pbMd5[0x03] | pbMd5[0x04] | pbMd5[0x05] | pbMd5[0x06] | pbMd5[0x07];
490  BitSummary |= pbMd5[0x08] | pbMd5[0x09] | pbMd5[0x0A] | pbMd5[0x0B] | pbMd5[0x0C] | pbMd5[0x0D] | pbMd5[0x0E] | pbMd5[0x0F];
491  return (BitSummary != 0);
492 }
unsigned char BYTE
Definition: CascPort.h:136

+ Here is the caller graph for this function:

size_t NormalizeFileName ( const unsigned char *  NormTable,
char *  szNormName,
const char *  szFileName,
size_t  cchMaxChars 
)
237 {
238  char * szNormNameEnd = szNormName + cchMaxChars;
239  size_t i;
240 
241  // Normalize the file name: ToLower + BackSlashToSlash
242  for(i = 0; szFileName[0] != 0 && szNormName < szNormNameEnd; i++)
243  *szNormName++ = NormTable[*szFileName++];
244 
245  // Terminate the string
246  szNormName[0] = 0;
247  return i;
248 }

+ Here is the caller graph for this function:

size_t NormalizeFileName_LowerSlash ( char *  szNormName,
const char *  szFileName,
size_t  cchMaxChars 
)
256 {
257  return NormalizeFileName(AsciiToLowerTable_Slash, szNormName, szFileName, cchMaxChars);
258 }
size_t NormalizeFileName(const unsigned char *NormTable, char *szNormName, const char *szFileName, size_t cchMaxChars)
Definition: Common.cpp:236
unsigned char AsciiToLowerTable_Slash[256]
Definition: Common.cpp:20

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t NormalizeFileName_UpperBkSlash ( char *  szNormName,
const char *  szFileName,
size_t  cchMaxChars 
)
251 {
252  return NormalizeFileName(AsciiToUpperTable_BkSlash, szNormName, szFileName, cchMaxChars);
253 }
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
size_t NormalizeFileName(const unsigned char *NormTable, char *szNormName, const char *szFileName, size_t cchMaxChars)
Definition: Common.cpp:236

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void qsort_pointer_array ( void **  base,
size_t  num,
int(*)(const void *, const void *, const void *)  compare,
const void *  context 
)
534 {
535  size_t lo, hi; /* ends of sub-array currently sorting */
536  size_t mid; /* points to middle of subarray */
537  size_t loguy, higuy; /* traveling pointers for partition step */
538  size_t size; /* size of the sub-array */
539  size_t lostk[STKSIZ], histk[STKSIZ];
540  void * temp;
541  int stkptr; /* stack for saving sub-array to be processed */
542 
543  /* validation section */
544  assert(base != NULL);
545  assert(compare != NULL);
546 
547  if (num < 2)
548  return; /* nothing to do */
549 
550  stkptr = 0; /* initialize stack */
551 
552  lo = 0;
553  hi = (num-1); /* initialize limits */
554 
555  /* this entry point is for pseudo-recursion calling: setting
556  lo and hi and jumping to here is like recursion, but stkptr is
557  preserved, locals aren't, so we preserve stuff on the stack */
558 recurse:
559 
560  size = (hi - lo) + 1; /* number of el's to sort */
561 
562  /* First we pick a partitioning element. The efficiency of the
563  algorithm demands that we find one that is approximately the median
564  of the values, but also that we select one fast. We choose the
565  median of the first, middle, and last elements, to avoid bad
566  performance in the face of already sorted data, or data that is made
567  up of multiple sorted runs appended together. Testing shows that a
568  median-of-three algorithm provides better performance than simply
569  picking the middle element for the latter case. */
570 
571  mid = lo + (size / 2); /* find middle element */
572 
573  /* Sort the first, middle, last elements into order */
574  if (compare(context, base[lo], base[mid]) > 0) {
575  SWAP_ENTRIES(lo, mid);
576  }
577  if (compare(context, base[lo], base[hi]) > 0) {
578  SWAP_ENTRIES(lo, hi);
579  }
580  if (compare(context, base[mid], base[hi]) > 0) {
581  SWAP_ENTRIES(mid, hi);
582  }
583 
584  /* We now wish to partition the array into three pieces, one consisting
585  of elements <= partition element, one of elements equal to the
586  partition element, and one of elements > than it. This is done
587  below; comments indicate conditions established at every step. */
588 
589  loguy = lo;
590  higuy = hi;
591 
592  /* Note that higuy decreases and loguy increases on every iteration,
593  so loop must terminate. */
594  for (;;) {
595  /* lo <= loguy < hi, lo < higuy <= hi,
596  A[i] <= A[mid] for lo <= i <= loguy,
597  A[i] > A[mid] for higuy <= i < hi,
598  A[hi] >= A[mid] */
599 
600  /* The doubled loop is to avoid calling comp(mid,mid), since some
601  existing comparison funcs don't work when passed the same
602  value for both pointers. */
603 
604  if (mid > loguy) {
605  do {
606  loguy ++;
607  } while (loguy < mid && compare(context, base[loguy], base[mid]) <= 0);
608  }
609  if (mid <= loguy) {
610  do {
611  loguy ++;
612  } while (loguy <= hi && compare(context, base[loguy], base[mid]) <= 0);
613  }
614 
615  /* lo < loguy <= hi+1, A[i] <= A[mid] for lo <= i < loguy,
616  either loguy > hi or A[loguy] > A[mid] */
617 
618  do {
619  higuy --;
620  } while (higuy > mid && compare(context, base[higuy], base[mid]) > 0);
621 
622  /* lo <= higuy < hi, A[i] > A[mid] for higuy < i < hi,
623  either higuy == lo or A[higuy] <= A[mid] */
624 
625  if (higuy < loguy)
626  break;
627 
628  /* if loguy > hi or higuy == lo, then we would have exited, so
629  A[loguy] > A[mid], A[higuy] <= A[mid],
630  loguy <= hi, higuy > lo */
631 
632  SWAP_ENTRIES(loguy, higuy);
633 
634  /* If the partition element was moved, follow it. Only need
635  to check for mid == higuy, since before the swap,
636  A[loguy] > A[mid] implies loguy != mid. */
637 
638  if (mid == higuy)
639  mid = loguy;
640 
641  /* A[loguy] <= A[mid], A[higuy] > A[mid]; so condition at top
642  of loop is re-established */
643  }
644 
645  /* A[i] <= A[mid] for lo <= i < loguy,
646  A[i] > A[mid] for higuy < i < hi,
647  A[hi] >= A[mid]
648  higuy < loguy
649  implying:
650  higuy == loguy-1
651  or higuy == hi - 1, loguy == hi + 1, A[hi] == A[mid] */
652 
653  /* Find adjacent elements equal to the partition element. The
654  doubled loop is to avoid calling comp(mid,mid), since some
655  existing comparison funcs don't work when passed the same value
656  for both pointers. */
657 
658  higuy ++;
659  if (mid < higuy) {
660  do {
661  higuy --;
662  } while (higuy > mid && compare(context, base[higuy], base[mid]) == 0);
663  }
664  if (mid >= higuy) {
665  do {
666  higuy --;
667  } while (higuy > lo && compare(context, base[higuy], base[mid]) == 0);
668  }
669 
670  /* OK, now we have the following:
671  higuy < loguy
672  lo <= higuy <= hi
673  A[i] <= A[mid] for lo <= i <= higuy
674  A[i] == A[mid] for higuy < i < loguy
675  A[i] > A[mid] for loguy <= i < hi
676  A[hi] >= A[mid] */
677 
678  /* We've finished the partition, now we want to sort the subarrays
679  [lo, higuy] and [loguy, hi].
680  We do the smaller one first to minimize stack usage.
681  We only sort arrays of length 2 or more.*/
682 
683  if ( higuy - lo >= hi - loguy ) {
684  if (lo < higuy) {
685  lostk[stkptr] = lo;
686  histk[stkptr] = higuy;
687  ++stkptr;
688  } /* save big recursion for later */
689 
690  if (loguy < hi) {
691  lo = loguy;
692  goto recurse; /* do small recursion */
693  }
694  }
695  else {
696  if (loguy < hi) {
697  lostk[stkptr] = loguy;
698  histk[stkptr] = hi;
699  ++stkptr; /* save big recursion for later */
700  }
701 
702  if (lo < higuy) {
703  hi = higuy;
704  goto recurse; /* do small recursion */
705  }
706  }
707 
708  /* We have sorted the array, except for any pending sorts on the stack.
709  Check if there are any, and do them. */
710 
711  --stkptr;
712  if (stkptr >= 0) {
713  lo = lostk[stkptr];
714  hi = histk[stkptr];
715  goto recurse; /* pop subarray from stack */
716  }
717  else
718  return; /* all subarrays done */
719 }
#define STKSIZ
Definition: Common.cpp:524
arena_t NULL
Definition: jemalloc_internal.h:624
#define SWAP_ENTRIES(index1, index2)
Definition: Common.cpp:526
void SetLastError ( int  nError)
76 {
77  nLastError = nError;
78 }
static int nLastError
Definition: Common.cpp:68

+ Here is the caller graph for this function:

char* StringFromBinary ( LPBYTE  pbBinary,
size_t  cbBinary,
char *  szBuffer 
)
373 {
374  char * szSaveBuffer = szBuffer;
375 
376  // Convert the string to the array of MD5
377  // Copy the blob data as text
378  for(size_t i = 0; i < cbBinary; i++)
379  {
380  *szBuffer++ = IntToHexChar[pbBinary[0] >> 0x04];
381  *szBuffer++ = IntToHexChar[pbBinary[0] & 0x0F];
382  pbBinary++;
383  }
384 
385  // Terminate the string
386  *szBuffer = 0;
387  return szSaveBuffer;
388 }
unsigned char IntToHexChar[]
Definition: Common.cpp:62

+ Here is the caller graph for this function:

char* StringFromMD5 ( LPBYTE  md5,
char *  szBuffer 
)
391 {
392  return StringFromBinary(md5, MD5_HASH_SIZE, szBuffer);
393 }
#define MD5_HASH_SIZE
Definition: CascLib.h:105
char * StringFromBinary(LPBYTE pbBinary, size_t cbBinary, char *szBuffer)
Definition: Common.cpp:372

+ Here is the call graph for this function:

bool VerifyDataBlockHash ( void *  pvDataBlock,
DWORD  cbDataBlock,
LPBYTE  expected_md5 
)
495 {
496  hash_state md5_state;
497  BYTE md5_digest[MD5_HASH_SIZE];
498 
499  // Don't verify the block if the MD5 is not valid.
500  if(!IsValidMD5(expected_md5))
501  return true;
502 
503  // Calculate the MD5 of the data block
504  md5_init(&md5_state);
505  md5_process(&md5_state, (unsigned char *)pvDataBlock, cbDataBlock);
506  md5_done(&md5_state, md5_digest);
507 
508  // Does the MD5's match?
509  return (memcmp(md5_digest, expected_md5, MD5_HASH_SIZE) == 0);
510 }
static void md5_process(md5_state_t *pms, const md5_byte_t *data)
Definition: Crypto_md5.cpp:220
bool IsValidMD5(LPBYTE pbMd5)
Definition: Common.cpp:484
static void md5_init(md5_state_t *pms)
Definition: Crypto_md5.cpp:401
#define MD5_HASH_SIZE
Definition: CascLib.h:105
Definition: tomcrypt_hash.h:105
unsigned char BYTE
Definition: CascPort.h:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

unsigned char AsciiToLowerTable_Slash[256]
Initial value:
=
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x5B, 0x2F, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
}
unsigned char AsciiToUpperTable_BkSlash[256]
Initial value:
=
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x5C,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
}
unsigned char IntToHexChar[] = "0123456789abcdef"
int nLastError = ERROR_SUCCESS
static