Changeset 1981 for trunk/eraser
- Timestamp:
- 4/28/2010 8:26:57 AM (3 years ago)
- Location:
- trunk/eraser
- Files:
-
- 7 edited
-
Eraser.BlackBox/Eraser.BlackBox.csproj (modified) (1 diff)
-
Eraser.BlackBox/Plugin.cs (modified) (1 diff)
-
Eraser.BlackBox/Properties/AssemblyInfo.cs (modified) (1 diff)
-
Eraser.DefaultPlugins/Properties/AssemblyInfo.cs (modified) (1 diff)
-
Eraser.Manager/Plugins.cs (modified) (5 diffs)
-
Eraser.Util/Eraser.Util.csproj (modified) (1 diff)
-
Eraser/SettingsPanel.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.BlackBox/Eraser.BlackBox.csproj
r1980 r1981 116 116 </ProjectReference> 117 117 </ItemGroup> 118 <ItemGroup>119 <None Include="Strong Name.snk" />120 </ItemGroup>121 118 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 122 119 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
trunk/eraser/Eraser.BlackBox/Plugin.cs
r1979 r1981 47 47 public string Name 48 48 { 49 get { throw new NotImplementedException(); }49 get { return "Eraser BlackBox"; } 50 50 } 51 51 52 52 public string Author 53 53 { 54 get { throw new NotImplementedException(); }54 get { return "The Eraser Project <eraser-development@lists.sourceforge.net>"; } 55 55 } 56 56 57 57 public bool Configurable 58 58 { 59 get { throw new NotImplementedException(); }59 get { return false; } 60 60 } 61 61 -
trunk/eraser/Eraser.BlackBox/Properties/AssemblyInfo.cs
r1973 r1981 24 24 // The following GUID is for the ID of the typelib if this project is exposed to COM 25 25 [assembly: Guid("3460478d-ed1b-4ecc-96c9-2ca0e8500557")] 26 27 // The plugin is an optional Eraser plugin, which should default to not load. 28 [assembly: Eraser.Manager.Plugin.LoadingPolicy(Eraser.Manager.Plugin.LoadingPolicy.DefaultOff)] -
trunk/eraser/Eraser.DefaultPlugins/Properties/AssemblyInfo.cs
r1682 r1981 26 26 27 27 // The plugin is a Core Eraser plugin, declare it so. 28 [assembly: Eraser.Manager.Plugin. Core]28 [assembly: Eraser.Manager.Plugin.LoadingPolicy(Eraser.Manager.Plugin.LoadingPolicy.Core)] -
trunk/eraser/Eraser.Manager/Plugins.cs
r1815 r1981 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Linq; 26 25 27 using System.IO; 26 28 using System.Reflection; … … 213 215 plugins.Add(instance); 214 216 215 // The plugin was not disabled or it was loaded for the first time. Check216 // the plugin for the presence ofa valid signature.217 //If the plugin does not have an approval or denial, check for the presence of 218 //a valid signature. 217 219 IDictionary<Guid, bool> approvals = ManagerLibrary.Settings.PluginApprovals; 218 if ((reflectAssembly.GetName().GetPublicKey().Length == 0 || 220 if (!approvals.ContainsKey(instance.AssemblyInfo.Guid) && 221 (reflectAssembly.GetName().GetPublicKey().Length == 0 || 219 222 !Security.VerifyStrongName(filePath) || 220 instance.AssemblyAuthenticode == null) && 221 !approvals.ContainsKey(instance.AssemblyInfo.Guid)) 223 instance.AssemblyAuthenticode == null)) 222 224 { 223 225 return; 224 226 } 225 227 226 //Load the plugin 228 //The plugin either is explicitly allowed or disallowed to load, or 229 //it has an Authenticode Signature as well as a Strong Name. Get the 230 //loading policy of the plugin. 227 231 instance.Assembly = Assembly.LoadFrom(filePath); 228 229 //See if the plugin belongs to us (same signature) and if the assembly 230 //declares an IsCore attribute. 231 if (reflectAssembly.GetName().GetPublicKey().Length == 232 Assembly.GetExecutingAssembly().GetName().GetPublicKey().Length) 233 { 234 bool sameKey = true; 235 byte[] reflectAssemblyKey = reflectAssembly.GetName().GetPublicKey(); 236 byte[] thisAssemblyKey = Assembly.GetExecutingAssembly().GetName().GetPublicKey(); 237 for (int i = 0, j = reflectAssemblyKey.Length; i != j; ++i) 238 if (reflectAssemblyKey[i] != thisAssemblyKey[i]) 232 LoadingPolicy policy = LoadingPolicy.None; 233 { 234 object[] attr = instance.Assembly.GetCustomAttributes(typeof(LoadingPolicyAttribute), true); 235 if (attr.Length != 0) 236 { 237 policy = ((LoadingPolicyAttribute)attr[0]).Policy; 238 239 //If the loading policy is that the plugin is Core, we need to verify 240 //the public key of the assembly. 241 if (policy == LoadingPolicy.Core && 242 !reflectAssembly.GetName().GetPublicKey().SequenceEqual( 243 Assembly.GetExecutingAssembly().GetName().GetPublicKey())) 239 244 { 240 sameKey = false; 241 break; 245 policy = LoadingPolicy.None; 242 246 } 243 244 //Check for the IsCore attribute. 245 if (sameKey) 247 } 248 } 249 250 bool loadPlugin = false; 251 252 //If the loading policy is such that the plugin is a core plugin, ALWAYS load it. 253 if (policy == LoadingPolicy.Core) 254 loadPlugin = true; 255 256 //The plugin is not a core plugin, is there an approval or denial? 257 else if (approvals.ContainsKey(instance.AssemblyInfo.Guid)) 258 loadPlugin = approvals[instance.AssemblyInfo.Guid]; 259 260 //There's no approval or denial, what is the specified loading policy? 261 else 262 loadPlugin = policy != LoadingPolicy.DefaultOff; 263 264 265 if (loadPlugin) 266 { 267 try 246 268 { 247 object[] attr = instance.Assembly.GetCustomAttributes(typeof(CoreAttribute), true); 248 if (attr.Length != 0) 249 instance.IsCore = true; 269 //Initialize the plugin 270 IPlugin pluginInterface = (IPlugin)Activator.CreateInstance( 271 instance.Assembly.GetType(typePlugin.ToString())); 272 pluginInterface.Initialize(this); 273 instance.Plugin = pluginInterface; 274 275 //And broadcast the plugin load event 276 OnPluginLoaded(this, new PluginLoadedEventArgs(instance)); 250 277 } 251 } 252 253 //See if the user disabled this plugin (users cannot disable Core plugins) 254 if (approvals.ContainsKey(instance.AssemblyInfo.Guid) && 255 !approvals[instance.AssemblyInfo.Guid] && !instance.IsCore) 256 { 257 return; 258 } 259 260 try 261 { 262 //Initialize the plugin 263 IPlugin pluginInterface = (IPlugin)Activator.CreateInstance( 264 instance.Assembly.GetType(typePlugin.ToString())); 265 pluginInterface.Initialize(this); 266 instance.Plugin = pluginInterface; 267 268 //And broadcast the plugin load event 269 OnPluginLoaded(this, new PluginLoadedEventArgs(instance)); 270 } 271 catch (System.Security.SecurityException e) 272 { 273 MessageBox.Show(S._("Could not load the plugin {0}.\n\nThe error returned was: {1}", 274 filePath, e.Message), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error, 275 MessageBoxDefaultButton.Button1, Localisation.IsRightToLeft(null) ? 276 MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0); 278 catch (System.Security.SecurityException e) 279 { 280 MessageBox.Show(S._("Could not load the plugin {0}.\n\nThe error returned was: {1}", 281 filePath, e.Message), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error, 282 MessageBoxDefaultButton.Button1, Localisation.IsRightToLeft(null) ? 283 MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0); 284 } 277 285 } 278 286 } … … 310 318 Assembly = assembly; 311 319 Plugin = plugin; 312 IsCore = false;313 320 314 321 //Verify the certificate in the assembly. … … 361 368 /// therefore cannot be disabled.) 362 369 /// </summary> 363 public bool IsCore{ get; internal set; }370 public LoadingPolicy LoadingPolicy { get; internal set; } 364 371 365 372 /// <summary> … … 477 484 478 485 /// <summary> 479 /// Declares that the entity referenced is a core plugin and cannot be unloaded. 480 /// Only plugins signed with the same signature as the Manager library will be 481 /// considered to be safe and therefore checked for this attribute. 482 /// </summary> 483 [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] 484 public sealed class CoreAttribute : Attribute 485 { 486 /// Loading policies applicable for a given plugin. 487 /// </summary> 488 public enum LoadingPolicy 489 { 490 /// <summary> 491 /// The host decides the best policy for loading the plugin. 492 /// </summary> 493 None, 494 495 /// <summary> 496 /// The host will enable the plugin by default. 497 /// </summary> 498 DefaultOn, 499 500 /// <summary> 501 /// The host will disable the plugin by default 502 /// </summary> 503 DefaultOff, 504 505 /// <summary> 506 /// The host must always load the plugin. 507 /// </summary> 508 /// <remarks>For this policy to have an effect, the plugin assembly must 509 /// have the same Strong Name as the loading assembly, otherwise it defaults 510 /// to None.</remarks> 511 Core 512 } 513 514 /// <summary> 515 /// Declares the loading policy for the assembly containing the plugin. Only 516 /// plugins signed with an Authenticode signature will be trusted and have 517 /// this attribute checked at initialisation. 518 /// </summary> 519 [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] 520 public sealed class LoadingPolicyAttribute : Attribute 521 { 522 /// <summary> 523 /// Constructor. 524 /// </summary> 525 /// <param name="policy">The policy used for loading the plugin.</param> 526 public LoadingPolicyAttribute(LoadingPolicy policy) 527 { 528 Policy = policy; 529 } 530 531 /// <summary> 532 /// The loading policy to be applied to the assembly. 533 /// </summary> 534 public LoadingPolicy Policy 535 { 536 get; 537 set; 538 } 486 539 } 487 540 } -
trunk/eraser/Eraser.Util/Eraser.Util.csproj
r1976 r1981 63 63 </Reference> 64 64 <Reference Include="System.Data" /> 65 <Reference Include="System.Data.Linq"> 66 <RequiredTargetFramework>3.5</RequiredTargetFramework> 67 </Reference> 65 68 <Reference Include="System.Drawing" /> 66 69 <Reference Include="System.Management" /> -
trunk/eraser/Eraser/SettingsPanel.cs
r1802 r1981 77 77 //Visually display the other metadata associated with the assembly 78 78 item.ImageIndex = e.Instance.AssemblyAuthenticode == null ? -1 : 0; 79 item.Group = e.Instance. IsCore ? pluginsManager.Groups[0] :80 pluginsManager.Groups[ 1];79 item.Group = e.Instance.LoadingPolicy == LoadingPolicy.Core ? 80 pluginsManager.Groups[0] : pluginsManager.Groups[1]; 81 81 item.SubItems.Add(e.Instance.Assembly.GetName().Version.ToString()); 82 82 item.SubItems.Add(e.Instance.Assembly.Location); … … 308 308 ListViewItem item = pluginsManager.Items[e.Index]; 309 309 PluginInstance instance = (PluginInstance)item.Tag; 310 if (instance. IsCore)310 if (instance.LoadingPolicy == LoadingPolicy.Core) 311 311 e.NewValue = CheckState.Checked; 312 312 }
Note: See TracChangeset
for help on using the changeset viewer.
