Пример #1
0
        CAArgument ReadFixedArg(TypeSig argType)
        {
            if (!recursionCounter.Increment())
            {
                throw new CABlobParserException("Too much recursion");
            }
            if (argType == null)
            {
                throw new CABlobParserException("null argType");
            }
            CAArgument result;

            var arrayType = argType as SZArraySig;

            if (arrayType != null)
            {
                result = ReadArrayArgument(arrayType);
            }
            else
            {
                result = ReadElem(argType);
            }

            recursionCounter.Decrement();
            return(result);
        }
Пример #2
0
 /// <summary>
 /// Increment recursion counter
 /// </summary>
 /// <exception cref="TypeNameParserException">If this method has been called too many times</exception>
 protected void RecursionIncrement()
 {
     if (!recursionCounter.Increment())
     {
         throw new TypeNameParserException("Stack overflow");
     }
 }
        IEnumerable <TypeDef> GetTypes(IEnumerable <TypeDef> types)
        {
            if (!recursionCounter.Increment())
            {
            }
            else
            {
                foreach (var type in types.GetSafeEnumerable())
                {
                    if (visited.ContainsKey(type))
                    {
                        continue;
                    }
                    visited[type] = true;
                    yield return(type);

                    if (type.NestedTypes.Count > 0)
                    {
                        foreach (var nested in GetTypes(type.NestedTypes))
                        {
                            yield return(nested);
                        }
                    }
                }
                recursionCounter.Decrement();
            }
        }
Пример #4
0
        MethodSig ResolveGenericArgs(MethodSig sig)
        {
            if (sig == null)
            {
                return(null);
            }
            if (!recursionCounter.Increment())
            {
                return(null);
            }

            MethodSig result = ResolveGenericArgs(new MethodSig(sig.GetCallingConvention()), sig);

            recursionCounter.Decrement();
            return(result);
        }
Пример #5
0
        /// <summary>
        /// Reads the signature
        /// </summary>
        /// <returns>A new <see cref="CallingConventionSig"/> instance or <c>null</c> if invalid signature</returns>
        CallingConventionSig ReadSig()
        {
            if (!recursionCounter.Increment())
            {
                return(null);
            }

            CallingConventionSig result;
            var callingConvention = (CallingConvention)reader.ReadByte();

            switch (callingConvention & CallingConvention.Mask)
            {
            case CallingConvention.Default:
            case CallingConvention.C:
            case CallingConvention.StdCall:
            case CallingConvention.ThisCall:
            case CallingConvention.FastCall:
            case CallingConvention.VarArg:
            case CallingConvention.NativeVarArg:
                result = ReadMethod(callingConvention);
                break;

            case CallingConvention.Field:
                result = ReadField(callingConvention);
                break;

            case CallingConvention.LocalSig:
                result = ReadLocalSig(callingConvention);
                break;

            case CallingConvention.Property:
                result = ReadProperty(callingConvention);
                break;

            case CallingConvention.GenericInst:
                result = ReadGenericInstMethod(callingConvention);
                break;

            case CallingConvention.Unmanaged:
            default:
                result = null;
                break;
            }

            recursionCounter.Decrement();
            return(result);
        }
Пример #6
0
		void BuildNodeMap(BamlBlockNode node, RecursionCounter counter) {
			if (node == null || !counter.Increment())
				return;

			NodeMap[node.Header] = node;

			foreach (var child in node.Children) {
				var childBlock = child as BamlBlockNode;
				if (childBlock != null)
					BuildNodeMap(childBlock, counter);
			}

			counter.Decrement();
		}
Пример #7
0
        bool ContainsGenericParameterInternal(TypeSpec type)
        {
            if (type == null)
            {
                return(false);
            }
            if (!recursionCounter.Increment())
            {
                return(false);
            }

            bool res = ContainsGenericParameterInternal(type.TypeSig);

            recursionCounter.Decrement();
            return(res);
        }
Пример #8
0
        /// <summary>
        /// Imports a <see cref="IType"/>
        /// </summary>
        /// <param name="type">The type</param>
        /// <returns>The imported type or <c>null</c></returns>
        public IType Import(IType type)
        {
            if (type == null)
            {
                return(null);
            }
            if (!recursionCounter.Increment())
            {
                return(null);
            }

            IType    result;
            TypeDef  td;
            TypeRef  tr;
            TypeSpec ts;
            TypeSig  sig;

            if ((td = type as TypeDef) != null)
            {
                result = Import(td);
            }
            else if ((tr = type as TypeRef) != null)
            {
                result = Import(tr);
            }
            else if ((ts = type as TypeSpec) != null)
            {
                result = Import(ts);
            }
            else if ((sig = type as TypeSig) != null)
            {
                result = Import(sig);
            }
            else
            {
                result = null;
            }

            recursionCounter.Decrement();
            return(result);
        }
