Changeset 601
- Timestamp:
- 11/19/2008 1:00:48 PM (4 years ago)
- Location:
- branches/eraser6
- Files:
-
- 4 edited
-
DefaultPlugins/EraseGutmann.cs (modified) (2 diffs)
-
DefaultPlugins/EraseRandom.cs (modified) (2 diffs)
-
DefaultPlugins/RNGCrypto.cs (modified) (2 diffs)
-
Manager/Settings.cs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/DefaultPlugins/EraseGutmann.cs
r374 r601 26 26 using System.Collections.Generic; 27 27 using System.Text; 28 using System.Runtime.InteropServices; 28 29 29 30 using Eraser.Manager; … … 32 33 namespace Eraser.DefaultPlugins 33 34 { 34 class Gutmann : PassBasedErasureMethod 35 [DefaultFileErasure(1)] 36 [Guid("1407FC4E-FEFF-4375-B4FB-D7EFBB7E9922")] 37 public class Gutmann : PassBasedErasureMethod 35 38 { 36 39 public override string Name -
branches/eraser6/DefaultPlugins/EraseRandom.cs
r348 r601 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Runtime.InteropServices; 25 26 26 27 using Eraser.Manager; … … 29 30 namespace Eraser.DefaultPlugins 30 31 { 32 [DefaultUnusedSpaceErasure(1)] 33 [Guid("BF8BA267-231A-4085-9BF9-204DE65A6641")] 31 34 class Pseudorandom : PassBasedErasureMethod 32 35 { -
branches/eraser6/DefaultPlugins/RNGCrypto.cs
r348 r601 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Runtime.InteropServices; 25 26 26 27 using Eraser.Manager; … … 30 31 namespace Eraser.DefaultPlugins 31 32 { 33 [DefaultPRNG(1)] 34 [Guid("6BF35B8E-F37F-476e-B6B2-9994A92C3B0C")] 32 35 public class RNGCrypto : PRNG 33 36 { -
branches/eraser6/Manager/Settings.cs
r583 r601 25 25 using System.Reflection; 26 26 using System.Runtime.InteropServices; 27 using Eraser.Util; 27 28 28 29 namespace Eraser.Manager … … 92 93 } 93 94 95 #region Default attributes 96 /// <summary> 97 /// Indicates that the marked class should be used as a default when no 98 /// settings have been set by the user. 99 /// </summary> 100 [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] 101 public abstract class DefaultAttribute : Attribute 102 { 103 /// <summary> 104 /// Constructor. 105 /// </summary> 106 /// <param name="priority">The priority of the current element in terms of 107 /// it being the default.</param> 108 public DefaultAttribute(int priority) 109 { 110 Priority = priority; 111 } 112 113 /// <summary> 114 /// The priority of the default. 115 /// </summary> 116 public int Priority 117 { 118 get 119 { 120 return priority; 121 } 122 private set 123 { 124 priority = value; 125 } 126 } 127 128 private int priority; 129 } 130 131 /// <summary> 132 /// Indicates that the marked class should be used as the default file erasure 133 /// method. 134 /// </summary> 135 [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)] 136 public sealed class DefaultFileErasureAttribute : DefaultAttribute 137 { 138 /// <summary> 139 /// Constructor. 140 /// </summary> 141 /// <param name="priority">The priority of the current element in terms of 142 /// it being the default.</param> 143 public DefaultFileErasureAttribute(int priority) 144 : base(priority) 145 { 146 } 147 } 148 149 /// <summary> 150 /// Indicates that the marked class should be used as the default unused space 151 /// erasure method. 152 /// </summary> 153 [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)] 154 public sealed class DefaultUnusedSpaceErasureAttribute : DefaultAttribute 155 { 156 /// <summary> 157 /// Constructor. 158 /// </summary> 159 /// <param name="priority">The priority of the current element in terms of 160 /// it being the default.</param> 161 public DefaultUnusedSpaceErasureAttribute(int priority) 162 : base(priority) 163 { 164 } 165 } 166 167 /// <summary> 168 /// Indicates that the marked class should be used as the default PRNG. 169 /// </summary> 170 [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)] 171 public sealed class DefaultPRNGAttribute : DefaultAttribute 172 { 173 /// <summary> 174 /// Constructor. 175 /// </summary> 176 /// <param name="priority">The priority of the current element in terms of 177 /// it being the default.</param> 178 public DefaultPRNGAttribute(int priority) 179 : base(priority) 180 { 181 } 182 } 183 #endregion 184 94 185 /// <summary> 95 186 /// Handles the settings related to the Eraser Manager. … … 116 207 get 117 208 { 118 return settings["DefaultFileErasureMethod"] == null ? 119 new Guid("1407FC4E-FEFF-4375-B4FB-D7EFBB7E9922") : 120 (Guid)settings["DefaultFileErasureMethod"]; 209 //If the user did not define anything for this field, check all plugins 210 //and use the method which was declared by us to be the highest 211 //priority default 212 if (settings["DefaultFileErasureMethod"] == null) 213 { 214 Guid result = FindHighestPriorityDefault(typeof(ErasureMethod), 215 typeof(DefaultFileErasureAttribute)); 216 return result == Guid.Empty ? new Guid("{1407FC4E-FEFF-4375-B4FB-D7EFBB7E9922}") : 217 result; 218 } 219 else 220 return (Guid)settings["DefaultFileErasureMethod"]; 121 221 } 122 222 set … … 135 235 get 136 236 { 137 return settings["DefaultUnusedSpaceErasureMethod"] == null ? 138 new Guid("{BF8BA267-231A-4085-9BF9-204DE65A6641}") : 139 (Guid)settings["DefaultUnusedSpaceErasureMethod"]; 237 if (settings["DefaultUnusedSpaceErasureMethod"] == null) 238 { 239 Guid result = FindHighestPriorityDefault(typeof(UnusedSpaceErasureMethod), 240 typeof(DefaultUnusedSpaceErasureAttribute)); 241 return result == Guid.Empty ? new Guid("{BF8BA267-231A-4085-9BF9-204DE65A6641}") : 242 result; 243 } 244 else 245 return (Guid)settings["DefaultUnusedSpaceErasureMethod"]; 140 246 } 141 247 set … … 153 259 get 154 260 { 155 return settings["ActivePRNG"] == null ? 156 new Guid("{6BF35B8E-F37F-476e-B6B2-9994A92C3B0C}") : 157 (Guid)settings["ActivePRNG"]; 261 if (settings["ActivePRNG"] == null) 262 { 263 Guid result = FindHighestPriorityDefault(typeof(PRNG), 264 typeof(DefaultPRNGAttribute)); 265 return result == Guid.Empty ? new Guid("{6BF35B8E-F37F-476e-B6B2-9994A92C3B0C}") : 266 result; 267 } 268 else 269 return (Guid)settings["ActivePRNG"]; 158 270 } 159 271 set … … 249 361 } 250 362 363 #region Default Attributes retrieval 364 private static Guid FindHighestPriorityDefault(Type superClass, 365 Type attributeType) 366 { 367 Plugin.Host pluginHost = ManagerLibrary.Instance.Host; 368 List<Plugin.PluginInstance> plugins = pluginHost.Plugins; 369 SortedList<int, Guid> priorities = new SortedList<int, Guid>(); 370 371 foreach (Plugin.PluginInstance plugin in plugins) 372 { 373 Type[] types = FindTypeAttributeInAssembly(plugin.Assembly, 374 superClass, attributeType); 375 376 //Prioritize the types. 377 if (types != null) 378 foreach (Type type in types) 379 { 380 object[] guids = 381 type.GetCustomAttributes(typeof(GuidAttribute), false); 382 DefaultAttribute defaultAttr = (DefaultAttribute) 383 type.GetCustomAttributes(attributeType, false)[0]; 384 385 if (guids.Length == 1) 386 priorities.Add(defaultAttr.Priority, 387 new Guid(((GuidAttribute)guids[0]).Value)); 388 } 389 } 390 391 //Return the highest priority one. 392 if (priorities.Count > 0) 393 return priorities[priorities.Keys[priorities.Count - 1]]; 394 return Guid.Empty; 395 } 396 397 private static Type[] FindTypeAttributeInAssembly(Assembly assembly, Type superClass, 398 Type attributeType) 399 { 400 //Check whether the plugin is signed by us. 401 byte[] pluginKey = assembly.GetName().GetPublicKey(); 402 byte[] ourKey = Assembly.GetExecutingAssembly().GetName().GetPublicKey(); 403 404 //Definitely not signed by us. 405 if (pluginKey.Length != ourKey.Length || 406 !MsCorEEAPI.VerifyStrongName(assembly.Location)) 407 return null; 408 409 //Not by us, either 410 bool officialPlugin = true; 411 for (int i = 0, j = ourKey.Length; i != j; ++i) 412 if (pluginKey[i] != ourKey[i]) 413 officialPlugin = false; 414 if (!officialPlugin) 415 return null; 416 417 //Yes, if we got here the plugin is signed by us. Find the 418 //type which inherits from ErasureMethod. 419 Type[] types = assembly.GetExportedTypes(); 420 List<Type> result = new List<Type>(); 421 foreach (Type type in types) 422 { 423 if (!type.IsPublic || type.IsAbstract) 424 //Not interesting. 425 continue; 426 427 //Try to see if this class inherits from the specified super class. 428 if (!type.IsSubclassOf(superClass)) 429 continue; 430 431 //See if this class has the DefaultFileErasureAttribute 432 object[] attributes = type.GetCustomAttributes(attributeType, false); 433 if (attributes.Length > 0) 434 result.Add(type); 435 } 436 437 return result.ToArray(); 438 } 439 #endregion 440 251 441 /// <summary> 252 442 /// Holds user decisions on whether the plugin will be loaded at the next
Note: See TracChangeset
for help on using the changeset viewer.
