private Widget GetWidget(SecurityDeclarationCollection sdc) { FontDescription fd = FontDescription.FromString("Courier 10 Pitch 10"); VBox vbox = new VBox(false, 0); actions = new Action[list.Length]; for (int i = 0; i < list.Length; i++) { actions [i] = new Action(list [i]); actions [i].TextView.ModifyFont(fd); vbox.Add(actions [i].Expander); } ScrolledWindow sw = new ScrolledWindow(); sw.AddWithViewport(vbox); if ((sdc != null) && (sdc.Count >= 0)) { foreach (SecurityDeclaration declsec in sdc) { actions [(int)declsec.Action - 1].SetText(declsec.PermissionSet.ToString()); } } vbox.Show(); sw.Show(); return(sw); }
public virtual void VisitSecurityDeclarationCollection(SecurityDeclarationCollection secDecls) { foreach (SecurityDeclaration securityDeclaration in secDecls) { VisitSecurityDeclaration(securityDeclaration); } }
public MethodDefinition(string name, MethodAttributes attributes, MethodSignature signature) : base(new MetadataToken(MetadataTokenType.Method)) { if (name == null) { throw new ArgumentNullException("name"); } if (signature == null) { throw new ArgumentNullException("signature"); } _name = new LazyValue <string>(name); Attributes = attributes; ImplAttributes = MethodImplAttributes.IL | MethodImplAttributes.Managed; _signature = new LazyValue <MethodSignature>(signature); Parameters = new DelegatedMemberCollection <MethodDefinition, ParameterDefinition>(this, GetParamOwner, SetParamOwner); _methodBody = new LazyValue <MethodBody>(); _pinvokeMap = new LazyValue <ImplementationMap>(); _declaringType = new LazyValue <TypeDefinition>(); CustomAttributes = new CustomAttributeCollection(this); SecurityDeclarations = new SecurityDeclarationCollection(this); GenericParameters = new GenericParameterCollection(this); }
static void ShowSecurity(TextWriter tw, string header, SecurityDeclarationCollection declarations) { foreach (SecurityDeclaration declsec in declarations) { tw.WriteLine("{0} {1} Permission Set:{2}{3}", header, declsec.Action, Environment.NewLine, declsec.PermissionSet); } }
private void InitializeDeclarativeSecurity(AddDeclarativeSecurityDelegate addDeclarativeSecurity, SecurityDeclarationCollection securityDeclarations) { foreach (SecurityDeclaration securityDeclaration in securityDeclarations) { addDeclarativeSecurity( (System.Security.Permissions.SecurityAction)securityDeclaration.Action, securityDeclaration.PermissionSet); } }
internal MethodDefinition(MetadataImage image, MetadataRow <FileSegment, MethodImplAttributes, MethodAttributes, uint, uint, uint> row) : base(row.MetadataToken) { _image = image; var stringStream = image.Header.GetStream <StringStream>(); var blobStream = image.Header.GetStream <BlobStream>(); ImplAttributes = row.Column2; Attributes = row.Column3; _name = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column4)); IBinaryStreamReader blobReader; if (blobStream.TryCreateBlobReader(row.Column5, out blobReader)) { _signature = new LazyValue <MethodSignature>(() => MethodSignature.FromReader(image, blobReader)); } _methodBody = new LazyValue <MethodBody>(() => { var rawBody = row.Column1 as CilRawMethodBody; if (rawBody != null) { return(CilMethodBody.FromRawMethodBody(this, rawBody)); } // TODO: handler for native methods. return(null); }); _declaringType = new LazyValue <TypeDefinition>(() => { var table = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.TypeDef); var typeRow = table.GetRowClosestToKey(5, row.MetadataToken.Rid); return((TypeDefinition)table.GetMemberFromRow(image, typeRow)); }); _pinvokeMap = new LazyValue <ImplementationMap>(() => { if (!row.Column3.HasFlag(MethodAttributes.PInvokeImpl)) { return(null); } var table = (ImplementationMapTable)image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.ImplMap); var mapRow = table.FindImplementationMapOfOwner(row.MetadataToken); return(mapRow != null ? (ImplementationMap)table.GetMemberFromRow(image, mapRow) : null); }); Parameters = new RangedMemberCollection <MethodDefinition, ParameterDefinition>(this, MetadataTokenType.Param, 5, GetParamOwner, SetParamOwner); CustomAttributes = new CustomAttributeCollection(this); SecurityDeclarations = new SecurityDeclarationCollection(this); GenericParameters = new GenericParameterCollection(this); }
private static bool DoHasLinkDemand(SecurityDeclarationCollection decs) { foreach (SecurityDeclaration dec in decs) { if (dec.Action == SecurityAction.LinkDemand || dec.Action == SecurityAction.NonCasLinkDemand) // TODO: why do we need the NonCas stuff? { return(true); } } return(false); }
private static bool DoHasInheritanceDemand(SecurityDeclarationCollection decs) { foreach (SecurityDeclaration dec in decs) { if (dec.Action == SecurityAction.InheritDemand || dec.Action == SecurityAction.NonCasInheritance) { return(true); } } return(false); }
private bool DoHasAssert(SecurityDeclarationCollection secs) { foreach (SecurityDeclaration dec in secs) { if (dec.Action == SecurityAction.Assert) { Log.DebugLine(this, " has an assert attr"); return(true); } } return(false); }
private bool DoHasDemand(SecurityDeclarationCollection secs) { foreach (SecurityDeclaration dec in secs) { if (dec.Action == SecurityAction.NonCasDemand || dec.Action == SecurityAction.NonCasLinkDemand || dec.Action == SecurityAction.Demand || dec.Action == SecurityAction.LinkDemand) // TODO: may be a mono or cecil bug here, doesn't seem like we should have to check NonCasDemand { Log.DebugLine(this, " has a demand attr"); return(true); } } return(false); }
public AssemblyDefinition(IAssemblyDescriptor info) : base(new MetadataToken(MetadataTokenType.Assembly)) { _name = new LazyValue <string>(info.Name); Version = info.Version; _culture = new LazyValue <string>(info.Culture); _publicKey = new LazyValue <DataBlobSignature>(info.PublicKeyToken == null ? null : new DataBlobSignature(info.PublicKeyToken)); Modules = new DelegatedMemberCollection <AssemblyDefinition, ModuleDefinition>(this, GetModuleOwner, SetModuleOwner); AssemblyReferences = new Collection <AssemblyReference>(); ModuleReferences = new Collection <ModuleReference>(); SecurityDeclarations = new SecurityDeclarationCollection(this); Resources = new Collection <ManifestResource>(); Files = new Collection <FileReference>(); OperatingSystems = new DelegatedMemberCollection <AssemblyDefinition, AssemblyOs>(this, GetOsOwner, SetOsOwner); Processors = new DelegatedMemberCollection <AssemblyDefinition, AssemblyProcessor>(this, GetProcessorOwner, SetProcessorOwner); }
public AssemblyDefinition(string name, Version version) : base(new MetadataToken(MetadataTokenType.Assembly)) { _name = new LazyValue <string>(name); _version = version; _culture = new LazyValue <string>(); _publicKey = new LazyValue <DataBlobSignature>(); Modules = new DelegatedMemberCollection <AssemblyDefinition, ModuleDefinition>(this, GetModuleOwner, SetModuleOwner); AssemblyReferences = new Collection <AssemblyReference>(); ModuleReferences = new Collection <ModuleReference>(); CustomAttributes = new CustomAttributeCollection(this); SecurityDeclarations = new SecurityDeclarationCollection(this); Resources = new Collection <ManifestResource>(); Files = new Collection <FileReference>(); OperatingSystems = new DelegatedMemberCollection <AssemblyDefinition, AssemblyOs>(this, GetOsOwner, SetOsOwner); Processors = new DelegatedMemberCollection <AssemblyDefinition, AssemblyProcessor>(this, GetProcessorOwner, SetProcessorOwner); }
internal AssemblyDefinition(MetadataImage image, MetadataRow <AssemblyHashAlgorithm, ushort, ushort, ushort, ushort, AssemblyAttributes, uint, uint, uint> row) : base(row.MetadataToken) { Image = image; var tableStream = image.Header.GetStream <TableStream>(); var stringStream = image.Header.GetStream <StringStream>(); var blobStream = image.Header.GetStream <BlobStream>(); HashAlgorithm = row.Column1; Version = new Version(row.Column2, row.Column3, row.Column4, row.Column5); Attributes = row.Column6; _publicKey = new LazyValue <DataBlobSignature>(() => row.Column7 == 0 ? null : DataBlobSignature.FromReader(blobStream.CreateBlobReader(row.Column7))); _name = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column8)); _culture = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column9)); Modules = new TableMemberCollection <AssemblyDefinition, ModuleDefinition>( this, tableStream.GetTable(MetadataTokenType.Module), GetModuleOwner, SetModuleOwner); AssemblyReferences = new TableMemberCollection <AssemblyDefinition, AssemblyReference>( this, tableStream.GetTable(MetadataTokenType.AssemblyRef), GetReferenceOwner, SetReferenceOwner); ModuleReferences = new TableMemberCollection <AssemblyDefinition, ModuleReference>( this, tableStream.GetTable(MetadataTokenType.ModuleRef), GetReferenceOwner, SetReferenceOwner); Resources = new TableMemberCollection <AssemblyDefinition, ManifestResource>( this, tableStream.GetTable(MetadataTokenType.ManifestResource), GetResourceOwner, SetResourceOwner); Files = new TableMemberCollection <AssemblyDefinition, FileReference>( this, tableStream.GetTable(MetadataTokenType.File), GetFileOwner, SetFileOwner); CustomAttributes = new CustomAttributeCollection(this); SecurityDeclarations = new SecurityDeclarationCollection(this); OperatingSystems = new TableMemberCollection <AssemblyDefinition, AssemblyOs>( this, tableStream.GetTable(MetadataTokenType.AssemblyOs), GetOsOwner, SetOsOwner); Processors = new TableMemberCollection <AssemblyDefinition, AssemblyProcessor>( this, tableStream.GetTable(MetadataTokenType.AssemblyProcessor), GetProcessorOwner, SetProcessorOwner); }
private PermissionSet AddPermissionsToSet(PermissionSet permissionSet, SecurityDeclarationCollection securityDeclarations) { foreach (SecurityDeclaration declaration in securityDeclarations) { if (declaration.PermissionSet != null && declaration.PermissionSet.Count > 0) { if (permissionSet == null) { permissionSet = declaration.PermissionSet; } else { permissionSet = permissionSet.Union(declaration.PermissionSet); } } } return(permissionSet); }
static SecurityElement AddSecurityXml(SecurityDeclarationCollection declarations) { ArrayList list = new ArrayList(); foreach (SecurityDeclaration declsec in declarations) { SecurityElement child = new SecurityElement("Action"); AddAttribute(child, "Name", declsec.Action.ToString()); child.AddChild(declsec.PermissionSet.ToXml()); list.Add(child); } // sort actions list.Sort(Comparer); SecurityElement se = new SecurityElement("Actions"); foreach (SecurityElement child in list) { se.AddChild(child); } return(se); }
public TypeDefinition(string @namespace, string name, TypeAttributes attributes, ITypeDefOrRef baseType = null) : base(new MetadataToken(MetadataTokenType.TypeDef)) { Attributes = attributes; _namespace = new LazyValue <string>(@namespace); _name = new LazyValue <string>(name); _baseType = new LazyValue <ITypeDefOrRef>(baseType); Fields = new DelegatedMemberCollection <TypeDefinition, FieldDefinition>(this, GetFieldOwner, SetFieldOwner); Methods = new DelegatedMemberCollection <TypeDefinition, MethodDefinition>(this, GetMethodOwner, SetMethodOwner); _classLayout = new LazyValue <ClassLayout>(); _propertyMap = new LazyValue <PropertyMap>(); _eventMap = new LazyValue <EventMap>(); _declaringType = new LazyValue <TypeDefinition>(); CustomAttributes = new CustomAttributeCollection(this); SecurityDeclarations = new SecurityDeclarationCollection(this); NestedClasses = new NestedClassCollection(this); GenericParameters = new GenericParameterCollection(this); Interfaces = new InterfaceImplementationCollection(this); MethodImplementations = new MethodImplementationCollection(this); }
public void VisitSecurityDeclarationCollection(SecurityDeclarationCollection secDecls) { }
internal TypeDefinition(MetadataImage image, MetadataRow <TypeAttributes, uint, uint, uint, uint, uint> row) : base(row.MetadataToken) { Module = image.Assembly.Modules.FirstOrDefault(); var tableStream = image.Header.GetStream <TableStream>(); var stringStream = image.Header.GetStream <StringStream>(); Attributes = row.Column1; _name = _namespace = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column2)); _namespace = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column3)); _baseType = new LazyValue <ITypeDefOrRef>(() => { var baseTypeToken = tableStream.GetIndexEncoder(CodedIndex.TypeDefOrRef).DecodeIndex(row.Column4); if (baseTypeToken.Rid != 0) { IMetadataMember baseType; if (image.TryResolveMember(baseTypeToken, out baseType)) { return(baseType as ITypeDefOrRef); } } return(null); }); Fields = new RangedMemberCollection <TypeDefinition, FieldDefinition>(this, MetadataTokenType.Field, 4, GetFieldOwner, SetFieldOwner); Methods = new RangedMemberCollection <TypeDefinition, MethodDefinition>(this, MetadataTokenType.Method, 5, GetMethodOwner, SetMethodOwner); _classLayout = new LazyValue <ClassLayout>(() => { var table = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.ClassLayout); var layoutRow = table.GetRowByKey(2, row.MetadataToken.Rid); return(layoutRow != null ? (ClassLayout)table.GetMemberFromRow(image, layoutRow) : null); }); _propertyMap = new LazyValue <PropertyMap>(() => { var table = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.PropertyMap); var mapRow = table.GetRowByKey(0, row.MetadataToken.Rid); return(mapRow != null ? (PropertyMap)table.GetMemberFromRow(image, mapRow) : null); }); _eventMap = new LazyValue <EventMap>(() => { var table = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.EventMap); var mapRow = table.GetRowByKey(0, row.MetadataToken.Rid); return(mapRow != null ? (EventMap)table.GetMemberFromRow(image, mapRow) : null); }); _declaringType = new LazyValue <TypeDefinition>(() => { var table = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.NestedClass); var nestedClassRow = table.GetRowByKey(0, row.MetadataToken.Rid); return(nestedClassRow != null ? ((NestedClass)table.GetMemberFromRow(image, nestedClassRow)).EnclosingClass : null); }); CustomAttributes = new CustomAttributeCollection(this); SecurityDeclarations = new SecurityDeclarationCollection(this); NestedClasses = new NestedClassCollection(this); GenericParameters = new GenericParameterCollection(this); Interfaces = new InterfaceImplementationCollection(this); MethodImplementations = new MethodImplementationCollection(this); }
public Widget GetWidget(MethodDefinition method) { SecurityDeclarationCollection sdc = (method == null) ? null : method.SecurityDeclarations; return(GetWidget(sdc)); }
public Widget GetWidget(TypeDefinition type) { SecurityDeclarationCollection sdc = (type == null) ? null : type.SecurityDeclarations; return(GetWidget(sdc)); }
public Widget GetWidget(AssemblyDefinition assembly) { SecurityDeclarationCollection sdc = (assembly == null) ? null : assembly.SecurityDeclarations; return(GetWidget(sdc)); }
private static string Security(SecurityDeclarationCollection declarations, bool stackmods) { StringBuilder sb = null; foreach (SecurityDeclaration declsec in declarations) { switch (declsec.Action) { case Mono.Cecil.SecurityAction.Assert: case Mono.Cecil.SecurityAction.PermitOnly: case Mono.Cecil.SecurityAction.Deny: if (!stackmods) { continue; } break; default: if (stackmods) { continue; } break; } if (sb == null) { sb = new StringBuilder(); sb.AppendFormat(",{0}label=\"", !stackmods ? String.Empty /*"head"*/ : "tail"); } sb.AppendFormat("{0}\\l", declsec.Action); PermissionSet pset = declsec.PermissionSet; if (pset.Count > 0) { foreach (IPermission p in pset) { if (p is SecurityPermission) { sb.AppendFormat(" SecurityPermission\\l {0}\\l", (p as SecurityPermission).Flags); } else if (p is ReflectionPermission) { sb.Append(GetReflectionPermission(p as ReflectionPermission)); } else if (p is FileIOPermission) { sb.Append(GetFileIOPermission(p as FileIOPermission)); } else if (p is EnvironmentPermission) { sb.Append(GetEnvironmentPermission(p as EnvironmentPermission)); } else if (p is IsolatedStorageFilePermission) { sb.Append(GetIsolatedStorageFilePermission(p as IsolatedStorageFilePermission)); } else { string ps = p.ToString().Replace('"', '\''); ps = ps.Replace(Environment.NewLine, "\\l"); sb.AppendFormat(" {0}\\l", ps); } } } else if (pset.IsUnrestricted()) { sb.Append(" PermissionSet Unrestricted\\l"); } } if (sb == null) { return(String.Empty); } return(sb.Append("\"").ToString()); }