예제 #1
0
        public void CanSetFileNames()
        {
            var reader     = new StandardBinReader();
            var parameters = new ReaderParameters
            {
                Endianness = EndiannessMode.LittleEndian,
                FileNames  = new[] { "test/file1" },
            };

            reader.Initialize(parameters);

            byte[] data =
            {
                0xF9, 0x7D, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0xBA, 0xAD, 0xF0, 0x0D, 0xBA, 0xAD, 0xF0, 0x0D, 0xBA, 0xAD, 0xF0, 0x0D, 0xBA, 0xAD, 0xF0, 0x0D,
            };
            using DataStream stream = DataStreamFactory.FromArray(data, 0, data.Length);
            var format = new BinaryFormat(stream);

            var result = reader.Convert(format);

            Assert.AreEqual(1, result.Root.Children.Count);
            Assert.AreEqual("test", result.Root.Children[0].Name);
            Assert.AreEqual(1, result.Root.Children[0].Children.Count);
            Assert.AreEqual(FileType.Normal, result.Root.Children[0].Children[0].Tags["Type"]);
            Assert.AreEqual("file1", result.Root.Children[0].Children[0].Name);
        }
예제 #2
0
        public void CanReadDummyFiles()
        {
            var reader     = new StandardBinReader();
            var parameters = new ReaderParameters
            {
                Endianness = EndiannessMode.BigEndian,
                FileNames  = Array.Empty <string>(),
            };

            reader.Initialize(parameters);

            byte[] data =
            {
                0x00, 0x07, 0x7D, 0xF9, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x70, 0x83, 0x5F, 0x83, 0x7E,
                0x83, 0x5F, 0x83, 0x7E, 0x81, 0x5B, 0x82, 0xC5, 0x82, 0xB7, 0x2E, 0x0D, 0x0A, 0x90, 0xB3, 0x8E,
                0xAE, 0x82, 0xC8, 0x83, 0x66, 0x81, 0x5B, 0x83, 0x5E, 0x82, 0xAA, 0x93, 0xFC, 0x82, 0xE9, 0x82,
                0xDC, 0x82, 0xC5, 0x81, 0x41, 0x82, 0xD0, 0x82, 0xC6, 0x82, 0xDC, 0x82, 0xB8, 0x83, 0x8A, 0x83,
                0x93, 0x83, 0x4E, 0x83, 0x66, 0x81, 0x5B, 0x83, 0x5E, 0x82, 0xF0, 0x8D, 0xEC, 0x90, 0xAC, 0x82,
                0xB7, 0x82, 0xE9, 0x82, 0xBD, 0x82, 0xDF, 0x82, 0xCC, 0x83, 0x5F, 0x83, 0x7E, 0x81, 0x5B, 0x83,
                0x74, 0x83, 0x40, 0x83, 0x43, 0x83, 0x8B, 0x82, 0xC6, 0x82, 0xB5, 0x82, 0xC4, 0x8D, 0xEC, 0x90,
                0xAC, 0x82, 0xB3, 0x82, 0xEA, 0x82, 0xC4, 0x82, 0xA2, 0x82, 0xDC, 0x82, 0xB7, 0x2E, 0x0D, 0x0A,
            };
            using DataStream stream = DataStreamFactory.FromArray(data, 0, data.Length);
            var format = new BinaryFormat(stream);

            var result = reader.Convert(format);

            Assert.AreEqual(1, result.Root.Children.Count);
            Assert.AreEqual(FileType.Dummy, result.Root.Children[0].Tags["Type"]);
        }
