|
|
1.1.1.5 root 1: /* 1.1.1.12! root 2: Copyright (c) 2005-2009 TrueCrypt Developers Association. All rights reserved. 1.1 root 3: 1.1.1.12! root 4: Governed by the TrueCrypt License 2.8 the full text of which is contained in ! 5: the file License.txt included in TrueCrypt binary and source code distribution ! 6: packages. 1.1 root 7: */ 8: 9: #include "../Common/Dictionary.h" 10: #include <windows.h> 1.1.1.11 root 11: #include <map> 12: #include <string> 1.1 root 13: 1.1.1.11 root 14: using namespace std; 15: 16: static map <string, void *> StringKeyMap; 17: static map <int, void *> IntKeyMap; 1.1 root 18: 19: static void *DataPool = NULL; 20: static size_t DataPoolSize = 0; 21: 22: 1.1.1.11 root 23: void AddDictionaryEntry (char *key, int intKey, void *value) 24: { 25: if (key) 26: StringKeyMap[key] = value; 1.1 root 27: 1.1.1.11 root 28: if (intKey != 0) 29: IntKeyMap[intKey] = value; 1.1 root 30: } 31: 32: 1.1.1.9 root 33: void *GetDictionaryValue (const char *key) 1.1 root 34: { 1.1.1.11 root 35: map <string, void *>::const_iterator i = StringKeyMap.find (key); 36: 37: if (i == StringKeyMap.end()) 38: return NULL; 1.1 root 39: 1.1.1.11 root 40: return i->second; 1.1 root 41: } 42: 43: 44: void *GetDictionaryValueByInt (int intKey) 45: { 1.1.1.11 root 46: map <int, void *>::const_iterator i = IntKeyMap.find (intKey); 1.1 root 47: 1.1.1.11 root 48: if (i == IntKeyMap.end()) 49: return NULL; 50: 51: return i->second; 1.1 root 52: } 53: 54: 55: void *AddPoolData (void *data, size_t dataSize) 56: { 57: if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL; 58: 59: if (DataPool == NULL) 60: { 61: DataPool = malloc (DATA_POOL_CAPACITY); 62: if (DataPool == NULL) return NULL; 63: } 64: 65: memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize); 66: 1.1.1.2 root 67: // Ensure 32-bit alignment for next entries 68: dataSize = (dataSize + 3) & (~(size_t)3); 69: 1.1 root 70: DataPoolSize += dataSize; 71: return (BYTE *)DataPool + DataPoolSize - dataSize; 72: } 73: 74: 75: void ClearDictionaryPool () 76: { 77: DataPoolSize = 0; 1.1.1.11 root 78: StringKeyMap.clear(); 79: IntKeyMap.clear(); 1.1 root 80: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.