Annotation of truecrypt/common/registry.c, revision 1.1.1.4

1.1.1.4 ! root        1: /* 
        !             2: Copyright (c) 2004-2005 TrueCrypt Foundation. All rights reserved. 
        !             3: Copyright (c) 2004 TrueCrypt Team. All rights reserved. 
        !             4: 
        !             5: Covered by TrueCrypt License 2.0 the full text of which is contained in the file
        !             6: License.txt included in TrueCrypt binary and source code distribution archives. 
        !             7: */
1.1       root        8: 
1.1.1.4 ! root        9: #include "Tcdefs.h"
        !            10: #include "Registry.h"
1.1       root       11: 
1.1.1.4 ! root       12: int ReadRegistryInt (char *subKey, char *name, int defaultValue)
1.1       root       13: {
                     14:        HKEY hkey = 0;
                     15:        DWORD value, size = sizeof (DWORD);
                     16: 
1.1.1.4 ! root       17:        if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root       18:                0, KEY_READ, &hkey) != ERROR_SUCCESS)
                     19:                return defaultValue;
                     20: 
                     21:        if (RegQueryValueEx (hkey, name, 0,     0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
                     22:                value = defaultValue;
                     23: 
                     24:        RegCloseKey (hkey);
                     25:        return value;
                     26: }
                     27: 
1.1.1.4 ! root       28: char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *str, int maxLen)
1.1       root       29: {
                     30:        HKEY hkey = 0;
1.1.1.4 ! root       31:        char value[MAX_PATH*4];
1.1       root       32:        DWORD size = sizeof (value);
                     33: 
                     34:        strncpy (str, defaultValue, maxLen-1);
                     35: 
                     36:        ZeroMemory (value, sizeof value);
1.1.1.4 ! root       37:        if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root       38:                0, KEY_READ, &hkey) == ERROR_SUCCESS)
                     39:                if (RegQueryValueEx (hkey, name, 0,     0, (LPBYTE) &value,     &size) == ERROR_SUCCESS)
                     40:                        strncpy (str, value, maxLen-1);
                     41: 
                     42:        RegCloseKey (hkey);
                     43:        return str;
                     44: }
                     45: 
1.1.1.4 ! root       46: DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen)
        !            47: {
        !            48:        HKEY hkey = 0;
        !            49:        DWORD size = maxLen;
        !            50:        BOOL success = FALSE;
        !            51: 
        !            52:        if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
        !            53:                return 0;
        !            54: 
        !            55:        success = (RegQueryValueEx (hkey, name, 0,      0, (LPBYTE) value,      &size) == ERROR_SUCCESS);
        !            56:        RegCloseKey (hkey);
        !            57: 
        !            58:        return success ? size : 0;
        !            59: }
        !            60: 
        !            61: void WriteRegistryInt (char *subKey, char *name, int value)
1.1       root       62: {
                     63:        HKEY hkey = 0;
                     64:        DWORD disp;
                     65: 
1.1.1.4 ! root       66:        if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root       67:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
                     68:                return;
                     69: 
                     70:        RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
                     71:        RegCloseKey (hkey);
                     72: }
                     73: 
1.1.1.4 ! root       74: void WriteRegistryString (char *subKey, char *name, char *str)
1.1       root       75: {
                     76:        HKEY hkey = 0;
                     77:        DWORD disp;
                     78: 
1.1.1.4 ! root       79:        if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root       80:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
                     81:                return;
                     82: 
                     83:        RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, strlen (str) + 1);
                     84:        RegCloseKey (hkey);
                     85: }
1.1.1.4 ! root       86: 
        !            87: BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size)
        !            88: {
        !            89:        HKEY hkey = 0;
        !            90:        DWORD disp;
        !            91:        BOOL res;
        !            92: 
        !            93:        if (RegCreateKeyEx (HKEY_CURRENT_USER, path,
        !            94:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
        !            95:                return FALSE;
        !            96: 
        !            97:        res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size);
        !            98:        RegCloseKey (hkey);
        !            99:        return res == ERROR_SUCCESS;
        !           100: }
        !           101: 
        !           102: void DeleteRegistryValue (char *subKey, char *name)
        !           103: {
        !           104:        HKEY hkey = 0;
        !           105: 
        !           106:        if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS)
        !           107:                return;
        !           108: 
        !           109:        RegDeleteValue (hkey, name);
        !           110:        RegCloseKey (hkey);
        !           111: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.