Esempio n. 1
0
        public void WriteConstantPool(AsConstantPoolInfo constantPool)
        {
            WriteU30((uint)(constantPool.Integers.Length <= 1 ? 0 : constantPool.Integers.Length));
            for (var i = 1; i < constantPool.Integers.Length; i++) {
                WriteS32(constantPool.Integers[i]);
            }

            WriteU30((uint)(constantPool.UnsignedIntegers.Length <= 1 ? 0 : constantPool.UnsignedIntegers.Length));
            for (var i = 1; i < constantPool.UnsignedIntegers.Length; i++) {
                WriteU32(constantPool.UnsignedIntegers[i]);
            }

            WriteU30((uint)(constantPool.Doubles.Length <= 1 ? 0 : constantPool.Doubles.Length));
            for (var i = 1; i < constantPool.Doubles.Length; i++) {
                WriteD64(constantPool.Doubles[i]);
            }

            WriteU30((uint)(constantPool.Strings.Length <= 1 ? 0 : constantPool.Strings.Length));
            for (var i = 1; i < constantPool.Strings.Length; i++) {
                WriteString(constantPool.Strings[i]);
            }

            WriteU30((uint)(constantPool.Namespaces.Length <= 1 ? 0 : constantPool.Namespaces.Length));
            for (var i = 1; i < constantPool.Namespaces.Length; i++) {
                WriteNamespace(ref constantPool.Namespaces[i]);
            }

            WriteU30((uint)(constantPool.NamespaceSets.Length <= 1 ? 0 : constantPool.NamespaceSets.Length));
            for (var i = 1; i < constantPool.NamespaceSets.Length; i++)
                WriteNamespaceSet(constantPool.NamespaceSets[i]);

            WriteU30((uint)(constantPool.Multinames.Length <= 1 ? 0 : constantPool.Multinames.Length));
            for (var i = 1; i < constantPool.Multinames.Length; i++)
                WriteMultiname(ref constantPool.Multinames[i]);
        }
Esempio n. 2
0
        public AsConstantPoolInfo ReadConstantPool()
        {
            var res = new AsConstantPoolInfo();

            res.Integers = new int[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.Integers.Length; i++)
            {
                res.Integers[i] = ReadS32();
            }

            res.UnsignedIntegers = new uint[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.UnsignedIntegers.Length; i++)
            {
                res.UnsignedIntegers[i] = ReadU32();
            }

            res.Doubles    = new double[Math.Max(ReadU30(), 1)];
            res.Doubles[0] = double.NaN;
            for (var i = 1; i < res.Doubles.Length; i++)
            {
                res.Doubles[i] = ReadD64();
            }

            res.Strings    = new string[Math.Max(ReadU30(), 1)];
            res.Strings[0] = string.Empty;
            for (var i = 1; i < res.Strings.Length; i++)
            {
                res.Strings[i] = ReadString();
            }

            res.Namespaces = new AsNamespaceInfo[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.Namespaces.Length; i++)
            {
                res.Namespaces[i] = ReadNamespace();
            }

            res.NamespaceSets = new AsNamespaceSetInfo[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.NamespaceSets.Length; i++)
            {
                res.NamespaceSets[i] = ReadNamespaceSet();
            }

            res.Multinames = new AsMultinameInfo[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.Multinames.Length; i++)
            {
                res.Multinames[i] = ReadMultiname();
            }

            return(res);
        }
Esempio n. 3
0
        public void WriteConstantPool(AsConstantPoolInfo constantPool)
        {
            WriteU30((uint)(constantPool.Integers.Count <= 1 ? 0 : constantPool.Integers.Count));
            for (var i = 1; i < constantPool.Integers.Count; i++)
            {
                WriteS32(constantPool.Integers[i]);
            }

            WriteU30((uint)(constantPool.UnsignedIntegers.Count <= 1 ? 0 : constantPool.UnsignedIntegers.Count));
            for (var i = 1; i < constantPool.UnsignedIntegers.Count; i++)
            {
                WriteU32(constantPool.UnsignedIntegers[i]);
            }

            WriteU30((uint)(constantPool.Doubles.Count <= 1 ? 0 : constantPool.Doubles.Count));
            for (var i = 1; i < constantPool.Doubles.Count; i++)
            {
                WriteD64(constantPool.Doubles[i]);
            }

            WriteU30((uint)(constantPool.Strings.Count <= 1 ? 0 : constantPool.Strings.Count));
            for (var i = 1; i < constantPool.Strings.Count; i++)
            {
                WriteString(constantPool.Strings[i]);
            }

            WriteU30((uint)(constantPool.Namespaces.Count <= 1 ? 0 : constantPool.Namespaces.Count));
            for (var i = 1; i < constantPool.Namespaces.Count; i++)
            {
                WriteNamespace(constantPool.Namespaces[i]);
            }

            WriteU30((uint)(constantPool.NamespaceSets.Count <= 1 ? 0 : constantPool.NamespaceSets.Count));
            for (var i = 1; i < constantPool.NamespaceSets.Count; i++)
            {
                WriteNamespaceSet(constantPool.NamespaceSets[i]);
            }

            WriteU30((uint)(constantPool.Multinames.Count <= 1 ? 0 : constantPool.Multinames.Count));
            for (var i = 1; i < constantPool.Multinames.Count; i++)
            {
                WriteMultiname(constantPool.Multinames[i]);
            }
        }
