Example #1
0
        private void elements_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (elements.SelectedItem == null || (elements.SelectedItem as AssemblyElementPicker.TreeNodeViewModel) == null ||
                !((elements.SelectedItem as AssemblyElementPicker.TreeNodeViewModel).Object is IAnnotationProvider))
            {
                confusionList.ItemsSource = null;
                elementSet.IsEnabled      = false;
                return;
            }
            else
            {
                elementSet.IsEnabled = true;
            }

            IAnnotationProvider provider = (elements.SelectedItem as AssemblyElementPicker.TreeNodeViewModel).Object as IAnnotationProvider;
            IDictionary <Core.IConfusion, NameValueCollection> dict;

            if (!provider.Annotations.Contains("ConfusionSets"))
            {
                provider.Annotations["ConfusionSets"] = dict = new ConfusionSets();
            }
            else
            {
                dict = provider.Annotations["ConfusionSets"] as IDictionary <Core.IConfusion, NameValueCollection>;
            }

            confusionList.ItemsSource = dict;
        }
Example #2
0
 /// <summary>
 /// Create annotations for all included attributes
 /// </summary>
 public static void Create(AssemblyCompiler compiler, ICustomAttributeProvider attributeProvider,
                           IAnnotationProvider annotationProvider, DexTargetPackage targetPackage, bool customAttributesOnly = false)
 {
     if (!attributeProvider.HasCustomAttributes)
         return;
     var annotations = new List<Annotation>();
     foreach (var attr in attributeProvider.CustomAttributes)
     {
         var attributeType = attr.AttributeType.Resolve();
         if (!attributeType.HasIgnoreAttribute())
         {
             Create(compiler, attr, attributeType, annotations, targetPackage);
         }
     }
     if (annotations.Count > 0)
     {
         // Create 1 IAttributes annotation
         var attrsAnnotation = new Annotation { Visibility = AnnotationVisibility.Runtime };
         attrsAnnotation.Type = compiler.GetDot42InternalType("IAttributes").GetClassReference(targetPackage);
         attrsAnnotation.Arguments.Add(new AnnotationArgument("Attributes", annotations.ToArray()));
         annotationProvider.Annotations.Add(attrsAnnotation);
     }
     if (!customAttributesOnly)
     {
         // Add annotations specified using AnnotationAttribute
         foreach (var attr in attributeProvider.CustomAttributes.Where(IsAnnotationAttribute))
         {
             var annotationType = (TypeReference) attr.ConstructorArguments[0].Value;
             var annotationClass = annotationType.GetClassReference(targetPackage, compiler.Module);
             annotationProvider.Annotations.Add(new Annotation(annotationClass, AnnotationVisibility.Runtime));
         }
     }
 }
        public static Parameters CreateParameters(List <string> colChoice, IAnnotationProvider annotationProvider)
        {
            int colInd = 0;

            for (int i = 0; i < colChoice.Count; i++)
            {
                if (colChoice[i].ToUpper().Contains("GENE NAME"))
                {
                    colInd = i;
                    break;
                }
            }
            int selFile     = 0;
            var textSources = annotationProvider.TextSources();

            for (int i = 0; i < textSources.Length; i++)
            {
                if (textSources[i].source.ToLower().Contains("mainannot"))
                {
                    selFile = i;
                    break;
                }
            }
            Parameters[] subParams = new Parameters[textSources.Length];
            for (int i = 0; i < subParams.Length; i++)
            {
                int selInd = 0;
                var annot  = textSources[i];
                for (int j = 0; j < annot.names.Length; j++)
                {
                    if (annot.names[j].ToLower().Contains("gene name"))
                    {
                        selInd = j;
                        break;
                    }
                }
                subParams[i] =
                    new Parameters(
                        new SingleChoiceParam("Identifiers")
                {
                    Values = colChoice,
                    Value  = colInd,
                    Help   =
                        "Specify here the column that contains the identifiers which are going to be matched back to " +
                        annot.id +
                        " identifiers."
                }, new SingleChoiceParam("Identifier type")
                {
                    Values = annot.names, Value = selInd
                });
            }
            return
                (new Parameters(new SingleChoiceWithSubParams("Source", selFile)
            {
                Values = textSources.Select(source => source.source).ToArray(),
                SubParams = subParams,
                ParamNameWidth = 136,
                TotalWidth = 735
            }));
        }
