/// <summary> /// Constructs an instance of <see cref="SimpleTag"/>. /// </summary> /// <param name="identifier">The tag identifier to use.</param> public SimpleTag(TagIdentifier identifier) { Identifier = identifier; Description = string.Empty; Units = string.Empty; Type = TagType.Numeric; MinimumValue = double.MinValue; MaximumValue = double.MaxValue; }
public int ReadFrom(byte[] buffer, int offset) { TagIdentifier = (TagIdentifier)Utilities.ToUInt16LittleEndian(buffer, offset); DescriptorVersion = Utilities.ToUInt16LittleEndian(buffer, offset + 2); TagChecksum = buffer[offset + 4]; TagSerialNumber = Utilities.ToUInt16LittleEndian(buffer, offset + 6); DescriptorCrc = Utilities.ToUInt16LittleEndian(buffer, offset + 8); DescriptorCrcLength = Utilities.ToUInt16LittleEndian(buffer, offset + 10); TagLocation = Utilities.ToUInt32LittleEndian(buffer, offset + 12); return(16); }
public void TagIdentifier_FromString_Valid() { TagIdentifier id = "haha.123"; Assert.AreEqual("haha", id.Source); Assert.AreEqual("123", id.Name); TagIdentifier id2 = "haha.123.asdf"; Assert.AreEqual("haha", id2.Source); Assert.AreEqual("123.asdf", id2.Name); }
public int ReadFrom(byte[] buffer, int offset) { TagIdentifier = (TagIdentifier)Utilities.ToUInt16LittleEndian(buffer, offset); DescriptorVersion = Utilities.ToUInt16LittleEndian(buffer, offset + 2); TagChecksum = buffer[offset + 4]; TagSerialNumber = Utilities.ToUInt16LittleEndian(buffer, offset + 6); DescriptorCrc = Utilities.ToUInt16LittleEndian(buffer, offset + 8); DescriptorCrcLength = Utilities.ToUInt16LittleEndian(buffer, offset + 10); TagLocation = Utilities.ToUInt32LittleEndian(buffer, offset + 12); return 16; }
public override void GenerateTags(ProceduralLevel level) { List <TagSpawnWeight> tags = new List <TagSpawnWeight>(); foreach (TagSpawnWeight tsw in m_TagSpawnWeights) { if (tsw.RequiredDifficulty > level.Difficulty) { continue; } tags.Add(tsw); } int weight = 0; for (int i = 0; i < tags.Count; i++) { weight += tags[i].Weight; } float minTagCount = m_MinimumTagCount.Evaluate(level.Difficulty); float maxTagCount = m_MaximumTagCount.Evaluate(level.Difficulty); int tagCount = (int)Math.Round(Random.Range(minTagCount, maxTagCount)); TagList tagList = new TagList(); for (int i = 0; i < tagCount; i++) { if (tags.Count == 0) { break; } int roll = (int)(Random.Range(0, weight)); int tagIndex = 0; while (roll > tags[tagIndex].Weight) { roll -= tags[tagIndex].Weight; tagIndex++; } TagIdentifier tagIdentifier = tags[tagIndex].TagIdentifier; tagList.Add(tagIdentifier.Object); weight -= tags[tagIndex].Weight; tags.RemoveAt(tagIndex); } if (tagList.Count == 0) { tagList.Add(m_DefaultTag.Object); } level.TagList = tagList; }
public bool Identify(IMediaImage imagePlugin, Partition partition) { // UDF needs at least that if (partition.End - partition.Start < 256) { return(false); } // UDF needs at least that if (imagePlugin.Info.SectorSize < 512) { return(false); } byte[] sector; AnchorVolumeDescriptorPointer anchor = new AnchorVolumeDescriptorPointer(); // All positions where anchor may reside ulong[] positions = { 256, 512, partition.End - 256, partition.End }; bool anchorFound = false; foreach (ulong position in positions.Where(position => position + partition.Start < partition.End)) { sector = imagePlugin.ReadSector(position); anchor = new AnchorVolumeDescriptorPointer(); IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor)); Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor)); anchor = (AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr, typeof(AnchorVolumeDescriptorPointer)); Marshal.FreeHGlobal(anchorPtr); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagIdentifier = {0}", anchor.tag.tagIdentifier); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorVersion = {0}", anchor.tag.descriptorVersion); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagChecksum = 0x{0:X2}", anchor.tag.tagChecksum); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.reserved = {0}", anchor.tag.reserved); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagSerialNumber = {0}", anchor.tag.tagSerialNumber); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrc = 0x{0:X4}", anchor.tag.descriptorCrc); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrcLength = {0}", anchor.tag.descriptorCrcLength); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagLocation = {0}", anchor.tag.tagLocation); DicConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.length = {0}", anchor.mainVolumeDescriptorSequenceExtent.length); DicConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.location = {0}", anchor.mainVolumeDescriptorSequenceExtent.location); DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.length = {0}", anchor.reserveVolumeDescriptorSequenceExtent.length); DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.location = {0}", anchor.reserveVolumeDescriptorSequenceExtent.location); if (anchor.tag.tagIdentifier != TagIdentifier.AnchorVolumeDescriptorPointer || anchor.tag.tagLocation != position || anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start >= partition.End) { continue; } anchorFound = true; break; } if (!anchorFound) { return(false); } ulong count = 0; while (count < 256) { sector = imagePlugin.ReadSector(partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count); TagIdentifier tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0); uint location = BitConverter.ToUInt32(sector, 0x0C); if (location == partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count) { if (tagId == TagIdentifier.TerminatingDescriptor) { break; } if (tagId == TagIdentifier.LogicalVolumeDescriptor) { LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor(); IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd)); Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd)); lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor)); Marshal.FreeHGlobal(lvdPtr); return(UDF_Magic.SequenceEqual(lvd.domainIdentifier.identifier)); } } else { break; } count++; } return(false); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { // UDF is always UTF-8 Encoding = Encoding.UTF8; byte[] sector; StringBuilder sbInformation = new StringBuilder(); sbInformation.AppendLine("Universal Disk Format"); AnchorVolumeDescriptorPointer anchor = new AnchorVolumeDescriptorPointer(); // All positions where anchor may reside ulong[] positions = { 256, 512, partition.End - 256, partition.End }; foreach (ulong position in positions) { sector = imagePlugin.ReadSector(position); anchor = new AnchorVolumeDescriptorPointer(); IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor)); Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor)); anchor = (AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr, typeof(AnchorVolumeDescriptorPointer)); Marshal.FreeHGlobal(anchorPtr); if (anchor.tag.tagIdentifier == TagIdentifier.AnchorVolumeDescriptorPointer && anchor.tag.tagLocation == position && anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start < partition.End) { break; } } ulong count = 0; PrimaryVolumeDescriptor pvd = new PrimaryVolumeDescriptor(); LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor(); LogicalVolumeIntegrityDescriptor lvid = new LogicalVolumeIntegrityDescriptor(); LogicalVolumeIntegrityDescriptorImplementationUse lvidiu = new LogicalVolumeIntegrityDescriptorImplementationUse(); while (count < 256) { sector = imagePlugin.ReadSector(partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count); TagIdentifier tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0); uint location = BitConverter.ToUInt32(sector, 0x0C); if (location == partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count) { if (tagId == TagIdentifier.TerminatingDescriptor) { break; } switch (tagId) { case TagIdentifier.LogicalVolumeDescriptor: IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd)); Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd)); lvd = (LogicalVolumeDescriptor) Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor)); Marshal.FreeHGlobal(lvdPtr); break; case TagIdentifier.PrimaryVolumeDescriptor: IntPtr pvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pvd)); Marshal.Copy(sector, 0, pvdPtr, Marshal.SizeOf(pvd)); pvd = (PrimaryVolumeDescriptor) Marshal.PtrToStructure(pvdPtr, typeof(PrimaryVolumeDescriptor)); Marshal.FreeHGlobal(pvdPtr); break; } } else { break; } count++; } sector = imagePlugin.ReadSector(lvd.integritySequenceExtent.location); IntPtr lvidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvid)); Marshal.Copy(sector, 0, lvidPtr, Marshal.SizeOf(lvid)); lvid = (LogicalVolumeIntegrityDescriptor) Marshal.PtrToStructure(lvidPtr, typeof(LogicalVolumeIntegrityDescriptor)); Marshal.FreeHGlobal(lvidPtr); if (lvid.tag.tagIdentifier == TagIdentifier.LogicalVolumeIntegrityDescriptor && lvid.tag.tagLocation == lvd.integritySequenceExtent.location) { IntPtr lvidiuPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvidiu)); Marshal.Copy(sector, (int)(lvid.numberOfPartitions * 8 + 80), lvidiuPtr, Marshal.SizeOf(lvidiu)); lvidiu = (LogicalVolumeIntegrityDescriptorImplementationUse)Marshal.PtrToStructure(lvidiuPtr, typeof( LogicalVolumeIntegrityDescriptorImplementationUse )); Marshal.FreeHGlobal(lvidiuPtr); } else { lvid = new LogicalVolumeIntegrityDescriptor(); } sbInformation.AppendFormat("Volume is number {0} of {1}", pvd.volumeSequenceNumber, pvd.maximumVolumeSequenceNumber).AppendLine(); sbInformation.AppendFormat("Volume set identifier: {0}", StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier)).AppendLine(); sbInformation .AppendFormat("Volume name: {0}", StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier)) .AppendLine(); sbInformation.AppendFormat("Volume uses {0} bytes per block", lvd.logicalBlockSize).AppendLine(); sbInformation.AppendFormat("Volume was las written in {0}", EcmaToDateTime(lvid.recordingDateTime)) .AppendLine(); sbInformation.AppendFormat("Volume contains {0} partitions", lvid.numberOfPartitions).AppendLine(); sbInformation .AppendFormat("Volume contains {0} files and {1} directories", lvidiu.files, lvidiu.directories) .AppendLine(); sbInformation.AppendFormat("Volume conforms to {0}", Encoding.GetString(lvd.domainIdentifier.identifier).TrimEnd('\u0000')) .AppendLine(); sbInformation.AppendFormat("Volume was last written by: {0}", Encoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000')) .AppendLine(); sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be read", Convert.ToInt32($"{(lvidiu.minimumReadUDF & 0xFF00) >> 8}", 10), Convert.ToInt32($"{lvidiu.minimumReadUDF & 0xFF}", 10)).AppendLine(); sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be written to", Convert.ToInt32($"{(lvidiu.minimumWriteUDF & 0xFF00) >> 8}", 10), Convert.ToInt32($"{lvidiu.minimumWriteUDF & 0xFF}", 10)).AppendLine(); sbInformation.AppendFormat("Volume cannot be written by any UDF version higher than {0}.{1:X2}", Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10), Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10)).AppendLine(); XmlFsType = new FileSystemType { Type = $"UDF v{Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10)}.{Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10):X2}", ApplicationIdentifier = Encoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000'), ClusterSize = (int)lvd.logicalBlockSize, ModificationDate = EcmaToDateTime(lvid.recordingDateTime), ModificationDateSpecified = true, Files = lvidiu.files, FilesSpecified = true, VolumeName = StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier), VolumeSetIdentifier = StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier), SystemIdentifier = Encoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000') }; XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / (ulong)XmlFsType.ClusterSize); information = sbInformation.ToString(); }
protected BaseTaggedDescriptor(TagIdentifier id) { RequiredTagIdentifier = id; }
protected TaggedDescriptor(TagIdentifier id) : base(id) { }
void IDefinition.FromArray(byte[] buffer) { BinaryReader bin = new BinaryReader(new MemoryStream(buffer)); bin.BaseStream.Seek(12, SeekOrigin.Begin); Shader = bin.ReadTagID(); }
public IMap this[TagIdentifier tag_id] { get { if (current_tag.Identifier == tag_id) return this; current_tag = Tags[tag_id.Index]; return this; } }
/// <inheritdoc /> public async Task <ITag> ResolveTagAsync(TagIdentifier tagId) { return(new SimpleTag(tagId)); }