Beispiel #1
0
        public ConstantPoolInfo ReadConstantPoolInfo()
        {
            ConstantPoolInfo result = new ConstantPoolInfo();

            result.IntArrayCapacity = ReadU30();
            for (uint i = 1; i < result.IntArrayCapacity; i++)
            {
                result.SetIntAt(ReadS32(), i);
            }

            result.UIntArrayCapacity = ReadU30();
            for (uint i = 1; i < result.UIntArrayCapacity; i++)
            {
                result.SetUIntAt(ReadU30(), i);
            }

            result.DoubleArrayCapacity = ReadU30();
            for (uint i = 1; i < result.DoubleArrayCapacity; i++)
            {
                result.SetDoubleAt(ReadDouble(), i);
            }

            result.StringArrayCapacity = ReadU30();
            for (uint i = 1; i < result.StringArrayCapacity; i++)
            {
                result.SetStringAt(new StringInfo(i, ReadString()), i);
            }

            result.NamespaceArrayCapacity = ReadU30();
            for (uint i = 1; i < result.NamespaceArrayCapacity; i++)
            {
                NamespaceInfo namespaceInfo = new NamespaceInfo(result, i);
                namespaceInfo.Kind = (NamespaceKind)ReadByte();
                namespaceInfo.Name = result.GetStringAt(ReadU30());
                result.SetNamespaceAt(namespaceInfo, i);
            }

            result.NamespaceSetArrayCapacity = ReadU30();
            for (uint i = 1; i < result.NamespaceSetArrayCapacity; i++)
            {
                NamespaceSetInfo namespaceSetInfo = new NamespaceSetInfo(i);
                namespaceSetInfo.NamespaceArray = new NamespaceInfo[ReadU30()];
                for (int j = 0; j < namespaceSetInfo.NamespaceArray.Length; j++)
                {
                    namespaceSetInfo.NamespaceArray[j] = result.GetNamespaceAt(ReadU30());
                }

                result.SetNamespaceSetAt(namespaceSetInfo, i);
            }

            result.MultinameArrayCapacity = ReadU30();
            for (uint i = 1; i < result.MultinameArrayCapacity; i++)
            {
                result.SetMultinameAt(ReadMultinameInfo(result, i), i);
            }
            return(result);
        }