Example #4
0
        public static void ProcessData(IDataWithAnnotationColumns mdata, IAnnotationProvider annotationProvider, Parameters para, ProcessInfo processInfo)
        {
            string[] baseIds = GetBaseIds(mdata, annotationProvider, para);
            bool     success = ProcessDataAddAnnotation(mdata.RowCount, annotationProvider, para, baseIds, processInfo, out string[] name,
                                                        out int[] catColInds,
                                                        out int[] textColInds, out int[] numColInds, out string[][][] catCols, out string[][] textCols,
                                                        out double[][] numCols);

            if (!success)
            {
                return;
            }
            for (int i = 0; i < catCols.Length; i++)
            {
                mdata.AddCategoryColumn(name[catColInds[i]], "", catCols[i]);
            }
            for (int i = 0; i < textCols.Length; i++)
            {
                mdata.AddStringColumn(name[textColInds[i]], "", textCols[i]);
            }
            for (int i = 0; i < numCols.Length; i++)
            {
                mdata.AddNumericColumn(name[numColInds[i]], "", numCols[i]);
            }
        }
Example #5
0
 void AnalyzeCustomAttributeArgs(CustomAttributeArgument arg)
 {
     if (arg.Value is TypeReference)
     {
         TypeReference typeRef = arg.Value as TypeReference;
         bool          has     = false;
         foreach (var i in ivtMap)
         {
             if (i.Key.Name.Name == typeRef.Scope.Name)
             {
                 has = true;
                 break;
             }
         }
         if (has)
         {
             IAnnotationProvider type = (arg.Value as TypeReference).Resolve();
             if (type.Annotations[RenRef] != null)
             {
                 (type.Annotations[RenRef] as List <IReference>).Add(new CustomAttributeTypeReference(arg.Value as TypeReference));
             }
         }
     }
     else if (arg.Value is CustomAttributeArgument[])
     {
         foreach (var i in arg.Value as CustomAttributeArgument[])
         {
             AnalyzeCustomAttributeArgs(i);
         }
     }
 }
Example #6
0
 private static void Check(IAnnotationProvider provider)
 {
     //this is just very helpful for figuring out why something is marked but not recorded why
     if (provider.ToString().Contains("System.Security.SecurityManager"))
     {
     }
 }
        private string GenerateMarkBackTrace(IAnnotationProvider t, int depth)
        {
            if (depth == 40)
            {
                return("");
            }
            var r = Annotations.GetMarkReason(t);

            if (r == null)
            {
                return("unknown");
            }
            var sb = new StringBuilder();

            if (r is IAnnotationProvider)
            {
                sb.Append(r);
                sb.AppendLine();
                for (int i = 0; i != depth + 1; i++)
                {
                    sb.Append("...");
                }
                sb.Append(GenerateMarkBackTrace((IAnnotationProvider)r, depth + 1));
                return(sb.ToString());
            }
            return(r.ToString());
        }
Example #8
0
        public PianoAnnotator(IAnnotationProvider taProvider, ISequenceProvider sequenceProvider)
        {
            _taProvider       = taProvider;
            _sequenceProvider = sequenceProvider;

            GenomeAssembly = GetGenomeAssembly();
        }
Example #9
0
 public static IAnnotator GetAnnotator(IAnnotationProvider taProvider, ISequenceProvider sequenceProvider,
                                       IAnnotationProvider saProviders, IAnnotationProvider conservationProvider,
                                       IGeneAnnotationProvider geneAnnotationProviders, IEnumerable <IPlugin> plugins = null)
 {
     return(new Annotator(taProvider, sequenceProvider, saProviders, conservationProvider,
                          geneAnnotationProviders, plugins));
 }
		static void ProcessProvider (IAnnotationProvider provider)
		{
			if (!TunerAnnotations.IsInternalized (provider))
				return;

			Console.WriteLine ("[internalized] {0}", provider);
		}
Example #11
0
 /// <summary>
 /// Convert annotations into text
 /// </summary>
 internal static string LoadAnnotations(IAnnotationProvider provider)
 {
     if (provider.Annotations.Count == 0)
     {
         return(string.Empty);
     }
     return(string.Join(Environment.NewLine, provider.Annotations.Select(x => "  -  " + x).ToArray()));
 }
