public CLRSigLocalVarSig(CLRSignatureParser parser) { if (parser.NextToken() != CLRSignatureParser.Token.LOCAL_SIG) throw new ParseFailedException("Invalid local var sig"); parser.ConsumeToken(); uint numLocals = parser.ReadCompressedUInt(); LocalVars = new CLRSigLocalVar[numLocals]; for (uint i = 0; i < numLocals; i++) LocalVars[i] = new CLRSigLocalVar(parser); }
public CLRSigMethodSpec(CLRSignatureParser parser) { if (parser.NextToken() != CLRSignatureParser.Token.GENERICINST) throw new ParseFailedException("Malformed method spec"); parser.ConsumeToken(); uint numGenericParams = parser.ReadCompressedUInt(); Types = new CLRSigType[numGenericParams]; for (uint i = 0; i < numGenericParams; i++) { Types[i] = CLRSigType.Parse(parser, false); } }
public static string ReadUTF8String(CLRSignatureParser parser) { byte firstByte = parser.NextByte(); if (firstByte == 0xff) return null; else { uint stringLengthBytes = parser.ReadCompressedUInt(); if (stringLengthBytes == 0) return ""; else { byte[] utf8chars = new byte[stringLengthBytes]; parser.ReadBytes(utf8chars, stringLengthBytes); return System.Text.Encoding.UTF8.GetString(utf8chars); } } }
public CLRSigPropertySig(CLRSignatureParser parser) { CLRSignatureParser.Token headToken = parser.NextToken(); parser.ConsumeToken(); if (headToken == CLRSignatureParser.Token.PROPERTY_HASTHIS) HasThis = true; else if (headToken == CLRSignatureParser.Token.PROPERTY) HasThis = false; else throw new ParseFailedException("Malformed PropertySig"); uint paramCount = parser.ReadCompressedUInt(); CustomMods = CLRSigType.ReadCustomMods(parser); Type = CLRSigType.Parse(parser, false); Parameters = new CLRSigParamType[paramCount]; for (uint i = 0; i < paramCount; i++) Parameters[i] = new CLRSigParamType(parser, false); }
public CLRSigMethodDefOrRefSig(CLRSignatureParser parser, Kind allowedKind) { byte baseByte = parser.NextByte(); parser.ConsumeByte(); CLRSignatureParser.Token callingConvention = (CLRSignatureParser.Token)(baseByte & 0x0f); if ((baseByte & (byte)CLRSignatureParser.Token.HASTHIS) != 0) { HasThis = true; if ((baseByte & (byte)CLRSignatureParser.Token.EXPLICITTHIS) != 0) ExplicitThis = true; } if ((baseByte & (int)CLRSignatureParser.Token.GENERIC) != 0) { if (allowedKind != Kind.Def && allowedKind != Kind.DefOrRef && allowedKind != Kind.Ref) throw new ParseFailedException("Invalid method signature"); allowedKind = Kind.Def; NumGenericParameters = parser.ReadCompressedUInt(); } switch (callingConvention) { case CLRSignatureParser.Token.DEFAULT: if (allowedKind != Kind.Def && allowedKind != Kind.DefOrRef && allowedKind != Kind.Ref) throw new ParseFailedException("Invalid method signature"); allowedKind = Kind.Def; CallingConvention = CallingConventionType.Default; break; case CLRSignatureParser.Token.VARARG: CallingConvention = CallingConventionType.VarArg; break; case CLRSignatureParser.Token.C: if (allowedKind != Kind.StandAlone) throw new ParseFailedException("Invalid method signature"); CallingConvention = CallingConventionType.C; break; case CLRSignatureParser.Token.STDCALL: if (allowedKind != Kind.StandAlone) throw new ParseFailedException("Invalid method signature"); CallingConvention = CallingConventionType.StdCall; break; case CLRSignatureParser.Token.THISCALL: if (allowedKind != Kind.StandAlone) throw new ParseFailedException("Invalid method signature"); CallingConvention = CallingConventionType.ThisCall; break; case CLRSignatureParser.Token.FASTCALL: if (allowedKind != Kind.StandAlone) throw new ParseFailedException("Invalid method signature"); CallingConvention = CallingConventionType.FastCall; break; default: throw new ParseFailedException("Unexpected signature token"); } uint paramCount = parser.ReadCompressedUInt(); // Return type RetType = new CLRSigRetType(parser); ParamTypes = new CLRSigParamType[paramCount]; bool allowSentinel = (allowedKind == Kind.StandAlone) && (CallingConvention == CallingConventionType.C || CallingConvention == CallingConventionType.VarArg); // Parameter types for (uint i = 0; i < paramCount; i++) ParamTypes[i] = new CLRSigParamType(parser, allowSentinel); }
public CLRSigTypeVarOrMVar(ElementType type, CLRSignatureParser parser) { BasicType = type; Value = parser.ReadCompressedUInt(); }
public CLRSigTypeGenericInstantiation(ElementType type, CLRSignatureParser parser) { BasicType = type; ElementType instType = (ElementType)parser.NextByte(); parser.ConsumeByte(); if (instType == ElementType.CLASS) InstantiationType = InstType.Class; else if (instType == ElementType.VALUETYPE) InstantiationType = InstType.ValueType; else throw new ParseFailedException("Unexpected instantiation type"); GenericType = parser.ReadTypeDefOrRefOrSpecEncoded(); uint genArgCount = parser.ReadCompressedUInt(); ArgTypes = new CLRSigType[genArgCount]; for (uint i = 0; i < genArgCount; i++) ArgTypes[i] = CLRSigType.Parse(parser, false); }
public CLRSigTypeArray(ElementType type, CLRSignatureParser parser) { BasicType = type; ContainedType = CLRSigType.Parse(parser, false); // ArrayShape (II.23.2.13) Rank = parser.ReadCompressedUInt(); uint numSizes = parser.ReadCompressedUInt(); if (numSizes > Rank) throw new ParseFailedException("Invalid array"); Sizes = new uint[numSizes]; for (uint i = 0; i < numSizes; i++) Sizes[i] = parser.ReadCompressedUInt(); uint numLowBounds = parser.ReadCompressedUInt(); if (numLowBounds > Rank) throw new ParseFailedException("Invalid array"); LowBounds = new int[numLowBounds]; for (uint i = 0; i < numLowBounds; i++) LowBounds[i] = parser.ReadCompressedInt(); }