public void VerifyBlockIndexes() { Console.WriteLine("Verifying blocks."); VolumeStream.Position = TocOffset + 0x12; ushort blockCount = VolumeStream.ReadUInt16(); BlockInfo block = GetBlock(0); BlockDebugInfo blockDebInfo = new BlockDebugInfo(); blockDebInfo.ReadFromBlockInfo(block); foreach (var entry in blockDebInfo.Entries) { var childIndexBlock = GetBlock(entry.BlockIndex); BlockDebugInfo childblockDebInfo = new BlockDebugInfo(); childblockDebInfo.ReadFromBlockInfo(childIndexBlock); for (int i = 0; i < childblockDebInfo.Entries.Count; i++) { BlockDebugEntryInfo cutoff = childblockDebInfo.Entries[i]; // Get the entries in the middle var prevEntryBlock = GetBlock(cutoff.BlockIndex); BlockDebugInfo prevEntryBlockDebInfo = new BlockDebugInfo(); prevEntryBlockDebInfo.ReadFromBlockInfo(prevEntryBlock); var nextEntryBlock = GetBlock(cutoff.BlockIndex + 1); BlockDebugInfo nextEntryBlockDebInfo = new BlockDebugInfo(); nextEntryBlockDebInfo.ReadFromBlockInfo(nextEntryBlock); var lastEntry = prevEntryBlockDebInfo.Entries[^ 1];
public void T01_Should_create() { // kiloWatt var power = Power.FromKiloWatt(123); var theSamePower = new Power(123, PowerUnits.KiloWatt); // Temperature var tempC = CelsiusTemperature.FromDegree(23); var tempK = KelvinTemperature.FromDegree(300); // length var meters = Length.FromMeter(10); var miliMeter = Length.FromMilimeters(45); // density kg/m³ var density = new Density(23, MassUnits.Kg, VolumeUnits.CubicMeter); // stream [m³/s] [m³/h] var stream1 = new VolumeStream(34, VolumeUnits.CubicMeter, TimeUnits.Second); var stream2 = new VolumeStream(34, VolumeUnits.CubicMeter, TimeUnits.Hour); // [J/kg*K] is supported // [kJ/kg*C] is not supported var specificHeatCapacityUnit = new SpecificHeatCapacityUnit( EnergyUnits.Joule, MassUnits.Kg, KelvinTemperatureUnits.Degree); var waterSpecificHeatCapacity = new SpecificHeatCapacity(4211, specificHeatCapacityUnit); var velocity1 = Velocity.FromMeterPerSecond(12); var velocity2 = new Velocity(2, LengthUnits.Feet, TimeUnits.Minute); var pressure = new Pressure(123, PressureUnits.KiloPascal); }
public void T06_should_mul_volumeStream_by_density() { // volumeStream(CubicInch,Second) * density(Pound,CubicInch) = massStream(Pound,Second) var left = new VolumeStream(15m, VolumeUnits.CubicInch, TimeUnits.Second); var right = new Density(30m, MassUnits.Pound, VolumeUnits.CubicInch); var expected = new MassStream(450m, MassUnits.Pound, TimeUnits.Second); var result = left * right; _testOutputHelper.WriteLine("Check if " + left + " * " + right + " = " + expected); Assert.Equal(expected.Value, result.Value, 12); Assert.Equal(expected.Unit.UnitName, result.Unit.UnitName); } // end of method
public void T04_should_div_massStream_by_volumeStream() { // massStream(Kg,Second) / volumeStream(CubicMeter,Second) = density(Kg,CubicMeter) var left = new MassStream(450m, MassUnits.Kg, TimeUnits.Second); var right = new VolumeStream(15m, VolumeUnits.CubicMeter, TimeUnits.Second); var expected = new Density(30m, MassUnits.Kg, VolumeUnits.CubicMeter); var result = left / right; _testOutputHelper.WriteLine("Check if " + left + " / " + right + " = " + expected); Assert.Equal(expected.Value, result.Value, 12); Assert.Equal(expected.Unit.UnitName, result.Unit.UnitName); } // end of method
public void T08_should_div_massStream_by_density() { // massStream(Kg,Second) / density(Pound,CubicInch) = volumeStream(CubicInch,Second) var left = new MassStream(500m, MassUnits.Kg, TimeUnits.Second); var right = new Density(25m, MassUnits.Pound, VolumeUnits.CubicInch); var expected = new VolumeStream(44.092452436975516144594760270m, VolumeUnits.CubicInch, TimeUnits.Second); var result = left / right; _testOutputHelper.WriteLine("Check if " + left + " / " + right + " = " + expected); Assert.Equal(expected.Value, result.Value, 12); Assert.Equal(expected.Unit.UnitName, result.Unit.UnitName); } // end of method
public void T07_should_div_massStream_by_density() { // massStream(Tone,Second) / density(Pound,CubicInch) = volumeStream(CubicInch,Second) var left = new MassStream(450m, MassUnits.Tone, TimeUnits.Second); var right = new Density(30m, MassUnits.Pound, VolumeUnits.CubicInch); var expected = new VolumeStream(33069.339327731637108446070202m, VolumeUnits.CubicInch, TimeUnits.Second); var result = left / right; _testOutputHelper.WriteLine("Check if " + left + " / " + right + " = " + expected); Assert.Equal(expected.Value, result.Value, 12); Assert.Equal(expected.Unit.UnitName, result.Unit.UnitName); } // end of method
public byte[] GetBlockBuffer(int index) { if (!IsEncryptedRoFSMagic()) { int beginOffset = GetEntryOffset(index); int endOffset = GetEntryOffset(index + 1); using var decompressStream = new MemoryStream(); using var decompressionStream = new DeflateStream(new MemoryStream(VolumeStream.ReadBytes(endOffset - beginOffset)), CompressionMode.Decompress); decompressionStream.CopyTo(decompressStream); return(decompressStream.ToArray()); } else { int beginOffset = GetEntryOffsetSecure(index); int endOffset = GetEntryOffsetSecure(index + 1); return(DecryptBlock(VolumeStream, TocOffset + beginOffset, endOffset - beginOffset)); } }
public void T09_Should_deserialize_VolumeStream(string expected, string jsonToDeserialize, string theVolumeUnits, string theTimeUnits) { var u1 = TestUtils.LoadUnit <VolumeUnit>(theVolumeUnits); var u2 = TestUtils.LoadUnit <TimeUnit>(theTimeUnits); // serialization var obj = new VolumeStream(45.87m, u1, u2); expected = "\"" + expected + "\""; var json = JsonConvert.SerializeObject(obj); _testOutputHelper.WriteLine("serialized to " + json); Assert.Equal(expected, json); // deserialization jsonToDeserialize = "\"" + jsonToDeserialize + "\""; _testOutputHelper.WriteLine("Try deserialize " + jsonToDeserialize); var deserialized = JsonConvert.DeserializeObject <VolumeStream>(jsonToDeserialize); Assert.Equal(obj.Value, deserialized.Value); Assert.Equal(obj.Unit, deserialized.Unit); }
// Non original public void DebugWriteEntryInfos() { VolumeStream.Position = TocOffset + 0x12; ushort blockCount = VolumeStream.ReadUInt16(); using var sw = new StreamWriter("block_info.txt"); for (int i = 0; i < blockCount; i++) { BlockInfo block = GetBlock(i); SpanReader sr = new SpanReader(block.BlockBuffer); short blockType = sr.ReadInt16(); short entryCount = sr.ReadInt16(); int realEntryCount = (entryCount / 2); sw.WriteLine($"Block #{i} {(blockType == 1 ? "[INDEXER]" : "")} - {entryCount} entries [{realEntryCount} actual]"); sr.Position = BlockSize - (realEntryCount * 0x08); if (blockType == 1) { sr.Position -= 4; sw.WriteLine($"Last Entry Index: {sr.ReadInt32()}"); } else { sr.Position -= 2; sw.WriteLine($"Offset: {sr.ReadInt16()}"); } for (int j = 0; j < realEntryCount; j++) { sr.Position = BlockSize - (j * 0x08) - 0x08; short entryOffset = sr.ReadInt16(); short entryLen = sr.ReadInt16(); if (blockType == 1) { int blockIndex = sr.ReadInt16(); sr.Position = entryOffset; sr.Endian = Syroot.BinaryData.Core.Endian.Big; int parentNode = sr.ReadInt32(); sr.Endian = Syroot.BinaryData.Core.Endian.Little; string str; if (entryLen >= 4) { str = sr.ReadStringRaw(entryLen - 4); } else { str = "string was null"; } sw.WriteLine($"{j} -> Offset: {entryOffset:X2} - Length: {entryLen} - Points to Block: {blockIndex} | ParentNode: {parentNode}, Name: {str}"); } else { short entryMetaTypeOffset = sr.ReadInt16(); short entryMetaTypeLen = sr.ReadInt16(); sr.Position = entryOffset; sr.Endian = Syroot.BinaryData.Core.Endian.Big; int parentNode = sr.ReadInt32(); sr.Endian = Syroot.BinaryData.Core.Endian.Little; string str = sr.ReadStringRaw(entryLen - 4); sw.WriteLine($"{j} -> Offset: {entryOffset:X2} - Length: {entryLen} - Data Offset: {entryMetaTypeOffset} - Data Len: {entryMetaTypeLen} | ParentNode: {parentNode}, Name: {str}"); } } sw.WriteLine(); } }
public bool IsEncryptedRoFSMagic() { VolumeStream.Position = TocOffset; return(VolumeStream.ReadInt32(ByteConverter.Big) == TocHeader.MagicValueEncrypted); }
public int GetEntryOffsetSecure(int blockIndex) { VolumeStream.Position = TocOffset + TocHeader.HeaderSize + (blockIndex * 4); return(VolumeStream.ReadInt32() ^ blockIndex * Volume.OffsetCryptKey + Volume.OffsetCryptKey); }
public int GetEntryOffset(int blockIndex) { VolumeStream.Position = TocOffset + TocHeader.HeaderSize + (blockIndex * 4); return(VolumeStream.ReadInt32()); }