Example #12
0
        protected static bool CheckProcessed(IAnnotationProvider provider)
        {
            if (Annotations.IsProcessed (provider))
                return true;

            Annotations.Processed (provider);
            return false;
        }
Example #13
0
        /// <summary>
        /// Create an android MemberClasses annotation and attach it to the given provider.
        /// </summary>
        public static void AddMemberClassesAnnotation(this IAnnotationProvider provider, ClassReference[] classes)
        {
            var annotation = new Annotation {
                Type = new ClassReference("dalvik/annotation/MemberClasses"), Visibility = AnnotationVisibility.System
            };

            annotation.Arguments.Add(new AnnotationArgument("value", classes));
            provider.Annotations.Add(annotation);
        }
Example #14
0
 public static void Mark(IAnnotationProvider provider, object markReason)
 {
     Check(provider);
     provider.Annotations[_markedKey] = _markedKey;
     if (provider.Annotations[_markedReasonKey] == null)
     {
         provider.Annotations[_markedReasonKey] = markReason;
     }
 }
Example #15
0
        /// <summary>
        /// Create an android EnclosingClass annotation and attach it to the given provider.
        /// </summary>
        public static void AddEnclosingClassAnnotation(this IAnnotationProvider provider, ClassReference @class)
        {
            var annotation = new Annotation {
                Type = new ClassReference("dalvik/annotation/EnclosingClass"), Visibility = AnnotationVisibility.System
            };

            annotation.Arguments.Add(new AnnotationArgument("class", @class));
            provider.Annotations.Add(annotation);
        }
Example #16
0
        static void ProcessProvider(IAnnotationProvider provider)
        {
            if (!TunerAnnotations.IsInternalized(provider))
            {
                return;
            }

            Console.WriteLine("[internalized] {0}", provider);
        }
Example #17
0
        private void ReadAnnotationDirectory(BinaryReader reader, IAnnotationProvider provider, uint annotationOffset)
        {
            reader.PreserveCurrentPosition(annotationOffset, () =>
            {
                uint classAnnotationOffset   = reader.ReadUInt32();
                uint annotatedFieldsSize     = reader.ReadUInt32();
                uint annotatedMethodsSize    = reader.ReadUInt32();
                uint annotatedParametersSize = reader.ReadUInt32();

                if (classAnnotationOffset > 0)
                {
                    provider.Annotations = ReadAnnotationSet(reader, classAnnotationOffset);
                }

                for (var j = 0; j < annotatedFieldsSize; j++)
                {
                    var fieldDefinition = Dex.FieldReferences[reader.ReadInt32()] as FieldDefinition;
                    if (fieldDefinition != null)
                    {
                        fieldDefinition.Annotations = ReadAnnotationSet(reader, reader.ReadUInt32());
                    }
                }

                for (var j = 0; j < annotatedMethodsSize; j++)
                {
                    var methodDefinition = Dex.MethodReferences[reader.ReadInt32()] as MethodDefinition;
                    if (methodDefinition != null)
                    {
                        methodDefinition.Annotations = ReadAnnotationSet(reader, reader.ReadUInt32());
                    }
                }

                for (var j = 0; j < annotatedParametersSize; j++)
                {
                    var methodIndex = reader.ReadInt32();
                    var offset      = reader.ReadUInt32();
                    var annotations = ReadAnnotationSetRefList(reader, offset);
                    var mdef        = (Dex.MethodReferences[methodIndex] as MethodDefinition);

                    if (mdef == null)
                    {
                        break;
                    }

                    for (var i = 0; i < annotations.Count; i++)
                    {
                        if (annotations[i].Count <= 0)
                        {
                            continue;
                        }

                        mdef.Prototype.Parameters[i].Annotations = annotations[i];
                    }
                }
            });
        }
