/// <summary> /// Create a ConsoleDataBlock from a given byte array /// </summary> /// <param name="ba">The byte array</param> /// <returns>A ConsoleDataBlock object</returns> public static ConsoleDataBlock FromByteArray(byte[] ba) { ConsoleDataBlock ConsoleDataBlock = new ConsoleDataBlock(); if (ba.Length < 0xCC) { throw new ArgumentException(String.Format("Size of the ConsoleDataBlock Structure is less than 204 ({0})", ba.Length)); } UInt32 BlockSize = BitConverter.ToUInt32(ba, 0); if (BlockSize > ba.Length) { throw new ArgumentException(String.Format("BlockSize is {0} is incorrect (expected {1})", BlockSize, ConsoleDataBlock.BlockSize)); } BlockSignature BlockSignature = (BlockSignature)BitConverter.ToUInt32(ba, 4); if (BlockSignature != ConsoleDataBlock.BlockSignature) { throw new ArgumentException(String.Format("BlockSignature is {0} is incorrect (expected {1})", BlockSignature, ConsoleDataBlock.BlockSignature)); } ConsoleDataBlock.FillAttributes = (FillAttributes)BitConverter.ToUInt16(ba, 8); ConsoleDataBlock.PopupFillAttributes = (FillAttributes)BitConverter.ToUInt16(ba, 10); ConsoleDataBlock.ScreenBufferSizeX = BitConverter.ToUInt16(ba, 12); ConsoleDataBlock.ScreenBufferSizeY = BitConverter.ToUInt16(ba, 14); ConsoleDataBlock.WindowSizeX = BitConverter.ToUInt16(ba, 16); ConsoleDataBlock.WindowSizeY = BitConverter.ToUInt16(ba, 18); ConsoleDataBlock.WindowOriginX = BitConverter.ToUInt16(ba, 20); ConsoleDataBlock.WindowOriginY = BitConverter.ToUInt16(ba, 22); ConsoleDataBlock.Unused1 = BitConverter.ToUInt32(ba, 24); ConsoleDataBlock.Unused2 = BitConverter.ToUInt32(ba, 28); ConsoleDataBlock.FontSize = BitConverter.ToUInt32(ba, 32); ConsoleDataBlock.FontFamily = (FontFamily)(BitConverter.ToUInt32(ba, 36) & 0xF0); ConsoleDataBlock.FontPitch = (FontPitch)(BitConverter.ToUInt32(ba, 36) & 0xF); ConsoleDataBlock.FontWeight = BitConverter.ToUInt32(ba, 40); byte[] FaceName = new byte[64]; Buffer.BlockCopy(ba, 44, FaceName, 0, 64); ConsoleDataBlock.FaceName = Encoding.Unicode.GetString(FaceName).TrimEnd(new char[] { (char)0 }); ConsoleDataBlock.CursorSize = BitConverter.ToUInt32(ba, 108); ConsoleDataBlock.FullScreen = BitConverter.ToUInt32(ba, 112) != 0; ConsoleDataBlock.QuickEdit = BitConverter.ToUInt32(ba, 116) != 0; ConsoleDataBlock.InsertMode = BitConverter.ToUInt32(ba, 120) != 0; ConsoleDataBlock.AutoPosition = BitConverter.ToUInt32(ba, 124) != 0; ConsoleDataBlock.HistoryBufferSize = BitConverter.ToUInt32(ba, 128); ConsoleDataBlock.NumberOfHistoryBuffers = BitConverter.ToUInt32(ba, 132); ConsoleDataBlock.HistoryNoDup = BitConverter.ToUInt32(ba, 136) != 0; Buffer.BlockCopy(ba, 140, ConsoleDataBlock.ColorTable, 0, 64); return(ConsoleDataBlock); }
/// <summary> /// Create an ExtraData from a given byte array /// </summary> /// <param name="ba">The byte array</param> /// <returns>An ExtraData object</returns> public static ExtraData FromByteArray(byte[] ba) { ExtraData ExtraData = new ExtraData(); if (ba.Length < 4) { throw new ArgumentException(String.Format("Size of the ExtraData Structure is less than 4 ({0})", ba.Length)); } UInt32 BlockSize = BitConverter.ToUInt32(ba, 0); while (BlockSize > 4) { if (BlockSize > ba.Length) { throw new ArgumentException(String.Format("BlockSize is {0} is incorrect (bytes left {1})", BlockSize, ba.Length)); } BlockSignature BlockSignature = (BlockSignature)BitConverter.ToUInt32(ba, 4); switch (BlockSignature) { case BlockSignature.CONSOLE_PROPS: ExtraData.ConsoleDataBlock = ConsoleDataBlock.FromByteArray(ba); break; case BlockSignature.CONSOLE_FE_PROPS: ExtraData.ConsoleFEDataBlock = ConsoleFEDataBlock.FromByteArray(ba); break; case BlockSignature.DARWIN_PROPS: ExtraData.DarwinDataBlock = DarwinDataBlock.FromByteArray(ba); break; case BlockSignature.ENVIRONMENT_PROPS: ExtraData.EnvironmentVariableDataBlock = EnvironmentVariableDataBlock.FromByteArray(ba); break; case BlockSignature.ICON_ENVIRONMENT_PROPS: ExtraData.IconEnvironmentDataBlock = IconEnvironmentDataBlock.FromByteArray(ba); break; case BlockSignature.KNOWN_FOLDER_PROPS: ExtraData.KnownFolderDataBlock = KnownFolderDataBlock.FromByteArray(ba); break; case BlockSignature.PROPERTY_STORE_PROPS: ExtraData.PropertyStoreDataBlock = PropertyStoreDataBlock.FromByteArray(ba); break; case BlockSignature.SHIM_PROPS: ExtraData.ShimDataBlock = ShimDataBlock.FromByteArray(ba); break; case BlockSignature.SPECIAL_FOLDER_PROPS: ExtraData.SpecialFolderDataBlock = SpecialFolderDataBlock.FromByteArray(ba); break; case BlockSignature.TRACKER_PROPS: ExtraData.TrackerDataBlock = TrackerDataBlock.FromByteArray(ba); break; case BlockSignature.VISTA_AND_ABOVE_IDLIST_PROPS: ExtraData.VistaAndAboveIDListDataBlock = VistaAndAboveIDListDataBlock.FromByteArray(ba); break; default: throw new ArgumentException(String.Format("BlockSignature is {0} is incorrect", BlockSignature)); } ba = ba.Skip((int)BlockSize).ToArray(); BlockSize = BitConverter.ToUInt32(ba, 0); } return(ExtraData); }
/// <inheritdoc /> public override String ToString() { StringBuilder builder = new StringBuilder(); builder.Append(base.ToString()); if (ConsoleDataBlock != null) { builder.Append(ConsoleDataBlock.ToString()); } if (ConsoleFEDataBlock != null) { builder.Append(ConsoleFEDataBlock.ToString()); } if (DarwinDataBlock != null) { builder.Append(DarwinDataBlock.ToString()); } if (EnvironmentVariableDataBlock != null) { builder.Append(EnvironmentVariableDataBlock.ToString()); } if (IconEnvironmentDataBlock != null) { builder.Append(IconEnvironmentDataBlock.ToString()); } if (KnownFolderDataBlock != null) { builder.Append(KnownFolderDataBlock.ToString()); } if (PropertyStoreDataBlock != null) { builder.Append(PropertyStoreDataBlock.ToString()); } if (ShimDataBlock != null) { builder.Append(ShimDataBlock.ToString()); } if (SpecialFolderDataBlock != null) { builder.Append(SpecialFolderDataBlock.ToString()); } if (TrackerDataBlock != null) { builder.Append(TrackerDataBlock.ToString()); } if (VistaAndAboveIDListDataBlock != null) { builder.Append(VistaAndAboveIDListDataBlock.ToString()); } return(builder.ToString()); }
/// <inheritdoc /> public override byte[] GetBytes() { int Offset = 0; byte[] ExtraData = new byte[ExtraDataSize]; if (ConsoleDataBlock != null) { Buffer.BlockCopy(ConsoleDataBlock.GetBytes(), 0, ExtraData, Offset, (int)ConsoleDataBlock.BlockSize); Offset += (int)ConsoleDataBlock.BlockSize; } if (ConsoleFEDataBlock != null) { Buffer.BlockCopy(ConsoleFEDataBlock.GetBytes(), 0, ExtraData, Offset, (int)ConsoleFEDataBlock.BlockSize); Offset += (int)ConsoleFEDataBlock.BlockSize; } if (DarwinDataBlock != null) { Buffer.BlockCopy(DarwinDataBlock.GetBytes(), 0, ExtraData, Offset, (int)DarwinDataBlock.BlockSize); Offset += (int)DarwinDataBlock.BlockSize; } if (EnvironmentVariableDataBlock != null) { Buffer.BlockCopy(EnvironmentVariableDataBlock.GetBytes(), 0, ExtraData, Offset, (int)EnvironmentVariableDataBlock.BlockSize); Offset += (int)EnvironmentVariableDataBlock.BlockSize; } if (IconEnvironmentDataBlock != null) { Buffer.BlockCopy(IconEnvironmentDataBlock.GetBytes(), 0, ExtraData, Offset, (int)IconEnvironmentDataBlock.BlockSize); Offset += (int)IconEnvironmentDataBlock.BlockSize; } if (KnownFolderDataBlock != null) { Buffer.BlockCopy(KnownFolderDataBlock.GetBytes(), 0, ExtraData, Offset, (int)KnownFolderDataBlock.BlockSize); Offset += (int)KnownFolderDataBlock.BlockSize; } if (PropertyStoreDataBlock != null) { Buffer.BlockCopy(PropertyStoreDataBlock.GetBytes(), 0, ExtraData, Offset, (int)PropertyStoreDataBlock.BlockSize); Offset += (int)PropertyStoreDataBlock.BlockSize; } if (ShimDataBlock != null) { Buffer.BlockCopy(ShimDataBlock.GetBytes(), 0, ExtraData, Offset, (int)ShimDataBlock.BlockSize); Offset += (int)ShimDataBlock.BlockSize; } if (SpecialFolderDataBlock != null) { Buffer.BlockCopy(SpecialFolderDataBlock.GetBytes(), 0, ExtraData, Offset, (int)SpecialFolderDataBlock.BlockSize); Offset += (int)SpecialFolderDataBlock.BlockSize; } if (TrackerDataBlock != null) { Buffer.BlockCopy(TrackerDataBlock.GetBytes(), 0, ExtraData, Offset, (int)TrackerDataBlock.BlockSize); Offset += (int)TrackerDataBlock.BlockSize; } if (VistaAndAboveIDListDataBlock != null) { Buffer.BlockCopy(VistaAndAboveIDListDataBlock.GetBytes(), 0, ExtraData, Offset, (int)VistaAndAboveIDListDataBlock.BlockSize); Offset += (int)VistaAndAboveIDListDataBlock.BlockSize; } Buffer.BlockCopy(TerminalBlock.GetBytes(), 0, ExtraData, Offset, 4); return(ExtraData); }