Exemplo n.º 1
0
        private static void ProcessFile(string type, Node n, string dirToSave, string dataToInsert)
        {
            Identify i = new Identify();

            IFormat inputFormat = i.GetFormat(n);

            // Compressed file
            if (inputFormat.ToString() == FORMATPREFIX + "DSCP")
            {
                BinaryFormat binary = Utils.Lzss(new BinaryFormat(n.Stream), "-d");
                n           = new Node(n.Name, binary);
                inputFormat = i.GetFormat(n);
            }

            log.Info("IFormat detected: " + inputFormat.ToString());

            switch (type)
            {// inputFilename - dirtosave - (dir/file to insert)
            case "-e":
                Export(inputFormat.ToString(), n, dirToSave);
                break;

            case "-i":
                Import(inputFormat.ToString(), n, dirToSave, dataToInsert);
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Identifies the drive.
        /// </summary>
        protected void IdentifyDrive()
        {
            byte         drive = (byte)(((deviceHead & 0x10) != 0x10) ? 0 : 1);
            byte         d     = (byte)('0' + drive + 1);
            BinaryFormat data  = new BinaryFormat(bufferData);

            data.Fill(0, 0, 512);

            // fixed drive and over 5Mb/sec
            data.SetUShort(0x00, 0x140);
            // Serial Number
            data.Fill(0x0A * 2, d, 20);
            data.SetByte(0x0A * 2, d);
            // Firmware version
            data.Fill(0x17 * 2, d, 8);
            data.SetChar(0x17 * 2 + 0, '1');
            data.SetChar(0x17 * 2 + 1, '.');
            data.SetChar(0x17 * 2 + 2, '0');
            // Model Number
            data.Fill(0x1B * 2, d, 40);
            data.SetChar(0x17 * 2 + 0, 'D');
            data.SetChar(0x17 * 2 + 1, 'R');
            data.SetChar(0x17 * 2 + 2, 'I');
            data.SetChar(0x17 * 2 + 3, 'V');
            data.SetChar(0x17 * 2 + 4, 'E');
            data.SetByte(0x1B * 2 + 5, d);
            // lba28
            data.SetUInt(0x3C * 2, (uint)(driveFiles[drive].Length / 512));

            commandStatus = (byte)((commandStatus | 0x08) & ~0x80);             // Set DRQ (bit 3), clear BUSY (bit 7)

            status = DeviceStatus.IdentifyDrive;
        }
Exemplo n.º 3
0
        private static ClassMap GetConfiguration(Type type, BinaryFormat binaryFormat)
        {
            var conf = new CsvConfiguration(CultureInfo.CurrentCulture);

            var opt1 = conf.TypeConverterOptionsCache.GetOptions <DateTime>();

            opt1.DateTimeStyle = DateTimeStyles.AssumeUniversal;
            opt1.Formats       = new[] { "O" };

            var byteArrayOptions = GetOptions(binaryFormat);

            conf.TypeConverterCache.AddConverter(typeof(Guid), new GuidConverter(binaryFormat));
            conf.TypeConverterCache.AddConverter(typeof(byte[]), new ByteArrayConverter(byteArrayOptions));

            type.GetProperties()
            .Select(it => it.PropertyType)
            .ToList()
            .ForEach(prop =>
            {
                if (prop.IsNullable(out _) || prop.IsClass)
                {
                    conf.TypeConverterCache.AddConverter(prop, new NullConverter(prop, conf.TypeConverterCache));
                }

                if (prop.IsEnum || prop.IsNullableEnum())
                {
                    var opts     = conf.TypeConverterOptionsCache.GetOptions(prop);
                    opts.Formats = new[] { "D" };
                }
            });

            return(ClassAutoMapper.AutoMap(type, conf));
        }
Exemplo n.º 4
0
        public Po Convert(BinaryFormat source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            DataReader reader = new DataReader(source.Stream)
            {
                DefaultEncoding = Encoding.GetEncoding("utf-16"),
            };

            Po po = new Po {
                Header = new PoHeader(
                    "AttackFridayMonster Translation",
                    "*****@*****.**",
                    "es-ES"),
            };

            while (!source.Stream.EndOfStream)
            {
                uint id = reader.ReadUInt32();

                // Japanese version has 0x38 bytes of text and 0x74 of unknown
                string text = reader.ReadString(0x50).Replace("\0", string.Empty);
                source.Stream.Seek(0x6C, SeekMode.Current); // Unknown

                po.Add(new PoEntry(text)
                {
                    Context = "id:" + id
                });
            }

            return(po);
        }
Exemplo n.º 5
0
        public void BadCompressedFilesThrowsException()
        {
            byte[] data =
            {
                0x01, 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 decompressor = new Decompressor();

            Assert.Throws <ExtractionException>(() => decompressor.Convert(format));
        }
Exemplo n.º 6
0
        static void CompareText(BinaryFormat binary, string expected)
        {
            binary.Stream.Position = 0;
            TextReader reader = new TextReader(binary.Stream);

            Assert.AreEqual(expected, reader.ReadToEnd());
        }
Exemplo n.º 7
0
        public cfgSettings()
        {
            identifier        = _identifier;
            id_number         = 1;
            allows_multiple   = false;
            binary_struct     = new BinaryFormat();
            binary_struct.led = new sbyte[16];

            configs = new List <ConfigParameter>();

            configs.Add(new ConfigParameter("af_high_hz", 15, 1, 120));
            configs.Add(new ConfigParameter("af_high_duty_pc", 50, 0, 100));
            configs.Add(new ConfigParameter("af_low_hz", 5, 1, 120));
            configs.Add(new ConfigParameter("af_low_duty_pc", 50, 0, 100));
            configs.Add(new ConfigParameter("af_remember_state", 0, 0, 1));

            for (int i = 1; i <= 16; i++)
            {
                configs.Add(new ConfigParameter("led" + i.ToString(), 0, 0, 255));
            }

            configs.Add(new ConfigParameter("led_output_inversion_map", 0, 0, 65535));
            configs.Add(new ConfigParameter("led_display_mapping", 0, 0, 2));
            configs.Add(new ConfigParameter("led_display_timeout_ms", 0, 0, 65535));

            configs.Add(new ConfigParameter("meta_af_toggle", 0, 0, 1));
            configs.Add(new ConfigParameter("meta_af_select_with_stick", 0, 0, 1));
            configs.Add(new ConfigParameter("meta_mapping_select_with_stick", 0, 0, 1));

            configs.Add(new ConfigParameter("rotary_num_positions", 0, 0, 16));
            configs.Add(new ConfigParameter("rotary_enable_pov", 0, 0, 1));
            configs.Add(new ConfigParameter("rotary_enable_buttons", 0, 0, 1));
        }
        public override void ImportPo(string inputFile, bool save = true)
        {
            var dataStream = DataStreamFactory.FromFile(inputFile, FileOpenMode.Read);
            var binary     = new BinaryFormat(dataStream);
            var binary2Po  = new Yarhl.Media.Text.Po2Binary();
            var po         = binary2Po.Convert(binary);

            _text = GetText();
            var tmp = _text.Text.Replace(LineEnding.ShownLineEnding, LineEnding.PoLineEnding);

            if (string.IsNullOrEmpty(tmp))
            {
                tmp = "<!empty>";
            }
            var entry = po.FindEntry(tmp);

            if (!string.IsNullOrEmpty(entry.Translated))
            {
                _text.Translation = entry.Translated.Replace(LineEnding.PoLineEnding, LineEnding.ShownLineEnding);
            }

            if (save)
            {
                SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void CanReadFiles()
        {
            var reader = new DlcBinReader();

            byte[] data =
            {
                0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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(0x10, result.Root.Children[0].Stream.Length);
        }
Exemplo n.º 10
0
        public void ImportPO(string poFileName)
        {
            DataStream   inputPO    = new DataStream(poFileName, FileOpenMode.Read);
            BinaryFormat binaryFile = new BinaryFormat(inputPO);
            Po           newPO      = binaryFile.ConvertTo <Po>();

            variables.textoOriginal  = new string[newPO.Entries.Count];
            variables.textoTraducido = new string[newPO.Entries.Count];
            variables.contexto       = new string[newPO.Entries.Count];
            inputPO.Dispose();
            int contador = 0;

            listBox1.Items.Clear();
            Array.Clear(variables.textoOriginal, 0, variables.textoOriginal.Length);
            Array.Clear(variables.textoTraducido, 0, variables.textoTraducido.Length);
            Array.Clear(variables.contexto, 0, variables.contexto.Length);
            foreach (var entry in newPO.Entries)
            {
                listBox1.Items.Add(entry.Context);
                variables.textoOriginal[contador] = entry.Original;
                variables.contexto[contador]      = entry.Context;

                if (entry.Translated == "")
                {
                    variables.textoTraducido[contador] = "<!empty>";
                }
                variables.textoTraducido[contador] = entry.Translated;
                contador++;
            }
            listBox1.SelectedIndex = 0;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
            {
                return(false);
            }

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
            {
                return(false);
            }

            if (first == FileNameAttribute.Escape)
            {
                return(false);
            }

            uint startcluster = FatFileSystem.GetClusterEntry(data, offset, type);

            if (startcluster == cluster)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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"]);
        }
Exemplo n.º 14
0
        private void Test_storage_key(int keyLength)
        {
            var r = new Random();

            Span <byte> scriptHashSpan = stackalloc byte[HashHelpers.Hash160Size];

            r.NextBytes(scriptHashSpan);
            UInt160 scriptHash = new UInt160(scriptHashSpan);

            var keyBuffer = new byte[keyLength];

            r.NextBytes(keyBuffer);

            var key1 = new StorageKey(scriptHash, keyBuffer);

            key1.ScriptHash.Should().Be(scriptHash);
            key1.Key.Span.SequenceEqual(keyBuffer).Should().BeTrue();

            var writeBuffer = new byte[key1.GetSize()];

            key1.TryWrite(writeBuffer, out var bytesWritten).Should().BeTrue();
            bytesWritten.Should().Be(writeBuffer.Length);

            BinaryFormat.TryReadBytes(writeBuffer, out var key2).Should().BeTrue();
            key2.ScriptHash.Should().Be(scriptHash);
            key2.Key.Span.SequenceEqual(keyBuffer).Should().BeTrue();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
            {
                return(false);
            }

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
            {
                return(false);
            }

            if (first == FileNameAttribute.Escape)
            {
                return(false);
            }

            string entryname = FatFileSystem.ExtractFileName(data, offset);

            if (entryname == name)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 16
0
        protected JusFormat transform(BinaryFormat source, bool hasCount)
        {
            jus = DataFactory.createFormat(type);
            var reader = new DataReader(source.Stream)
            {
                DefaultEncoding = Encoding.GetEncoding("shift_jis")
            };

            JusData.reader         = reader;
            reader.Stream.Position = type == DataType.Commwin ? 0x04 : 0x00;

            if (hasCount)
            {
                int count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    jus.data.Add(DataFactory.readData(type));
                }
            }
            else
            {
                int textStart = reader.ReadInt32() - 1;
                reader.Stream.Position = 0x00;
                while (reader.Stream.Position < textStart)
                {
                    jus.data.Add(DataFactory.readData(type));
                }
            }

            return(jus);
        }
Exemplo n.º 17
0
        public static void TranslatePOwithAnotherPO(string BasePO, string TargetPo)
        {
            Po BPo = null, TPo = null;

            using (DataStream name = DataStreamFactory.FromFile(BasePO, FileOpenMode.Read))
                using (BinaryFormat binaryname = new BinaryFormat(name))
                {
                    BPo = (Po)ConvertFormat.With <Po2Binary>(binaryname);
                }

            using (DataStream name = DataStreamFactory.FromFile(TargetPo, FileOpenMode.Read))
                using (BinaryFormat binaryname = new BinaryFormat(name))
                {
                    TPo = (Po)ConvertFormat.With <Po2Binary>(binaryname);
                }

            foreach (PoEntry entryBPo in BPo.Entries)
            {
                foreach (PoEntry entryTPo in TPo.Entries)
                {
                    if (entryBPo.Original == entryTPo.Original && (entryBPo.Translated != null && entryBPo.Translated != ""))
                    {
                        entryTPo.Translated = entryBPo.Translated;

                        if (entryBPo.TranslatorComment != string.Empty && entryBPo.TranslatorComment != null && entryBPo.TranslatorComment.Trim() != "")
                        {
                            entryTPo.TranslatorComment = entryBPo.TranslatorComment;
                        }
                    }
                }
            }

            ConvertFormat.To <BinaryFormat>(TPo).Stream.WriteTo(TargetPo);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(Entry.DOSName + offset);

            if (first == FileNameAttribute.LastEntry)
            {
                return(false);
            }

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
            {
                return(false);
            }

            if (first == FileNameAttribute.Escape)
            {
                return(false);
            }

            FatFileAttributes attribute = (FatFileAttributes)entry.GetByte(Entry.FileAttributes + offset);

            if ((attribute & FatFileAttributes.VolumeLabel) == FatFileAttributes.VolumeLabel)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 19
0
        private static void Import(BinaryFormat input, string pngPath, string output, ColorFormat format)
        {
            MmTex texture;

            if (format == ColorFormat.Indexed_A5I3)
            {
                texture = input.ConvertWith <Binary2MmTex, BinaryFormat, MmTex>();
            }
            else
            {
                texture = input.ConvertWith <Binary2MmTexA3, BinaryFormat, MmTex>();
            }

            input.Dispose();

            // Import the new PNG file
            Bitmap newImage     = (Bitmap)Image.FromFile(pngPath);
            var    quantization = new FixedPaletteQuantization(texture.Palette.GetPalette(0));

            Texim.Media.Image.ImageConverter importer = new Texim.Media.Image.ImageConverter
            {
                Format        = format,
                PixelEncoding = PixelEncoding.Lineal,
                Quantization  = quantization
            };
            (Palette _, PixelArray pixelInfo) = importer.Convert(newImage);
            texture.Pixels = pixelInfo;

            // Save the texture
            texture.ConvertWith <Binary2MmTex, MmTex, BinaryFormat>()
            .Stream.WriteTo(output);
        }
Exemplo n.º 20
0
        public FatFileLocation FindEntry(ACompare compare, uint startCluster)
        {
            uint activeSector = ((startCluster - RootCluster) * SectorsPerCluster) + DataSector;

            if (startCluster == 0)
            {
                activeSector = (FatType == FatType.FAT32) ? GetSectorByCluster(RootCluster) : RootSector;
            }

            byte[] aData = new byte[512 * SectorsPerCluster];
            this.IDevice.Read(activeSector, SectorsPerCluster, aData);

            BinaryFormat directory = new BinaryFormat(aData);

            for (uint index = 0; index < EntriesPerSector * SectorsPerCluster; index++)
            {
                Console.WriteLine("Lawl: %d\n" + ((uint)(index * 32)).ToString());
                if (compare.Compare(directory.Data, index * 32, FatType))
                {
                    FatFileAttributes attribute = (FatFileAttributes)directory.GetByte((index * Entry.EntrySize) + Entry.FileAttributes);
                    return(new FatFileLocation(GetClusterEntry(directory.Data, index, FatType), activeSector, index, (attribute & FatFileAttributes.SubDirectory) != 0, directory.GetUInt((index * Entry.EntrySize) + Entry.FileSize)));
                }

                if (directory.GetByte(Entry.DOSName + (index * Entry.EntrySize)) == FileNameAttribute.LastEntry)
                {
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 21
0
        protected uint GetClusterEntryValue(uint cluster)
        {
            uint fatoffset = 0;


            fatoffset = cluster * 4;

            uint sector       = ReservedSector + (fatoffset / BytePerSector);
            uint sectorOffset = fatoffset % BytePerSector;
            uint nbrSectors   = 1;

            if ((FatType == FatType.FAT12) && (sectorOffset == BytePerSector - 1))
            {
                nbrSectors = 2;
            }

            var xdata = new byte[512 * nbrSectors];

            this.IDevice.Read(sector, nbrSectors, xdata);
            BinaryFormat fat = new BinaryFormat(xdata);

            uint clusterValue;

            clusterValue = fat.GetUInt(sectorOffset) & 0x0FFFFFFF;

            return(clusterValue);
        }
Exemplo n.º 22
0
        protected bool SetClusterEntryValue(uint cluster, uint nextcluster)
        {
            uint fatOffset = 0;

            fatOffset = cluster * 4;

            uint sector       = ReservedSector + (fatOffset / BytePerSector);
            uint sectorOffset = fatOffset % BytePerSector;
            uint nbrSectors   = 1;

            if ((FatType == FatType.FAT12) && (sectorOffset == BytePerSector - 1))
            {
                nbrSectors = 2;
            }

            var xData = new byte[512 * nbrSectors];

            this.IDevice.Read(sector, nbrSectors, xData);
            BinaryFormat fat = new BinaryFormat(xData);


            fat.SetUInt(sectorOffset, nextcluster);

            this.IDevice.Write(sector, nbrSectors, fat.Data);

            return(true);
        }
Exemplo n.º 23
0
        public override void MakeDirectory(string DirName)
        {
            //TODO: Same Entry Exist exception.
            FatFileLocation location = FindEntry(new FileSystem.Find.Empty(), FatCurrentDirectoryEntry);

            uint FirstCluster = AllocateFirstCluster();

            var xdata = new byte[512 * SectorsPerCluster];

            this.IDevice.Read(location.DirectorySector, SectorsPerCluster, xdata);
            BinaryFormat directory = new BinaryFormat(xdata);

            directory.SetString(Entry.DOSName + location.DirectorySectorIndex * 32, "            ", 11);
            directory.SetString(Entry.DOSName + location.DirectorySectorIndex * 32, DirName);

            directory.SetByte(Entry.FileAttributes + location.DirectorySectorIndex * 32, (byte)0x10);
            directory.SetByte(Entry.Reserved + location.DirectorySectorIndex * 32, 0);
            directory.SetByte(Entry.CreationTimeFine + location.DirectorySectorIndex * 32, 0);
            directory.SetUShort(Entry.CreationTime + location.DirectorySectorIndex * 32, 0);
            directory.SetUShort(Entry.CreationDate + location.DirectorySectorIndex * 32, 0);
            directory.SetUShort(Entry.LastAccessDate + location.DirectorySectorIndex * 32, 0);
            directory.SetUShort(Entry.LastModifiedTime + location.DirectorySectorIndex * 32, 0);
            directory.SetUShort(Entry.LastModifiedDate + location.DirectorySectorIndex * 32, 0);
            directory.SetUShort(Entry.FirstCluster + location.DirectorySectorIndex * 32, (ushort)FirstCluster);
            directory.SetUInt(Entry.FileSize + location.DirectorySectorIndex * 32, 0);
            this.IDevice.Write(location.DirectorySector, SectorsPerCluster, xdata);

            FatFileLocation loc = FindEntry(new FileSystem.Find.Empty(), FirstCluster);

            xdata = new byte[512 * SectorsPerCluster];
            this.IDevice.Read(loc.DirectorySector, SectorsPerCluster, xdata);
            directory = new BinaryFormat(xdata);
            for (int i = 0; i < 2; i++)
            {
                directory.SetString(Entry.DOSName + loc.DirectorySectorIndex * 32, "            ", 11);
                if (i == 0)
                {
                    directory.SetString(Entry.DOSName + loc.DirectorySectorIndex * 32, ".");
                    directory.SetUShort(Entry.FirstCluster + loc.DirectorySectorIndex * 32, (ushort)FirstCluster);
                }
                else
                {
                    directory.SetString(Entry.DOSName + loc.DirectorySectorIndex * 32, "..");
                    directory.SetUShort(Entry.FirstCluster + loc.DirectorySectorIndex * 32, (ushort)FatCurrentDirectoryEntry);
                }
                directory.SetByte(Entry.FileAttributes + loc.DirectorySectorIndex * 32, (byte)0x10);
                directory.SetByte(Entry.Reserved + loc.DirectorySectorIndex * 32, 0);
                directory.SetByte(Entry.CreationTimeFine + loc.DirectorySectorIndex * 32, 0);
                directory.SetUShort(Entry.CreationTime + loc.DirectorySectorIndex * 32, 0);
                directory.SetUShort(Entry.CreationDate + loc.DirectorySectorIndex * 32, 0);
                directory.SetUShort(Entry.LastAccessDate + loc.DirectorySectorIndex * 32, 0);
                directory.SetUShort(Entry.LastModifiedTime + loc.DirectorySectorIndex * 32, 0);
                directory.SetUShort(Entry.LastModifiedDate + loc.DirectorySectorIndex * 32, 0);
                directory.SetUInt(Entry.FileSize + loc.DirectorySectorIndex * 32, 0);
                loc.DirectorySectorIndex += 1;
            }

            this.IDevice.Write(loc.DirectorySector, SectorsPerCluster, xdata);
        }
Exemplo n.º 24
0
        public void GetStreamWhenBinaryFormatReturnsStream()
        {
            BinaryFormat format = new BinaryFormat();

            using Node node = new Node("myteset", format);
            Assert.AreEqual(format.Stream, node.Stream);
            node.Dispose();
        }
Exemplo n.º 25
0
        static Po ConvertStringToPo(string binary)
        {
            using BinaryFormat textFormat = new BinaryFormat();
            new TextWriter(textFormat.Stream).Write(binary);
            textFormat.Stream.Position = 0;

            return(ConvertFormat.To <Po>(textFormat));
        }
Exemplo n.º 26
0
 /// <summary> Get binary. Must have linked with wantbinary </summary>
 public byte[] GetBinary(out BinaryFormat binformat)
 {
     GL.GetProgram(Id, (GetProgramParameterName)0x8741, out int len);
     byte[] array = new byte[len];
     GL.GetProgramBinary(Id, len, out int binlen, out binformat, array);
     GLStatics.Check();
     return(array);
 }
        public Po Convert(BinaryFormat source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            source.Stream.Seek(0, SeekMode.Start);
            DataReader reader = new DataReader(source.Stream);
            Po         po     = new Po {
                Header = new PoHeader(
                    "Attack of the Friday Monsters Translatation",
                    "*****@*****.**",
                    "es-ES"),
            };

            uint numSections = reader.ReadUInt32();

            if (numSections < 3)
            {
                throw new FormatException($"Missing sections");
            }

            // We skip the first 3 sections with unknown content
            reader.ReadBytes(3 * 4);
            for (int s = 3; s < numSections; s++)
            {
                uint sectionOffset = reader.ReadUInt32();
                if (sectionOffset == 0)
                {
                    continue;
                }

                source.Stream.PushToPosition(sectionOffset, SeekMode.Start);
                ushort charId = reader.ReadUInt16();
                if (charId == 0x4D30)
                {
                    source.Stream.PopPosition();
                    continue;
                }

                if (!Characters.ContainsKey(charId))
                {
                    throw new FormatException("Unknown char: " + charId);
                }

                PoEntry entry = new PoEntry {
                    Original          = ReadTokenizedString(reader),
                    Context           = $"s:{s}",
                    ExtractedComments = Characters[charId],
                };

                po.Add(entry);
                source.Stream.PopPosition();
            }

            return(po);
        }
Exemplo n.º 28
0
        public static BinaryFormat Lzss(BinaryFormat bf, string mode)
        {
            string tempFile = Path.GetTempFileName();

            if (mode == "-d")
            {
                using (var substream = new DataStream(bf.Stream, 4, bf.Stream.Length - 4))
                {
                    substream.WriteTo(tempFile);
                }
            }
            else
            {
                using (var substream = new DataStream(bf.Stream, 0, bf.Stream.Length))
                {
                    substream.WriteTo(tempFile);
                }
            }



            string program = System.IO.Path.GetFullPath(@"..\..\") + @"\lib\NDS_Compressors_CUE\lzss.exe";

            string arguments = mode + " " + tempFile;

            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                program = System.IO.Path.GetFullPath(@"../../") + "/lib/NDS_Compressors_CUE/lzss";
            }

            Process process = new Process();

            process.StartInfo.FileName               = program;
            process.StartInfo.Arguments              = arguments;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.ErrorDialog            = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.Start();

            process.WaitForExit();

            DataStream fileStream   = DataStreamFactory.FromFile(tempFile, FileOpenMode.Read);
            DataStream memoryStream = new DataStream();

            if (mode != "-d")
            {
                memoryStream.Seek(0);
                memoryStream.Write(Encoding.ASCII.GetBytes("DSCP"), 0, 4);
            }

            fileStream.WriteTo(memoryStream);

            fileStream.Dispose();
            File.Delete(tempFile);

            return(new BinaryFormat(memoryStream));
        }
Exemplo n.º 29
0
        /// <summary>
        /// Reads the LBA48.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="drive">The drive.</param>
        /// <param name="lba">The lba.</param>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <returns></returns>
        protected bool ReadLBA48(SectorOperation operation, uint drive, uint lba, byte[] data, uint offset)
        {
            if (drive > MaximunDriveCount)
            {
                return(false);
            }

            FeaturePort.Write8(0);
            FeaturePort.Write8(0);

            SectorCountPort.Write8(0);
            SectorCountPort.Write8(1);

            LBALowPort.Write8((byte)((lba >> 24) & 0xFF));
            LBALowPort.Write8((byte)(lba & 0xFF));

            LBAMidPort.Write8((byte)((lba >> 32) & 0xFF));
            LBAMidPort.Write8((byte)((lba >> 8) & 0xFF));

            LBAHighPort.Write8((byte)((lba >> 40) & 0xFF));
            LBAHighPort.Write8((byte)((lba >> 16) & 0xFF));

            DeviceHeadPort.Write8((byte)(0x40 | (drive << 4)));

            if (operation == SectorOperation.Write)
            {
                CommandPort.Write8(0x34);
            }
            else
            {
                CommandPort.Write8(0x24);
            }

            if (!WaitForReqisterReady())
            {
                return(false);
            }

            BinaryFormat sector = new BinaryFormat(data);

            //TODO: Don't use PIO
            if (operation == SectorOperation.Read)
            {
                for (uint index = 0; index < 256; index++)
                {
                    sector.SetUShort(offset + (index * 2), DataPort.Read16());
                }
            }
            else
            {
                for (uint index = 0; index < 256; index++)
                {
                    DataPort.Write16(sector.GetUShort(offset + (index * 2)));
                }
            }

            return(true);
        }
        public void TracerBuilder_ValidArgs()
        {
            var builder = new TracerBuilder();

            bool processorFactoryCalled = false;
            bool collectorFactoryCalled = true;

            var sampler      = new ProbabilitySampler(0.1);
            var exporter     = new TestExporter(_ => { });
            var options      = new TracerConfiguration(1, 1, 1);
            var binaryFormat = new BinaryFormat();
            var textFormat   = new TraceContextFormat();

            builder
            .SetSampler(sampler)
            .AddProcessorPipeline(p => p
                                  .SetExporter(exporter)
                                  .SetExportingProcessor(e =>
            {
                processorFactoryCalled = true;
                Assert.Same(e, exporter);
                return(new SimpleSpanProcessor(e));
            }))
            .SetTracerOptions(options)
            .SetBinaryFormat(binaryFormat)
            .SetTextFormat(textFormat)
            .AddCollector(t =>
            {
                Assert.NotNull(t);
                return(new TestCollector(t));
            });

            Assert.Same(sampler, builder.Sampler);

            Assert.NotNull(builder.ProcessingPipelines);
            Assert.Single(builder.ProcessingPipelines);
            Assert.Same(exporter, builder.ProcessingPipelines[0].Exporter);

            Assert.NotNull(builder.ProcessingPipelines[0].Build());
            Assert.True(processorFactoryCalled);

            Assert.Same(options, builder.TracerConfigurationOptions);
            Assert.Same(binaryFormat, builder.BinaryFormat);
            Assert.Same(textFormat, builder.TextFormat);
            Assert.Single(builder.CollectorFactories);

            var collectorFactory = builder.CollectorFactories.Single();

            Assert.Equal(nameof(TestCollector), collectorFactory.Name);
            Assert.Equal("semver:" + typeof(TestCollector).Assembly.GetName().Version, collectorFactory.Version);

            Assert.NotNull(collectorFactory.Factory);
            collectorFactory.Factory(new Tracer(new SimpleSpanProcessor(exporter), new AlwaysSampleSampler(), options, binaryFormat, textFormat,
                                                Resource.Empty));

            Assert.True(collectorFactoryCalled);
        }
Exemplo n.º 31
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public static FormatSerializer GetBinarySerializer(BinaryFormat format)
 {
     switch (format)
     {
         case BinaryFormat.Tlv:
             return new TlvSerializer();
         default:
             throw new Exception(format + " format not supported");
     }
 }