Example #18
0
        public static IEnumerable<IAnnotationProvider> GetChildren(IAnnotationProvider obj)
        {
            if (obj is TypeDefinition)
            {
                TypeDefinition typeDef = (TypeDefinition)obj;

                foreach (TypeDefinition nested in from TypeDefinition x in typeDef.NestedTypes orderby x.Name select x)
                    yield return nested;
                foreach (MethodDefinition method in from MethodDefinition x in typeDef.Methods
                                                    orderby x.Name
                                                    orderby x.Name == ".cctor" ? 0 : (x.Name == ".ctor" ? 1 : 2)
                                                    where x.SemanticsAttributes == MethodSemanticsAttributes.None
                                                    select x)
                    yield return method;
                foreach (PropertyDefinition prop in from PropertyDefinition x in typeDef.Properties orderby x.Name select x)
                    yield return prop;
                foreach (EventDefinition evt in from EventDefinition x in typeDef.Events orderby x.Name select x)
                    yield return evt;
                foreach (FieldDefinition field in from FieldDefinition x in typeDef.Fields orderby x.Name select x)
                    yield return field;
            }
            else if (obj is AssemblyDefinition)
            {
                foreach (ModuleDefinition mod in from ModuleDefinition x in (obj as AssemblyDefinition).Modules orderby x.Name select x)
                    yield return mod;
            }
            else if (obj is ModuleDefinition)
            {
                foreach (var i in GetNamespaces(obj as ModuleDefinition))
                    yield return i;
            }
            else if (obj is Namespace)
            {
                foreach (var i in obj as Namespace)
                    yield return i;
            }
            else if (obj is PropertyDefinition)
            {
                PropertyDefinition propDef = (PropertyDefinition)obj;
                if (propDef.GetMethod != null) yield return propDef.GetMethod;
                if (propDef.SetMethod != null) yield return propDef.SetMethod;
                if (propDef.HasOtherMethods)
                    foreach (var i in propDef.OtherMethods)
                        yield return i;
            }
            else if (obj is EventDefinition)
            {
                EventDefinition evtDef = (EventDefinition)obj;
                if (evtDef.AddMethod != null) yield return evtDef.AddMethod;
                if (evtDef.RemoveMethod != null) yield return evtDef.RemoveMethod;
                if (evtDef.InvokeMethod != null) yield return evtDef.InvokeMethod;
                if (evtDef.HasOtherMethods)
                    foreach (var i in evtDef.OtherMethods)
                        yield return i;
            }
        }
Example #19
0
        protected static bool CheckProcessed(IAnnotationProvider provider)
        {
            if (Annotations.IsProcessed(provider))
            {
                return(true);
            }

            Annotations.Processed(provider);
            return(false);
        }
Example #20
0
        /// <summary>
        /// Create an android InnerClass annotation and attach it to the given provider.
        /// </summary>
        public static void AddInnerClassAnnotation(this IAnnotationProvider provider, string simpleName, AccessFlags accessFlags)
        {
            var annotation = new Annotation {
                Type = new ClassReference("dalvik/annotation/InnerClass"), Visibility = AnnotationVisibility.System
            };

            annotation.Arguments.Add(new AnnotationArgument("name", simpleName));
            annotation.Arguments.Add(new AnnotationArgument("accessFlags", (int)accessFlags));
            provider.Annotations.Add(annotation);
        }
Example #21
0
        /// <summary>
        /// Get the string column with the identifiers used in the mapping.
        /// </summary>
        /// <param name="mdata"></param>
        /// <param name="annotationProvider"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        private static string[] GetBaseIds(IDataWithAnnotationColumns mdata, IAnnotationProvider annotationProvider, Parameters para)
        {
            ParameterWithSubParams <int> spd = para.GetParamWithSubParams <int>("Source");
            int        ind     = spd.Value;
            Parameters param   = spd.GetSubParameters();
            int        baseCol = param.GetParam <int>(annotationProvider.Sources[ind].id + " column").Value;

            string[] baseIds = mdata.StringColumns[baseCol];
            return(baseIds);
        }
Example #22
0
        void MarkScope(IMetadataScope scope)
        {
            IAnnotationProvider provider = scope as IAnnotationProvider;

            if (provider == null)
            {
                return;
            }

            Annotations.Mark(provider);
        }
Example #23
0
 bool GetRenOk(IAnnotationProvider provider)
 {
     if (provider.Annotations[NameAnalyzer.RenOk] != null)
     {
         return((bool)provider.Annotations[NameAnalyzer.RenOk]);
     }
     else
     {
         return(false);
     }
 }
Example #24
0
 public Annotator(IAnnotationProvider taProvider, ISequenceProvider sequenceProvider,
                  IAnnotationProvider saProvider, IAnnotationProvider conservationProvider,
                  IGeneAnnotationProvider geneAnnotationProvider, IRepeatExpansionProvider repeatExpansionProvider)
 {
     _saProvider              = saProvider;
     _taProvider              = taProvider;
     _sequenceProvider        = sequenceProvider;
     _conservationProvider    = conservationProvider;
     _geneAnnotationProvider  = geneAnnotationProvider;
     _repeatExpansionProvider = repeatExpansionProvider;
     _affectedGenes           = new HashSet <string>();
     Assembly = GetAssembly();
 }
