|
|
1.1 root 1: /*
1.1.1.3 ! root 2: Copyright (c) 2004-2006 TrueCrypt Foundation. All rights reserved.
1.1 root 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:
1.1.1.2 root 11: static DictionaryEntry StringDictionary[4096];
1.1 root 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:
1.1.1.2 root 94: // Ensure 32-bit alignment for next entries
95: dataSize = (dataSize + 3) & (~(size_t)3);
96:
1.1 root 97: DataPoolSize += dataSize;
98: return (BYTE *)DataPool + DataPoolSize - dataSize;
99: }
100:
101:
102: void ClearDictionaryPool ()
103: {
104: DataPoolSize = 0;
105: LastDictionaryEntry = -1;
106: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.