Beispiel #2
0
        public static U30 GetMultiname(Abc46 abc, string argument)
        {
            if (argument.StartsWith("#"))
            {
                int index = int.Parse(argument.Substring(1, argument.Length - 1));

                if (index < abc.ConstantPool.MultinameTable.Count && index > 0)
                {
                    return((U30)index);
                }

                throw new Exception(String.Format("Invalid multiname {0}", index));
            }

            NamespaceInfo    ns;
            NamespaceSetInfo nss;
            StringInfo       name;

            bool skipQname = argument.IndexOf("[") == 0;

            if (skipQname)
            {
                //BAD quick dirty hack
                argument = argument.Replace(" ", "");
            }

            string tempName;
            U30    result = new U30();

            for (int i = 1, n = abc.ConstantPool.MultinameTable.Count; i < n; ++i)
            {
                MultinameInfo multiName = (MultinameInfo)abc.ConstantPool.MultinameTable[i];

                switch (multiName.Kind)
                {
                    #region QName, QNameA

                case MultinameInfo.QName:
                case MultinameInfo.QNameA:

                    if (skipQname)
                    {
                        continue;
                    }

                    ns   = ((NamespaceInfo)abc.ConstantPool.NamespaceTable[(int)multiName.Data[0].Value]);
                    name = ((StringInfo)abc.ConstantPool.StringTable[(int)multiName.Data[1].Value]);

                    tempName = "";

                    switch (ns.Kind)
                    {
                    case NamespaceInfo.Namespace:
                    case NamespaceInfo.ExplicitNamespace:
                        //TODO implement this
                        //user defined
                        break;

                    case NamespaceInfo.PrivateNs:
                        tempName = "private";
                        break;

                    case NamespaceInfo.ProtectedNamespace:
                        tempName = "protected";
                        break;

                    case NamespaceInfo.StaticProtectedNs:
                        tempName = "protected$";
                        break;

                    case NamespaceInfo.PackageInternalNs:
                        tempName = "internal";
                        break;

                    case NamespaceInfo.PackageNamespace:
                        tempName = "public";
                        break;

                    default:
                        tempName = "*";
                        break;
                    }

                    if (0 != ns.Name.Value)
                    {
                        string namespaceName = ((StringInfo)abc.ConstantPool.StringTable[(int)ns.Name.Value]).ToString();
                        if ("" != namespaceName && tempName != "")
                        {
                            tempName += "::";
                        }
                        tempName += namespaceName;
                    }

                    tempName += "::" + name.ToString();

                    if (tempName == argument)
                    {
                        result.Value = (uint)i;
                        return(result);
                    }
                    break;

                    #endregion

                    #region MultinameL, MultinameLA

                case MultinameInfo.MultinameL:
                case MultinameInfo.MultinameLA:

                    if (!skipQname)
                    {
                        continue;
                    }

                    tempName = "[";

                    nss = (NamespaceSetInfo)abc.ConstantPool.NamespaceSetTable[(int)multiName.Data[0].Value];

                    for (int j = 0, m = nss.NamespaceSet.Count; j < m; ++j)
                    {
                        U30 nssNs = (U30)nss.NamespaceSet[j];
                        ns = ((NamespaceInfo)abc.ConstantPool.NamespaceTable[(int)nssNs.Value]);

                        string r2 = "";

                        switch (ns.Kind)
                        {
                        case NamespaceInfo.Namespace:
                        case NamespaceInfo.ExplicitNamespace:
                            //TODO implement this
                            //user defined
                            break;

                        case NamespaceInfo.PrivateNs:
                            r2 = "private";
                            break;

                        case NamespaceInfo.ProtectedNamespace:
                            r2 = "protected";
                            break;

                        case NamespaceInfo.StaticProtectedNs:
                            r2 = "protected$";
                            break;

                        case NamespaceInfo.PackageInternalNs:
                            r2 = "internal";
                            break;

                        case NamespaceInfo.PackageNamespace:
                            r2 = "public";
                            break;

                        default:
                            r2 = "*";
                            break;
                        }

                        tempName += r2 + "::" + ((StringInfo)abc.ConstantPool.StringTable[(int)ns.Name.Value]).ToString();

                        if (j != (m - 1))
                        {
                            tempName += ",";
                        }
                    }

                    tempName += "]";

                    if (argument == tempName)
                    {
                        result.Value = (uint)i;
                        return(result);
                    }
                    break;

                    #endregion

                default:
                    continue;
                }
            }

            if (skipQname)
            {
                #region Create MultinameL
                //
                // Create a MultinameL
                //

                // Remove [] from argument
                argument = argument.Substring(1, argument.Length - 2);


                // Get new NamespaceSet index
                U30 setIndex = new U30();
                setIndex.Value = (uint)abc.ConstantPool.NamespaceSetTable.Count;


                // Create MultinameInfo
                MultinameInfo newName = new MultinameInfo();
                newName.Data = new U30[1] {
                    setIndex
                };
                newName.Kind = MultinameInfo.MultinameL;


                // Create NamespaceSet
                NamespaceSetInfo newSet = new NamespaceSetInfo();
                newSet.NamespaceSet = new ArrayList();

                abc.ConstantPool.NamespaceSetTable.Add(newSet);

                for (int i = 0, n = abc.ConstantPool.NamespaceTable.Count; i < n; ++i)
                {
                    ns = (NamespaceInfo)abc.ConstantPool.NamespaceTable[i];

                    string r2 = "";

                    switch (ns.Kind)
                    {
                    case NamespaceInfo.Namespace:
                    case NamespaceInfo.ExplicitNamespace:
                        //TODO implement this
                        //user defined
                        break;

                    case NamespaceInfo.PrivateNs:
                        r2 = "private";
                        break;

                    case NamespaceInfo.ProtectedNamespace:
                        r2 = "protected";
                        break;

                    case NamespaceInfo.StaticProtectedNs:
                        r2 = "protected$";
                        break;

                    case NamespaceInfo.PackageInternalNs:
                        r2 = "internal";
                        break;

                    case NamespaceInfo.PackageNamespace:
                        r2 = "public";
                        break;

                    default:
                        r2 = "*";
                        break;
                    }

                    r2 += "::" + ((StringInfo)abc.ConstantPool.StringTable[(int)ns.Name.Value]).ToString();

                    if (argument.IndexOf(r2) != -1)
                    {
                        U30 nsIndex = new U30();
                        nsIndex.Value = (uint)i;

                        newSet.NamespaceSet.Add(nsIndex);
                    }
                }

                result.Value = (uint)abc.ConstantPool.MultinameTable.Count;
                abc.ConstantPool.MultinameTable.Add(newName);

                #endregion
            }
            else
            {
                #region Create QName

                // Create a QName

                U30 nsIndex = new U30();

                if (argument.IndexOf("::") == argument.LastIndexOf("::"))
                {
                    nsIndex.Value = GetNamespace(abc, argument.Substring(0, argument.LastIndexOf("::") + 2)).Value;
                }
                else
                {
                    nsIndex.Value = GetNamespace(abc, argument.Substring(0, argument.LastIndexOf("::"))).Value;
                }

                MultinameInfo newQName = new MultinameInfo();
                newQName.Data = new U30[2] {
                    nsIndex, (U30)abc.ConstantPool.ResolveString(argument.Substring(argument.LastIndexOf("::") + 2))
                };
                newQName.Kind = MultinameInfo.QName;

                result.Value = (uint)abc.ConstantPool.MultinameTable.Count;

                abc.ConstantPool.MultinameTable.Add(newQName);

                #endregion
            }

            return(result);
        }