Example #25
0
 public Annotator(IAnnotationProvider taProvider, ISequenceProvider sequenceProvider,
                  IAnnotationProvider saProviders, IAnnotationProvider conservationProvider,
                  IGeneAnnotationProvider geneAnnotationProvider, IEnumerable <IPlugin> plugins = null)
 {
     _saProviders            = saProviders;
     _taProvider             = taProvider;
     _sequenceProvider       = sequenceProvider;
     _conservationProvider   = conservationProvider;
     _geneAnnotationProvider = geneAnnotationProvider;
     _affectedGenes          = new HashSet <string>();
     _plugins       = plugins;
     GenomeAssembly = GetGenomeAssembly();
 }
Example #26
0
        /// <summary>
        /// Create a IGnericDefinition annotation and attaches it to the given provider.
        /// </summary>
        public static void AddGenericDefinitionAnnotationIfGeneric(this IAnnotationProvider provider, XTypeReference xtype, AssemblyCompiler compiler, DexTargetPackage targetPackage, bool forceTypeDefinition = false)
        {
            if (!xtype.IsGenericInstance && !xtype.IsGenericParameter)
            {
                return;
            }

            Annotation annotation = GenericDefinitionAnnotationFactory.CreateAnnotation(xtype, forceTypeDefinition, compiler, targetPackage);

            if (annotation != null)
            {
                provider.Annotations.Add(annotation);
            }
        }
Example #27
0
        void Copy(IAnnotationProvider src, IAnnotationProvider dst)
        {
            Dictionary <Core.IConfusion, NameValueCollection> now = new Dictionary <Core.IConfusion, NameValueCollection>();

            if (src.Annotations.Contains("ConfusionSets"))
            {
                foreach (KeyValuePair <Core.IConfusion, NameValueCollection> set in src.Annotations["ConfusionSets"] as IDictionary <Core.IConfusion, NameValueCollection> )
                {
                    now.Add(set.Key, set.Value);
                }
            }
            dst.Annotations["ConfusionSets"] = now;
            dst.Annotations["GlobalParams"]  = now;
        }
Example #28
0
 bool GetCancel(IAnnotationProvider provider)
 {
     if (provider.Annotations[NameAnalyzer.RenRef] == null)
     {
         return(false);
     }
     foreach (IReference refer in provider.Annotations[NameAnalyzer.RenRef] as List <IReference> )
     {
         if (refer.QueryCancellation())
         {
             return(true);
         }
     }
     return(false);
 }
 private string GenerateMarkBackTrace(IAnnotationProvider t, int depth)
 {
     if (depth == 40) return "";
     var r = Annotations.GetMarkReason(t);
     if (r == null) return "unknown";
     var sb = new StringBuilder();
     if (r is IAnnotationProvider)
     {
         sb.Append(r);
         sb.AppendLine();
         for (int i = 0; i != depth+1; i++) sb.Append("...");
         sb.Append(GenerateMarkBackTrace((IAnnotationProvider) r, depth + 1));
         return sb.ToString();
     }
     return r.ToString();
 }
Example #30
0
        private uint WriteAnnotationSet(BinaryWriter writer, uint sectionOffset, IAnnotationProvider provider, bool writezero)
        {
            var  key = new AnnotationSet(provider);
            uint offset;

            if (!annotationSets.ContainsKey(key))
            {
                writer.EnsureAlignment(sectionOffset, 4);
                offset = (uint)writer.BaseStream.Position;

                if (provider.Annotations.Count > 0 || writezero)
                {
                    writer.Write(provider.Annotations.Count);
                }

                foreach (var annotation in provider.Annotations)
                {
                    if (annotationSetMarkers.ContainsKey(annotation))
                    {
                        annotationSetMarkers[annotation].CloneMarker();
                    }
                    else
                    {
                        annotationSetMarkers.Add(annotation, writer.MarkUInt());
                    }
                }

                if (provider.Annotations.Count > 0 || writezero)
                {
                    annotationSets.Add(key, offset);
                }
                else
                {
                    offset = DexConsts.NoIndex;
                }
            }
            else
            {
                offset = annotationSets[key];
            }

            return(offset);
        }
