| 0 ///////////////////////////////////////////////////////////////////// | 0 ///////////////////////////////////////////////////////////////////// |
| 1 // RegistryEditing.cs - defines functions required for retrieving// | 1 // RegistryEditing.cs - defines functions required for retrieving// |
| 2 // Ver 1.3 and editing the registry keys/vlaues // | 2 // Ver 1.3 and editing the registry keys/vlaues // |
| 3 // // | 3 // // |
| 4 // Language: C#, visual studio 7.0 // | 4 // Language: C#, visual studio 7.0 // |
| 5 // Platform: HP Invent, WinXP // | 5 // Platform: HP Invent, WinXP // |
| 6 // Application: CSE784, Software Studio,Registry Team, Fall 2003 // | 6 // Application: CSE784, Software Studio,Registry Team, Fall 2003 // |
| 7 // Author: Mayur Oberoi SU ID # 438992001 // | 7 // Author: Mayur Oberoi SU ID # 438992001 // |
| 8 // Date: 11/26/03 @ 08.10 pm // | 8 // Date: 11/26/03 @ 08.10 pm // |
| 9 // // | 9 // // |
| 10 ///////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////// |
| 11 /// | 11 /// |
| 12 /// It has the following classes | 12 /// It has the following classes |
| 13 /// 1)RegistryEditing class | 13 /// 1)RegistryEditing class |
| 14 /// | 14 /// |
| 15 /// It performs the 2 basic functions | 15 /// It performs the 2 basic functions |
| 16 /// 1) retrieving the values from the registry | 16 /// 1) retrieving the values from the registry |
| 17 /// 2) editing the registry | 17 /// 2) editing the registry |
| 18 /// | 18 /// |
| 19 /// 1) retrieving values | 19 /// 1) retrieving values |
| 20 /// three functions are provided for this purpose, namely getKeys, | 20 /// three functions are provided for this purpose, namely getKeys, |
| 21 /// getChildren and getValue. | 21 /// getChildren and getValue. |
| 22 /// getKeys gives the five hives | 22 /// getKeys gives the five hives |
| 23 /// getChildren returns the names of the children of the registrykey it was passed | 23 /// getChildren returns the names of the children of the registrykey it was passed |
| 24 /// getValues gives the values of the keys of a node | 24 /// getValues gives the values of the keys of a node |
| 25 /// | 25 /// |
| 26 /// 2) editing the registry | 26 /// 2) editing the registry |
| 27 /// an overloadeed match function is used | 27 /// an overloadeed match function is used |
| 28 /// a) public bool match(string fileName, ref RegistryMessage rm) | 28 /// a) public bool match(string fileName, ref RegistryMessage rm) |
| 29 /// b) public bool match(ref RegKeyObject keyName, ref RegistryMessage rm) | 29 /// b) public bool match(ref RegKeyObject keyName, ref RegistryMessage rm) |
| 30 /// c) public bool match(string entryName, string entryValue, ref RegistryMessage rm) | 30 /// c) public bool match(string entryName, string entryValue, ref RegistryMessage rm) |
| 31 /// each of these functions based on whether it is request or a response to a request(reply) | 31 /// each of these functions based on whether it is request or a response to a request(reply) |
| 32 /// either forms a message or edits the registry. | 32 /// either forms a message or edits the registry. |
| 33 /// | 33 /// |
| 34 /// | 34 /// |
| 35 /// Public Interface | 35 /// Public Interface |
| 36 /// ================ | 36 /// ================ |
| 37 /// | 37 /// |
| 38 /// RegistryEditing re = new RegistryEditing(); // creates an object of this class | 38 /// RegistryEditing re = new RegistryEditing(); // creates an object of this class |
| 39 /// re.getHiveNames(); // gives the returns the names of the | 39 /// re.getHiveNames(); // gives the returns the names of the |
| 40 /// // 5 hives | 40 /// // 5 hives |
| 41 /// re.getChildren(keyname, rm); // gives the names of the child nodes | 41 /// re.getChildren(keyname, rm); // gives the names of the child nodes |
| 42 /// // .. returns an ArrayList | 42 /// // .. returns an ArrayList |
| 43 /// re.getValue(keyname,rm); // gives the complete information of a key | 43 /// re.getValue(keyname,rm); // gives the complete information of a key |
| 44 /// // .. returns a RegKeyObject | 44 /// // .. returns a RegKeyObject |
| 45 /// re.match(fileName, rm) // match opertion for when a .reg file is passed | 45 /// re.match(fileName, rm) // match opertion for when a .reg file is passed |
| 46 /// re.match(keyName, rm) // match when key name is passed | 46 /// re.match(keyName, rm) // match when key name is passed |
| 47 /// re.match(entryName, entryvalue, rm) // match when the entryName and entryValue pair | 47 /// re.match(entryName, entryvalue, rm) // match when the entryName and entryValue pair |
| 48 /// // for a key is passed | 48 /// // for a key is passed |
| 49 /// | 49 /// |
| 50 /// Maintaince | 50 /// Maintaince |
| 51 /// =========== | 51 /// =========== |
| 52 /// ver1.0 11/12/03 @ 1:40 am | 52 /// ver1.0 11/12/03 @ 1:40 am |
| 53 /// first release | 53 /// first release |
| 54 /// ver1.1 11/13/03 @ 3.20 pm | 54 /// ver1.1 11/13/03 @ 3.20 pm |
| 55 /// wrote a function getRootKey to optimise code | 55 /// wrote a function getRootKey to optimise code |
| 56 /// ver1.2 11/16/03 @ 1.10 am | 56 /// ver1.2 11/16/03 @ 1.10 am |
| 57 /// incorporated match functions and changed getChildren and getValue functions | 57 /// incorporated match functions and changed getChildren and getValue functions |
| 58 /// var1.3 11/26/03 @ 8.10 pm | 58 /// var1.3 11/26/03 @ 8.10 pm |
| 59 /// changed match for file and added manual pages | 59 /// changed match for file and added manual pages |
| 60 /// | 60 /// |
| 61 /// | 61 /// |
| 62 | 62 |
| 63 | 63 |
| 64 | 64 |
| 65 using System; | 65 using System; |
| 66 using System.IO; | 66 using System.IO; |
| 67 using System.Configuration; | 67 using System.Configuration; |
| 68 using System.Collections; | 68 using System.Collections; |
| 69 using Microsoft.Win32; | 69 using Microsoft.Win32; |
| 70 using RegistryInterface; | 70 using RegistryInterface; |
| 71 | 71 |
| 72 namespace RegistryInterface | 72 namespace RegistryInterface |
| 73 { | 73 { |
| 74 public class RegistryEditing | 74 public class RegistryEditing |
| 75 { | 75 { |
| 76 /* data members */ | 76 /* data members */ |
| 77 private string _IP; | 77 private string _IP; |
| 78 private string _fileName; | 78 private string _fileName; |
| 79 private string _keyName; | 79 private string _keyName; |
| 80 private string _valueName; | 80 private string _valueName; |
| 81 private string _valueData; | 81 private string _valueData; |
| 82 private CRegistryFileHandler _regFileHnd; | 82 private CRegistryFileHandler _regFileHnd; |
| 83 private CRegistryRollback _regRollback; | 83 private CRegistryRollback _regRollback; |
| 84 | 84 |
| 85 //----< constructor >---- | 85 //----< constructor >---- |
| 86 | 86 |
| 87 public RegistryEditing() | 87 public RegistryEditing() |
| 88 { | 88 { |
| 89 } | 89 } |
| 90 | 90 |
| 91 //----< parameterized ctor >---- | 91 //----< parameterized ctor >---- |
| 92 // is controller checking if ro & rfh is null before passing ? | 92 // is controller checking if ro & rfh is null before passing ? |
| 93 | 93 |
| 94 public RegistryEditing(CRegistryRollback ro, CRegistryFileHandler rfh) | 94 public RegistryEditing(CRegistryRollback ro, CRegistryFileHandler rfh) |
| 95 { | 95 { |
| 96 _regRollback = ro; | 96 _regRollback = ro; |
| 97 _regFileHnd = rfh; | 97 _regFileHnd = rfh; |
| 98 } | 98 } |
| 99 | 99 |
| 100 //----< retrieves list of main hives >---- | 100 //----< retrieves list of main hives >---- |
| 101 | 101 |
| 102 public ArrayList getHiveNames () | 102 public ArrayList getHiveNames () |
| 103 { | 103 { |
| 104 ArrayList hiveList = new ArrayList(); | 104 ArrayList hiveList = new ArrayList(); |
| 105 hiveList.Add("HKEY_CLASSES_ROOT"); | 105 hiveList.Add("HKEY_CLASSES_ROOT"); |
| 106 hiveList.Add("HKEY_CURRENT_CONFIG"); | 106 hiveList.Add("HKEY_CURRENT_CONFIG"); |
| 107 hiveList.Add("HKEY_CURRENT_USER"); | 107 hiveList.Add("HKEY_CURRENT_USER"); |
| 108 hiveList.Add("HKEY_LOCAL_MACHINE"); | 108 hiveList.Add("HKEY_LOCAL_MACHINE"); |
| 109 hiveList.Add("HKEY_USERS"); | 109 hiveList.Add("HKEY_USERS"); |
| 110 return hiveList; | 110 return hiveList; |
| 111 } | 111 } |
| 112 | 112 |
| 113 //----< detects a valid string >---- | 113 //----< detects a valid string >---- |
| 114 | 114 |
| 115 private bool isValidString (string str) | 115 private bool isValidString (string str) |
| 116 { | 116 { |
| 117 return ( (str != null) && (str != "") && (str != " ") ) ; | 117 return ( (str != null) && (str != "") && (str != " ") ) ; |
| 118 } | 118 } |
| 119 | 119 |
| 120 //----< retrieves the value (names,types & data) for specified key >---- | 120 //----< retrieves the value (names,types & data) for specified key >---- |
| 121 // type of keyName expected "HKEY_CLASSES_ROOT\System.DirectSoundCaptureAecDemo" | 121 // type of keyName expected "HKEY_CLASSES_ROOT\System.DirectSoundCaptureAecDemo" |
| 122 // 39 lines | 122 // 39 lines |
| 123 public bool getValue(string keyName, ref RegistryMessage rm) | 123 public bool getValue(string keyName, ref RegistryMessage rm) |
| 124 { | 124 { |
| 125 try | 125 try |
| 126 { | 126 { |
| 127 if (isValidString(keyName)) | 127 if (isValidString(keyName)) |
| 128 { | 128 { |
| 129 _keyName = keyName; | 129 _keyName = keyName; |
| 130 _IP = rm.destinationIP; | 130 _IP = rm.destinationIP; |
| 131 } | 131 } |
| 132 if(rm.messageType == RegEnumMsg.RETRIEVE_VALUES_REQUEST) | 132 if(rm.messageType == RegEnumMsg.RETRIEVE_VALUES_REQUEST) |
| 133 { | 133 { |
| 134 rm.regkeyObject.keyName = _keyName; | 134 rm.regkeyObject.keyName = _keyName; |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 else if(rm.messageType == RegEnumMsg.RETRIEVE_VALUES_REPLY) | 137 else if(rm.messageType == RegEnumMsg.RETRIEVE_VALUES_REPLY) |
| 138 { | 138 { |
| 139 string[] names = _keyName.Split('\\'); | 139 string[] names = _keyName.Split('\\'); |
| 140 RegistryKey ourkey = Registry.LocalMachine; | 140 RegistryKey ourkey = Registry.LocalMachine; |
| 141 ourkey = getRootKey(names[0]); | 141 ourkey = getRootKey(names[0]); |
| 142 string temp= ""; | 142 string temp= ""; |
| 143 for(int i=1; i< names.Length; ++i) | 143 for(int i=1; i< names.Length; ++i) |
| 144 { | 144 { |
| 145 if (i == 1) | 145 if (i == 1) |
| 146 temp = names[1]; | 146 temp = names[1]; |
| 147 else | 147 else |
| 148 temp = temp + "\\" + names[i]; | 148 temp = temp + "\\" + names[i]; |
| 149 } | 149 } |
| 150 try | 150 try |
| 151 { | 151 { |
| 152 ourkey = ourkey.OpenSubKey(@temp,true); | 152 ourkey = ourkey.OpenSubKey(@temp,true); |
| 153 foreach(string valuename in ourkey.GetValueNames()) | 153 foreach(string valuename in ourkey.GetValueNames()) |
| 154 { | 154 { |
| 155 try | 155 try |
| 156 { | 156 { |
| 157 rm.regkeyObject.entryNames.Add(valuename); | 157 rm.regkeyObject.entryNames.Add(valuename); |
| 158 rm.regkeyObject.entryTypes.Add(ourkey.GetValue(valuename).GetType().ToString() ); | 158 rm.regkeyObject.entryTypes.Add(ourkey.GetValue(valuename).GetType().ToString() ); |
| 159 rm.regkeyObject.entryValues.Add(ourkey.GetValue(valuename).ToString()); | 159 rm.regkeyObject.entryValues.Add(ourkey.GetValue(valuename).ToString()); |
| 160 rm.regkeyObject.valueCount++; | 160 rm.regkeyObject.valueCount++; |
| 161 } | 161 } |
| 162 catch(Exception) | 162 catch(Exception) |
| 163 { | 163 { |
| 164 if(rm.regkeyObject.entryNames.Count > rm.regkeyObject.entryTypes.Count) | 164 if(rm.regkeyObject.entryNames.Count > rm.regkeyObject.entryTypes.Count) |
| 165 rm.regkeyObject.entryNames.RemoveAt(rm.regkeyObject.valueCount); | 165 rm.regkeyObject.entryNames.RemoveAt(rm.regkeyObject.valueCount); |
| 166 if(rm.regkeyObject.entryTypes.Count > rm.regkeyObject.entryValues.Count) | 166 if(rm.regkeyObject.entryTypes.Count > rm.regkeyObject.entryValues.Count) |
| 167 { | 167 { |
| 168 rm.regkeyObject.entryNames.RemoveAt(rm.regkeyObject.valueCount); | 168 rm.regkeyObject.entryNames.RemoveAt(rm.regkeyObject.valueCount); |
| 169 rm.regkeyObject.entryTypes.RemoveAt(rm.regkeyObject.valueCount); | 169 rm.regkeyObject.entryTypes.RemoveAt(rm.regkeyObject.valueCount); |
| 170 } | 170 } |
| 171 | 171 |
| 172 continue; | 172 continue; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 ourkey.Close(); | 175 ourkey.Close(); |
| 176 } | 176 } |
| 177 catch(System.Exception){rm.errorMsgType = RegEnumErr.RETRIEVE_REPLY_ERROR ; return false;} | 177 catch(System.Exception){rm.errorMsgType = RegEnumErr.RETRIEVE_REPLY_ERROR ; return false;} |
| 178 return true; | 178 return true; |
| 179 } | 179 } |
| 180 return false; | 180 return false; |
| 181 } | 181 } |
| 182 catch(Exception) {return false;} | 182 catch(Exception) {return false;} |
| 183 } | 183 } |
| 184 | 184 |
| 185 | 185 |
| 186 //----< retrieves the sub key names for specified key >---- | 186 //----< retrieves the sub key names for specified key >---- |
| 187 // 33 lines | 187 // 33 lines |
| 188 | 188 |
| 189 public bool getChildren(string keyName,ref RegistryMessage rm) | 189 public bool getChildren(string keyName,ref RegistryMessage rm) |
| 190 { | 190 { |
| 191 try | 191 try |
| 192 { | 192 { |
| 193 if (isValidString(keyName)) | 193 if (isValidString(keyName)) |
| 194 { | 194 { |
| 195 _keyName = keyName; | 195 _keyName = keyName; |
| 196 _IP = rm.destinationIP; | 196 _IP = rm.destinationIP; |
| 197 } | 197 } |
| 198 | 198 |
| 199 if(rm.messageType == RegEnumMsg.RETRIEVE_CHILDREN_REQUEST) | 199 if(rm.messageType == RegEnumMsg.RETRIEVE_CHILDREN_REQUEST) |
| 200 { | 200 { |
| 201 rm.regkeyObject.keyName = _keyName; | 201 rm.regkeyObject.keyName = _keyName; |
| 202 return true; | 202 return true; |
| 203 } | 203 } |
| 204 if(rm.messageType == RegEnumMsg.RETRIEVE_CHILDREN_REPLY) | 204 if(rm.messageType == RegEnumMsg.RETRIEVE_CHILDREN_REPLY) |
| 205 { | 205 { |
| 206 string[] names = _keyName.Split('\\'); | 206 string[] names = _keyName.Split('\\'); |
| 207 RegistryKey ourkey = Registry.ClassesRoot; | 207 RegistryKey ourkey = Registry.ClassesRoot; |
| 208 ourkey = getRootKey(names[0]); | 208 ourkey = getRootKey(names[0]); |
| 209 | 209 |
| 210 string temp= ""; | 210 string temp= ""; |
| 211 for(int i=1; i< names.Length; ++i) | 211 for(int i=1; i< names.Length; ++i) |
| 212 { | 212 { |
| 213 if (i == 1) | 213 if (i == 1) |
| 214 temp = names[1]; | 214 temp = names[1]; |
| 215 else | 215 else |
| 216 temp = temp + "\\" + names[i]; | 216 temp = temp + "\\" + names[i]; |
| 217 } | 217 } |
| 218 try | 218 try |
| 219 { | 219 { |
| 220 ourkey = ourkey.OpenSubKey(temp,true); | 220 ourkey = ourkey.OpenSubKey(temp,true); |
| 221 foreach (string sub in ourkey.GetSubKeyNames()) | 221 foreach (string sub in ourkey.GetSubKeyNames()) |
| 222 { | 222 { |
| 223 rm.regkeyObject.Children.Add(sub); | 223 rm.regkeyObject.Children.Add(sub); |
| 224 } | 224 } |
| 225 ourkey.Close(); | 225 ourkey.Close(); |
| 226 } | 226 } |
| 227 catch(System.Exception) {rm.errorMsgType = RegEnumErr.RETRIEVE_REPLY_ERROR; ourkey.Close(); return false;} | 227 catch(System.Exception) {rm.errorMsgType = RegEnumErr.RETRIEVE_REPLY_ERROR; ourkey.Close(); return false;} |
| 228 return true; | 228 return true; |
| 229 } | 229 } |
| 230 return false; | 230 return false; |
| 231 } | 231 } |
| 232 catch(Exception) {return false;} | 232 catch(Exception) {return false;} |
| 233 } | 233 } |
| 234 | 234 |
| 235 | 235 |
| 236 //--------<match when a fileName is passed>---------- | 236 //--------<match when a fileName is passed>---------- |
| 237 // 39 lines | 237 // 39 lines |
| 238 public bool match(string fileName, ref RegistryMessage rm) | 238 public bool match(string fileName, ref RegistryMessage rm) |
| 239 { | 239 { |
| 240 try | 240 try |
| 241 { | 241 { |
| 242 if(! isValidFileName(fileName) || rm == null || rm.messageType == RegEnumMsg.UNKNOWN_MESSAGE ) | 242 if(! isValidFileName(fileName) || rm == null || rm.messageType == RegEnumMsg.UNKNOWN_MESSAGE ) |
| 243 return false; | 243 return false; |
| 244 _fileName = fileName; | 244 _fileName = fileName; |
| 245 _keyName = ValidityChecker.getKeyfromFileName(fileName); | 245 _keyName = ValidityChecker.getKeyfromFileName(fileName); |
| 246 try | 246 try |
| 247 { | 247 { |
| 248 // to get operationID we will have to call names[3].Split('.'); ... names[3] = names[names.Lenght-1] in this case | 248 // to get operationID we will have to call names[3].Split('.'); ... names[3] = names[names.Lenght-1] in this case |
| 249 | 249 |
| 250 if(rm.messageType == RegEnumMsg.MATCH_REPLY) | 250 if(rm.messageType == RegEnumMsg.MATCH_REPLY) |
| 251 { | 251 { |
| 252 // first create roolback file | 252 // first create roolback file |
| 253 if(_regRollback.SaveRollbackInfo(getfileName(rm.destinationIP,_keyName,rm.sourceIP ,rm.operationID,"rbk"),_keyName)) | 253 if(_regRollback.SaveRollbackInfo(getfileName(rm.destinationIP,_keyName,rm.sourceIP ,rm.operationID,"rbk"),_keyName)) |
| 254 { | 254 { |
| 255 hive hv = new hive(); | 255 hive hv = new hive(); |
| 256 // note reversal or src and dest ip passed to this funct | 256 // note reversal or src and dest ip passed to this funct |
| 257 if(_regFileHnd.ifFileReceivedFromWire(fileName,rm.destinationIP, rm.sourceIP)) | 257 if(_regFileHnd.ifFileReceivedFromWire(fileName,rm.destinationIP, rm.sourceIP)) |
| 258 { | 258 { |
| 259 bool res = (hv.loadHiveFromFile(_regFileHnd.pathName+ _regFileHnd.backupDirectory+rm.fileName, _keyName)); | 259 bool res = (hv.loadHiveFromFile(_regFileHnd.pathName+ _regFileHnd.backupDirectory+rm.fileName, _keyName)); |
| 260 res &=_regFileHnd.deleteFile(fileName); | 260 res &=_regFileHnd.deleteFile(fileName); |
| 261 return res; | 261 return res; |
| 262 } | 262 } |
| 263 else | 263 else |
| 264 { | 264 { |
| 265 // send it to reporting ??? | 265 // send it to reporting ??? |
| 266 return false; | 266 return false; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 else return false; | 269 else return false; |
| 270 } | 270 } |
| 271 // it was neither a MATCH_REQUEST nor a MATCH_REPLY | 271 // it was neither a MATCH_REQUEST nor a MATCH_REPLY |
| 272 else return false; | 272 else return false; |
| 273 } | 273 } |
| 274 catch(System.Exception){return false;} | 274 catch(System.Exception){return false;} |
| 275 } | 275 } |
| 276 catch(Exception) {return false;} | 276 catch(Exception) {return false;} |
| 277 | 277 |
| 278 } | 278 } |
| 279 | 279 |
| 280 public bool matchL(string path, string fileName, ref RegistryMessage rm) | 280 public bool matchL(string path, string fileName, ref RegistryMessage rm) |
| 281 { | 281 { |
| 282 if(! isValidFileName(fileName)) | 282 if(! isValidFileName(fileName)) |
| 283 return false; | 283 return false; |
| 284 else | 284 else |
| 285 { | 285 { |
| 286 _keyName = ValidityChecker.getKeyfromFileName(fileName); | 286 _keyName = ValidityChecker.getKeyfromFileName(fileName); |
| 287 if(_regRollback.SaveLocalRollbackInfo(getfileName(rm.sourceIP,_keyName,rm.sourceIP ,rm.operationID,"rbk"),_keyName)) | 287 if(_regRollback.SaveLocalRollbackInfo(getfileName(rm.sourceIP,_keyName,rm.sourceIP ,rm.operationID,"rbk"),_keyName)) |
| 288 { | 288 { |
| 289 hive hv = new hive(); | 289 hive hv = new hive(); |
| 290 // note reversal or src and dest ip passed to this funct | 290 // note reversal or src and dest ip passed to this funct |
| 291 if(_regFileHnd.ifFileReceivedFromWire(fileName,rm.destinationIP, rm.sourceIP)) | 291 if(_regFileHnd.ifFileReceivedFromWire(fileName,rm.destinationIP, rm.sourceIP)) |
| 292 { | 292 { |
| 293 bool res = (hv.loadHiveFromFile(_regFileHnd.pathName+ _regFileHnd.backupDirectory+ rm.fileName, _keyName)); | 293 bool res = (hv.loadHiveFromFile(_regFileHnd.pathName+ _regFileHnd.backupDirectory+ rm.fileName, _keyName)); |
| 294 res &=_regFileHnd.deleteFile(fileName); | 294 res &=_regFileHnd.deleteFile(fileName); |
| 295 return res; | 295 return res; |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 return true; | 299 return true; |
| 300 } | 300 } |
| 301 | 301 |
| 302 | 302 |
| 303 | 303 |
| 304 | 304 |
| 305 //-------<match when a keyName is passed>--------- | 305 //-------<match when a keyName is passed>--------- |
| 306 // 47 lines | 306 // 47 lines |
| 307 public bool match(ref RegKeyObject keyName, ref RegistryMessage rm) | 307 public bool match(ref RegKeyObject keyName, ref RegistryMessage rm) |
| 308 { | 308 { |
| 309 try | 309 try |
| 310 { | 310 { |
| 311 if ((keyName == null) || !(isValidString(keyName.keyName))) | 311 if ((keyName == null) || !(isValidString(keyName.keyName))) |
| 312 return false; | 312 return false; |
| 313 RegistryKey ourkey = Registry.ClassesRoot; | 313 RegistryKey ourkey = Registry.ClassesRoot; |
| 314 string[] names = keyName.keyName.Split('\\'); | 314 string[] names = keyName.keyName.Split('\\'); |
| 315 ourkey = getRootKey(names[0]); | 315 ourkey = getRootKey(names[0]); |
| 316 string temp= ""; | 316 string temp= ""; |
| 317 for(int i=1; i< names.Length; ++i) | 317 for(int i=1; i< names.Length; ++i) |
| 318 { // to strip the root key | 318 { // to strip the root key |
| 319 if (i == 1) | 319 if (i == 1) |
| 320 temp = names[1]; | 320 temp = names[1]; |
| 321 else | 321 else |
| 322 temp = temp + "\\" + names[i]; | 322 temp = temp + "\\" + names[i]; |
| 323 } | 323 } |
| 324 _fileName = getfileName(rm.destinationIP,keyName.keyName,rm.sourceIP,rm.operationID,"rbk"); | 324 _fileName = getfileName(rm.destinationIP,keyName.keyName,rm.sourceIP,rm.operationID,"rbk"); |
| 325 if(rm.messageType == RegEnumMsg.MATCH_REPLY) | 325 if(rm.messageType == RegEnumMsg.MATCH_REPLY) |
| 326 { | 326 { |
| 327 try | 327 try |
| 328 { | 328 { |
| 329 // for rollback we just need the file name and not the comlete file path | 329 // for rollback we just need the file name and not the comlete file path |
| 330 | 330 |
| 331 if(_regRollback.SaveRollbackInfo(_fileName,keyName.keyName)) | 331 if(_regRollback.SaveRollbackInfo(_fileName,keyName.keyName)) |
| 332 { | 332 { |
| 333 ourkey = ourkey.OpenSubKey(temp,true); | 333 ourkey = ourkey.OpenSubKey(temp,true); |
| 334 string[] entryNames = new string[keyName.entryNames.Count]; | 334 string[] entryNames = new string[keyName.entryNames.Count]; |
| 335 keyName.entryNames.CopyTo(entryNames); | 335 keyName.entryNames.CopyTo(entryNames); |
| 336 string[] entryValues = new string[keyName.entryValues.Count]; | 336 string[] entryValues = new string[keyName.entryValues.Count]; |
| 337 keyName.entryValues.CopyTo(entryValues); | 337 keyName.entryValues.CopyTo(entryValues); |
| 338 if(!deleteCurrent(ourkey)) return false; | 338 if(!deleteCurrent(ourkey)) return false; |
| 339 if(!addNew(ourkey, entryNames, entryValues)) return false; | 339 if(!addNew(ourkey, entryNames, entryValues)) return false; |
| 340 rm.regkeyObject = keyName; | 340 rm.regkeyObject = keyName; |
| 341 ourkey.Close(); | 341 ourkey.Close(); |
| 342 return true; | 342 return true; |
| 343 } | 343 } |
| 344 else return false; | 344 else return false; |
| 345 } | 345 } |
| 346 catch(System.Exception){return false;} | 346 catch(System.Exception){return false;} |
| 347 } | 347 } |
| 348 if(rm.messageType == RegEnumMsg.MATCH_REQUEST) | 348 if(rm.messageType == RegEnumMsg.MATCH_REQUEST) |
| 349 { | 349 { |
| 350 try | 350 try |
| 351 { | 351 { |
| 352 ourkey = ourkey.OpenSubKey(@temp,true); | 352 ourkey = ourkey.OpenSubKey(@temp,true); |
| 353 foreach(string valuename in ourkey.GetValueNames()) | 353 foreach(string valuename in ourkey.GetValueNames()) |
| 354 { | 354 { |
| 355 keyName.valueCount++; | 355 keyName.valueCount++; |
| 356 keyName.entryNames.Add(valuename); | 356 keyName.entryNames.Add(valuename); |
| 357 keyName.entryTypes.Add(ourkey.GetValue(valuename).GetType().ToString() ); | 357 keyName.entryTypes.Add(ourkey.GetValue(valuename).GetType().ToString() ); |
| 358 keyName.entryValues.Add(ourkey.GetValue(valuename).ToString()); | 358 keyName.entryValues.Add(ourkey.GetValue(valuename).ToString()); |
| 359 rm.regkeyObject = keyName; | 359 rm.regkeyObject = keyName; |
| 360 } | 360 } |
| 361 ourkey.Close(); | 361 ourkey.Close(); |
| 362 } | 362 } |
| 363 catch(System.Exception){ ourkey.Close(); return false;} | 363 catch(System.Exception){ ourkey.Close(); return false;} |
| 364 } | 364 } |
| 365 return true; | 365 return true; |
| 366 } | 366 } |
| 367 catch(Exception) {return false;} | 367 catch(Exception) {return false;} |
| 368 } | 368 } |
| 369 | 369 |
| 370 | 370 |
| 371 //----<match when a (entryName, entryValue) pair for a key is passed>------- | 371 //----<match when a (entryName, entryValue) pair for a key is passed>------- |
| 372 // 40 lines | 372 // 40 lines |
| 373 public bool match(string entryName, string entryValue, ref RegistryMessage rm) | 373 public bool match(string entryName, string entryValue, ref RegistryMessage rm) |
| 374 { | 374 { |
| 375 try | 375 try |
| 376 { | 376 { |
| 377 _valueData = entryValue; | 377 _valueData = entryValue; |
| 378 RegistryKey ourkey = Registry.ClassesRoot; | 378 RegistryKey ourkey = Registry.ClassesRoot; |
| 379 string[] names = entryName.Split('\\'); | 379 string[] names = entryName.Split('\\'); |
| 380 ourkey = getRootKey(names[0]); | 380 ourkey = getRootKey(names[0]); |
| 381 _valueName = names[names.Length-1]; | 381 _valueName = names[names.Length-1]; |
| 382 // note keyName is the string entryName till names[lenght-2] | 382 // note keyName is the string entryName till names[lenght-2] |
| 383 string temp= ""; | 383 string temp= ""; |
| 384 for(int i=1; i< names.Length-1; ++i) | 384 for(int i=1; i< names.Length-1; ++i) |
| 385 { | 385 { |
| 386 if (i == 1) | 386 if (i == 1) |
| 387 temp = names[1]; | 387 temp = names[1]; |
| 388 else | 388 else |
| 389 temp = temp + "\\" + names[i]; | 389 temp = temp + "\\" + names[i]; |
| 390 } | 390 } |
| 391 _keyName = names[0] + temp; | 391 |
| 392 _fileName = getfileName(rm.sourceIP,names[0]+temp,rm.destinationIP,rm.operationID,"rbk"); | 392 _fileName = getfileName(rm.sourceIP,names[0]+temp,rm.destinationIP,rm.operationID,"rbk"); |
| 393 | 393 |
| 394 if(rm.messageType == RegEnumMsg.MATCH_REPLY) | 394 if(rm.messageType == RegEnumMsg.MATCH_REPLY) |
| 395 { | 395 { |
| 396 try | 396 try |
| 397 { | 397 { |
| 398 if(_regRollback.SaveLocalRollbackInfo(_fileName,_keyName)) | 398 ourkey = ourkey.OpenSubKey(temp,true); |
| 399 { | 399 System.Int32 data = getType(_valueData); |
| 400 ourkey = ourkey.OpenSubKey(temp,true); | 400 if(data != -1) |
| 401 System.Int32 data = getType(_valueData); | 401 ourkey.SetValue(_valueName,data); |
| 402 if(data != -1) | 402 |
| 403 ourkey.SetValue(_valueName,data); | 403 |
| 404 else | 404 |
| 405 ourkey.SetValue(_valueName,_valueData); // problem that may arrise .. type mismatch | 405 |
| 406 ourkey.Close(); | 406 |
| 407 } | 407 |
| 408 else | 408 else |
| 409 return false; | 409 ourkey.SetValue(_valueName,_valueData); // problem that may arrise .. type mismatch |
| 410 | 410 ourkey.Close(); |
| 411 } | 411 } |
| 412 | 412 |
| 413 catch(System.Exception) | 413 catch(System.Exception) |
| 414 { | 414 { |
| 415 ourkey.Close(); | 415 ourkey.Close(); |
| 416 return false; | 416 return false; |
| 417 } | 417 } |
| 418 } | 418 } |
| 419 // if request -- need to compaose a message | 419 // if request -- need to compaose a message |
| 420 if(rm.messageType == RegEnumMsg.MATCH_REQUEST) | 420 if(rm.messageType == RegEnumMsg.MATCH_REQUEST) |
| 421 { | 421 { |
| 422 // entryname is the last substring of entryName .. everything else in entryName is basically keyName | 422 // entryname is the last substring of entryName .. everything else in entryName is basically keyName |
| 423 rm.regkeyObject.entryNames.Add(entryName); | 423 rm.regkeyObject.entryNames.Add(entryName); |
| 424 rm.regkeyObject.entryValues.Add(entryValue); | 424 rm.regkeyObject.entryValues.Add(entryValue); |
| 425 rm.regkeyObject.valueCount++; | 425 rm.regkeyObject.valueCount++; |
| 426 } | 426 } |
| 427 return true; | 427 return true; |
| 428 } | 428 } |
| 429 catch(Exception) {return false;} | 429 catch(Exception) {return false;} |
| 430 } | 430 } |
| 431 | 431 |
| 432 //----< retrieves Root Name / Hive Name of given key >---- | 432 //----< retrieves Root Name / Hive Name of given key >---- |
| 433 | 433 |
| 434 private RegistryKey getRootKey(string name) | 434 private RegistryKey getRootKey(string name) |
| 435 { | 435 { |
| 436 switch (name) // name is the hive name | 436 switch (name) // name is the hive name |
| 437 { | 437 { |
| 438 case "HKEY_CLASSES_ROOT" : | 438 case "HKEY_CLASSES_ROOT" : |
| 439 return Registry.ClassesRoot; | 439 return Registry.ClassesRoot; |
| 440 case "HKEY_CURRENT_CONFIG" : | 440 case "HKEY_CURRENT_CONFIG" : |
| 441 return Registry.CurrentConfig; | 441 return Registry.CurrentConfig; |
| 442 case "HKEY_CURRENT_USER" : | 442 case "HKEY_CURRENT_USER" : |
| 443 return Registry.CurrentUser; | 443 return Registry.CurrentUser; |
| 444 case "HKEY_LOCAL_MACHINE" : | 444 case "HKEY_LOCAL_MACHINE" : |
| 445 return Registry.LocalMachine; | 445 return Registry.LocalMachine; |
| 446 case "HKEY_USERS" : | 446 case "HKEY_USERS" : |
| 447 return Registry.Users; | 447 return Registry.Users; |
| 448 case "HKEY_DYN_DATA" : | 448 case "HKEY_DYN_DATA" : |
| 449 return Registry.DynData; | 449 return Registry.DynData; |
| 450 case "HKEY_PERFORMANCE_DATA" : | 450 case "HKEY_PERFORMANCE_DATA" : |
| 451 return Registry.PerformanceData; | 451 return Registry.PerformanceData; |
| 452 default: | 452 default: |
| 453 break; | 453 break; |
| 454 } | 454 } |
| 455 return Registry.LocalMachine; | 455 return Registry.LocalMachine; |
| 456 } | 456 } |
| 457 | 457 |
| 458 public bool delete(string keyName, string srcip, string opId) | 458 public bool delete(string keyName) |
| 459 { | 459 { |
| 460 // call local rollback info | 460 // if(//call rollback) |
| 461 if(!_regRollback.SaveLocalRollbackInfo(getfileName(srcip, keyName, srcip, opId, ".rbk"),keyName)) | 461 |
| 462 { | 462 |
| 463 return false; | 463 |
| 464 } | 464 |
| 465 else | 465 |
| 466 { | 466 |
| 467 RegistryKey ourkey = Registry.ClassesRoot; | 467 |
| 468 string[] names = _keyName.Split('\\'); | 468 |
| 469 ourkey = getRootKey(names[0]); | 469 |
| 470 | 470 |
| 471 string temp= ""; | 471 |
| 472 for(int i=1; i< names.Length; ++i) | 472 |
| 473 { | 473 |
| 474 if (i == 1) | 474 |
| 475 temp = names[1]; | 475 |
| 476 else | 476 |
| 477 temp = temp + "\\" + names[i]; | 477 |
| 478 } | 478 |
| 479 try | 479 |
| 480 { | 480 |
| 481 ourkey = ourkey.OpenSubKey(@temp,true); | 481 |
| 482 if(!deleteCurrent(ourkey)) return false; | 482 |
| 483 } | 483 |
| 484 catch(Exception) | 484 |
| 485 { | 485 |
| 486 return false; | 486 |
| 487 } | 487 |
| 488 } | 488 |
| 489 return true; | 489 |
| 490 } | 490 |
| 491 | 491 |
| 492 | 492 RegistryKey ourkey = Registry.ClassesRoot; |
| 493 | 493 string[] names = _keyName.Split('\\'); |
| 494 | 494 ourkey = getRootKey(names[0]); |
| 495 | 495 |
| 496 | 496 string temp= ""; |
| 497 | 497 for(int i=1; i< names.Length; ++i) |
| 498 | 498 { |
| 499 | 499 if (i == 1) |
| 500 | 500 temp = names[1]; |
| 501 | 501 else |
| 502 | 502 temp = temp + "\\" + names[i]; |
| 503 | 503 } |
| 504 | 504 try |
| 505 | 505 { |
| 506 | 506 ourkey = ourkey.OpenSubKey(@temp,true); |
| 507 | 507 if(!deleteCurrent(ourkey)) return false; |
| 508 | 508 } |
| 509 | 509 catch(Exception) |
| 510 | 510 { |
| 511 | 511 return false; |
| 512 | 512 } |
| 513 | 513 return true; |
| 514 | 514 // else return false |
| 515 | 515 |
| 516 | 516 } |
| 517 | 517 |
| 518 private bool deleteCurrent(RegistryKey ourkey) | 518 private bool deleteCurrent(RegistryKey ourkey) |
| 519 { | 519 { |
| 520 try | 520 try |
| 521 { | 521 { |
| 522 foreach(string sub in ourkey.GetValueNames()) | 522 foreach(string sub in ourkey.GetValueNames()) |
| 523 { | 523 { |
| 524 ourkey.DeleteValue(sub); | 524 ourkey.DeleteValue(sub); |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 catch (System.Exception) | 527 catch (System.Exception) |
| 528 { | 528 { |
| 529 return false; | 529 return false; |
| 530 } | 530 } |
| 531 return true; | 531 return true; |
| 532 } | 532 } |
| 533 | 533 |
| 534 private bool addNew(RegistryKey ourkey, string[] entryNames, string[] entryValues) | 534 private bool addNew(RegistryKey ourkey, string[] entryNames, string[] entryValues) |
| 535 { | 535 { |
| 536 try | 536 try |
| 537 { | 537 { |
| 538 for(int i = 0; i< entryNames.Length; ++i) | 538 for(int i = 0; i< entryNames.Length; ++i) |
| 539 { | 539 { |
| 540 ourkey.SetValue(entryNames[i],(object)entryValues[i]); | 540 ourkey.SetValue(entryNames[i],(object)entryValues[i]); |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 catch(System.Exception) | 543 catch(System.Exception) |
| 544 { | 544 { |
| 545 return false; | 545 return false; |
| 546 } | 546 } |
| 547 return true; | 547 return true; |
| 548 } | 548 } |
| 549 | 549 |
| 550 private string getfileName(string sourceIP, string keyName, string destIP, string operationID, string extension) | 550 private string getfileName(string sourceIP, string keyName, string destIP, string operationID, string extension) |
| 551 { | 551 { |
| 552 return(sourceIP + "~" + keyName + "~" + destIP + "~" + operationID + "." + extension); | 552 return(sourceIP + "~" + keyName + "~" + destIP + "~" + operationID + "." + extension); |
| 553 } | 553 } |
| 554 | 554 |
| 555 | 555 |
| 556 private bool isValidFileName(string fileName) | 556 private bool isValidFileName(string fileName) |
| 557 { | 557 { |
| 558 fileName = Path.GetFileName(fileName); | 558 fileName = Path.GetFileName(fileName); |
| 559 if(fileName.Split('~').Length != 4) | 559 if(fileName.Split('~').Length != 4) |
| 560 return false; | 560 return false; |
| 561 if(fileName.IndexOf(".reg") == fileName.Length) | 561 if(fileName.IndexOf(".reg") == fileName.Length) |
| 562 return false; | 562 return false; |
| 563 return true; | 563 return true; |
| 564 } | 564 } |
| 565 | 565 |
| 566 private System.Int32 getType(string valueData) | 566 private System.Int32 getType(string valueData) |
| 567 { | 567 { |
| 568 bool flag = true; | 568 bool flag = true; |
| 569 System.Int32 data = 0; | 569 System.Int32 data = 0; |
| 570 int k = 1; | 570 int k = 1; |
| 571 for(int i =0; i<valueData.Length ; ++i) | 571 for(int i =0; i<valueData.Length ; ++i) |
| 572 { | 572 { |
| 573 if(!(valueData[i] >= 48) && (valueData[i] <= 57)) | 573 if(!(valueData[i] >= 48) && (valueData[i] <= 57)) |
| 574 { | 574 { |
| 575 flag = false; | 575 flag = false; |
| 576 break; | 576 break; |
| 577 } | 577 } |
| 578 else | 578 else |
| 579 { | 579 { |
| 580 data += k*(valueData[valueData.Length - i -1]-48); | 580 data += k*(valueData[valueData.Length - i -1]-48); |
| 581 k *= 10; | 581 k *= 10; |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 if (flag) { return data;} | 584 if (flag) { return data;} |
| 585 else { return -1 ;} | 585 else { return -1 ;} |
| 586 } | 586 } |
| 587 | 587 |
| 588 public static void Main() | 588 public static void Main() |
| 589 { | 589 { |
| 590 RegistryKey ourkey = Registry.CurrentConfig; | 590 RegistryKey ourkey = Registry.CurrentConfig; |
| 591 RegistryKey local; | 591 RegistryKey local; |
| 592 local = ourkey.OpenSubKey("Software\\Fonts",true); | 592 local = ourkey.OpenSubKey("Software\\Fonts",true); |
| 593 | 593 |
| 594 | 594 |
| 595 local.SetValue("LogPixels", 96); | 595 local.SetValue("LogPixels", 96); |
| 596 local.SetValue("FIXEDFON.FON","vvvvv.fon"); | 596 local.SetValue("FIXEDFON.FON","vvvvv.fon"); |
| 597 ourkey.Close(); | 597 ourkey.Close(); |
| 598 } | 598 } |
| 599 | 599 |
| 600 | 600 |
| 601 } | 601 } |
| 602 | 602 |
| 603 #if(TEST_REGEDITING) | 603 #if(TEST_REGEDITING) |
| 604 | 604 |
| 605 [TestFixture] | 605 [TestFixture] |
| 606 public class TestDriverRegEditing | 606 public class TestDriverRegEditing |
| 607 { | 607 { |
| 608 [Test] | 608 [Test] |
| 609 public void testgetChildren() | 609 public void testgetChildren() |
| 610 { | 610 { |
| 611 RegistryEditing re = new RegistryEditing(); | 611 RegistryEditing re = new RegistryEditing(); |
| 612 RegKeyObject ko = new RegKeyObject(); | 612 RegKeyObject ko = new RegKeyObject(); |
| 613 RegistryMessage rm = new RegistryMessage(); | 613 RegistryMessage rm = new RegistryMessage(); |
| 614 System.Console.WriteLine(" The children of HKEY_CURRENT_CONFIG \n" ); | 614 System.Console.WriteLine(" The children of HKEY_CURRENT_CONFIG \n" ); |
| 615 rm.messageType = RegEnumMsg.RETRIEVE_CHILDREN_REPLY; // cause this is reply | 615 rm.messageType = RegEnumMsg.RETRIEVE_CHILDREN_REPLY; // cause this is reply |
| 616 rm.destinationIP = "123.12.2.1"; | 616 rm.destinationIP = "123.12.2.1"; |
| 617 re.getChildren("HKEY_CURRENT_CONFIG",ref rm); | 617 re.getChildren("HKEY_CURRENT_CONFIG",ref rm); |
| 618 string[] children = new string[rm.regkeyObject.Children.Count]; | 618 string[] children = new string[rm.regkeyObject.Children.Count]; |
| 619 rm.regkeyObject.Children.CopyTo(children); | 619 rm.regkeyObject.Children.CopyTo(children); |
| 620 string[] testedchilds ={"Software", "System"}; | 620 string[] testedchilds ={"Software", "System"}; |
| 621 Assert.AreEqual(children[1],testedchilds[1]); | 621 Assert.AreEqual(children[1],testedchilds[1]); |
| 622 System.Console.WriteLine(" Correct children got for HKEY_CURRENT_REPLY "); | 622 System.Console.WriteLine(" Correct children got for HKEY_CURRENT_REPLY "); |
| 623 } | 623 } |
| 624 | 624 |
| 625 [Test] | 625 [Test] |
| 626 public void testgetValues() | 626 public void testgetValues() |
| 627 { | 627 { |
| 628 RegistryEditing re = new RegistryEditing(); | 628 RegistryEditing re = new RegistryEditing(); |
| 629 RegKeyObject ko = new RegKeyObject(); | 629 RegKeyObject ko = new RegKeyObject(); |
| 630 RegistryMessage rm = new RegistryMessage(); | 630 RegistryMessage rm = new RegistryMessage(); |
| 631 int i; | 631 int i; |
| 632 System.Console.WriteLine(" The values of HKEY_CURRENT_CONFIG\\Software\\Fonts \n" ); | 632 System.Console.WriteLine(" The values of HKEY_CURRENT_CONFIG\\Software\\Fonts \n" ); |
| 633 rm.messageType = RegEnumMsg.RETRIEVE_VALUES_REPLY; | 633 rm.messageType = RegEnumMsg.RETRIEVE_VALUES_REPLY; |
| 634 rm.destinationIP = "134.45.12.2"; | 634 rm.destinationIP = "134.45.12.2"; |
| 635 re.getValue("HKEY_CURRENT_CONFIG\\Software\\Fonts", ref rm); | 635 re.getValue("HKEY_CURRENT_CONFIG\\Software\\Fonts", ref rm); |
| 636 System.Console.WriteLine("NAME \t\t TYPE \t\t VALUE"); | 636 System.Console.WriteLine("NAME \t\t TYPE \t\t VALUE"); |
| 637 string[] entryNames = new string[rm.regkeyObject.entryNames.Count]; | 637 string[] entryNames = new string[rm.regkeyObject.entryNames.Count]; |
| 638 rm.regkeyObject.entryNames.CopyTo(entryNames); | 638 rm.regkeyObject.entryNames.CopyTo(entryNames); |
| 639 string[] entryTypes = new string[rm.regkeyObject.entryTypes.Count]; | 639 string[] entryTypes = new string[rm.regkeyObject.entryTypes.Count]; |
| 640 rm.regkeyObject.entryTypes.CopyTo(entryTypes); | 640 rm.regkeyObject.entryTypes.CopyTo(entryTypes); |
| 641 string[] entryValues = new string[rm.regkeyObject.entryValues.Count]; | 641 string[] entryValues = new string[rm.regkeyObject.entryValues.Count]; |
| 642 rm.regkeyObject.entryValues.CopyTo(entryValues); | 642 rm.regkeyObject.entryValues.CopyTo(entryValues); |
| 643 for(i=0; i< rm.regkeyObject.valueCount; ++i) | 643 for(i=0; i< rm.regkeyObject.valueCount; ++i) |
| 644 { | 644 { |
| 645 System.Console.Write(entryNames[i]); | 645 System.Console.Write(entryNames[i]); |
| 646 System.Console.Write("\t"); | 646 System.Console.Write("\t"); |
| 647 System.Console.Write(entryTypes[i]); | 647 System.Console.Write(entryTypes[i]); |
| 648 System.Console.Write("\t"); | 648 System.Console.Write("\t"); |
| 649 System.Console.Write(entryValues[i]); | 649 System.Console.Write(entryValues[i]); |
| 650 System.Console.WriteLine(); | 650 System.Console.WriteLine(); |
| 651 } | 651 } |
| 652 Assert.AreEqual(entryValues[1],"vgasys.fon"); | 652 Assert.AreEqual(entryValues[1],"vgasys.fon"); |
| 653 System.Console.WriteLine(" getValues() worked as expected for HKEY_CURRENT_CONFIG\\Software\\Fonts"); | 653 System.Console.WriteLine(" getValues() worked as expected for HKEY_CURRENT_CONFIG\\Software\\Fonts"); |
| 654 | 654 |
| 655 } | 655 } |
| 656 | 656 |
| 657 [Test] | 657 [Test] |
| 658 public void testmatch3() | 658 public void testmatch3() |
| 659 { | 659 { |
| 660 System.Console.WriteLine("Testing for match(entryName, entryValue, destIP"); | 660 System.Console.WriteLine("Testing for match(entryName, entryValue, destIP"); |
| 661 RegistryEditing re = new RegistryEditing(); | 661 RegistryEditing re = new RegistryEditing(); |
| 662 RegKeyObject ko = new RegKeyObject(); | 662 RegKeyObject ko = new RegKeyObject(); |
| 663 RegistryMessage rm = new RegistryMessage(); | 663 RegistryMessage rm = new RegistryMessage(); |
| 664 string old = ""; | 664 string old = ""; |
| 665 int i; | 665 int i; |
| 666 System.Console.WriteLine("Matching (key,value) pair for HKEY_CURRENT_CONFIG\\Software\\Fonts\\LogPixels \n changing it to 48 \n"); | 666 System.Console.WriteLine("Matching (key,value) pair for HKEY_CURRENT_CONFIG\\Software\\Fonts\\LogPixels \n changing it to 48 \n"); |
| 667 System.Console.Write("OLD value of the key : "); | 667 System.Console.Write("OLD value of the key : "); |
| 668 rm.messageType = RegEnumMsg.RETRIEVE_VALUES_REPLY; | 668 rm.messageType = RegEnumMsg.RETRIEVE_VALUES_REPLY; |
| 669 rm.destinationIP = "123.23.12.5"; | 669 rm.destinationIP = "123.23.12.5"; |
| 670 re.getValue("HKEY_CURRENT_CONFIG\\Software\\Fonts", ref rm); | 670 re.getValue("HKEY_CURRENT_CONFIG\\Software\\Fonts", ref rm); |
| 671 string[] entryNames = new string[rm.regkeyObject.entryNames.Count]; | 671 string[] entryNames = new string[rm.regkeyObject.entryNames.Count]; |
| 672 rm.regkeyObject.entryNames.CopyTo(entryNames); | 672 rm.regkeyObject.entryNames.CopyTo(entryNames); |
| 673 string[] entryValues = new string[rm.regkeyObject.entryValues.Count]; | 673 string[] entryValues = new string[rm.regkeyObject.entryValues.Count]; |
| 674 rm.regkeyObject.entryValues.CopyTo(entryValues); | 674 rm.regkeyObject.entryValues.CopyTo(entryValues); |
| 675 for(i=0; i< rm.regkeyObject.valueCount; ++i) | 675 for(i=0; i< rm.regkeyObject.valueCount; ++i) |
| 676 { | 676 { |
| 677 if(entryNames[i] == "LogPixels") | 677 if(entryNames[i] == "LogPixels") |
| 678 { | 678 { |
| 679 System.Console.Write(entryValues[i]); | 679 System.Console.Write(entryValues[i]); |
| 680 old = entryValues[i]; | 680 old = entryValues[i]; |
| 681 break; | 681 break; |
| 682 } | 682 } |
| 683 } | 683 } |
| 684 | 684 |
| 685 | 685 |
| 686 rm.messageType = RegEnumMsg.MATCH_REPLY; | 686 rm.messageType = RegEnumMsg.MATCH_REPLY; |
| 687 re.match("HKEY_CURRENT_CONFIG\\Software\\Fonts\\LogPixels" , "48", ref rm); | 687 re.match("HKEY_CURRENT_CONFIG\\Software\\Fonts\\LogPixels" , "48", ref rm); |
| 688 string newstr= ""; | 688 string newstr= ""; |
| 689 | 689 |
| 690 rm.regkeyObject.entryNames.Clear(); | 690 rm.regkeyObject.entryNames.Clear(); |
| 691 rm.regkeyObject.entryTypes.Clear(); | 691 rm.regkeyObject.entryTypes.Clear(); |
| 692 rm.regkeyObject.entryValues.Clear(); | 692 rm.regkeyObject.entryValues.Clear(); |
| 693 rm.regkeyObject.valueCount = 0; | 693 rm.regkeyObject.valueCount = 0; |
| 694 rm.messageType = RegEnumMsg.RETRIEVE_VALUES_REPLY; | 694 rm.messageType = RegEnumMsg.RETRIEVE_VALUES_REPLY; |
| 695 re.getValue("HKEY_CURRENT_CONFIG\\Software\\Fonts", ref rm); | 695 re.getValue("HKEY_CURRENT_CONFIG\\Software\\Fonts", ref rm); |
| 696 entryNames = new string[rm.regkeyObject.entryNames.Count]; | 696 entryNames = new string[rm.regkeyObject.entryNames.Count]; |
| 697 rm.regkeyObject.entryNames.CopyTo(entryNames); | 697 rm.regkeyObject.entryNames.CopyTo(entryNames); |
| 698 entryValues = new string[rm.regkeyObject.entryValues.Count]; | 698 entryValues = new string[rm.regkeyObject.entryValues.Count]; |
| 699 rm.regkeyObject.entryValues.CopyTo(entryValues); | 699 rm.regkeyObject.entryValues.CopyTo(entryValues); |
| 700 for(i=0; i< rm.regkeyObject.valueCount; ++i) | 700 for(i=0; i< rm.regkeyObject.valueCount; ++i) |
| 701 { | 701 { |
| 702 if(entryNames[i] == "LogPixels") | 702 if(entryNames[i] == "LogPixels") |
| 703 { | 703 { |
| 704 System.Console.Write("\n New Value of key : "); | 704 System.Console.Write("\n New Value of key : "); |
| 705 System.Console.WriteLine( entryValues[i]); | 705 System.Console.WriteLine( entryValues[i]); |
| 706 newstr = entryValues[i]; | 706 newstr = entryValues[i]; |
| 707 break; | 707 break; |
| 708 } | 708 } |
| 709 } | 709 } |
| 710 Assert.AreEqual("48",newstr); | 710 Assert.AreEqual("48",newstr); |
| 711 System.Console.Read (); | 711 System.Console.Read (); |
| 712 | 712 |
| 713 } | 713 } |
| 714 | 714 |
| 715 [Test] | 715 [Test] |
| 716 public void testmatch2() | 716 public void testmatch2() |
| 717 { | 717 { |
| 718 RegistryMessage rm = new RegistryMessage(); | 718 RegistryMessage rm = new RegistryMessage(); |
| 719 RegistryEditing re = new RegistryEditing(); | 719 RegistryEditing re = new RegistryEditing(); |
| 720 RegKeyObject ro = new RegKeyObject(); | 720 RegKeyObject ro = new RegKeyObject(); |
| 721 ro.keyName = "HKEY_CURRENT_CONFIG\\Software\\Fonts"; | 721 ro.keyName = "HKEY_CURRENT_CONFIG\\Software\\Fonts"; |
| 722 System.Console.WriteLine(" matching HKEY_CURRENT_CONFIG\\Software\\Fonts \n on to the same key on the local m/c "); | 722 System.Console.WriteLine(" matching HKEY_CURRENT_CONFIG\\Software\\Fonts \n on to the same key on the local m/c "); |
| 723 rm.messageType = RegEnumMsg.MATCH_REQUEST; | 723 rm.messageType = RegEnumMsg.MATCH_REQUEST; |
| 724 rm.sourceIP = "123.45.3.4"; | 724 rm.sourceIP = "123.45.3.4"; |
| 725 rm.destinationIP = "123.45.3.4"; | 725 rm.destinationIP = "123.45.3.4"; |
| 726 rm.regkeyObject.keyName = ro.keyName; | 726 rm.regkeyObject.keyName = ro.keyName; |
| 727 re.match(ref ro, ref rm); // first fill up the request message | 727 re.match(ref ro, ref rm); // first fill up the request message |
| 728 // now assuming that the message was recieved from the MBE call match again to form the reply message | 728 // now assuming that the message was recieved from the MBE call match again to form the reply message |
| 729 rm.messageType = RegEnumMsg.MATCH_REPLY; | 729 rm.messageType = RegEnumMsg.MATCH_REPLY; |
| 730 re.match(ref ro, ref rm); | 730 re.match(ref ro, ref rm); |
| 731 Assert.AreEqual (4, rm.regkeyObject.valueCount); | 731 Assert.AreEqual (4, rm.regkeyObject.valueCount); |
| 732 System.Console.WriteLine(" Match finished with expected results"); | 732 System.Console.WriteLine(" Match finished with expected results"); |
| 733 | 733 |
| 734 } | 734 } |
| 735 | 735 |
| 736 // to change once the .reg files are there | 736 // to change once the .reg files are there |
| 737 [Test] | 737 [Test] |
| 738 public void testmatch1() | 738 public void testmatch1() |
| 739 { | 739 { |
| 740 RegistryMessage rm = new RegistryMessage(); | 740 RegistryMessage rm = new RegistryMessage(); |
| 741 RegistryEditing re = new RegistryEditing(); | 741 RegistryEditing re = new RegistryEditing(); |
| 742 System.Console.WriteLine(" checking match with fileName and RegistryMessage "); | 742 System.Console.WriteLine(" checking match with fileName and RegistryMessage "); |
| 743 string fileName = "123.45.3.4~HKEY_CURRENT_CONFIG\\Software\\Fonts~123.45.3.4~897.reg"; | 743 string fileName = "123.45.3.4~HKEY_CURRENT_CONFIG\\Software\\Fonts~123.45.3.4~897.reg"; |
| 744 rm.fileName = fileName; | 744 rm.fileName = fileName; |
| 745 rm.sourceIP = "123.45.3.4"; | 745 rm.sourceIP = "123.45.3.4"; |
| 746 rm.destinationIP = "123.45.3.4"; | 746 rm.destinationIP = "123.45.3.4"; |
| 747 rm.messageType = RegEnumMsg.MATCH_REPLY; | 747 rm.messageType = RegEnumMsg.MATCH_REPLY; |
| 748 // this part will change | 748 // this part will change |
| 749 bool flag = re.match(fileName, ref rm); | 749 bool flag = re.match(fileName, ref rm); |
| 750 Assert.AreEqual(true,flag); | 750 Assert.AreEqual(true,flag); |
| 751 System.Console.WriteLine(" Performed as Expected ... (match with fileName and RegistryMessage)"); | 751 System.Console.WriteLine(" Performed as Expected ... (match with fileName and RegistryMessage)"); |
| 752 System.Console.Read(); | 752 System.Console.Read(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 | 755 |
| 756 [STAThread] | 756 [STAThread] |
| 757 static void Main() | 757 static void Main() |
| 758 { | 758 { |
| 759 TestDriverRegEditing tde = new TestDriverRegEditing(); | 759 TestDriverRegEditing tde = new TestDriverRegEditing(); |
| 760 tde.testgetChildren(); | 760 tde.testgetChildren(); |
| 761 tde.testmatch1() ; | 761 tde.testmatch1() ; |
| 762 tde.testmatch2(); | 762 tde.testmatch2(); |
| 763 tde.testmatch3() ; | 763 tde.testmatch3() ; |
| 764 } | 764 } |
| 765 | 765 |
| 766 } | 766 } |
| 767 | 767 |
| 768 #endif | 768 #endif |
| 769 } | 769 } |