public void RomMetadataCredits_ContainsEvilBytes_ProducesExpectedUnicodeString() { using (var metadataCreditsStream = new System.IO.MemoryStream()) { var bytes = new byte[255]; metadataCreditsStream.WriteByte(1); // Programmer credit for (var i = 1; i <= 255; ++i) { metadataCreditsStream.WriteByte((byte)i); bytes[i - 1] = (byte)i; } metadataCreditsStream.Seek(0, System.IO.SeekOrigin.Begin); using (var reader = new INTV.Core.Utility.BinaryReader(metadataCreditsStream)) { var streamLength = metadataCreditsStream.Length; var credits = new RomMetadataCredits((uint)streamLength); var bytesDecoded = credits.Deserialize(reader); // The first byte is 0x01 -- which is stuffed in credits parsing, so "stuff" it here. var expectedString = System.Text.Encoding.UTF8.GetString(bytes, 1, 254); Assert.Equal(streamLength, bytesDecoded); Assert.Equal(expectedString, credits.Programming.First()); } } }
/// <inheritdoc/> protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader) { var bytesParsed = 0u; var descriptionBuffer = new List <byte>(); var currentController = Controller.None; while (bytesParsed < Length) { var value = reader.ReadByte(); ++bytesParsed; var input = (InputSource)value; var controller = GetController(input); if (controller == Controller.None) { descriptionBuffer.Add(value); } else { // Finished previous. AddControllerToBindings(currentController, descriptionBuffer); currentController = controller; descriptionBuffer.Clear(); } } AddControllerToBindings(currentController, descriptionBuffer); return(Length); }
/// <inheritdoc/> protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader) { var publisherId = (PublisherId)reader.ReadByte(); Publisher = PublisherIdToString(publisherId, (int)Length, reader); return(Length); }
/// <inheritdoc/> protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader) { var parsedDateMetadata = reader.ParseDateTimeFromMetadata(Length); Date = parsedDateMetadata; return(Length); }
/// <summary> /// Creates a new instance of a RomMetadataBlock by inflating it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a RomMetadataBlock.</returns> /// <remarks>It is assumed that the reader is currently positioned at the beginning of a serialized ROM metadata block.</remarks> public static RomMetadataBlock Inflate(INTV.Core.Utility.BinaryReader reader) { RomMetadataBlock metadataBlock = null; int additionalBytesInPayloadLength; var payloadLength = DecodeLength(reader, out additionalBytesInPayloadLength); var metadataBlockType = (RomMetadataIdTag)reader.ReadByte(); switch (metadataBlockType) { case RomMetadataIdTag.Title: case RomMetadataIdTag.ShortTitle: case RomMetadataIdTag.License: case RomMetadataIdTag.Description: case RomMetadataIdTag.Version: case RomMetadataIdTag.UrlContactInfo: metadataBlock = new RomMetadataString(payloadLength, metadataBlockType); break; case RomMetadataIdTag.ReleaseDate: case RomMetadataIdTag.BuildDate: metadataBlock = new RomMetadataDate(payloadLength, metadataBlockType); break; case RomMetadataIdTag.Features: metadataBlock = new RomMetadataFeatures(payloadLength); break; case RomMetadataIdTag.Publisher: metadataBlock = new RomMetadataPublisher(payloadLength); break; case RomMetadataIdTag.Credits: metadataBlock = new RomMetadataCredits(payloadLength); break; case RomMetadataIdTag.ControllerBindings: metadataBlock = new RomMetadataControllerBindings(payloadLength); break; default: metadataBlock = new RomMetadataBlock(payloadLength, metadataBlockType); break; } metadataBlock._deserializeByteCount = (int)payloadLength + additionalBytesInPayloadLength + 1 + CrcByteCount + sizeof(RomMetadataIdTag); metadataBlock.Deserialize(reader); // Re-reading the block is more expensive than having a running CRC16 but it's easier to implement. :P var numBytesInForCrc = metadataBlock._deserializeByteCount - CrcByteCount; reader.BaseStream.Seek(-numBytesInForCrc, System.IO.SeekOrigin.Current); var payload = reader.ReadBytes(numBytesInForCrc); metadataBlock.Crc = (ushort)(((int)reader.ReadByte() << 8) | reader.ReadByte()); metadataBlock.ValidatePayloadCrc(payload); return(metadataBlock); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { for (int i = 0; i < FileSystemConstants.MaxItemCount; ++i) { _presentationOrder[i] = reader.ReadUInt16(); } Validate(); return(DeserializeByteCount); }
private static void VerifyLuigiZipEntry(Stream stream) { var magicKey = new byte[3] { (byte)'L', (byte)'T', (byte)'O' }; var reader = new INTV.Core.Utility.BinaryReader(stream); byte[] header = reader.ReadBytes(magicKey.Length); Assert.True(header.SequenceEqual(magicKey)); }
/// <summary> /// Creates a new instance of a RomMetadataBlock by inflating it from a Stream. /// </summary> /// <param name="stream">The stream containing the data to deserialize to create the object.</param> /// <returns>A new instance of a RomMetadataBlock.</returns> public static RomMetadataBlock Inflate(System.IO.Stream stream) { RomMetadataBlock metadataBlock = null; using (var reader = new INTV.Core.Utility.BinaryReader(stream)) { metadataBlock = Inflate(reader); } return(metadataBlock); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { ErrorIndex = reader.ReadUInt16(); for (int i = 0; i < BufferSize; ++i) { _errorBuffer[i] = reader.ReadUInt16(); } DecodeRawResults(); return(DeserializeByteCount); }
public void GZipMemberEntry_InflateUsingBinaryReader_ReturnsValidEntry() { var binGZip = TestResource.TagalongBinGZip; using (var reader = new INTV.Core.Utility.BinaryReader(binGZip.OpenResourceForReading())) { var entry = GZipMemberEntry.Inflate(reader); VerifyGZipMemberEntry(entry, binGZip.ArchiveContents.First(), 0, expectedLength: null); } }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { VirtualBlocksAvailable = reader.ReadUInt16(); VirtualBlocksTotal = reader.ReadUInt16(); PhysicalSectorsClean = reader.ReadUInt16(); PhysicalBlocksTotal = reader.ReadUInt16(); PhysicalSectorErasures = reader.ReadUInt32(); MetadataSectorErasures = reader.ReadUInt32(); VirtualToPhysicalMapVersion = reader.ReadUInt32(); ReservedData = reader.ReadBytes(ReservedSize); return(DeserializeByteCount); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { StartingVirtualBlock = reader.ReadUInt16(); byte[] rawuInt = new byte[4]; reader.ReadBytes(3).CopyTo(rawuInt, 0); Size = System.BitConverter.ToUInt32(rawuInt, 0); reader.ReadBytes(3).CopyTo(rawuInt, 0); Crc24 = System.BitConverter.ToUInt32(rawuInt, 0); // NOTE: The actual data in the fork, when downloading a GKT, is not included. // The CopyForkToRam command is used to upload the fork's data to RAM. // The DownloadDataBlockFromRam command will bring the data to the host PC. return(DeserializeByteCount); }
/// <inheritdoc/> protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader) { var allowLineBreaks = false; switch (Type) { case RomMetadataIdTag.Description: case RomMetadataIdTag.License: allowLineBreaks = true; break; default: break; } StringValue = reader.ParseStringFromMetadata(Length, allowLineBreaks); return(Length); }
/// <inheritdoc/> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { var asciiReader = (INTV.Shared.Utility.ASCIIBinaryReader)reader; var bytesRead = Directories.Deserialize(asciiReader); bytesRead += Files.Deserialize(asciiReader); bytesRead += Forks.Deserialize(asciiReader); #if FORCE_JLPFLASH_FORKS foreach (var file in Files.Where(f => (f != null))) { var fakeDataFork = new Fork(); fakeDataFork.Size = 0x0600; fakeDataFork.Crc24 = INTV.Core.Utility.RandomUtilities.Next24(); Forks.Add(fakeDataFork); file.JlpFlash = fakeDataFork; } #endif // FORCE_JLPFLASH_FORKS return(bytesRead); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { FileType = (FileType)reader.ReadByte(); Color = (INTV.Core.Model.Stic.Color)reader.ReadByte(); var nameBuffer = reader.ReadBytes(FileSystemConstants.MaxShortNameLength); var nameLength = System.Array.IndexOf(nameBuffer, (byte)0); if (nameLength < 0) { nameLength = FileSystemConstants.MaxShortNameLength; } if (nameLength > 0) { ShortName = System.Text.Encoding.ASCII.GetString(nameBuffer, 0, nameLength); } nameBuffer = reader.ReadBytes(FileSystemConstants.MaxLongNameLength); nameLength = System.Array.IndexOf(nameBuffer, (byte)0); if (nameLength < 0) { nameLength = FileSystemConstants.MaxLongNameLength; } if (nameLength > 0) { LongName = System.Text.Encoding.ASCII.GetString(nameBuffer, 0, nameLength); } GlobalDirectoryNumber = reader.ReadByte(); Reserved = reader.ReadByte(); for (int i = (int)ForkKind.FirstKind; i < (int)ForkKind.NumberOfForkKinds; ++i) { _forks[i] = reader.ReadUInt16(); } return(DeserializeByteCount); }
private static string PublisherIdToString(PublisherId publisherId, int payloadLength, INTV.Core.Utility.BinaryReader reader) { var publisher = string.Empty; var shouldReadMore = false; switch (publisherId) { case PublisherId.MattelElectronics: publisher = "Mattel Electronics"; break; case PublisherId.INTVCorp: publisher = "INTV Corporation"; break; case PublisherId.Imagic: publisher = "Imagic"; break; case PublisherId.Activision: publisher = "Activision"; break; case PublisherId.Atarisoft: publisher = "Atarisoft"; break; case PublisherId.Coleco: publisher = "Coleco"; break; case PublisherId.CBS: publisher = "CBS"; break; case PublisherId.ParkerBros: publisher = "Parker Brothers"; break; case PublisherId.Other: default: shouldReadMore = true; break; } var remainingPayload = payloadLength - sizeof(PublisherId); if (remainingPayload > 0) { var publisherData = reader.ParseStringFromMetadata((uint)remainingPayload, allowLineBreaks: false); if (shouldReadMore) { publisher = publisherData; } } return(publisher); }
/// <summary> /// Creates a new instance of a CfgVarMetadataBlock by inflating it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a CfgVarMetadataBlock.</returns> /// <remarks>It is assumed that the reader is currently positioned at the beginning of a serialized CFGVAR metadata entry.</remarks> public static CfgVarMetadataBlock Inflate(INTV.Core.Utility.BinaryReader reader) { CfgVarMetadataBlock metadataBlock = null; var metadataBlockType = DecodeBlockType(reader); switch (metadataBlockType) { case CfgVarMetadataIdTag.Name: case CfgVarMetadataIdTag.ShortName: case CfgVarMetadataIdTag.Author: case CfgVarMetadataIdTag.GameArt: case CfgVarMetadataIdTag.Music: case CfgVarMetadataIdTag.SoundEffects: case CfgVarMetadataIdTag.VoiceActing: case CfgVarMetadataIdTag.Description: case CfgVarMetadataIdTag.Documentation: case CfgVarMetadataIdTag.BoxOrOtherArtwork: case CfgVarMetadataIdTag.ConceptDesign: case CfgVarMetadataIdTag.MoreInfo: case CfgVarMetadataIdTag.Publisher: case CfgVarMetadataIdTag.License: case CfgVarMetadataIdTag.Version: metadataBlock = new CfgVarMetadataString(metadataBlockType); break; case CfgVarMetadataIdTag.ReleaseDate: case CfgVarMetadataIdTag.Year: case CfgVarMetadataIdTag.BuildDate: metadataBlock = new CfgVarMetadataDate(metadataBlockType); break; case CfgVarMetadataIdTag.EcsCompatibility: case CfgVarMetadataIdTag.IntellivoiceCompatibility: case CfgVarMetadataIdTag.IntellivisionIICompatibility: case CfgVarMetadataIdTag.KeyboardComponentCompatibility: case CfgVarMetadataIdTag.TutorvisionCompatibility: case CfgVarMetadataIdTag.Ecs: case CfgVarMetadataIdTag.Voice: case CfgVarMetadataIdTag.IntellivisionII: case CfgVarMetadataIdTag.JlpAccelerators: case CfgVarMetadataIdTag.Jlp: metadataBlock = new CfgVarMetadataFeatureCompatibility(metadataBlockType); break; case CfgVarMetadataIdTag.LtoFlashMapper: metadataBlock = new CfgVarMetadataBoolean(metadataBlockType); break; case CfgVarMetadataIdTag.JlpFlash: metadataBlock = new CfgVarMetadataInteger(metadataBlockType); break; default: break; } if (metadataBlock != null) { metadataBlock._deserializeByteCount = (int)reader.BaseStream.Length; metadataBlock.Deserialize(reader); } return(metadataBlock); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { throw new NotImplementedException(); }
/// <summary> /// Creates a new instance of a FileSystemFile by inflating it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a temporary FileSystemFile.</returns> public static FileSystemFile Inflate(INTV.Core.Utility.BinaryReader reader) { return(Inflate <FileSystemFile>(reader)); }
/// <summary> /// Creates a new instance of a PresentationOrder by inflating it from a Stream. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a PresentationOrder.</returns> public static PresentationOrder Inflate(INTV.Core.Utility.BinaryReader reader) { return(Inflate <PresentationOrder>(reader)); }
/// <summary> /// Creates a new instance of a LfsFileInfo by inflating it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a LfsFileInfo.</returns> public static LfsFileInfo Inflate(INTV.Core.Utility.BinaryReader reader) { return(Inflate <LfsFileInfo>(reader)); }
/// <summary> /// Creates a new instance of a Fork by inflating it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a Fork.</returns> public static Fork Inflate(INTV.Core.Utility.BinaryReader reader) { return(Inflate <Fork>(reader)); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { _crashBuffer = reader.ReadBytes(DeserializeByteCount); return(DeserializeByteCount); }
/// <inheritdoc/> protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader) { var remainingPayload = Length; if (remainingPayload < 3) { System.Diagnostics.Debug.WriteLine("Too few bytes in feature metadata!"); } if (remainingPayload > 0) { // The first byte contains compatibility: // . 7 6 5 4 3 2 1 0 // +---+---+---+---+---+---+---+---+ // | ECS | rsvd | VOICE | KEYBD | byte 0 // +---+---+---+---+---+---+---+---+ Features = ProgramFeatures.DefaultFeatures.Clone(); var featureBits = reader.ReadByte(); --remainingPayload; // Bits 0,1 are Keyboard Component compatibility. var compatibility = RawFeatureToFeatureCompatibility(featureBits & FeatureMask); Features.KeyboardComponent = (KeyboardComponentFeatures)compatibility; // Bits 2,3 are Intellivoice compatibility. compatibility = RawFeatureToFeatureCompatibility((featureBits >> 2) & FeatureMask); Features.Intellivoice = compatibility; // Bits 4,5 are reserved (used to be 4-controller capability) (ignored) ////compatibility = RawFeatureToFeatureCompatibility((featureBits >> 4) & FeatureMask); // Bits 6,7 are ECS compatibility. compatibility = RawFeatureToFeatureCompatibility((featureBits >> 6) & FeatureMask); Features.Ecs = (EcsFeatures)compatibility; } if (remainingPayload > 0) { // The second byte contains more compatibility: // . 7 6 5 4 3 2 1 0 // +---+---+---+---+---+---+---+---+ // | rsvd | rsvd | TUTOR | INTY2 | byte 1 // +---+---+---+---+---+---+---+---+ var featureBits = reader.ReadByte(); --remainingPayload; // Bits 0,1 are Intellivision II compatibility. var compatibility = RawFeatureToFeatureCompatibility(featureBits & FeatureMask); Features.IntellivisionII = compatibility; // Bits 2,3 are TutorVision compatibility. compatibility = RawFeatureToFeatureCompatibility((featureBits >> 2) & FeatureMask); Features.Tutorvision = compatibility; } if (remainingPayload > 0) { // The third byte contains emulator-specific guidance. // . 7 6 5 4 3 2 1 0 // +----+----+----+----+----+----+----+----+ // |rsvd|rsvd|rsvd|rsvd|rsvd|rsvd|rsvd|rsvd| byte 2 // +----+----+----+----+----+----+----+----+ // We're going to ignore this byte. reader.ReadByte(); --remainingPayload; } if (remainingPayload > 1) { // These two bytes contain JLP compatibility. // . 7 6 5 4 3 2 1 0 // +----+----+----+----+----+----+----+----+ // |JLP Accel|LTOM| Reserved |JLPf 9..8| byte 3 // +----+----+----+----+----+----+----+----+ var featureBits = reader.ReadByte(); --remainingPayload; var compatibility = (FeatureCompatibility)((featureBits >> 6) & FeatureMask); Features.Jlp = (JlpFeatures)compatibility; if (((1 << 5) & featureBits) != 0) { Features.LtoFlash |= LtoFlashFeatures.LtoFlashMemoryMapped; } var flashSectors = (ushort)((featureBits & FeatureMask) << 8); // . 7 6 5 4 3 2 1 0 // +----+----+----+----+----+----+----+----+ // | JLP Flash bits 7..0 | byte 4 // +----+----+----+----+----+----+----+----+ flashSectors |= reader.ReadByte(); --remainingPayload; Features.JlpFlashMinimumSaveSectors = flashSectors; if (Features.Jlp != JlpFeatures.Incompatible) { Features.JlpHardwareVersion = JlpHardwareVersion.Jlp03; // Assume minimal hardware version needed } } if (remainingPayload > 0) { reader.BaseStream.Seek(remainingPayload, System.IO.SeekOrigin.Current); } return(Length); }
/// <inheritdoc /> public override int Deserialize(INTV.Core.Utility.BinaryReader reader) { _parentDirectoryGlobalFileNumber = reader.ReadUInt16(); _presentationOrder = PresentationOrder.Inflate(reader); return(DeserializeByteCount); }
/// <summary> /// Creates a new instance of a GZipMemberEntry by parsing it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a GZipMemberEntry.</returns> /// <remarks>NOTE: The Length and Crc32 values will not be set. /// Do not confuse this with actually inflating the data that the GZIP has compressed! this method /// only harvests the metadata from a GZIP stream.</remarks> public static GZipMemberEntry Inflate(INTV.Core.Utility.BinaryReader reader) { return(Inflate <GZipMemberEntry>(reader)); }
/// <summary> /// Creates a new instance of a Directory by inflating it from a BinaryReader. /// </summary> /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param> /// <returns>A new instance of a Directory.</returns> public static Directory Inflate(INTV.Core.Utility.BinaryReader reader) { return(Inflate <Directory>(reader)); }