Inheritance: MetadataObject, ISecurityAttribute
Exemplo n.º 1
0
 internal SecurityCustomAttribute(SecurityAttribute containingSecurityAttribute, IMethodReference constructorReference, IMetadataNamedArgument[]/*?*/ namedArguments) {
   this.ContainingSecurityAttribute = containingSecurityAttribute;
   this.ConstructorReference = constructorReference;
   this.NamedArguments = namedArguments;
 }
Exemplo n.º 2
0
 internal SecurityAttributeDecoder20(PEFileToObjectModel peFileToObjectModel, MemoryReader signatureMemoryReader, SecurityAttribute securityAttribute)
   : base(peFileToObjectModel, signatureMemoryReader) {
   this.SecurityAttributes = Enumerable<ICustomAttribute>.Empty;
   byte prolog = this.SignatureMemoryReader.ReadByte();
   if (prolog != SerializationType.SecurityAttribute20Start) return;
   int numberOfAttributes = this.SignatureMemoryReader.ReadCompressedUInt32();
   var securityCustomAttributes = new ICustomAttribute[numberOfAttributes];
   for (int i = 0; i < numberOfAttributes; ++i) {
     var secAttr = this.ReadSecurityAttribute(securityAttribute);
     if (secAttr == null) {
       //  MDError...
       return;
     }
     securityCustomAttributes[i] = secAttr;
   }
   this.SecurityAttributes = IteratorHelper.GetReadonly(securityCustomAttributes);
 }
Exemplo n.º 3
0
    SecurityCustomAttribute/*?*/ ReadSecurityAttribute(SecurityAttribute securityAttribute) {
      string/*?*/ typeNameStr = this.GetSerializedString();
      if (typeNameStr == null)
        return null;
      ITypeReference/*?*/ moduleTypeReference = this.PEFileToObjectModel.GetSerializedTypeNameAsTypeReference(typeNameStr);
      if (moduleTypeReference == null)
        return null;
      IMethodReference ctorReference = Dummy.MethodReference;
      ITypeDefinition attributeType = moduleTypeReference.ResolvedType;
      if (!(attributeType is Dummy)) {
        foreach (ITypeDefinitionMember member in attributeType.GetMembersNamed(this.PEFileToObjectModel.NameTable.Ctor, false)) {
          IMethodDefinition/*?*/ method = member as IMethodDefinition;
          if (method == null) continue;
          if (!IteratorHelper.EnumerableHasLength(method.Parameters, 1)) continue;
          //TODO: check that parameter has the right type
          ctorReference = method;
          break;
        }
      } else {
        int ctorKey = this.PEFileToObjectModel.NameTable.Ctor.UniqueKey;
        foreach (ITypeMemberReference mref in this.PEFileToObjectModel.GetMemberReferences()) {
          IMethodReference/*?*/ methRef = mref as IMethodReference;
          if (methRef == null) continue;
          if (methRef.ContainingType.InternedKey != moduleTypeReference.InternedKey) continue;
          if (methRef.Name.UniqueKey != ctorKey) continue;
          if (!IteratorHelper.EnumerableHasLength(methRef.Parameters, 1)) continue;
          //TODO: check that parameter has the right type
          ctorReference = methRef;
          break;
        }
      }
      if (ctorReference is Dummy) {
        ctorReference = new MethodReference(this.PEFileToObjectModel.ModuleReader.metadataReaderHost, moduleTypeReference,
          CallingConvention.Default|CallingConvention.HasThis, this.PEFileToObjectModel.PlatformType.SystemVoid,
          this.PEFileToObjectModel.NameTable.Ctor, 0, this.PEFileToObjectModel.PlatformType.SystemSecurityPermissionsSecurityAction);
      }

      this.SignatureMemoryReader.ReadCompressedUInt32(); //  BlobSize...
      int numOfNamedArgs = this.SignatureMemoryReader.ReadCompressedUInt32();
      FieldOrPropertyNamedArgumentExpression[]/*?*/ namedArgumentArray = null;
      if (numOfNamedArgs > 0) {
        namedArgumentArray = new FieldOrPropertyNamedArgumentExpression[numOfNamedArgs];
        for (int i = 0; i < numOfNamedArgs; ++i) {
          bool isField = this.SignatureMemoryReader.ReadByte() == SerializationType.Field;
          ITypeReference/*?*/ memberType = this.GetFieldOrPropType();
          if (memberType == null)
            return null;
          string/*?*/ memberStr = this.GetSerializedString();
          if (memberStr == null)
            return null;
          IName memberName = this.PEFileToObjectModel.NameTable.GetNameFor(memberStr);
          ExpressionBase/*?*/ value = this.ReadSerializedValue(memberType);
          if (value == null)
            return null;
          namedArgumentArray[i] = new FieldOrPropertyNamedArgumentExpression(memberName, moduleTypeReference, isField, memberType, value);
        }
      }
      return new SecurityCustomAttribute(securityAttribute, ctorReference, namedArgumentArray);
    }