Example #31
0
            protected override void MarkModule(ModuleDefinition mod, IDictionary <IConfusion, NameValueCollection> current, Confuser cr)
            {
                IAnnotationProvider m = mod;

                m.Annotations.Clear();
                IAnnotationProvider src = (IAnnotationProvider)origin;

                foreach (object key in src.Annotations.Keys)
                {
                    m.Annotations.Add(key, src.Annotations[src]);
                }

                var dict = (IDictionary <IConfusion, NameValueCollection>)src.Annotations["ConfusionSets"];

                current.Clear();
                foreach (var i in dict)
                {
                    current.Add(i.Key, i.Value);
                }
            }
Example #32
0
            protected override void MarkAssembly(AssemblyDefinition asm, IDictionary <IConfusion, NameValueCollection> current, Confuser cr)
            {
                IAnnotationProvider m = asm;

                m.Annotations.Clear();
                IAnnotationProvider src = (IAnnotationProvider)origin.Assembly;

                current.Clear();
                foreach (var i in (IDictionary <IConfusion, NameValueCollection>)src.Annotations["ConfusionSets"])
                {
                    current.Add(i.Key, i.Value);
                }
                foreach (object key in src.Annotations.Keys)
                {
                    if (key.ToString() == "Packer" || key.ToString() == "PackerParams")
                    {
                        continue;
                    }
                    m.Annotations[key] = src.Annotations[key];
                }
            }
Example #33
0
        /// <summary>
        /// Create annotations for all included attributes
        /// </summary>
        public static void CreateAttributeAnnotations(AssemblyCompiler compiler, ICustomAttributeProvider attributeProvider,
                                                      IAnnotationProvider annotationProvider, DexTargetPackage targetPackage, bool customAttributesOnly = false)
        {
            if (!attributeProvider.HasCustomAttributes)
            {
                return;
            }

            var annotations = new List <Annotation>();

            foreach (var attr in attributeProvider.CustomAttributes)
            {
                var attributeType = attr.AttributeType.Resolve();
                if (!attributeType.HasIgnoreAttribute())
                {
                    CreateAttributeAnnotation(compiler, attr, attributeType, annotations, targetPackage);
                }
            }
            if (annotations.Count > 0)
            {
                // Create 1 IAttributes annotation
                var attrsAnnotation = new Annotation {
                    Visibility = AnnotationVisibility.Runtime
                };
                attrsAnnotation.Type = compiler.GetDot42InternalType("IAttributes").GetClassReference(targetPackage);
                attrsAnnotation.Arguments.Add(new AnnotationArgument("Attributes", annotations.ToArray()));
                annotationProvider.Annotations.Add(attrsAnnotation);
            }

            if (!customAttributesOnly)
            {
                // Add annotations specified using AnnotationAttribute
                foreach (var attr in attributeProvider.CustomAttributes.Where(IsAnnotationAttribute))
                {
                    var annotationType  = (TypeReference)attr.ConstructorArguments[0].Value;
                    var annotationClass = annotationType.GetClassReference(targetPackage, compiler.Module);
                    annotationProvider.Annotations.Add(new Annotation(annotationClass, AnnotationVisibility.Runtime));
                }
            }
        }
Example #34
0
        void SetChilds(IAnnotationProvider obj, IDictionary <Core.IConfusion, NameValueCollection> dict)
        {
            ConfusionSets s = new ConfusionSets();

            foreach (KeyValuePair <Core.IConfusion, NameValueCollection> pair in dict)
            {
                s.Add(pair.Key, pair.Value);
            }
            obj.Annotations["ConfusionSets"] = s;

            System.Collections.IEnumerable e;
            if (obj is AssemblyDefinition)
            {
                e = (obj as AssemblyDefinition).Modules;
            }
            else if (obj is ModuleDefinition)
            {
                e = (obj as ModuleDefinition).Types;
            }
            else if (obj is TypeDefinition)
            {
                TypeDefinition type = obj as TypeDefinition;
                System.Collections.ArrayList anno = new System.Collections.ArrayList();
                anno.AddRange(type.NestedTypes);
                anno.AddRange(type.Methods);
                anno.AddRange(type.Fields);
                anno.AddRange(type.Properties);
                anno.AddRange(type.Events);
                e = anno;
            }
            else
            {
                e = Enumerable.Empty <object>();
            }

            foreach (IAnnotationProvider provider in e)
            {
                SetChilds(provider, dict);
            }
        }
