diff options
-rw-r--r-- | src/Common/Registry.c | 33 | ||||
-rw-r--r-- | src/Common/Registry.h | 3 |
2 files changed, 31 insertions, 5 deletions
diff --git a/src/Common/Registry.c b/src/Common/Registry.c index c7496471..a68e5f18 100644 --- a/src/Common/Registry.c +++ b/src/Common/Registry.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include "Tcdefs.h" | 9 | #include "Tcdefs.h" |
10 | #include "Registry.h" | 10 | #include "Registry.h" |
11 | #include <Strsafe.h> | ||
11 | 12 | ||
12 | BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value) | 13 | BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value) |
13 | { | 14 | { |
@@ -105,13 +106,13 @@ char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *st | |||
105 | DWORD size = sizeof (value); | 106 | DWORD size = sizeof (value); |
106 | 107 | ||
107 | str[maxLen-1] = 0; | 108 | str[maxLen-1] = 0; |
108 | strncpy (str, defaultValue, maxLen-1); | 109 | StringCbCopyA (str, maxLen, defaultValue); |
109 | 110 | ||
110 | ZeroMemory (value, sizeof value); | 111 | ZeroMemory (value, sizeof value); |
111 | if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, | 112 | if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, |
112 | 0, KEY_READ, &hkey) == ERROR_SUCCESS) | 113 | 0, KEY_READ, &hkey) == ERROR_SUCCESS) |
113 | if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS) | 114 | if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS) |
114 | strncpy (str, value, maxLen-1); | 115 | StringCbCopyA (str, maxLen,value); |
115 | 116 | ||
116 | RegCloseKey (hkey); | 117 | RegCloseKey (hkey); |
117 | return str; | 118 | return str; |
@@ -169,6 +170,30 @@ BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value) | |||
169 | return TRUE; | 170 | return TRUE; |
170 | } | 171 | } |
171 | 172 | ||
173 | BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value) | ||
174 | { | ||
175 | HKEY hkey = 0; | ||
176 | DWORD disp; | ||
177 | LONG status; | ||
178 | |||
179 | if ((status = RegCreateKeyExW (HKEY_LOCAL_MACHINE, subKey, | ||
180 | 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS) | ||
181 | { | ||
182 | SetLastError (status); | ||
183 | return FALSE; | ||
184 | } | ||
185 | |||
186 | if ((status = RegSetValueExW (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS) | ||
187 | { | ||
188 | RegCloseKey (hkey); | ||
189 | SetLastError (status); | ||
190 | return FALSE; | ||
191 | } | ||
192 | |||
193 | RegCloseKey (hkey); | ||
194 | return TRUE; | ||
195 | } | ||
196 | |||
172 | BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size) | 197 | BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size) |
173 | { | 198 | { |
174 | HKEY hkey = 0; | 199 | HKEY hkey = 0; |
@@ -279,9 +304,9 @@ void DeleteRegistryValue (char *subKey, char *name) | |||
279 | } | 304 | } |
280 | 305 | ||
281 | 306 | ||
282 | void GetStartupRegKeyName (char *regk) | 307 | void GetStartupRegKeyName (char *regk, size_t cbRegk) |
283 | { | 308 | { |
284 | // The string is split in order to prevent some antivirus packages from falsely reporting | 309 | // The string is split in order to prevent some antivirus packages from falsely reporting |
285 | // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan). | 310 | // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan). |
286 | sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run"); | 311 | StringCbPrintfA (regk, cbRegk,"%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run"); |
287 | } | 312 | } |
diff --git a/src/Common/Registry.h b/src/Common/Registry.h index a0e2e732..693ddc0e 100644 --- a/src/Common/Registry.h +++ b/src/Common/Registry.h | |||
@@ -19,13 +19,14 @@ char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *st | |||
19 | DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen); | 19 | DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen); |
20 | void WriteRegistryInt (char *subKey, char *name, int value); | 20 | void WriteRegistryInt (char *subKey, char *name, int value); |
21 | BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value); | 21 | BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value); |
22 | BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value); | ||
22 | BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size); | 23 | BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size); |
23 | BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL expandable); | 24 | BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL expandable); |
24 | void WriteRegistryString (char *subKey, char *name, char *str); | 25 | void WriteRegistryString (char *subKey, char *name, char *str); |
25 | BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size); | 26 | BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size); |
26 | BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete); | 27 | BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete); |
27 | void DeleteRegistryValue (char *subKey, char *name); | 28 | void DeleteRegistryValue (char *subKey, char *name); |
28 | void GetStartupRegKeyName (char *regk); | 29 | void GetStartupRegKeyName (char *regk, size_t cbRegk); |
29 | 30 | ||
30 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
31 | } | 32 | } |