Exemplo n.º 1
0
        private void parseCpool(BinaryReader br)
        {
            long start = br.BaseStream.Position;
            int  n;

            // ints
            n    = readU32(br);
            ints = new int[n];
            if (n > 0)
            {
                ints[0] = 0;
            }
            for (int i = 1; i < n; i++)
            {
                ints[i] = readU32(br);
            }

            // uints
            n     = readU32(br);
            uints = new uint[n];
            if (n > 0)
            {
                uints[0] = 0;
            }
            for (int i = 1; i < n; i++)
            {
                uints[i] = (uint)readU32(br);
            }

            // doubles
            n       = readU32(br);
            doubles = new double[n];
            if (n > 0)
            {
                doubles[0] = double.NaN;
            }
            for (int i = 1; i < n; i++)
            {
                doubles[i] = br.ReadDouble();
            }

            // sb.append("Cpool numbers size "+(data.position-start)+" "+int(100*(data.position-start)/data.length)+" %")
            //Console.WriteLine("Cpool numbers size " + (br.BaseStream.Position - start) + " " + (int)(100 * (br.BaseStream.Position - start) / br.BaseStream.Length) + " %");
            start = br.BaseStream.Position;

            // strings
            n       = readU32(br);
            strings = new string[n];
            if (n > 0)
            {
                strings[0] = "";
            }
            for (int i = 1; i < n; i++)
            {
                strings[i] = readUTFBytes(br); //br.ReadString()
            }
            // sb.append("Cpool strings count "+ n +" size "+(data.position-start)+" "+int(100*(data.position-start)/data.length)+" %")
            //Console.WriteLine("Cpool strings count " + n + " size " + (br.BaseStream.Position - start) + " " + (int)(100 * (br.BaseStream.Position - start) / br.BaseStream.Length) + " %");
            start = br.BaseStream.Position;

            // namespaces
            n          = readU32(br);
            namespaces = new Namespace[n];
            if (n > 0)
            {
                namespaces[0] = publicNs;
            }
            for (int i = 1; i < n; i++)
            {
                switch ((ConstantKind)br.ReadSByte())
                {
                case ConstantKind.Namespace:
                case ConstantKind.PackageNs:
                case ConstantKind.PackageInternalNs:
                case ConstantKind.ProtectedNs:
                case ConstantKind.StaticProtectedNs:
                case ConstantKind.StaticProtectedNs2:
                    namespaces[i] = new Namespace((string)strings[readU32(br)]);
                    // todo mark kind of namespace.
                    break;

                case ConstantKind.PrivateNs:
                    readU32(br);
                    namespaces[i] = new Namespace(null, "private");
                    break;
                }
            }

            //Console.WriteLine("Cpool namespaces count "+ n +" size "+(br.BaseStream.Position-start)+" "+(int)(100*(br.BaseStream.Position-start)/br.BaseStream.Length)+" %");
            start = br.BaseStream.Position;

            // namespace sets
            n      = readU32(br);
            nssets = new Namespace[n][];
            if (n > 0)
            {
                nssets[0] = null;
            }
            for (int i = 1; i < n; i++)
            {
                int         count = readU32(br);
                Namespace[] nsset = new Namespace[count];
                nssets[i] = nsset;
                for (int j = 0; j < count; j++)
                {
                    nsset[j] = (Namespace)namespaces[readU32(br)];
                }
            }

            //Console.WriteLine("Cpool nssets count "+ n +" size "+(br.BaseStream.Position-start)+" "+(int)(100*(br.BaseStream.Position-start)/br.BaseStream.Length)+" %");
            start = br.BaseStream.Position;

            // multinames
            n     = readU32(br);
            names = new QName[n];
            if (n > 0)
            {
                names[0] = null;
            }
            namespaces[0] = anyNs;
            strings[0]    = "*";
            for (int i = 1; i < n; i++)
            {
                switch ((ConstantKind)br.ReadSByte())
                {
                case ConstantKind.Qname:
                case ConstantKind.QnameA:
                    names[i] = new QName((Namespace)namespaces[readU32(br)], (string)strings[readU32(br)]);
                    break;

                case ConstantKind.RTQname:
                case ConstantKind.RTQnameA:
                    names[i] = new QName((string)strings[readU32(br)]);
                    break;

                case ConstantKind.RTQnameL:
                case ConstantKind.RTQnameLA:
                    names[i] = null;
                    break;

                case ConstantKind.NameL:
                case ConstantKind.NameLA:
                    names[i] = new QName(new Namespace(""), null);
                    break;

                case ConstantKind.Multiname:
                case ConstantKind.MultinameA:
                    string localName = (string)strings[readU32(br)];
                    names[i] = new Multiname((Namespace[])nssets[readU32(br)], localName);
                    break;

                case ConstantKind.MultinameL:
                case ConstantKind.MultinameLA:
                    names[i] = new Multiname((Namespace[])nssets[readU32(br)], null);
                    break;

                case ConstantKind.TypeName:
                    QName   name       = (QName)names[readU32(br)] ?? new QName("Vector");
                    int     count      = readU32(br);
                    QName[] parameters = new QName[count];
                    for (int j = 0; j < count; ++j)
                    {
                        int idx = readU32(br);
                        parameters[j] = (QName)names[idx] ?? new QName("*");
                    }
                    names[i] = new ParameterizedQName(name, parameters);
                    break;

                default:
                    br.BaseStream.Position--;
                    Console.WriteLine("-- Error: Invalid constant kind [" + br.ReadSByte() + "]");
                    break;
                }
            }

            //Console.WriteLine("Cpool names count " + n + " size " + (br.BaseStream.Position - start) + " " + (int)(100 * (br.BaseStream.Position - start) / br.BaseStream.Length) + " %");

            namespaces[0] = publicNs;
            strings[0]    = "*";
        }
Exemplo n.º 2
0
 public QName(Namespace uri, string localName)
 {
     this.localName = localName;
     this.uri       = uri.uri;
 }