public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob) { BlobReader reader = new BlobReader(blob, null); this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction); this.blob = blob; if (reader.ReadByte() == '.') { // binary attribute uint attributeCount = reader.ReadCompressedUInt32(); for (uint i = 0; i < attributeCount; i++) { unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); attr.PositionalArguments.Add(this.securityAction); string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); } }
public IList<IAttribute> Resolve(IAssembly currentAssembly) { // TODO: make this a per-assembly cache // CacheManager cache = currentAssembly.Compilation.CacheManager; // IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this); // if (result != null) // return result; ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly); BlobReader reader = new BlobReader(blob, currentAssembly); if (reader.ReadByte() != '.') { // should not use UnresolvedSecurityDeclaration for XML secdecls throw new InvalidOperationException(); } ResolveResult securityActionRR = securityAction.Resolve(context); uint attributeCount = reader.ReadCompressedUInt32(); IAttribute[] attributes = new IAttribute[attributeCount]; try { ReadSecurityBlob(reader, attributes, context, securityActionRR); } catch (NotSupportedException) { // ignore invalid blobs //Debug.WriteLine(ex.ToString()); } for (int i = 0; i < attributes.Length; i++) { if (attributes[i] == null) attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType); } return attributes; // return (IList<IAttribute>)cache.GetOrAddShared(this, attributes); }
public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob) { BlobReader reader = new BlobReader(blob, null); this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction); this.blob = blob; if (reader.ReadByte() == '.') { // binary attribute uint attributeCount = reader.ReadCompressedUInt32(); for (uint i = 0; i < attributeCount; i++) { unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); attr.PositionalArguments.Add(this.securityAction); string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); } }
public IList <IAttribute> Resolve(IAssembly currentAssembly) { // TODO: make this a per-assembly cache // CacheManager cache = currentAssembly.Compilation.CacheManager; // IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this); // if (result != null) // return result; ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly); BlobReader reader = new BlobReader(blob, currentAssembly); if (reader.ReadByte() != '.') { // should not use UnresolvedSecurityDeclaration for XML secdecls throw new InvalidOperationException(); } ResolveResult securityActionRR = securityAction.Resolve(context); uint attributeCount = reader.ReadCompressedUInt32(); IAttribute[] attributes = new IAttribute[attributeCount]; try { ReadSecurityBlob(reader, attributes, context, securityActionRR); } catch (NotSupportedException ex) { // ignore invalid blobs Debug.WriteLine(ex.ToString()); } for (int i = 0; i < attributes.Length; i++) { if (attributes[i] == null) { attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType); } } return(attributes); // return (IList<IAttribute>)cache.GetOrAddShared(this, attributes); }
decimal? TryDecodeDecimalConstantAttribute(CustomAttributeData attribute) { if (attribute.ConstructorArguments.Count != 5) return null; var reader = new BlobReader(attribute.__GetBlob(), null); if (reader.ReadUInt16() != 0x0001) { Debug.WriteLine("Unknown blob prolog"); return null; } // DecimalConstantAttribute has the arguments (byte scale, byte sign, uint hi, uint mid, uint low) or (byte scale, byte sign, int hi, int mid, int low) // Both of these invoke the Decimal constructor (int lo, int mid, int hi, bool isNegative, byte scale) with explicit argument conversions if required. var ctorArgs = new object[attribute.ConstructorArguments.Count]; for (int i = 0; i < ctorArgs.Length; i++) { switch (attribute.ConstructorArguments[i].ArgumentType.FullName) { case "System.Byte": ctorArgs[i] = reader.ReadByte(); break; case "System.Int32": ctorArgs[i] = reader.ReadInt32(); break; case "System.UInt32": ctorArgs[i] = unchecked((int)reader.ReadUInt32()); break; default: return null; } } if (!ctorArgs.Select(a => a.GetType()).SequenceEqual(new[] { typeof(byte), typeof(byte), typeof(int), typeof(int), typeof(int) })) return null; return new decimal((int)ctorArgs[4], (int)ctorArgs[3], (int)ctorArgs[2], (byte)ctorArgs[1] != 0, (byte)ctorArgs[0]); }