TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Common.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAKE_OFFSET64(hi, lo)   (((ULONGLONG)hi << 32) | (ULONGLONG)lo)
 
#define ALIGN_TO_SIZE(x, a)   (((x) + (a)-1) & ~((a)-1))
 

Typedefs

typedef bool(* INDEX_FILE_FOUND )(const TCHAR *szFileName, PDWORD IndexArray, PDWORD OldIndexArray, void *pvContext)
 

Functions

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 *szPath, const TCHAR *szSubDir)
 
TCHARCombinePathAndString (const TCHAR *szPath, const char *szString, size_t nLength)
 
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)
 
bool CheckWildCard (const char *szString, const char *szWildCard)
 
const wchar_t * GetPlainFileName (const wchar_t *szFileName)
 
const char * GetPlainFileName (const char *szFileName)
 
ULONGLONG HashStringJenkins (const char *szFileName)
 
bool IsValidMD5 (LPBYTE pbMd5)
 
void CalculateDataBlockHash (void *pvDataBlock, DWORD cbDataBlock, LPBYTE md5_hash)
 
bool VerifyDataBlockHash (void *pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5)
 
bool DirectoryExists (const TCHAR *szDirectory)
 
int ScanIndexDirectory (const TCHAR *szIndexPath, INDEX_FILE_FOUND pfnOnFileFound, PDWORD IndexArray, PDWORD OldIndexArray, void *pvContext)
 

Variables

unsigned char AsciiToLowerTable_Slash [256]
 
unsigned char AsciiToUpperTable_BkSlash [256]
 
unsigned char IntToHexChar []
 

Macro Definition Documentation

#define ALIGN_TO_SIZE (   x,
 
)    (((x) + (a)-1) & ~((a)-1))
#define MAKE_OFFSET64 (   hi,
  lo 
)    (((ULONGLONG)hi << 32) | (ULONGLONG)lo)

Typedef Documentation

typedef bool(* INDEX_FILE_FOUND)(const TCHAR *szFileName, PDWORD IndexArray, PDWORD OldIndexArray, void *pvContext)

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 szPath,
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 }
bool DirectoryExists ( const TCHAR szDirectory)
19 {
20 #ifdef PLATFORM_WINDOWS
21 
22  DWORD dwAttributes = GetFileAttributes(szDirectory);
23  if((dwAttributes != INVALID_FILE_ATTRIBUTES) && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
24  return true;
25 
26 #else // PLATFORM_WINDOWS
27 
28  DIR * dir = opendir(szDirectory);
29 
30  if(dir != NULL)
31  {
32  closedir(dir);
33  return true;
34  }
35 
36 #endif
37 
38  return false;
39 }
arena_t NULL
Definition: jemalloc_internal.h:624
unsigned int DWORD
Definition: CascPort.h:139

+ 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 }
ULONGLONG HashStringJenkins ( const char *  szFileName)
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_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:

int ScanIndexDirectory ( const TCHAR szIndexPath,
INDEX_FILE_FOUND  pfnOnFileFound,
PDWORD  IndexArray,
PDWORD  OldIndexArray,
void *  pvContext 
)
47 {
48 #ifdef PLATFORM_WINDOWS
49 
50  WIN32_FIND_DATA wf;
51  TCHAR * szSearchMask;
52  HANDLE hFind;
53 
54  // Prepare the search mask
55  szSearchMask = CombinePath(szIndexPath, _T("*"));
56  if(szSearchMask == NULL)
58 
59  // Prepare directory search
60  hFind = FindFirstFile(szSearchMask, &wf);
61  if(hFind != INVALID_HANDLE_VALUE)
62  {
63  // Skip the first file as it's always just "." or ".."
64  while(FindNextFile(hFind, &wf))
65  {
66  // If the found object is a file, pass it to the handler
67  if(!(wf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
68  {
69  // Let the callback scan the file name
70  pfnOnFileFound(wf.cFileName, MainIndexes, OldIndexArray, pvContext);
71  }
72  }
73 
74  // Close the search handle
75  FindClose(hFind);
76  }
77 
78  CASC_FREE(szSearchMask);
79 
80 #else // PLATFORM_WINDOWS
81 
82  struct dirent * dir_entry;
83  DIR * dir;
84 
85  dir = opendir(szIndexPath);
86  if(dir != NULL)
87  {
88  while((dir_entry = readdir(dir)) != NULL)
89  {
90  if(dir_entry->d_type != DT_DIR)
91  {
92  pfnOnFileFound(dir_entry->d_name, MainIndexes, OldIndexArray, pvContext);
93  }
94  }
95 
96  closedir(dir);
97  }
98 
99 #endif
100 
101  return ERROR_SUCCESS;
102 }
void * HANDLE
Definition: CascPort.h:146
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:208
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148
#define _T(x)
Definition: CascPort.h:171
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
TCHAR * CombinePath(const TCHAR *szDirectory, const TCHAR *szSubDir)
Definition: Common.cpp:157
#define INVALID_HANDLE_VALUE
Definition: CascPort.h:169
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ 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]
unsigned char AsciiToUpperTable_BkSlash[256]
unsigned char IntToHexChar[]