|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2004-2005 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Covered by TrueCrypt License 2.0 the full text of which is contained in the file ! 5: License.txt included in TrueCrypt binary and source code distribution archives. ! 6: */ ! 7: ! 8: #include "../Common/Dictionary.h" ! 9: #include <windows.h> ! 10: ! 11: static DictionaryEntry StringDictionary[2048]; ! 12: static int LastDictionaryEntry = -1; ! 13: static int MaxDictionaryEntry = sizeof (StringDictionary) / sizeof (DictionaryEntry) - 1; ! 14: ! 15: static void *DataPool = NULL; ! 16: static size_t DataPoolSize = 0; ! 17: ! 18: int AddDictionaryEntry (char *key, int intKey, void *value) ! 19: { ! 20: int i; ! 21: if (LastDictionaryEntry >= MaxDictionaryEntry) return -1; ! 22: ! 23: // Replace identical key if it exists ! 24: for (i = 0; i <= LastDictionaryEntry; i++) ! 25: { ! 26: if ((StringDictionary[i].Key != NULL ! 27: && key != NULL ! 28: && strcmp (StringDictionary[i].Key, key) == 0) ! 29: || (key == NULL && StringDictionary[i].IntKey == intKey)) ! 30: { ! 31: StringDictionary[i].Key = key; ! 32: StringDictionary[i].IntKey = intKey; ! 33: StringDictionary[i].Value = value; ! 34: ! 35: return i; ! 36: } ! 37: } ! 38: ! 39: LastDictionaryEntry++; ! 40: ! 41: StringDictionary[LastDictionaryEntry].Key = key; ! 42: StringDictionary[LastDictionaryEntry].IntKey = intKey; ! 43: StringDictionary[LastDictionaryEntry].Value = value; ! 44: ! 45: return LastDictionaryEntry; ! 46: } ! 47: ! 48: ! 49: void *GetDictionaryValue (char *key) ! 50: { ! 51: int i; ! 52: for (i = 0; i <= LastDictionaryEntry; i++) ! 53: { ! 54: if (StringDictionary[i].Key != NULL ! 55: && strcmp (StringDictionary[i].Key, key) == 0) ! 56: return StringDictionary[i].Value; ! 57: } ! 58: ! 59: return NULL; ! 60: } ! 61: ! 62: ! 63: void *GetDictionaryValueByInt (int intKey) ! 64: { ! 65: int i; ! 66: for (i = 0; i <= LastDictionaryEntry; i++) ! 67: { ! 68: if (StringDictionary[i].IntKey == intKey) ! 69: return StringDictionary[i].Value; ! 70: } ! 71: ! 72: return NULL; ! 73: } ! 74: ! 75: ! 76: void *AddPoolData (void *data, size_t dataSize) ! 77: { ! 78: ! 79: if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL; ! 80: ! 81: if (DataPool == NULL) ! 82: { ! 83: DataPool = malloc (DATA_POOL_CAPACITY); ! 84: if (DataPool == NULL) return NULL; ! 85: } ! 86: ! 87: memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize); ! 88: ! 89: //if (wcschr((WCHAR *)((BYTE *)DataPool + DataPoolSize), '%') == 0) ! 90: // _wcsupr ((WCHAR *)((BYTE *)DataPool + DataPoolSize)); ! 91: //else ! 92: // ((WCHAR *)((BYTE *)DataPool + DataPoolSize))[0] = L'*'; ! 93: ! 94: DataPoolSize += dataSize; ! 95: ! 96: return (BYTE *)DataPool + DataPoolSize - dataSize; ! 97: } ! 98: ! 99: ! 100: void ClearDictionaryPool () ! 101: { ! 102: DataPoolSize = 0; ! 103: LastDictionaryEntry = -1; ! 104: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.