예제 #1
0
 public static void UpdateSettingsDecode(Asn1TreeNode rootNode)
 {
     foreach (Asn1Lite node in rootNode.Flatten())
     {
         node.UpdateView();
     }
 }
예제 #2
0
 public TextViewerVM(IDataSource data)
 {
     rootNode            = data.SelectedNode;
     CurrentLength       = defaultLength.ToString(CultureInfo.InvariantCulture);
     SaveCommand         = new RelayCommand(saveFile);
     PrintCommand        = new RelayCommand(print);
     ApplyCommand        = new RelayCommand(applyNewLength);
     TextBoxWidth        = Tools.MeasureString(master, Settings.Default.FontSize, false);
     CertutilViewChecked = true;
     renderer.RenderText(currentLength);
 }
예제 #3
0
 public TextViewerVM(IDataSource data)
 {
     rootNode      = data.SelectedNode;
     CurrentLength = defaultLength.ToString(CultureInfo.InvariantCulture);
     SaveCommand   = new RelayCommand(saveFile);
     PrintCommand  = new RelayCommand(print);
     ApplyCommand  = new RelayCommand(applyNewLength);
     CloseCommand  = new RelayCommand(close);
     TextBoxWidth  = Tools.MeasureString(master, Settings.Default.FontSize, false);
     generateTable();
 }
예제 #4
0
        async void pasteBefore(Object o)
        {
            Asn1TreeNode childNode = await ClipboardManager.GetClipboardDataAsync();

            _data.RawData.InsertRange(_data.SelectedNode.Value.Offset, ClipboardManager.GetClipboardBytes());
            _data.SelectedNode.Parent.InsertChildNode(
                childNode,
                _data.SelectedNode,
                NodeAddOption.Before
                );
            _data.FinishBinaryUpdate();
        }
예제 #5
0
        async void pasteLast(Object o)
        {
            Asn1TreeNode childNode = await ClipboardManager.GetClipboardDataAsync();

            var newOffset = _data.SelectedNode.Value.Offset + _data.SelectedNode.Value.TagLength;

            _data.RawData.InsertRange(newOffset, ClipboardManager.GetClipboardBytes());
            _data.SelectedNode.InsertChildNode(
                childNode,
                _data.SelectedNode,
                NodeAddOption.Last
                );
            _data.FinishBinaryUpdate();
        }
예제 #6
0
        static List <Int32> getParents(Asn1TreeNode node)
        {
            var          depths = new List <Int32>();
            Asn1TreeNode n      = node;

            while (n.Parent != null)
            {
                if (n.MyIndex < n.Parent.Children.Count - 1)
                {
                    depths.Add(n.Value.Depth);
                }
                n = n.Parent;
            }
            return(depths);
        }
예제 #7
0
        String getLeftPad(Asn1TreeNode node)
        {
            if (node.Parent == null)
            {
                return(String.Empty);
            }
            var          sb = new StringBuilder();
            List <Int32> l  = getParents(node);

            for (Int32 i = _rootNode.Value.Depth; i < node.Value.Depth; i++)
            {
                sb.Append(l.Contains(i) ? "|  " : "   ");
            }
            return(sb.ToString());
        }
예제 #8
0
        static void buildTree(Asn1Reader root, Asn1TreeNode tree)
        {
            root.MoveNext();
            Int32 index = 0;

            do
            {
                tree.AddChild(new Asn1Lite(root, tree, index));
                index++;
            } while (root.MoveNextCurrentLevel());
            root.Reset();
            foreach (Asn1TreeNode node in tree.Children.Where(node => node.Value.IsContainer && node.Value.PayloadLength > 0))
            {
                root.MoveToPosition(node.Value.Offset);
                buildTree(root, node);
            }
        }
예제 #9
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);
        }
예제 #10
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];
     }));
 }
예제 #11
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();
            }
        }
예제 #12
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);
        }
예제 #13
0
 public static void UpdateSettingsInteger(Asn1TreeNode rootNode, IList <Byte> rawData)
 {
     if (Settings.Default.IntAsInt)
     {
         foreach (Asn1Lite node in rootNode.Flatten().Where(x => x.Tag == (Byte)Asn1Type.INTEGER))
         {
             Byte[] raw = rawData.Skip(node.PayloadStartOffset).Take(node.PayloadLength).ToArray();
             node.ExplicitValue = new BigInteger(raw.Reverse().ToArray()).ToString();
         }
     }
     else
     {
         foreach (Asn1Lite node in rootNode.Flatten().Where(x => x.Tag == (Byte)Asn1Type.INTEGER))
         {
             Byte[] raw = rawData.Skip(node.PayloadStartOffset).Take(node.PayloadLength).ToArray();
             node.ExplicitValue = AsnFormatter.BinaryToString(
                 raw,
                 EncodingType.HexRaw,
                 EncodingFormat.NOCRLF
                 );
         }
     }
 }
예제 #14
0
 public OpenSSLRenderer(Asn1TreeNode node)
 {
     rootNode = node;
 }
예제 #15
0
 public CertutilRenderer(Asn1TreeNode node)
 {
     _rootNode   = node;
     _dataSource = App.Container.Resolve <IDataSource>();
 }