bool CheckCA(IDsDocument file, IHasCustomAttribute hca, object parent, CAArgument o) { var value = o.Value; var u = value as UTF8String; if (!ReferenceEquals(u, null)) value = u.String; if (!IsMatch(null, value)) return false; options.OnMatch(new SearchResult { Context = options.Context, Object = hca, NameObject = hca, ObjectImageReference = GetImageReference(hca), LocationObject = parent is string ? new NamespaceSearchResult((string)parent) : parent, LocationImageReference = GetImageReference(parent), Document = file, }); return true; }
private MosaCustomAttribute.Argument ToMosaCAArgument(CAArgument arg) { var value = arg.Value; if (value is UTF8String) { value = ((UTF8String)value).String; } else if (value is TypeSig) { value = metadata.Loader.GetType((TypeSig)value); } else if (value is CAArgument[]) { var valueArray = (CAArgument[])value; var resultArray = new MosaCustomAttribute.Argument[valueArray.Length]; for (int i = 0; i < resultArray.Length; i++) resultArray[i] = ToMosaCAArgument(valueArray[i]); } return new MosaCustomAttribute.Argument(metadata.Loader.GetType(arg.Type), value); }
CAArgument ReadArrayArgument(SZArraySig arrayType) { if (!recursionCounter.Increment()) throw new CABlobParserException("Too much recursion"); var arg = new CAArgument(arrayType); int arrayCount = reader.ReadInt32(); if (arrayCount == -1) { // -1 if it's null } else if (arrayCount < 0) throw new CABlobParserException("Array is too big"); else { var array = ThreadSafeListCreator.Create<CAArgument>(arrayCount); arg.Value = array; for (int i = 0; i < arrayCount; i++) array.Add(ReadFixedArg(FixTypeSig(arrayType.Next))); } recursionCounter.Decrement(); return arg; }
void Add(CAArgument arg) { // It's a struct so can't be null Add(arg.Type); }
/// <summary> /// Constructor /// </summary> /// <param name="isField"><c>true</c> if field, <c>false</c> if property</param> /// <param name="type">Field/property type</param> /// <param name="name">Name of field/property</param> /// <param name="argument">Field/property argument</param> public CANamedArgument(bool isField, TypeSig type, UTF8String name, CAArgument argument) { this.isField = isField; this.type = type; this.name = name; this.argument = argument; }
void AnalyzeCAArgument(ConfuserContext context, INameService service, CAArgument arg) { if (arg.Type.DefinitionAssembly.IsCorLib() && arg.Type.FullName == "System.Type") { var typeSig = (TypeSig)arg.Value; foreach (ITypeDefOrRef typeRef in typeSig.FindTypeRefs()) { TypeDef typeDef = typeRef.ResolveTypeDefThrow(); if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) { if (typeRef is TypeRef) service.AddReference(typeDef, new TypeRefReference((TypeRef)typeRef, typeDef)); service.ReduceRenameMode(typeDef, RenameMode.ASCII); } } } else if (arg.Value is CAArgument[]) { foreach (CAArgument elem in (CAArgument[])arg.Value) AnalyzeCAArgument(context, service, elem); } }
void Load(CAArgument obj) { Add(obj.Type); AddCAValue(obj.Value); }