예제 #3
0
        public void BadMagicThrowsException()
        {
            var reader = new StandardBinReader();

            byte[] data = { 0xF9, 0x7D, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            using DataStream stream = DataStreamFactory.FromArray(data, 0, data.Length);
            var format = new BinaryFormat(stream);

            Assert.Throws <FormatException>(() => reader.Convert(format));
        }
예제 #4
0
        public void CanReadEmptyFiles()
        {
            var reader = new StandardBinReader();

            byte[] data =
            {
                0xF9, 0x7D, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            };
            using DataStream stream = DataStreamFactory.FromArray(data, 0, data.Length);
            var format = new BinaryFormat(stream);
            var result = reader.Convert(format);

            Assert.AreEqual(1, result.Root.Children.Count);
            Assert.AreEqual(FileType.Empty, result.Root.Children[0].Tags["Type"]);
        }
예제 #5
0
        public void CanReadCompressedFilesChangingEndianness()
        {
            var reader     = new StandardBinReader();
            var parameters = new ReaderParameters
            {
                Endianness = EndiannessMode.BigEndian,
                FileNames  = Array.Empty <string>(),
            };

            reader.Initialize(parameters);

            // BIN is Big Endian but has a file in Little Endian
            using DataStream stream = DataStreamFactory.FromFile("MultiEndianTests.bin", FileOpenMode.Read);
            var format = new BinaryFormat(stream);

            var result = reader.Convert(format);

            Assert.AreEqual(2, result.Root.Children.Count);
            Assert.AreEqual(FileType.Normal, result.Root.Children[0].Tags["Type"]);
            Assert.AreEqual(FileType.CompressedAlternateEndian, result.Root.Children[1].Tags["Type"]);
        }
예제 #6
0
        public void CanReadCompressedFiles()
        {
            var reader = new StandardBinReader();

            byte[] data =
            {
                0xF9, 0x7D, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
                0x00, 0x02, 0x00, 0x00, 0x31, 0x01, 0x00, 0x00, 0x78, 0xDA, 0x4D, 0x91, 0xCB, 0x6D, 0xC4, 0x30,
                0x0C, 0x44, 0x5B, 0x99, 0x02, 0x8C, 0xED, 0x21, 0xF7, 0x24, 0xC8, 0x25, 0x05, 0xD0, 0x32, 0xE3,
                0x25, 0x40, 0x49, 0x0E, 0x3F, 0x8B, 0x94, 0x1F, 0x7A, 0xF3, 0xBD, 0x48, 0x10, 0x35, 0x22, 0xE7,
                0x8D, 0x1E, 0xA7, 0x71, 0x87, 0x1C, 0x9E, 0x1D, 0xDB, 0xD4, 0x69, 0x70, 0x09, 0x50, 0xE7, 0x58,
                0xD0, 0xE6, 0x70, 0x6E, 0xC1, 0x91, 0x06, 0xDA, 0xE4, 0x10, 0x6F, 0x32, 0x76, 0xB0, 0x4A, 0x5C,
                0xF0, 0x34, 0x6D, 0x15, 0x1C, 0x57, 0x32, 0x0E, 0x23, 0x64, 0xE0, 0x76, 0x5E, 0x80, 0x77, 0x0E,
                0x1C, 0xD3, 0x82, 0x2E, 0x78, 0x0D, 0xA4, 0x2A, 0xF5, 0x36, 0xED, 0x60, 0x5B, 0x30, 0x64, 0xBD,
                0x82, 0x20, 0xBD, 0x4E, 0x9B, 0x94, 0x4E, 0xA8, 0xA5, 0x8A, 0x2F, 0xE8, 0xB4, 0x0F, 0x82, 0x89,
                0xA7, 0xA3, 0xA5, 0x9D, 0xDB, 0xE0, 0xF7, 0xE4, 0x05, 0xA5, 0x72, 0xDA, 0x25, 0x42, 0xBC, 0x54,
                0xEE, 0x54, 0xC7, 0x43, 0x78, 0x80, 0x5A, 0xF5, 0x73, 0xF9, 0x71, 0xF2, 0x63, 0x1B, 0xEC, 0x7F,
                0x2F, 0x96, 0x2F, 0x27, 0x88, 0x5A, 0x4F, 0x34, 0xDE, 0x16, 0xF8, 0x54, 0x95, 0x26, 0x91, 0x9B,
                0x0C, 0xBC, 0x95, 0x67, 0xBF, 0xE0, 0x99, 0x7A, 0xD9, 0xF7, 0x90, 0x35, 0xB5, 0x82, 0x50, 0xD9,
                0x53, 0x09, 0x54, 0x8D, 0xF8, 0xF4, 0x8A, 0x9B, 0xDC, 0xD8, 0xAC, 0x88, 0x5E, 0xAE, 0xE4, 0xAC,
                0x7A, 0xB7, 0xD7, 0xA0, 0x54, 0xE9, 0x9D, 0xB8, 0x69, 0x59, 0x5D, 0x9E, 0x88, 0x1B, 0x0F, 0xF2,
                0x33, 0x89, 0xAF, 0x1A, 0x64, 0x44, 0xA1, 0x66, 0x5F, 0xB0, 0x2A, 0x8D, 0xAD, 0x3C, 0xAA, 0xAC,
                0x6C, 0xB3, 0x2E, 0x16, 0xEC, 0x46, 0x37, 0xD9, 0x6A, 0x4E, 0xEE, 0xC9, 0xD5, 0xDB, 0x66, 0x39,
                0x62, 0xE5, 0xCE, 0x23, 0xCE, 0xEF, 0x48, 0x81, 0x6C, 0xDF, 0xD1, 0x44, 0x65, 0x13, 0x52, 0x89,
                0xFC, 0xB2, 0x9D, 0xF3, 0xD2, 0xEE, 0xA9, 0x7C, 0x48, 0xAF, 0x59, 0xFF, 0x24, 0x5C, 0x03, 0x2B,
                0x9F, 0x43, 0xA9, 0xB1, 0x15, 0x86, 0xF2, 0x44, 0x14, 0x4A, 0xA9, 0x0A, 0xE2, 0x41, 0x4B, 0x55,
                0xC4, 0x55, 0xBD, 0x7C, 0x02, 0x79, 0xB7, 0xBB, 0xBF, 0x00, 0x00, 0x00, 0x00,
            };
            using DataStream stream = DataStreamFactory.FromArray(data, 0, data.Length);
            var format = new BinaryFormat(stream);

            var result = reader.Convert(format);

            Assert.AreEqual(1, result.Root.Children.Count);
            Assert.AreEqual(FileType.Compressed, result.Root.Children[0].Tags["Type"]);
        }
예제 #7
0
        public void NullSourceThrowsException()
        {
            var reader = new StandardBinReader();

            Assert.Throws <ArgumentNullException>(() => reader.Convert(null));
        }