Exemplo n.º 4
0
    internal IEnumerable<ICustomAttribute> GetSecurityAttributeData(SecurityAttribute securityAttribute) {
      DeclSecurityRow declSecurity = this.PEFileReader.DeclSecurityTable[securityAttribute.DeclSecurityRowId];
      //  TODO: Check is securityAttribute.Value is within the range
      MemoryBlock signatureMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(declSecurity.PermissionSet);
      //  TODO: Error checking enough space in signature memoryBlock.
      MemoryReader memoryReader = new MemoryReader(signatureMemoryBlock);
      //  TODO: 1.0 etc later on...

      this.ModuleReader.metadataReaderHost.StartGuessingGame();
      SecurityAttributeDecoder20 securityAttrDecoder = new SecurityAttributeDecoder20(this, memoryReader, securityAttribute);
      while (securityAttrDecoder.decodeFailed && this.ModuleReader.metadataReaderHost.TryNextPermutation())
        securityAttrDecoder = new SecurityAttributeDecoder20(this, memoryReader, securityAttribute);
      if (!securityAttrDecoder.decodeFailed)
        this.ModuleReader.metadataReaderHost.WinGuessingGame();
      //else
      //TODO: error

      return securityAttrDecoder.SecurityAttributes;
    }
Exemplo n.º 5
0
     internal SecurityCustomAttribute(
   SecurityAttribute containingSecurityAttribute,
   IMethodReference constructorReference,
   EnumerableArrayWrapper<ExpressionBase, IMetadataExpression> arguments,
   EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument> namedArguments
 )
     {
         this.ContainingSecurityAttribute = containingSecurityAttribute;
           this.ConstructorReference = constructorReference;
           this.Arguments = arguments;
           this.NamedArguments = namedArguments;
     }
Exemplo n.º 6
0
 //^ [NotDelayed]
 internal SecurityAttributeDecoder20(
   PEFileToObjectModel peFileToObjectModel,
   MemoryReader signatureMemoryReader,
   SecurityAttribute securityAttribute
 )
   : base(peFileToObjectModel, signatureMemoryReader) {
   //^ this.SignatureMemoryReader = signatureMemoryReader; //TODO: Spec# bug. This assignment should not be necessary.
   this.SecurityAttributes = TypeCache.EmptySecurityAttributes;
   //^ base;
   byte prolog = this.SignatureMemoryReader.ReadByte();
   if (prolog != SerializationType.SecurityAttribute20Start) {
     return;
   }
   int numberOfAttributes = this.SignatureMemoryReader.ReadCompressedUInt32();
   SecurityCustomAttribute[] securityCustomAttributes = new SecurityCustomAttribute[numberOfAttributes];
   for (int i = 0; i < numberOfAttributes; ++i) {
     SecurityCustomAttribute/*?*/ secAttr = this.ReadSecurityAttribute(securityAttribute);
     if (secAttr == null) {
       //  MDError...
       return;
     }
     securityCustomAttributes[i] = secAttr;
   }
   //^ NonNullType.AssertInitialized(securityCustomAttributes);
   this.SecurityAttributes = new EnumerableArrayWrapper<SecurityCustomAttribute, ICustomAttribute>(securityCustomAttributes, Dummy.CustomAttribute);
 }