Beispiel #1
0
        public ABCReader(byte[] buf, uint pos)
        {
            try
            {
                this.buf = buf;
                this.pos = pos;
                abc      = new ABCFile();

                abc.minorVersion = readU16();
                abc.majorVersion = readU16();

                Func <uint, uint> atLeastOne = (uint n) => { return(n != 0 ? n : 1); };

                abc.ints = new long?[atLeastOne(readU30())];
                for (int i = 1; i < abc.ints.Length; i++)
                {
                    abc.ints[i] = readS32();
                }

                abc.uints = new ulong?[atLeastOne(readU30())];
                for (int i = 1; i < abc.uints.Length; i++)
                {
                    abc.uints[i] = readU32();
                }

                abc.doubles = new double?[atLeastOne(readU30())];
                for (int i = 1; i < abc.doubles.Length; i++)
                {
                    abc.doubles[i] = readD64();
                }

                abc.strings = new string[atLeastOne(readU30())];
                for (int i = 1; i < abc.strings.Length; i++)
                {
                    abc.strings[i] = readString();
                }

                abc.namespaces = new ABCFile.Namespace[atLeastOne(readU30())];
                for (int i = 1; i < abc.namespaces.Length; i++)
                {
                    abc.namespaces[i] = readNamespace();
                }

                abc.namespaceSets = new uint[atLeastOne(readU30())][];
                for (int i = 1; i < abc.namespaceSets.Length; i++)
                {
                    abc.namespaceSets[i] = readNamespaceSet();
                }

                abc.multinames = new ABCFile.Multiname[atLeastOne(readU30())];
                for (int i = 1; i < abc.multinames.Length; i++)
                {
                    abc.multinames[i] = readMultiname();
                }

                abc.methods = new ABCFile.MethodInfo[readU30()];
                for (int i = 0; i < abc.methods.Length; i++)
                {
                    abc.methods[i] = readMethodInfo();
                }

                abc.metadata = new ABCFile.Metadata[readU30()];
                for (int i = 0; i < abc.metadata.Length; i++)
                {
                    abc.metadata[i] = readMetadata();
                }

                abc.instances = new ABCFile.Instance[readU30()];
                for (int i = 0; i < abc.instances.Length; i++)
                {
                    abc.instances[i] = readInstance();
                }

                abc.classes = new ABCFile.Class[abc.instances.Length];
                for (int i = 0; i < abc.classes.Length; i++)
                {
                    abc.classes[i] = readClass();
                }

                abc.scripts = new ABCFile.Script[readU30()];
                for (int i = 0; i < abc.scripts.Length; i++)
                {
                    abc.scripts[i] = readScript();
                }

                abc.bodies = new ABCFile.MethodBody[readU30()];
                for (int i = 0; i < abc.bodies.Length; i++)
                {
                    abc.bodies[i] = readMethodBody();
                }
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Error at {0} (0x{1:x8}):", pos, pos), e);
            }
        }
Beispiel #2
0
        public ABCWriter(ABCFile abc)
        {
            this.abc = abc;
            buf      = new byte[1024];

            writeU16(abc.minorVersion);
            writeU16(abc.majorVersion);

            writeU30((uint)(abc.ints.Length <= 1 ? 0 : abc.ints.Length));
            for (int i = 1; i < abc.ints.Length; i++)
            {
                writeS32(abc.ints[i].Value);
            }

            writeU30((uint)(abc.uints.Length <= 1 ? 0 : abc.uints.Length));
            for (int i = 1; i < abc.uints.Length; i++)
            {
                writeU32(abc.uints[i].Value);
            }

            writeU30((uint)(abc.doubles.Length <= 1 ? 0 : abc.doubles.Length));
            for (int i = 1; i < abc.doubles.Length; i++)
            {
                writeD64(abc.doubles[i].Value);
            }

            writeU30((uint)(abc.strings.Length <= 1 ? 0 : abc.strings.Length));
            for (int i = 1; i < abc.strings.Length; i++)
            {
                writeString(abc.strings[i]);
            }

            writeU30((uint)(abc.namespaces.Length <= 1 ? 0 : abc.namespaces.Length));
            for (int i = 1; i < abc.namespaces.Length; i++)
            {
                writeNamespace(abc.namespaces[i]);
            }

            writeU30((uint)(abc.namespaceSets.Length <= 1 ? 0 : abc.namespaceSets.Length));
            for (int i = 1; i < abc.namespaceSets.Length; i++)
            {
                writeNamespaceSet(abc.namespaceSets[i]);
            }

            writeU30((uint)(abc.multinames.Length <= 1 ? 0 : abc.multinames.Length));
            for (int i = 1; i < abc.multinames.Length; i++)
            {
                writeMultiname(abc.multinames[i]);
            }

            writeU30((uint)abc.methods.Length);
            for (int i = 0; i < abc.methods.Length; i++)
            {
                writeMethodInfo(abc.methods[i]);
            }

            writeU30((uint)abc.metadata.Length);
            for (int i = 0; i < abc.metadata.Length; i++)
            {
                writeMetadata(abc.metadata[i]);
            }

            writeU30((uint)abc.instances.Length);
            for (int i = 0; i < abc.instances.Length; i++)
            {
                writeInstance(abc.instances[i]);
            }

            for (int i = 0; i < abc.classes.Length; i++)
            {
                writeClass(abc.classes[i]);
            }

            writeU30((uint)abc.scripts.Length);
            for (int i = 0; i < abc.scripts.Length; i++)
            {
                writeScript(abc.scripts[i]);
            }

            writeU30((uint)abc.bodies.Length);
            for (int i = 0; i < abc.bodies.Length; i++)
            {
                writeMethodBody(abc.bodies[i]);
            }

            Array.Resize(ref buf, (int)pos);
        }