示例#1
0
		string ReadUTF8String() {
			byte b = reader.ReadByte();
			if (b == 0xFF)
				return null;
			uint len = reader.ReadCompressedUInt32(b);
			if (len == 0)
				return string.Empty;
			return Encoding.UTF8.GetString(reader.ReadBytes((int)len));
		}
        // Reads the old (.NET 1.x) DeclSecurity blob format
        DmdCustomAttributeData[] ReadXmlFormat(SecurityAction action)
        {
            reader.Position = 0;
            var xml  = Encoding.Unicode.GetString(reader.ReadBytes((int)reader.Length));
            var type = module.AppDomain.GetWellKnownType(DmdWellKnownType.System_Security_Permissions_PermissionSetAttribute);

            var(ctor, ctorArguments) = GetConstructor(type, action);
            var xmlProp = type.GetProperty("XML", module.AppDomain.System_String, Array.Empty <DmdType>());

            Debug.Assert((object)ctor != null);
            Debug.Assert((object)xmlProp != null);
            if ((object)ctor == null || (object)xmlProp == null)
            {
                return(Array.Empty <DmdCustomAttributeData>());
            }
            var namedArguments = new[] { new DmdCustomAttributeNamedArgument(xmlProp, new DmdCustomAttributeTypedArgument(module.AppDomain.System_String, xml)) };

            return(new[] { new DmdCustomAttributeData(ctor, ctorArguments, namedArguments, isPseudoCustomAttribute: false) });
        }
示例#3
0
        string ReadUTF8String()
        {
            byte b = reader.ReadByte();

            if (b == 0xFF)
            {
                return(null);
            }
            uint len = reader.ReadCompressedUInt32(b);

            if (len == 0)
            {
                return(string.Empty);
            }
            return(Encoding.UTF8.GetString(reader.ReadBytes((int)len)));
        }
示例#4
0
        DmdMethodBody Read()
        {
            if (!ReadHeader(out var localSignatureMetadataToken, out var maxStackSize, out var initLocals, out var codeSize, out var hasExceptionHandlers))
            {
                return(null);
            }

            DmdLocalVariableInfo[] localVariables;
            if ((localSignatureMetadataToken & 0x00FFFFFF) != 0 && (byte)(localSignatureMetadataToken >> 24) == 0x11)
            {
                var localTypes = methodBodyResolver.ReadLocals(localSignatureMetadataToken, genericTypeArguments, genericMethodArguments);
                localVariables = new DmdLocalVariableInfo[localTypes.Length];
                for (int i = 0; i < localVariables.Length; i++)
                {
                    var info = localTypes[i];
                    localVariables[i] = new DmdLocalVariableInfo(info.type, i, info.isPinned);
                }
            }
            else
            {
                localVariables = Array.Empty <DmdLocalVariableInfo>();
            }

            var ilBytes = reader.ReadBytes(codeSize);

            DmdExceptionHandlingClause[] exceptionHandlingClauses;
            if (hasExceptionHandlers)
            {
                exceptionHandlingClauses = ReadExceptionHandlingClauses();
            }
            else
            {
                exceptionHandlingClauses = Array.Empty <DmdExceptionHandlingClause>();
            }

            return(new DmdMethodBodyImpl(localSignatureMetadataToken, maxStackSize, initLocals, localVariables, exceptionHandlingClauses, genericTypeArguments, genericMethodArguments, ilBytes));
        }
示例#5
0
        string ReadUTF8String()
        {
            uint len = reader.ReadCompressedUInt32();

            return(len == 0 ? string.Empty : Encoding.UTF8.GetString(reader.ReadBytes((int)len)));
        }