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