示例#1
0
        public bool Equals(AnnotationSet other)
        {
            bool result = Count == other.Count;

            if (result)
            {
                for (int i = 0; i < Count; i++)
                {
                    result &= this[i].Equals(other[i]);
                }
            }

            return(result);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Write a single annotation_directory_item structure
        /// </summary>
        private void WriteAnnotationDirectoryItem(BinaryWriter writer, int index, ref uint count, Dictionary <AnnotationSet, uint> classAnnotationSets, ClassDefinition @class)
        {
            var annotatedFields         = @class.Fields.Where(x => x.Annotations.Any()).ToList();
            var annotatedMethods        = @class.Methods.Where(x => x.Annotations.Any()).ToList();
            var annotatedParametersList = @class.Methods.Where(x => x.Prototype.ContainsAnnotation()).ToList();

            var total = @class.Annotations.Count + annotatedFields.Count + annotatedMethods.Count + annotatedParametersList.Count;

            if (total <= 0)
            {
                return;
            }

            // all datas except class annotations are specific.
            if (total == @class.Annotations.Count)
            {
                var set = new AnnotationSet(@class);
                if (classAnnotationSets.ContainsKey(set))
                {
                    classDefinitionsMarkers[index].AnnotationsMarker.Value = classAnnotationSets[set];
                    return;
                }
                classAnnotationSets.Add(set, (uint)writer.BaseStream.Position);
            }

            classDefinitionsMarkers[index].AnnotationsMarker.Value = (uint)writer.BaseStream.Position;
            count++;

            if (@class.Annotations.Count > 0)
            {
                writer.Write(annotationSets[new AnnotationSet(@class)]);
            }
            else
            {
                writer.Write((uint)0);
            }

            writer.Write(annotatedFields.Count);
            writer.Write(annotatedMethods.Count);
            writer.Write(annotatedParametersList.Count);

            var fields = new List <FieldReference>(annotatedFields);

            fields.Sort(new FieldReferenceComparer());
            foreach (FieldDefinition field in fields)
            {
                writer.Write(fieldLookup[field]);
                writer.Write(annotationSets[new AnnotationSet(field)]);
            }

            var methods = new List <MethodReference>(annotatedMethods);

            methods.Sort(new MethodReferenceComparer());
            foreach (MethodDefinition method in methods)
            {
                writer.Write(methodLookup[method]);
                writer.Write(annotationSets[new AnnotationSet(method)]);
            }

            methods = new List <MethodReference>(annotatedParametersList);
            methods.Sort(new MethodReferenceComparer());
            foreach (MethodDefinition method in methods)
            {
                writer.Write(methodLookup[method]);
                writer.Write(annotationSetRefLists[method]);
            }
        }