|
|
1.1.1.7 root 1: /* 1.1.1.9 root 2: Copyright (c) 2004-2008 TrueCrypt Foundation. All rights reserved. 1.1.1.4 root 3: 1.1.1.10! root 4: Governed by the TrueCrypt License 2.5 the full text of which is contained 1.1.1.7 root 5: in the file License.txt included in TrueCrypt binary and source code 6: distribution packages. 1.1.1.4 root 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.9 root 12: BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value) 13: { 14: HKEY hkey = 0; 15: DWORD size = sizeof (*value); 1.1.1.10! root 16: DWORD type; 1.1.1.9 root 17: 18: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS) 19: return FALSE; 20: 1.1.1.10! root 21: if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, &size) != ERROR_SUCCESS) 1.1.1.9 root 22: { 23: RegCloseKey (hkey); 24: return FALSE; 25: } 26: 27: RegCloseKey (hkey); 1.1.1.10! root 28: return type == REG_DWORD; ! 29: } ! 30: ! 31: BOOL ReadLocalMachineRegistryMultiString (char *subKey, char *name, char *value, DWORD *size) ! 32: { ! 33: HKEY hkey = 0; ! 34: DWORD type; ! 35: ! 36: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS) ! 37: return FALSE; ! 38: ! 39: if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, size) != ERROR_SUCCESS) ! 40: { ! 41: RegCloseKey (hkey); ! 42: return FALSE; ! 43: } ! 44: ! 45: RegCloseKey (hkey); ! 46: return type == REG_MULTI_SZ; 1.1.1.9 root 47: } 48: 1.1.1.4 root 49: int ReadRegistryInt (char *subKey, char *name, int defaultValue) 1.1 root 50: { 51: HKEY hkey = 0; 52: DWORD value, size = sizeof (DWORD); 53: 1.1.1.4 root 54: if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 1.1 root 55: 0, KEY_READ, &hkey) != ERROR_SUCCESS) 56: return defaultValue; 57: 58: if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS) 59: value = defaultValue; 60: 61: RegCloseKey (hkey); 62: return value; 63: } 64: 1.1.1.4 root 65: char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *str, int maxLen) 1.1 root 66: { 67: HKEY hkey = 0; 1.1.1.4 root 68: char value[MAX_PATH*4]; 1.1 root 69: DWORD size = sizeof (value); 70: 71: strncpy (str, defaultValue, maxLen-1); 72: 73: ZeroMemory (value, sizeof value); 1.1.1.4 root 74: if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 1.1 root 75: 0, KEY_READ, &hkey) == ERROR_SUCCESS) 76: if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS) 77: strncpy (str, value, maxLen-1); 78: 79: RegCloseKey (hkey); 80: return str; 81: } 82: 1.1.1.4 root 83: DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen) 84: { 85: HKEY hkey = 0; 86: DWORD size = maxLen; 87: BOOL success = FALSE; 88: 89: if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS) 90: return 0; 91: 92: success = (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS); 93: RegCloseKey (hkey); 94: 95: return success ? size : 0; 96: } 97: 98: void WriteRegistryInt (char *subKey, char *name, int value) 1.1 root 99: { 100: HKEY hkey = 0; 101: DWORD disp; 102: 1.1.1.4 root 103: if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey, 1.1 root 104: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS) 105: return; 106: 107: RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value); 108: RegCloseKey (hkey); 109: } 110: 1.1.1.9 root 111: BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value) 112: { 113: HKEY hkey = 0; 114: DWORD disp; 1.1.1.10! root 115: LONG status; 1.1.1.9 root 116: 1.1.1.10! root 117: if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey, ! 118: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS) ! 119: { ! 120: SetLastError (status); 1.1.1.9 root 121: return FALSE; 1.1.1.10! root 122: } ! 123: ! 124: if ((status = RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS) ! 125: { ! 126: RegCloseKey (hkey); ! 127: SetLastError (status); ! 128: return FALSE; ! 129: } ! 130: ! 131: RegCloseKey (hkey); ! 132: return TRUE; ! 133: } ! 134: ! 135: BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size) ! 136: { ! 137: HKEY hkey = 0; ! 138: DWORD disp; ! 139: LONG status; ! 140: ! 141: if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey, ! 142: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS) ! 143: { ! 144: SetLastError (status); ! 145: return FALSE; ! 146: } 1.1.1.9 root 147: 1.1.1.10! root 148: if ((status = RegSetValueEx (hkey, name, 0, REG_MULTI_SZ, (BYTE *) multiString, size)) != ERROR_SUCCESS) 1.1.1.9 root 149: { 150: RegCloseKey (hkey); 1.1.1.10! root 151: SetLastError (status); 1.1.1.9 root 152: return FALSE; 153: } 154: 155: RegCloseKey (hkey); 156: return TRUE; 157: } 158: 1.1.1.4 root 159: void WriteRegistryString (char *subKey, char *name, char *str) 1.1 root 160: { 161: HKEY hkey = 0; 162: DWORD disp; 163: 1.1.1.4 root 164: if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey, 1.1 root 165: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS) 166: return; 167: 168: RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, strlen (str) + 1); 169: RegCloseKey (hkey); 170: } 1.1.1.4 root 171: 172: BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size) 173: { 174: HKEY hkey = 0; 175: DWORD disp; 176: BOOL res; 177: 178: if (RegCreateKeyEx (HKEY_CURRENT_USER, path, 179: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS) 180: return FALSE; 181: 182: res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size); 183: RegCloseKey (hkey); 184: return res == ERROR_SUCCESS; 185: } 186: 187: void DeleteRegistryValue (char *subKey, char *name) 188: { 189: HKEY hkey = 0; 190: 191: if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS) 192: return; 193: 194: RegDeleteValue (hkey, name); 195: RegCloseKey (hkey); 196: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.