Beispiel #3
0
 public MKMultiname(ConstantPoolInfo cPool)
     : base(cPool)
 {
     Name         = cPool.GetStringAt(1);
     NamespaceSet = cPool.GetNamespaceSetAt(1);
 }
Beispiel #4
0
        public void ReadExternal(BinaryReader input)
        {
            #region integer

            uint n = Primitives.ReadU30(input).Value;

            _intTable = new ArrayList(Capacity.Max(n));
            _intTable.Add(new S32());

            for (uint i = 1; i < n; ++i)
            {
                _intTable.Add(Primitives.ReadS32(input));
            }

            #endregion

            #region uinteger

            n = Primitives.ReadU30(input).Value;

            _uintTable = new ArrayList(Capacity.Max(n));
            _uintTable.Add(new U32());

            for (uint i = 1; i < n; ++i)
            {
                _uintTable.Add(Primitives.ReadU32(input));
            }

            #endregion

            #region double

            n = Primitives.ReadU30(input).Value;

            _doubleTable = new ArrayList(Capacity.Max(n));
            _doubleTable.Add(double.NaN);

            for (uint i = 1; i < n; ++i)
            {
                _doubleTable.Add(input.ReadDouble());
            }

            #endregion

            #region string_info

            n = Primitives.ReadU30(input).Value;

            _stringTable = new ArrayList(Capacity.Max(n));
            _stringTable.Add(new StringInfo());

            for (uint i = 1; i < n; ++i)
            {
                StringInfo stringInfo = new StringInfo();
                stringInfo.ReadExternal(input);

                _stringTable.Add(stringInfo);
            }

            #endregion

            #region namespace_info

            n = Primitives.ReadU30(input).Value;

            _namespaceTable = new ArrayList(Capacity.Max(n));
            _namespaceTable.Add(new NamespaceInfo());

            for (uint i = 1; i < n; ++i)
            {
                NamespaceInfo namespaceInfo = new NamespaceInfo();
                namespaceInfo.ReadExternal(input);

                _namespaceTable.Add(namespaceInfo);
            }

            #endregion

            #region ns_set_info

            n = Primitives.ReadU30(input).Value;

            _nsTable = new ArrayList(Capacity.Max(n));
            _nsTable.Add(new NamespaceSetInfo());

            for (uint i = 1; i < n; ++i)
            {
                NamespaceSetInfo nsInfo = new NamespaceSetInfo();
                nsInfo.ReadExternal(input);

                _nsTable.Add(nsInfo);
            }

            #endregion

            #region multiname_info

            n = Primitives.ReadU30(input).Value;

            _multinameTable = new ArrayList(Capacity.Max(n));
            _multinameTable.Add(new MultinameInfo());

            for (uint i = 1; i < n; ++i)
            {
                MultinameInfo multinameInfo = new MultinameInfo();
                multinameInfo.ReadExternal(input);

                _multinameTable.Add(multinameInfo);
            }

            #endregion
        }