/// <summary>
        /// Deserializes the specified JSON string into a DisassemblyAnnotation
        /// instance
        /// </summary>
        /// <param name="json">JSON representation</param>
        /// <returns>The deserialized object</returns>
        public static DisassemblyAnnotation Deserialize(string json)
        {
            var data   = JsonConvert.DeserializeObject <DisassemblyDecorationData>(json);
            var result = new DisassemblyAnnotation();

            if (data != null)
            {
                result = new DisassemblyAnnotation
                {
                    _labels              = data.Labels,
                    _comments            = data.Comments,
                    _prefixComments      = data.PrefixComments,
                    _literals            = data.Literals,
                    _literalReplacements = data.LiteralReplacements
                };
                foreach (var section in data.MemorySections)
                {
                    result.MemoryMap.Add(section);
                }
                foreach (var literal in data.Literals)
                {
                    foreach (var item in literal.Value)
                    {
                        result._literalValues[item] = literal.Key;
                    }
                }
            }
            result.InitReadOnlyProps();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the disassebly output to the specified writer.
        /// </summary>
        /// <param name="writer">Writer to save the disassembly output</param>
        /// <param name="output">Disassembly output</param>
        /// <param name="annotations">Optional annotations</param>
        public void SaveDisassembly(TextWriter writer, DisassemblyOutput output,
                                    DisassemblyAnnotation annotations = null)
        {
            foreach (var item in output.OutputItems)
            {
                // --- Optional prefix comment
                if (annotations != null && annotations.PrefixComments.ContainsKey(item.Address))
                {
                    writer.WriteLine($"; {annotations.PrefixComments[item.Address]}");
                }

                // --- Create label
                var label = "    ";
                if (annotations != null && annotations.Labels.ContainsKey(item.Address))
                {
                    label = $"{annotations.Labels[item.Address]}: ";
                }
                else if (item.HasLabel)
                {
                    label = $"L{item.Address}: ";
                }

                // --- Create comment
                var comment = string.Empty;
                if (annotations != null && annotations.Comments.ContainsKey(item.Address))
                {
                    comment = $" ; {annotations.Comments[item.Address]}";
                }

                writer.WriteLine($"{label}{item.Instruction} {comment}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserializes the specified JSON string into a DisassemblyAnnotation
        /// instance
        /// </summary>
        /// <param name="json">JSON representation</param>
        /// <param name="annotations">The deserialized object</param>
        /// <returns>True, if deserialization is successful; otherwise, false</returns>
        public static bool DeserializeBankAnnotations(string json, out Dictionary <int, DisassemblyAnnotation> annotations)
        {
            annotations = new Dictionary <int, DisassemblyAnnotation>();
            Dictionary <int, DisassemblyDecorationData> dataList;

            try
            {
                dataList = JsonConvert.DeserializeObject <Dictionary <int, DisassemblyDecorationData> >(json);
            }
            catch
            {
                return(false);
            }
            if (dataList == null)
            {
                return(false);
            }

            foreach (var disAnn in dataList)
            {
                var data = disAnn.Value;
                var ann  = new DisassemblyAnnotation
                {
                    _labels              = data.Labels,
                    _comments            = data.Comments,
                    _prefixComments      = data.PrefixComments,
                    _literals            = data.Literals,
                    _literalReplacements = data.LiteralReplacements,
                    DisassemblyFlags     = data.DisassemblyFlags
                };
                foreach (var section in data.MemorySections)
                {
                    ann.MemoryMap.Add(section);
                }
                foreach (var literal in data.Literals)
                {
                    foreach (var item in literal.Value)
                    {
                        ann._literalValues[item] = literal.Key;
                    }
                }
                ann.InitReadOnlyProps();
                annotations.Add(disAnn.Key, ann);
            }
            return(true);
        }
        /// <summary>
        /// Merges this decoration with another one
        /// </summary>
        /// <param name="other">Other disassembly decoration</param>
        /// <remarks>
        /// Definitions in the other decoration override the ones defeined here
        /// </remarks>
        public void Merge(DisassemblyAnnotation other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (other == this)
            {
                return;
            }

            foreach (var label in other.Labels)
            {
                _labels[label.Key] = label.Value;
            }
            foreach (var comment in other.Comments)
            {
                _comments[comment.Key] = comment.Value;
            }
            foreach (var prefixComment in other.PrefixComments)
            {
                _prefixComments[prefixComment.Key] = prefixComment.Value;
            }
            foreach (var literal in other.Literals)
            {
                if (_literals.ContainsKey(literal.Key))
                {
                    _literals[literal.Key] = literal.Value.Union(_literals[literal.Key]).Distinct().ToList();
                }
                else
                {
                    _literals[literal.Key] = literal.Value;
                }
            }
            foreach (var replacement in other.LiteralReplacements)
            {
                _literalReplacements[replacement.Key] = replacement.Value;
            }
            foreach (var section in other.MemoryMap)
            {
                MemoryMap.Add(section);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Deserializes the specified JSON string into a DisassemblyAnnotation
        /// instance
        /// </summary>
        /// <param name="json">JSON representation</param>
        /// <param name="annotation">The deserialized object</param>
        /// <returns>True, if deserialization is successful; otherwise, false</returns>
        public static bool Deserialize(string json, out DisassemblyAnnotation annotation)
        {
            DisassemblyDecorationData data;

            try
            {
                data = JsonConvert.DeserializeObject <DisassemblyDecorationData>(json);
            }
            catch
            {
                annotation = new DisassemblyAnnotation();
                return(false);
            }

            annotation = new DisassemblyAnnotation();
            if (data != null)
            {
                annotation = new DisassemblyAnnotation
                {
                    _labels              = data.Labels,
                    _comments            = data.Comments,
                    _prefixComments      = data.PrefixComments,
                    _literals            = data.Literals,
                    _literalReplacements = data.LiteralReplacements,
                    DisassemblyFlags     = data.DisassemblyFlags
                };
                foreach (var section in data.MemorySections)
                {
                    annotation.MemoryMap.Add(section);
                }
                foreach (var literal in data.Literals)
                {
                    foreach (var item in literal.Value)
                    {
                        annotation._literalValues[item] = literal.Key;
                    }
                }
            }
            annotation.InitReadOnlyProps();
            return(true);
        }