Пример #9
0
		static void CreateDisplayName(StringBuilder sb, RecursionCounter recu, TypeSig sig, bool fullName) {
			if (sig == null) {
				sb.Append("<<<NULL>>>");
				return;
			}
			if (!recu.Increment()) {
				sb.Append("<<<INFRECURSION>>>");
				return;
			}

			switch (sig.ElementType) {
				case ElementType.Void:
				case ElementType.Boolean:
				case ElementType.Char:
				case ElementType.I1:
				case ElementType.U1:
				case ElementType.I2:
				case ElementType.U2:
				case ElementType.I4:
				case ElementType.U4:
				case ElementType.I8:
				case ElementType.U8:
				case ElementType.R4:
				case ElementType.R8:
				case ElementType.String:
				case ElementType.TypedByRef:
				case ElementType.I:
				case ElementType.U:
				case ElementType.Object:
				case ElementType.ValueType:
				case ElementType.Class:
					var type = ((TypeDefOrRefSig)sig).TypeDefOrRef;
					if (fullName)
						sb.Append(type.ReflectionFullName);
					else
						sb.Append(type.Name ?? "<<<NULL>>>");
					break;

				case ElementType.Ptr:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					sb.Append('*');
					break;

				case ElementType.ByRef:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					sb.Append('&');
					break;

				case ElementType.Array: {
					CreateDisplayName(sb, recu, sig.Next, fullName);
					var arraySig = (ArraySig)sig;
					sb.Append('[');
					uint rank = arraySig.Rank;
					if (rank == 0)
						sb.Append("<RANK0>"); // Not allowed
					else if (rank == 1)
						sb.Append('*');
					else
						for (int i = 0; i < (int)rank; i++) {
							if (i != 0)
								sb.Append(", ");

							const int NO_LOWER = int.MinValue;
							const uint NO_SIZE = uint.MaxValue;
							int lower = arraySig.LowerBounds.Get(i, NO_LOWER);
							uint size = arraySig.Sizes.Get(i, NO_SIZE);
							if (lower != NO_LOWER) {
								sb.Append(lower);
								sb.Append("..");
								if (size != NO_SIZE)
									sb.Append(lower + (int)size - 1);
								else
									sb.Append('.');
							}
						}
					sb.Append(']');
					break;
				}

				case ElementType.SZArray:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					sb.Append("[]");
					break;

				case ElementType.CModReqd:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					sb.Append(" modreq(");
					sb.Append(((ModifierSig)sig).Modifier.Name ?? "<<<NULL>>>");
					sb.Append(")");
					break;

				case ElementType.CModOpt:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					sb.Append(" modopt(");
					sb.Append(((ModifierSig)sig).Modifier.Name ?? "<<<NULL>>>");
					sb.Append(")");
					break;

				case ElementType.Pinned:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					break;

				case ElementType.ValueArray:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					var valueArraySig = (ValueArraySig)sig;
					sb.Append(" ValueArray(");
					sb.Append(valueArraySig.Size);
					sb.Append(')');
					break;

				case ElementType.Module:
					CreateDisplayName(sb, recu, sig.Next, fullName);
					var moduleSig = (ModuleSig)sig;
					sb.Append(" Module(");
					sb.Append(moduleSig.Index);
					sb.Append(')');
					break;

				case ElementType.GenericInst: {
					var genericInstSig = (GenericInstSig)sig;
					var typeGenArgs = genericInstSig.GenericArguments;
					CreateDisplayName(sb, recu, genericInstSig.GenericType, fullName);
					sb.Append('<');
					int i = -1;
					foreach (var genArg in typeGenArgs.GetSafeEnumerable()) {
						i++;
						if (i != 0)
							sb.Append(", ");
						CreateDisplayName(sb, recu, genArg, false);
					}
					sb.Append('>');
				}
					break;

				case ElementType.Var:
				case ElementType.MVar:
					var gs = (GenericSig)sig;
					var gp = gs.GenericParam;
					if (gp == null || UTF8String.IsNullOrEmpty(gp.Name)) {
						sb.Append(gs.IsMethodVar ? "!!" : "!");
						sb.Append(gs.Number);
					}
					else
						sb.Append(gp.Name);
					break;

				case ElementType.FnPtr:
					sb.Append("(fnptr)");
					break;

				case ElementType.Sentinel:
					break;

				case ElementType.End:
				case ElementType.R:
				case ElementType.Internal:
				default:
					break;
			}

			recu.Decrement();
		}