Esempio n. 4
0
        public AsConstantPoolInfo ReadConstantPool()
        {
            var res = new AsConstantPoolInfo();

            res.Integers = new int[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.Integers.Length; i++) {
                res.Integers[i] = ReadS32();
            }

            res.UnsignedIntegers = new uint[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.UnsignedIntegers.Length; i++) {
                res.UnsignedIntegers[i] = ReadU32();
            }

            res.Doubles = new double[Math.Max(ReadU30(), 1)];
            res.Doubles[0] = double.NaN;
            for (var i = 1; i < res.Doubles.Length; i++) {
                res.Doubles[i] = ReadD64();
            }

            res.Strings = new string[Math.Max(ReadU30(), 1)];
            res.Strings[0] = string.Empty;
            for (var i = 1; i < res.Strings.Length; i++) {
                res.Strings[i] = ReadString();
            }

            res.Namespaces = new AsNamespaceInfo[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.Namespaces.Length; i++) {
                res.Namespaces[i] = ReadNamespace();
            }

            res.NamespaceSets = new AsNamespaceSetInfo[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.NamespaceSets.Length; i++) {
                res.NamespaceSets[i] = ReadNamespaceSet();
            }

            res.Multinames = new AsMultinameInfo[Math.Max(ReadU30(), 1)];
            for (var i = 1; i < res.Multinames.Length; i++) {
                res.Multinames[i] = ReadMultiname();
            }

            return res;
        }
Esempio n. 5
0
        public void ReadWriteConstantPoolTest()
        {
            var pool = new AsConstantPoolInfo {
                Doubles = new[] { double.NaN, 1.2, 5.3 },
                Integers = new[] { 0, -123, 456 },
                Multinames = new AsMultinameInfo[0],
                NamespaceSets = new AsNamespaceSetInfo[0],
                Namespaces = new AsNamespaceInfo[0],
                Strings = new[] { "", "abc", "def" },
                UnsignedIntegers = new uint[] { 0, 1, uint.MaxValue }
            };
            var mem = new MemoryStream();
            var writer = new AbcDataWriter(mem);
            writer.WriteConstantPool(pool);
            mem.Seek(0, SeekOrigin.Begin);
            var reader = new AbcDataReader(mem);
            var res = reader.ReadConstantPool();

            Assert.AreEqual(pool.Doubles.Length, res.Doubles.Length);
            for (var i = 0; i < pool.Doubles.Length; i++) {
                Assert.AreEqual(pool.Doubles[i], res.Doubles[i]);
            }

            Assert.AreEqual(pool.Integers.Length, res.Integers.Length);
            for (var i = 0; i < pool.Integers.Length; i++) {
                Assert.AreEqual(pool.Integers[i], res.Integers[i]);
            }

            //Assert.AreEqual(pool.Multinames.Length, res.Multinames.Length);
            //Assert.AreEqual(pool.NamespaceSets.Length, res.NamespaceSets.Length);
            //Assert.AreEqual(pool.Namespaces.Length, res.Namespaces.Length);

            Assert.AreEqual(pool.Strings.Length, res.Strings.Length);
            for (var i = 0; i < pool.Strings.Length; i++) {
                Assert.AreEqual(pool.Strings[i], res.Strings[i]);
            }

            Assert.AreEqual(pool.UnsignedIntegers.Length, res.UnsignedIntegers.Length);
            for (var i = 0; i < pool.UnsignedIntegers.Length; i++) {
                Assert.AreEqual(pool.UnsignedIntegers[i], res.UnsignedIntegers[i]);
            }
        }