Ejemplo n.º 1
0
        private TreeNode TdfToTree(Blaze.Tdf tdf)
        {
            TreeNode t, t2, t3;

            switch (tdf.Type)
            {
            case 3:
                t = tdf.ToTree();
                Blaze.TdfStruct str = (Blaze.TdfStruct)tdf;
                if (str.startswith2)
                {
                    t.Text += " (Starts with 2)";
                }
                foreach (Blaze.Tdf td in str.Values)
                {
                    t.Nodes.Add(TdfToTree(td));
                }
                t.Name = (inlistcount++).ToString();
                inlist.Add(tdf);
                return(t);

            case 4:
                t = tdf.ToTree();
                Blaze.TdfList l = (Blaze.TdfList)tdf;
                if (l.SubType == 3)
                {
                    List <Blaze.TdfStruct> l2 = (List <Blaze.TdfStruct>)l.List;
                    for (int i = 0; i < l2.Count; i++)
                    {
                        t2 = new TreeNode("Entry #" + i);
                        if (l2[i].startswith2)
                        {
                            t2.Text += " (Starts with 2)";
                        }
                        List <Blaze.Tdf> l3 = l2[i].Values;
                        for (int j = 0; j < l3.Count; j++)
                        {
                            t2.Nodes.Add(TdfToTree(l3[j]));
                        }
                        t.Nodes.Add(t2);
                    }
                }
                t.Name = (inlistcount++).ToString();
                inlist.Add(tdf);
                return(t);

            case 5:
                t = tdf.ToTree();
                Blaze.TdfDoubleList ll = (Blaze.TdfDoubleList)tdf;
                t2 = new TreeNode("List 1");
                if (ll.SubType1 == 3)
                {
                    List <Blaze.TdfStruct> l2 = (List <Blaze.TdfStruct>)ll.List1;
                    for (int i = 0; i < l2.Count; i++)
                    {
                        t3 = new TreeNode("Entry #" + i);
                        if (l2[i].startswith2)
                        {
                            t2.Text += " (Starts with 2)";
                        }
                        List <Blaze.Tdf> l3 = l2[i].Values;
                        for (int j = 0; j < l3.Count; j++)
                        {
                            t3.Nodes.Add(TdfToTree(l3[j]));
                        }
                        t2.Nodes.Add(t3);
                    }
                    t.Nodes.Add(t2);
                }
                t2 = new TreeNode("List 2");
                if (ll.SubType2 == 3)
                {
                    List <Blaze.TdfStruct> l2 = (List <Blaze.TdfStruct>)ll.List2;
                    for (int i = 0; i < l2.Count; i++)
                    {
                        t3 = new TreeNode("Entry #" + i);
                        if (l2[i].startswith2)
                        {
                            t2.Text += " (Starts with 2)";
                        }
                        List <Blaze.Tdf> l3 = l2[i].Values;
                        for (int j = 0; j < l3.Count; j++)
                        {
                            t3.Nodes.Add(TdfToTree(l3[j]));
                        }
                        t2.Nodes.Add(t3);
                    }
                    t.Nodes.Add(t2);
                }
                t.Name = (inlistcount++).ToString();
                inlist.Add(tdf);
                return(t);

            case 6:
                t = tdf.ToTree();
                Blaze.TdfUnion tu = (Blaze.TdfUnion)tdf;
                if (tu.UnionType != 0x7F)
                {
                    t.Nodes.Add(TdfToTree(tu.UnionContent));
                }
                t.Name = (inlistcount++).ToString();
                inlist.Add(tdf);
                return(t);

            default:
                t      = tdf.ToTree();
                t.Name = (inlistcount++).ToString();
                inlist.Add(tdf);
                return(t);
            }
        }
