Beispiel #1
0
        /// <exception cref="TjsException"></exception>
        private void ReadObjects(ScriptBlock block, byte[] buff, int offset, int size)
        {
            string[]     strarray = mStringArray;
            ByteBuffer[] bbarray  = mByteBufferArray;
            double[]     dblarray = mDoubleArray;
            byte[]       barray   = mByteArray;
            short[]      sarray   = mShortArray;
            int[]        iarray   = mIntArray;
            long[]       larray   = mLongArray;
            int          toplevel = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                    + 3] & unchecked ((int)(0xff))) << 24;

            offset += 4;
            int objcount = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                           (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                           + 3] & unchecked ((int)(0xff))) << 24;

            offset += 4;
            //Log.v("test","count:"+objcount);
            mObjectsCache.Create(objcount);
            InterCodeObject[] objs = mObjectsCache.mObjs;
            AList <ByteCodeLoader.VariantRepalace> work = mObjectsCache.mWork;

            int[]   parent           = mObjectsCache.mParent;
            int[]   propSetter       = mObjectsCache.mPropSetter;
            int[]   propGetter       = mObjectsCache.mPropGetter;
            int[]   superClassGetter = mObjectsCache.mSuperClassGetter;
            int[][] properties       = mObjectsCache.mProperties;
            for (int o = 0; o < objcount; o++)
            {
                int tag = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                          (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                          + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                if (tag != FILE_TAG_LE)
                {
                    throw new TjsException(Error.ByteCodeBroken);
                }
                //int objsize = (buff[offset]&0xff) | (buff[offset+1]&0xff) << 8 | (buff[offset+2]&0xff) << 16 | (buff[offset+3]&0xff) << 24;
                offset   += 4;
                parent[o] = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                            (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                            + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int name = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                           (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                           + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int contextType = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                  (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                  + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int maxVariableCount = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1
                                                                                   ] & unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) <<
                                       16 | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int variableReserveCount = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset
                                                                                            + 1] & unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff)
                                                                                                                                                                  )) << 16 | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int maxFrameCount = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] &
                                                                                unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16
                                    | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int funcDeclArgCount = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1
                                                                                   ] & unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) <<
                                       16 | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int funcDeclUnnamedArgArrayBase = (buff[offset] & unchecked ((int)(0xff))) | (buff
                                                                                              [offset + 1] & unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int
                                                                                                                                                                             )(0xff))) << 16 | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int funcDeclCollapseBase = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset
                                                                                            + 1] & unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff)
                                                                                                                                                                  )) << 16 | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset       += 4;
                propSetter[o] = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                + 3] & unchecked ((int)(0xff))) << 24;
                offset       += 4;
                propGetter[o] = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                superClassGetter[o] = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1]
                                                                                  & unchecked ((int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) <<
                                      16 | (buff[offset + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int count = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                            (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                            + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                LongBuffer srcpos;
                // codePos/srcPos は今のところ使ってない、ソート济みなので、longにする必要はないが……
                offset += count << 3;
                srcpos  = null;
                count   = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked ((
                                                                                                        int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                                       + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                short[] code = new short[count];
                for (int i = 0; i < count; i++)
                {
                    code[i] = (short)((buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                      (int)(0xff))) << 8);
                    offset += 2;
                }
                offset += (count & 1) << 1;
                count   = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked ((
                                                                                                        int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                                       + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int vcount = count << 1;
                if (mVariantTypeData == null || mVariantTypeData.Length < vcount)
                {
                    mVariantTypeData = new short[vcount];
                }
                short[] data = mVariantTypeData;
                for (int i_1 = 0; i_1 < vcount; i_1++)
                {
                    data[i_1] = (short)((buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] &
                                                                                    unchecked ((int)(0xff))) << 8);
                    offset += 2;
                }
                Variant[] vdata     = new Variant[count];
                int       datacount = count;
                Variant   tmp;
                for (int i_2 = 0; i_2 < datacount; i_2++)
                {
                    int pos   = i_2 << 1;
                    int type  = data[pos];
                    int index = data[pos + 1];
                    switch (type)
                    {
                    case TYPE_VOID:
                    {
                        vdata[i_2] = new Variant();
                        // null
                        break;
                    }

                    case TYPE_OBJECT:
                    {
                        vdata[i_2] = new Variant(null, null);
                        // null Array Dictionary はまだサポートしていない TODO
                        break;
                    }

                    case TYPE_INTER_OBJECT:
                    {
                        tmp = new Variant();
                        work.AddItem(new ByteCodeLoader.VariantRepalace(tmp, index));
                        vdata[i_2] = tmp;
                        break;
                    }

                    case TYPE_INTER_GENERATOR:
                    {
                        tmp = new Variant();
                        work.AddItem(new ByteCodeLoader.VariantRepalace(tmp, index));
                        vdata[i_2] = tmp;
                        break;
                    }

                    case TYPE_STRING:
                    {
                        vdata[i_2] = new Variant(strarray[index]);
                        break;
                    }

                    case TYPE_OCTET:
                    {
                        vdata[i_2] = new Variant(bbarray[index]);
                        break;
                    }

                    case TYPE_REAL:
                    {
                        vdata[i_2] = new Variant(dblarray[index]);
                        break;
                    }

                    case TYPE_BYTE:
                    {
                        vdata[i_2] = new Variant(barray[index]);
                        break;
                    }

                    case TYPE_SHORT:
                    {
                        vdata[i_2] = new Variant(sarray[index]);
                        break;
                    }

                    case TYPE_INTEGER:
                    {
                        vdata[i_2] = new Variant(iarray[index]);
                        break;
                    }

                    case TYPE_LONG:
                    {
                        vdata[i_2] = new Variant(larray[index]);
                        break;
                    }

                    case TYPE_UNKNOWN:
                    default:
                    {
                        vdata[i_2] = new Variant();
                        // null;
                        break;
                    }
                    }
                }
                count = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked ((
                                                                                                      int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                                     + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                int[] scgetterps = new int[count];
                for (int i_3 = 0; i_3 < count; i_3++)
                {
                    scgetterps[i_3] = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                      (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                      + 3] & unchecked ((int)(0xff))) << 24;
                    offset += 4;
                }
                // properties
                count = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked ((
                                                                                                      int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                                     + 3] & unchecked ((int)(0xff))) << 24;
                offset += 4;
                if (count > 0)
                {
                    int   pcount = count << 1;
                    int[] props  = new int[pcount];
                    for (int i_4 = 0; i_4 < pcount; i_4++)
                    {
                        props[i_4] = (buff[offset] & unchecked ((int)(0xff))) | (buff[offset + 1] & unchecked (
                                                                                     (int)(0xff))) << 8 | (buff[offset + 2] & unchecked ((int)(0xff))) << 16 | (buff[offset
                                                                                                                                                                     + 3] & unchecked ((int)(0xff))) << 24;
                        offset += 4;
                    }
                    properties[o] = props;
                }
                //IntVector superpointer = IntVector.wrap( scgetterps );
                InterCodeObject obj = new InterCodeObject(block, mStringArray[name], contextType,
                                                          code, vdata, maxVariableCount, variableReserveCount, maxFrameCount, funcDeclArgCount
                                                          , funcDeclUnnamedArgArrayBase, funcDeclCollapseBase, true, srcpos, scgetterps);
                //objs.add(obj);
                objs[o] = obj;
            }
            Variant val = new Variant();

            for (int o_1 = 0; o_1 < objcount; o_1++)
            {
                InterCodeObject parentObj           = null;
                InterCodeObject propSetterObj       = null;
                InterCodeObject propGetterObj       = null;
                InterCodeObject superClassGetterObj = null;
                if (parent[o_1] >= 0)
                {
                    parentObj = objs[parent[o_1]];
                }
                if (propSetter[o_1] >= 0)
                {
                    propSetterObj = objs[propSetter[o_1]];
                }
                if (propGetter[o_1] >= 0)
                {
                    propGetterObj = objs[propGetter[o_1]];
                }
                if (superClassGetter[o_1] >= 0)
                {
                    superClassGetterObj = objs[superClassGetter[o_1]];
                }
                objs[o_1].SetCodeObject(parentObj, propSetterObj, propGetterObj, superClassGetterObj
                                        );
                if (properties[o_1] != null)
                {
                    InterCodeObject obj = parentObj;
                    // objs.get(o).mParent;
                    int[] prop   = properties[o_1];
                    int   length = (int)(((uint)prop.Length) >> 1);
                    for (int i = 0; i < length; i++)
                    {
                        int pos   = i << 1;
                        int pname = prop[pos];
                        int pobj  = prop[pos + 1];
                        val.Set(objs[pobj]);
                        obj.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, mStringArray[pname], val
                                    , obj);
                    }
                    properties[o_1] = null;
                }
            }
            int count_1 = work.Count;

            for (int i_5 = 0; i_5 < count_1; i_5++)
            {
                ByteCodeLoader.VariantRepalace w = work[i_5];
                w.Work.Set(objs[w.Index]);
            }
            work.Clear();
            InterCodeObject top = null;

            if (toplevel >= 0)
            {
                top = objs[toplevel];
            }
            block.SetObjects(top, objs, objcount);
        }