Example #35
0
 public static bool IsMarked(IAnnotationProvider provider)
 {
     return provider.Annotations.Contains (_markedKey);
 }
Example #36
0
 public static bool IsProcessed(IAnnotationProvider provider)
 {
     return provider.Annotations.Contains (_processedKey);
 }
Example #37
0
        private void ReadAnnotationDirectory(BinaryReader reader, IAnnotationProvider provider, uint annotationOffset)
        {
            reader.PreserveCurrentPosition(annotationOffset, () =>
            {
                uint classAnnotationOffset = reader.ReadUInt32();
                uint annotatedFieldsSize = reader.ReadUInt32();
                uint annotatedMethodsSize = reader.ReadUInt32();
                uint annotatedParametersSize = reader.ReadUInt32();

                if (classAnnotationOffset > 0)
                    provider.Annotations = ReadAnnotationSet(reader, classAnnotationOffset);

                for (var j = 0; j < annotatedFieldsSize; j++)
                {
                    var fieldDefinition = Dex.FieldReferences[reader.ReadInt32()] as FieldDefinition;
                    if (fieldDefinition != null)
                        fieldDefinition.Annotations = ReadAnnotationSet(reader, reader.ReadUInt32());
                }

                for (var j = 0; j < annotatedMethodsSize; j++)
                {
                    var methodDefinition = Dex.MethodReferences[reader.ReadInt32()] as MethodDefinition;
                    if (methodDefinition != null)
                        methodDefinition.Annotations = ReadAnnotationSet(reader, reader.ReadUInt32());
                }

                for (var j = 0; j < annotatedParametersSize; j++)
                {
                    var methodIndex = reader.ReadInt32();
                    var offset = reader.ReadUInt32();
                    var annotations = ReadAnnotationSetRefList(reader, offset);
                    var mdef = (Dex.MethodReferences[methodIndex] as MethodDefinition);

                    if (mdef == null)
                        break;

                    for (var i = 0; i < annotations.Count; i++)
                    {
                        if (annotations[i].Count <= 0)
                            continue;

                        mdef.Prototype.Parameters[i].Annotations = annotations[i];
                    }
                }
            });
        }
Example #38
0
        private static void Check(IAnnotationProvider provider)
        {
            //this is just very helpful for figuring out why something is marked but not recorded why
            if (provider.ToString().Contains("System.Security.SecurityManager"))
            {

            }
        }
Example #39
0
        public static IEnumerable <IAnnotationProvider> GetChildren(IAnnotationProvider obj)
        {
            if (obj is TypeDefinition)
            {
                TypeDefinition typeDef = (TypeDefinition)obj;

                foreach (TypeDefinition nested in from TypeDefinition x in typeDef.NestedTypes orderby x.Name select x)
                {
                    yield return(nested);
                }
                foreach (MethodDefinition method in from MethodDefinition x in typeDef.Methods
                         orderby x.Name
                         orderby x.Name == ".cctor" ? 0 : (x.Name == ".ctor" ? 1 : 2)
                         where x.SemanticsAttributes == MethodSemanticsAttributes.None
                         select x)
                {
                    yield return(method);
                }
                foreach (PropertyDefinition prop in from PropertyDefinition x in typeDef.Properties orderby x.Name select x)
                {
                    yield return(prop);
                }
                foreach (EventDefinition evt in from EventDefinition x in typeDef.Events orderby x.Name select x)
                {
                    yield return(evt);
                }
                foreach (FieldDefinition field in from FieldDefinition x in typeDef.Fields orderby x.Name select x)
                {
                    yield return(field);
                }
            }
            else if (obj is AssemblyDefinition)
            {
                foreach (ModuleDefinition mod in from ModuleDefinition x in (obj as AssemblyDefinition).Modules orderby x.Name select x)
                {
                    yield return(mod);
                }
            }
            else if (obj is ModuleDefinition)
            {
                foreach (var i in GetNamespaces(obj as ModuleDefinition))
                {
                    yield return(i);
                }
            }
            else if (obj is Namespace)
            {
                foreach (var i in obj as Namespace)
                {
                    yield return(i);
                }
            }
            else if (obj is PropertyDefinition)
            {
                PropertyDefinition propDef = (PropertyDefinition)obj;
                if (propDef.GetMethod != null)
                {
                    yield return(propDef.GetMethod);
                }
                if (propDef.SetMethod != null)
                {
                    yield return(propDef.SetMethod);
                }
                if (propDef.HasOtherMethods)
                {
                    foreach (var i in propDef.OtherMethods)
                    {
                        yield return(i);
                    }
                }
            }
            else if (obj is EventDefinition)
            {
                EventDefinition evtDef = (EventDefinition)obj;
                if (evtDef.AddMethod != null)
                {
                    yield return(evtDef.AddMethod);
                }
                if (evtDef.RemoveMethod != null)
                {
                    yield return(evtDef.RemoveMethod);
                }
                if (evtDef.InvokeMethod != null)
                {
                    yield return(evtDef.InvokeMethod);
                }
                if (evtDef.HasOtherMethods)
                {
                    foreach (var i in evtDef.OtherMethods)
                    {
                        yield return(i);
                    }
                }
            }
        }