Ejemplo n.º 2
0
        private void tv1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode t = e.Node;

            if (t != null && t.Name != "")
            {
                int       n   = Convert.ToInt32(t.Name);
                Blaze.Tdf tdf = inlist[n];
                string    s;
                switch (tdf.Type)
                {
                case 0:
                    Blaze.TdfInteger ti = (Blaze.TdfInteger)tdf;
                    rtb2.Text = "0x" + ti.Value.ToString("X");
                    if (ti.Label == "IP  ")
                    {
                        rtb2.Text += Environment.NewLine + "(" + Blaze.GetStringFromIP(ti.Value) + ")";
                    }
                    break;

                case 1:
                    rtb2.Text = ((Blaze.TdfString)tdf).Value.ToString();
                    break;

                case 2:
                    rtb2.Text  = "Length: " + ((Blaze.TdfBlob)tdf).Data.Length.ToString();
                    rtb2.Text += Environment.NewLine + Blaze.HexDump(((Blaze.TdfBlob)tdf).Data);
                    break;

                case 4:
                    Blaze.TdfList l = (Blaze.TdfList)tdf;
                    s = "";
                    for (int i = 0; i < l.Count; i++)
                    {
                        switch (l.SubType)
                        {
                        case 0:
                            s += "{" + ((List <long>)l.List)[i] + "} ";
                            break;

                        case 1:
                            s += "{" + ((List <string>)l.List)[i] + "} ";
                            break;

                        case 9:
                            Blaze.TrippleVal t2 = ((List <Blaze.TrippleVal>)l.List)[i];
                            s += "{" + t2.v1.ToString("X") + "; " + t2.v2.ToString("X") + "; " + t2.v3.ToString("X") + "} ";
                            break;
                        }
                    }
                    rtb2.Text = s;
                    break;

                case 5:
                    s = "";
                    Blaze.TdfDoubleList ll = (Blaze.TdfDoubleList)tdf;
                    for (int i = 0; i < ll.Count; i++)
                    {
                        s += "{";
                        switch (ll.SubType1)
                        {
                        case 0:
                            List <long> l1 = (List <long>)ll.List1;
                            s += l1[i].ToString("X");
                            break;

                        case 1:
                            List <string> l2 = (List <string>)ll.List1;
                            s += l2[i];
                            break;

                        case 0xA:
                            List <float> lf1 = (List <float>)ll.List1;
                            s += lf1[i].ToString();
                            break;

                        default:
                            s += "(see List1[" + i + "])";
                            break;
                        }
                        s += " ; ";
                        switch (ll.SubType2)
                        {
                        case 0:
                            List <long> l1 = (List <long>)ll.List2;
                            s += l1[i].ToString("X");
                            break;

                        case 1:
                            List <string> l2 = (List <string>)ll.List2;
                            s += l2[i];
                            break;

                        case 0xA:
                            List <float> lf1 = (List <float>)ll.List2;
                            s += lf1[i].ToString();
                            break;

                        default:
                            s += "(see List2[" + i + "])";
                            break;
                        }
                        s += "}\n";
                    }
                    rtb2.Text = s;
                    break;

                case 6:
                    rtb2.Text = "Type: 0x" + ((Blaze.TdfUnion)tdf).UnionType.ToString("X2");
                    break;

                case 7:
                    Blaze.TdfIntegerList til = (Blaze.TdfIntegerList)tdf;
                    s = "";
                    for (int i = 0; i < til.Count; i++)
                    {
                        s += til.List[i].ToString("X");
                        if (i < til.Count - 1)
                        {
                            s += "; ";
                        }
                    }
                    rtb2.Text = s;
                    break;

                case 8:
                    Blaze.TdfDoubleVal dval = (Blaze.TdfDoubleVal)tdf;
                    rtb2.Text = "0x" + dval.Value.v1.ToString("X") + " 0x" + dval.Value.v2.ToString("X");
                    break;

                case 9:
                    Blaze.TdfTrippleVal tval = (Blaze.TdfTrippleVal)tdf;
                    rtb2.Text = "0x" + tval.Value.v1.ToString("X") + " 0x" + tval.Value.v2.ToString("X") + " 0x" + tval.Value.v3.ToString("X");
                    break;

                default:
                    rtb2.Text = "";
                    break;
                }
            }
        }
        public static string PrintTdf(Blaze.Tdf tdf, int tabs)
        {
            StringBuilder sb  = new StringBuilder();
            string        tab = "";

            for (int i = 0; i < tabs; i++)
            {
                tab += "\t";
            }
            sb.Append(tab + "[" + tdf.Label + "]:" + tdf.GetTypeDesc() + " = ");
            long   n;
            string s;

            Blaze.DoubleVal  dv;
            List <Blaze.Tdf> tdfl;

            switch (tdf.Type)
            {
            case 0:
                n = ((Blaze.TdfInteger)tdf).Value;
                sb.AppendLine("0x" + n.ToString("X") + "(" + n + ")");
                break;

            case 1:
                s = ((Blaze.TdfString)tdf).Value;
                sb.AppendLine("\"" + s + "\"");
                break;

            case 3:
                tdfl = ((Blaze.TdfStruct)tdf).Values;
                sb.AppendLine();
                if (((Blaze.TdfStruct)tdf).startswith2)
                {
                    sb.AppendLine(tab + "{(*starts with 0x02)");
                }
                else
                {
                    sb.AppendLine(tab + "{");
                }
                foreach (Blaze.Tdf tdf2 in tdfl)
                {
                    sb.Append(PrintTdf(tdf2, tabs + 1));
                }
                sb.AppendLine(tab + "}");
                break;

            case 4:
                sb.AppendLine();
                sb.AppendLine(tab + "{");
                sb.Append(PrintTdfList((Blaze.TdfList)tdf, tabs + 1));
                sb.AppendLine(tab + "}");
                break;

            case 5:
                sb.AppendLine();
                sb.AppendLine(tab + "{");
                sb.Append(PrintTdfDoubleList((Blaze.TdfDoubleList)tdf, tabs + 1));
                sb.AppendLine(tab + "}");
                break;

            case 6:
                if (((Blaze.TdfUnion)tdf).Type != 0x7f)
                {
                    sb.AppendLine();
                    sb.AppendLine(tab + "{");
                    sb.Append(PrintTdf(((Blaze.TdfUnion)tdf).UnionContent, tabs + 1));
                    sb.AppendLine(tab + "}");
                }
                break;

            case 8:
                dv = ((Blaze.TdfDoubleVal)tdf).Value;
                sb.AppendLine("{0x" + dv.v1.ToString("X") + "(" + dv.v1 + "),0x" + dv.v2.ToString("X") + "(" + dv.v2 + ")}");
                break;

            default:
                sb.AppendLine();
                break;
            }
            return(sb.ToString());
        }