예제 #1
0
        public static String GetHexString(IEnumerable <Byte> rawData, Asn1Lite node)
        {
            Int32 startOffset = node.Offset + node.TagLength - node.PayloadLength;
            Int32 endOffset   = node.Offset + node.TagLength;

            return(AsnFormatter.BinaryToString(rawData.ToArray(), EncodingType.Hex, 0, startOffset, endOffset - startOffset));
        }
예제 #2
0
        String calculateValue(Asn1Lite node, Int32 padding)
        {
            if (String.IsNullOrEmpty(node.ExplicitValue))
            {
                return(nl);
            }
            if (24 + padding + node.ExplicitValue.Length <= width)
            {
                return($"'{node.ExplicitValue.Trim()}'{nl}");
            }
            Int32 remaining = width - 22 - padding;

            if (node.ExplicitValue.Length <= remaining - 2)
            {
                return(String.Format(
                           "{0}{1}{4}{2}{3}{2}{0}",
                           nl,
                           delimiter,
                           "'",
                           node.ExplicitValue.Trim(),
                           new String(' ', padding + 3)
                           ));
            }
            return(node.ExplicitValue
                   .SplitByLength(width - padding)
                   .Aggregate(nl, (current, line) =>
                              current + $"{delimiter}{new String(' ', padding + 3)}{line.Trim()}{nl}"));
        }
예제 #3
0
        Byte[] getTagBinaryValue(Asn1Lite node)
        {
            Int32 skip = node.Tag == (Byte)Asn1Type.BIT_STRING ? node.PayloadStartOffset + 1 : node.PayloadStartOffset;
            Int32 take = node.Tag == (Byte)Asn1Type.BIT_STRING ? node.PayloadLength - 1 : node.PayloadLength;

            return(_dataSource.RawData.Skip(skip).Take(take).ToArray());
        }
예제 #4
0
        void writeContent(Asn1TreeNode node, String leftPadString)
        {
            Asn1Lite value = node.Value;

            line.Clear();

            Byte[] binValue = getTagBinaryValue(node.Value);
            String strValue = AsnFormatter.BinaryToString(binValue, _noAsciiTags.Contains(value.Tag)
                ? EncodingType.Hex
                : EncodingType.HexAscii).TrimEnd();
            var lines = strValue.Split(new[] { nl }, StringSplitOptions.RemoveEmptyEntries).ToList();

            if (node.Value.Tag == (Byte)Asn1Type.BIT_STRING)
            {
                lines.Insert(0, $"{node.Value.UnusedBits:x2} ; UNUSED BITS");
            }
            String padLeftContent = String.Empty;

            if (node.Parent != null)
            {
                padLeftContent = node.MyIndex < node.Parent.Children.Count - 1 ? "|  " : "   ";
            }

            for (Int32 i = 0; i < lines.Count; i++)
            {
                line.AppendFormat("{0:x4}: ", value.PayloadStartOffset + i * 16);
                // shift right nested content
                line.Append(leftPadString).Append(padLeftContent);
                if (!_noAsciiTags.Contains(value.Tag))
                {
                    Int32 index = lines[i].LastIndexOf("  ", StringComparison.InvariantCulture);
                    if (index >= 0)
                    {
                        lines[i] = lines[i].Insert(index + 1, ";");
                    }
                }
                line.AppendLine(lines[i]);
            }
            // write decoded content
            if (_explicitTextTags.Contains(value.Tag))
            {
                line.Append(new String(' ', 6)).Append(leftPadString).Append(padLeftContent);
                line.AppendLine($"   ; \"{value.ExplicitValue}\"");
            }
            _sb.Append(line);
        }
예제 #5
0
 public static Task <Asn1TreeNode> BuildTree(Byte[] rawData)
 {
     return(Task.Factory.StartNew(() => {
         Asn1Reader asn = new Asn1Reader(rawData);
         asn.BuildOffsetMap();
         Asn1Lite root = new Asn1Lite(asn);
         Asn1TreeNode parent = new Asn1TreeNode(root);
         if (asn.NextOffset == 0)
         {
             return parent;
         }
         List <Asn1TreeNode> list = new List <Asn1TreeNode> {
             parent
         };
         buildTree(asn, parent);
         return list[0];
     }));
 }
예제 #6
0
        void addNewNode(Object o)
        {
            Asn1Lite nodeValue = _windowFactory.ShowNodeContentEditor(NodeEditMode.NewNode);

            if (nodeValue == null)
            {
                return;
            }
            if (_data.Tree.Count == 0)
            {
                // add new root node
                Asn1TreeNode node = new Asn1TreeNode(nodeValue);
                _data.Tree.Add(node);
                _data.FinishBinaryUpdate();
            }
            else
            {
                _data.SelectedNode.AddChild(nodeValue, true);
                _data.FinishBinaryUpdate();
            }
        }
예제 #7
0
        void writeTagHeader(Asn1TreeNode node, String leftPadString)
        {
            Asn1Lite value = node.Value;

            line.Clear();
            _headList.Clear();
            _headList.Add(value.Tag);
            _headList.AddRange(Asn1Utils.GetLengthBytes(value.PayloadLength));
            // write tag address
            line.AppendFormat("{0:x4}: ", value.Offset);
            // pad from
            line.Append(leftPadString);
            line.Append(AsnFormatter.BinaryToString(_headList.ToArray(), EncodingType.Hex, EncodingFormat.NOCRLF));
            if (line.Length < 48)
            {
                Int32 padLeft = 48 - line.Length;
                line.Append(new String(' ', padLeft));
            }
            line.AppendFormat("; {0} ({1:x} Bytes)", value.TagName, value.PayloadLength);
            line.Append(nl);
            _sb.Append(line);
        }