Example #40
0
 public static object GetMarkReason(IAnnotationProvider provider)
 {
     return provider.Annotations[_markedReasonKey];
 }
		static bool IsMarkedAsPublic (IAnnotationProvider provider)
		{
			return Annotations.IsPublic (provider);
		}
		static void InternalMark (IAnnotationProvider provider)
		{
			Annotations.Mark (provider);
			Annotations.SetPublic (provider);
		}
Example #43
0
 public static void Processed(IAnnotationProvider provider)
 {
     provider.Annotations [_processedKey] = _processedKey;
 }
Example #44
0
 bool GetCancel(IAnnotationProvider provider)
 {
     if (provider.Annotations[NameAnalyzer.RenRef] == null)
         return false;
     foreach (IReference refer in provider.Annotations[NameAnalyzer.RenRef] as List<IReference>)
         if (refer.QueryCancellation())
             return true;
     return false;
 }
Example #45
0
 static void SetAction(IAnnotationProvider provider, object action)
 {
     provider.Annotations [_actionKey] = action;
 }
Example #46
0
 static object GetAction(IAnnotationProvider provider)
 {
     return provider.Annotations [_actionKey];
 }
Example #47
0
 public static bool HasAction(IAnnotationProvider provider)
 {
     return provider.Annotations.Contains (_actionKey);
 }
 private string GenerateMarkBackTrace(IAnnotationProvider t)
 {
     return GenerateMarkBackTrace(t,0);
 }
Example #49
0
 public static void Mark(IAnnotationProvider provider, object markReason)
 {
     Check(provider);
     provider.Annotations[_markedKey] = _markedKey;
     if (provider.Annotations[_markedReasonKey] == null)
         provider.Annotations[_markedReasonKey] = markReason;
 }
		static void MarkInternalized (IAnnotationProvider provider)
		{
			TunerAnnotations.Internalized (provider);
		}
Example #51
0
 /// <summary>
 /// Convert annotations into text
 /// </summary>
 internal static string LoadAnnotations(IAnnotationProvider provider)
 {
     if (provider.Annotations.Count == 0)
         return string.Empty;
     return string.Join(Environment.NewLine, provider.Annotations.Select(x => "  -  " + x).ToArray());
 }
Example #52
0
 bool GetRenOk(IAnnotationProvider provider)
 {
     if (provider.Annotations[NameAnalyzer.RenOk] != null)
         return (bool)provider.Annotations[NameAnalyzer.RenOk];
     else
         return false;
 }
		public static bool IsInternalized (IAnnotationProvider provider)
		{
			return provider.Annotations.Contains (_internalizedKey);
		}
Example #54
0
 public static bool IsPublic(IAnnotationProvider provider)
 {
     return provider.Annotations.Contains (_publicKey);
 }
Example #55
0
 public static void SetPublic(IAnnotationProvider provider)
 {
     provider.Annotations [_publicKey] = _publicKey;
 }
Example #56
0
 public static void Mark(IAnnotationProvider provider)
 {
     Check(provider);
     provider.Annotations [_markedKey] = _markedKey;
 }
		public static void Internalized (IAnnotationProvider provider)
		{
			provider.Annotations [_internalizedKey] = _internalizedKey;
		}