Initial commit - WPinternals 2.6

This commit is contained in:
Rene Lergner
2018-10-25 22:35:49 +02:00
commit 396ae57f05
483 changed files with 159677 additions and 0 deletions
@@ -0,0 +1,55 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
/// <summary>
/// Enumeration of known application image types.
/// </summary>
public enum ApplicationImageType
{
/// <summary>
/// Unknown type.
/// </summary>
None = 0x0,
/// <summary>
/// Firmware application.
/// </summary>
Firmware = 0x1,
/// <summary>
/// Windows boot loader.
/// </summary>
WindowsBoot = 0x2,
/// <summary>
/// Legacy boot loader.
/// </summary>
LegacyLoader = 0x3,
/// <summary>
/// Real mode boot loader.
/// </summary>
RealMode = 0x4
}
}
+80
View File
@@ -0,0 +1,80 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
/// <summary>
/// Enumeration of known application types.
/// </summary>
public enum ApplicationType
{
/// <summary>
/// Unknown type.
/// </summary>
None = 0,
/// <summary>
/// Firmware boot manager (e.g. UEFI).
/// </summary>
FirmwareBootManager = 1,
/// <summary>
/// Windows boot manager.
/// </summary>
BootManager = 2,
/// <summary>
/// Operating System Loader.
/// </summary>
OsLoader = 3,
/// <summary>
/// Resume loader.
/// </summary>
Resume = 4,
/// <summary>
/// Memory diagnostic application.
/// </summary>
MemoryDiagnostics = 5,
/// <summary>
/// Legacy NT loader application.
/// </summary>
NtLoader = 6,
/// <summary>
/// Windows setup application.
/// </summary>
SetupLoader = 7,
/// <summary>
/// Boot sector application.
/// </summary>
BootSector = 8,
/// <summary>
/// Startup application.
/// </summary>
Startup = 9
}
}
+75
View File
@@ -0,0 +1,75 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Collections.Generic;
/// <summary>
/// Base class for BCD storage repositories.
/// </summary>
internal abstract class BaseStorage
{
/// <summary>
/// Tests if an element is present (i.e. has a value) on an object.
/// </summary>
/// <param name="obj">The object to inspect.</param>
/// <param name="element">The element to inspect.</param>
/// <returns><c>true</c> if present, else <c>false</c>.</returns>
public abstract bool HasValue(Guid obj, int element);
/// <summary>
/// Gets the value of a string element.
/// </summary>
/// <param name="obj">The object to inspect.</param>
/// <param name="element">The element to retrieve.</param>
/// <returns>The value as a string.</returns>
public abstract string GetString(Guid obj, int element);
public abstract byte[] GetBinary(Guid obj, int element);
public abstract void SetString(Guid obj, int element, string value);
public abstract void SetBinary(Guid obj, int element, byte[] value);
public abstract string[] GetMultiString(Guid obj, int element);
public abstract void SetMultiString(Guid obj, int element, string[] values);
public abstract IEnumerable<Guid> EnumerateObjects();
public abstract IEnumerable<int> EnumerateElements(Guid obj);
public abstract int GetObjectType(Guid obj);
public abstract bool ObjectExists(Guid obj);
public abstract Guid CreateObject(Guid obj, int type);
public abstract void CreateElement(Guid obj, int element);
public abstract void DeleteObject(Guid obj);
public abstract void DeleteElement(Guid obj, int element);
}
}
+365
View File
@@ -0,0 +1,365 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
//
// Symbolic names of BCD Objects taken from Geoff Chappell's website:
// http://www.geoffchappell.com/viewer.htm?doc=notes/windows/boot/bcd/objects.htm
//
//
namespace DiscUtils.BootConfig
{
using System;
using System.Collections.Generic;
/// <summary>
/// Represents a Boot Configuration Database object (application, device or inherited settings).
/// </summary>
public class BcdObject
{
/// <summary>
/// Well-known object for Emergency Management Services settings.
/// </summary>
public const string EmsSettingsGroupId = "{0CE4991B-E6B3-4B16-B23C-5E0D9250E5D9}";
/// <summary>
/// Well-known object for the Resume boot loader.
/// </summary>
public const string ResumeLoaderSettingsGroupId = "{1AFA9C49-16AB-4A5C-4A90-212802DA9460}";
/// <summary>
/// Alias for the Default boot entry.
/// </summary>
public const string DefaultBootEntryId = "{1CAE1EB7-A0DF-4D4D-9851-4860E34EF535}";
/// <summary>
/// Well-known object for Emergency Management Services settings.
/// </summary>
public const string DebuggerSettingsGroupId = "{4636856E-540F-4170-A130-A84776F4C654}";
/// <summary>
/// Well-known object for NTLDR application.
/// </summary>
public const string WindowsLegacyNtldrId = "{466F5A88-0AF2-4F76-9038-095B170DC21C}";
/// <summary>
/// Well-known object for bad memory settings.
/// </summary>
public const string BadMemoryGroupId = "{5189B25C-5558-4BF2-BCA4-289B11BD29E2}";
/// <summary>
/// Well-known object for Boot Loader settings.
/// </summary>
public const string BootLoaderSettingsGroupId = "{6EFB52BF-1766-41DB-A6B3-0EE5EFF72BD7}";
/// <summary>
/// Well-known object for EFI setup.
/// </summary>
public const string WindowsSetupEfiId = "{7254A080-1510-4E85-AC0F-E7FB3D444736}";
/// <summary>
/// Well-known object for Global settings.
/// </summary>
public const string GlobalSettingsGroupId = "{7EA2E1AC-2E61-4728-AAA3-896D9D0A9F0E}";
/// <summary>
/// Well-known object for Windows Boot Manager.
/// </summary>
public const string WindowsBootManagerId = "{9DEA862C-5CDD-4E70-ACC1-F32B344D4795}";
/// <summary>
/// Well-known object for PCAT Template.
/// </summary>
public const string WindowsOsTargetTemplatePcatId = "{A1943BBC-EA85-487C-97C7-C9EDE908A38A}";
/// <summary>
/// Well-known object for Firmware Boot Manager.
/// </summary>
public const string FirmwareBootManagerId = "{A5A30FA2-3D06-4E9F-B5F4-A01DF9D1FCBA}";
/// <summary>
/// Well-known object for Windows Setup RAMDISK options.
/// </summary>
public const string WindowsSetupRamdiskOptionsId = "{AE5534E0-A924-466C-B836-758539A3EE3A}";
/// <summary>
/// Well-known object for EFI template.
/// </summary>
public const string WindowsOsTargetTemplateEfiId = "{B012B84D-C47C-4ED5-B722-C0C42163E569}";
/// <summary>
/// Well-known object for Windows memory tester application.
/// </summary>
public const string WindowsMemoryTesterId = "{B2721D73-1DB4-4C62-BF78-C548A880142D}";
/// <summary>
/// Well-known object for Windows PCAT setup.
/// </summary>
public const string WindowsSetupPcatId = "{CBD971BF-B7B8-4885-951A-FA03044F5D71}";
/// <summary>
/// Alias for the current boot entry.
/// </summary>
public const string CurrentBootEntryId = "{FA926493-6F1C-4193-A414-58F0B2456D1E}";
private static Dictionary<string, Guid> s_nameToGuid;
private static Dictionary<Guid, string> s_guidToName;
private BaseStorage _storage;
private Guid _id;
private int _type;
static BcdObject()
{
s_nameToGuid = new Dictionary<string, Guid>();
s_guidToName = new Dictionary<Guid, string>();
AddMapping("{emssettings}", EmsSettingsGroupId);
AddMapping("{resumeloadersettings}", ResumeLoaderSettingsGroupId);
AddMapping("{default}", DefaultBootEntryId);
AddMapping("{dbgsettings}", DebuggerSettingsGroupId);
AddMapping("{legacy}", WindowsLegacyNtldrId);
AddMapping("{ntldr}", WindowsLegacyNtldrId);
AddMapping("{badmemory}", BadMemoryGroupId);
AddMapping("{bootloadersettings}", BootLoaderSettingsGroupId);
AddMapping("{globalsettings}", GlobalSettingsGroupId);
AddMapping("{bootmgr}", WindowsBootManagerId);
AddMapping("{fwbootmgr}", FirmwareBootManagerId);
AddMapping("{ramdiskoptions}", WindowsSetupRamdiskOptionsId);
AddMapping("{memdiag}", WindowsMemoryTesterId);
AddMapping("{current}", CurrentBootEntryId);
}
internal BcdObject(BaseStorage store, Guid id)
{
_storage = store;
_id = id;
_type = _storage.GetObjectType(id);
}
/// <summary>
/// Gets the identity of this object.
/// </summary>
public Guid Identity
{
get { return _id; }
}
/// <summary>
/// Gets the friendly name for this object, if known.
/// </summary>
public string FriendlyName
{
get
{
string name;
if (s_guidToName.TryGetValue(_id, out name))
{
return name;
}
return _id.ToString("B");
}
}
/// <summary>
/// Gets the object type for this object.
/// </summary>
public ObjectType ObjectType
{
get { return (ObjectType)((_type >> 28) & 0xF); }
}
/// <summary>
/// Gets the image type for this application.
/// </summary>
public ApplicationImageType ApplicationImageType
{
get { return IsApplication ? (ApplicationImageType)((_type & 0x00F00000) >> 20) : 0; }
}
/// <summary>
/// Gets the application type for this application.
/// </summary>
public ApplicationType ApplicationType
{
get { return IsApplication ? (ApplicationType)(_type & 0xFFFFF) : 0; }
}
/// <summary>
/// Gets the elements in this object.
/// </summary>
public IEnumerable<Element> Elements
{
get
{
foreach (var el in _storage.EnumerateElements(_id))
{
yield return new Element(_storage, _id, ApplicationType, el);
}
}
}
private bool IsApplication
{
get { return ObjectType == ObjectType.Application; }
}
/// <summary>
/// Indicates if the settings in this object are inheritable by another object.
/// </summary>
/// <param name="type">The type of the object to test for inheritability.</param>
/// <returns><c>true</c> if the settings can be inherited, else <c>false</c>.</returns>
public bool IsInheritableBy(ObjectType type)
{
if (type == ObjectType.Inherit)
{
throw new ArgumentException("Can not test inheritability by inherit objects", "type");
}
if (ObjectType != ObjectType.Inherit)
{
return false;
}
InheritType setting = (InheritType)((_type & 0x00F00000) >> 20);
return setting == InheritType.AnyObject
|| (setting == InheritType.ApplicationObjects && type == ObjectType.Application)
|| (setting == InheritType.DeviceObjects && type == ObjectType.Device);
}
/// <summary>
/// Indicates if this object has a specific element.
/// </summary>
/// <param name="id">The identity of the element to look for.</param>
/// <returns><c>true</c> if present, else <c>false</c>.</returns>
public bool HasElement(int id)
{
return _storage.HasValue(_id, id);
}
/// <summary>
/// Indicates if this object has a specific element.
/// </summary>
/// <param name="id">The identity of the element to look for.</param>
/// <returns><c>true</c> if present, else <c>false</c>.</returns>
public bool HasElement(WellKnownElement id)
{
return HasElement((int)id);
}
/// <summary>
/// Gets a specific element in this object.
/// </summary>
/// <param name="id">The identity of the element to look for.</param>
/// <returns>The element object.</returns>
public Element GetElement(int id)
{
if (HasElement(id))
{
return new Element(_storage, _id, ApplicationType, id);
}
return null;
}
/// <summary>
/// Gets a specific element in this object.
/// </summary>
/// <param name="id">The identity of the element to look for.</param>
/// <returns>The element object.</returns>
public Element GetElement(WellKnownElement id)
{
return GetElement((int)id);
}
/// <summary>
/// Adds an element in this object.
/// </summary>
/// <param name="id">The identity of the element to add.</param>
/// <param name="initialValue">The initial value of the element.</param>
/// <returns>The element object.</returns>
public Element AddElement(int id, ElementValue initialValue)
{
_storage.CreateElement(_id, id);
Element el = new Element(_storage, _id, ApplicationType, id);
el.Value = initialValue;
return el;
}
/// <summary>
/// Adds an element in this object.
/// </summary>
/// <param name="id">The identity of the element to add.</param>
/// <param name="initialValue">The initial value of the element.</param>
/// <returns>The element object.</returns>
public Element AddElement(WellKnownElement id, ElementValue initialValue)
{
return AddElement((int)id, initialValue);
}
/// <summary>
/// Removes a specific element.
/// </summary>
/// <param name="id">The element to remove.</param>
public void RemoveElement(int id)
{
_storage.DeleteElement(_id, id);
}
/// <summary>
/// Removes a specific element.
/// </summary>
/// <param name="id">The element to remove.</param>
public void RemoveElement(WellKnownElement id)
{
RemoveElement((int)id);
}
/// <summary>
/// Returns the object identity as a GUID string.
/// </summary>
/// <returns>A string representation, with surrounding curly braces.</returns>
public override string ToString()
{
return _id.ToString("B");
}
internal static int MakeApplicationType(ApplicationImageType imageType, ApplicationType appType)
{
return 0x10000000 | (((int)imageType << 20) & 0x00F00000) | ((int)appType & 0x0000FFFF);
}
internal static int MakeInheritType(InheritType inheritType)
{
return 0x20000000 | (((int)inheritType << 20) & 0x00F00000);
}
private static void AddMapping(string name, string id)
{
Guid guid = new Guid(id);
s_nameToGuid[name] = guid;
s_guidToName[guid] = name;
}
}
}
@@ -0,0 +1,54 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
internal class BooleanElementValue : ElementValue
{
private bool _value;
public BooleanElementValue(byte[] value)
{
_value = value[0] != 0;
}
public BooleanElementValue(bool value)
{
_value = value;
}
public override ElementFormat Format
{
get { return ElementFormat.Boolean; }
}
public override string ToString()
{
return _value ? "True" : "False";
}
internal byte[] GetBytes()
{
return new byte[] { (_value ? (byte)1 : (byte)0) };
}
}
}
@@ -0,0 +1,58 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Text;
internal class DeviceAndPathRecord : DeviceRecord
{
private DeviceRecord _container;
private string _path;
public override int Size
{
get { throw new NotImplementedException(); }
}
public override void GetBytes(byte[] data, int offset)
{
throw new NotImplementedException();
}
public override string ToString()
{
return _container.ToString() + ":" + _path;
}
protected override void DoParse(byte[] data, int offset)
{
base.DoParse(data, offset);
_container = DeviceRecord.Parse(data, offset + 0x34);
int pathStart = 0x34 + _container.Size;
_path = Encoding.Unicode.GetString(data, offset + pathStart, Length - pathStart);
}
}
}
+114
View File
@@ -0,0 +1,114 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Globalization;
internal class DeviceElementValue : ElementValue
{
private Guid _parentObject;
private DeviceRecord _record;
public DeviceElementValue()
{
_parentObject = Guid.Empty;
PartitionRecord record = new PartitionRecord();
record.Type = 5;
_record = record;
}
public DeviceElementValue(Guid parentObject, PhysicalVolumeInfo pvi)
{
_parentObject = parentObject;
PartitionRecord record = new PartitionRecord();
record.Type = 6;
if (pvi.VolumeType == PhysicalVolumeType.BiosPartition)
{
record.PartitionType = 1;
record.DiskIdentity = new byte[4];
Utilities.WriteBytesLittleEndian(pvi.DiskSignature, record.DiskIdentity, 0);
record.PartitionIdentity = new byte[8];
Utilities.WriteBytesLittleEndian(pvi.PhysicalStartSector * 512, record.PartitionIdentity, 0);
}
else if (pvi.VolumeType == PhysicalVolumeType.GptPartition)
{
record.PartitionType = 0;
record.DiskIdentity = new byte[16];
Utilities.WriteBytesLittleEndian(pvi.DiskIdentity, record.DiskIdentity, 0);
record.PartitionIdentity = new byte[16];
Utilities.WriteBytesLittleEndian(pvi.PartitionIdentity, record.PartitionIdentity, 0);
}
else
{
throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "Unknown how to convert volume type {0} to a Device element", pvi.VolumeType));
}
_record = record;
}
public DeviceElementValue(byte[] value)
{
_parentObject = Utilities.ToGuidLittleEndian(value, 0x00);
_record = DeviceRecord.Parse(value, 0x10);
}
public override Guid ParentObject
{
get { return _parentObject; }
}
public override ElementFormat Format
{
get { return ElementFormat.Device; }
}
public override string ToString()
{
if (_parentObject != Guid.Empty)
{
return _parentObject.ToString() + ":" + _record.ToString();
}
else if (_record != null)
{
return _record.ToString();
}
else
{
return "<unknown>";
}
}
internal byte[] GetBytes()
{
byte[] buffer = new byte[_record.Size + 0x10];
Utilities.WriteBytesLittleEndian(_parentObject, buffer, 0);
_record.GetBytes(buffer, 0x10);
return buffer;
}
}
}
+84
View File
@@ -0,0 +1,84 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.IO;
internal abstract class DeviceRecord
{
public int Type { get; set; }
public int Length { get; set; }
public abstract int Size { get; }
public static DeviceRecord Parse(byte[] data, int offset)
{
int type = Utilities.ToInt32LittleEndian(data, offset);
int length = Utilities.ToInt32LittleEndian(data, offset + 0x8);
if (offset + length > data.Length)
{
throw new InvalidDataException("Device record is truncated");
}
DeviceRecord newRecord = null;
switch (type)
{
case 0:
newRecord = new DeviceAndPathRecord();
break;
case 5: // Logical 'boot' device
case 6: // Disk partition
newRecord = new PartitionRecord();
break;
case 8: // custom:nnnnnn
break;
default:
throw new NotImplementedException("Unknown device type: " + type);
}
if (newRecord != null)
{
newRecord.DoParse(data, offset);
}
return newRecord;
}
public abstract void GetBytes(byte[] data, int offset);
protected virtual void DoParse(byte[] data, int offset)
{
Type = Utilities.ToInt32LittleEndian(data, offset);
Length = Utilities.ToInt32LittleEndian(data, offset + 0x8);
}
protected void WriteHeader(byte[] data, int offset)
{
Length = Size;
Utilities.WriteBytesLittleEndian(Type, data, offset);
Utilities.WriteBytesLittleEndian(Size, data, offset + 0x8);
}
}
}
@@ -0,0 +1,162 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Collections.Generic;
using System.Globalization;
using DiscUtils.Registry;
internal class DiscUtilsRegistryStorage : BaseStorage
{
private const string ElementsPathTemplate = @"Objects\{0}\Elements";
private const string ElementPathTemplate = @"Objects\{0}\Elements\{1:X8}";
private const string ObjectTypePathTemplate = @"Objects\{0}\Description";
private const string ObjectsPath = @"Objects";
private RegistryKey _rootKey;
public DiscUtilsRegistryStorage(RegistryKey key)
{
_rootKey = key;
}
public override string GetString(Guid obj, int element)
{
return GetValue(obj, element) as string;
}
public override void SetString(Guid obj, int element, string value)
{
SetValue(obj, element, value);
}
public override byte[] GetBinary(Guid obj, int element)
{
return GetValue(obj, element) as byte[];
}
public override void SetBinary(Guid obj, int element, byte[] value)
{
SetValue(obj, element, value);
}
public override string[] GetMultiString(Guid obj, int element)
{
return GetValue(obj, element) as string[];
}
public override void SetMultiString(Guid obj, int element, string[] values)
{
SetValue(obj, element, values);
}
public override IEnumerable<Guid> EnumerateObjects()
{
RegistryKey parentKey = _rootKey.OpenSubKey("Objects");
foreach (var key in parentKey.GetSubKeyNames())
{
yield return new Guid(key);
}
}
public override IEnumerable<int> EnumerateElements(Guid obj)
{
string path = string.Format(CultureInfo.InvariantCulture, ElementsPathTemplate, obj.ToString("B"));
RegistryKey parentKey = _rootKey.OpenSubKey(path);
foreach (var key in parentKey.GetSubKeyNames())
{
yield return int.Parse(key, NumberStyles.HexNumber);
}
}
public override int GetObjectType(Guid obj)
{
string path = string.Format(CultureInfo.InvariantCulture, ObjectTypePathTemplate, obj.ToString("B"));
RegistryKey descKey = _rootKey.OpenSubKey(path);
object val = descKey.GetValue("Type");
return (int)val;
}
public override bool HasValue(Guid obj, int element)
{
string path = string.Format(CultureInfo.InvariantCulture, ElementPathTemplate, obj.ToString("B"), element);
return _rootKey.OpenSubKey(path) != null;
}
public override bool ObjectExists(Guid obj)
{
string path = string.Format(CultureInfo.InvariantCulture, ObjectTypePathTemplate, obj.ToString("B"));
return _rootKey.OpenSubKey(path) != null;
}
public override Guid CreateObject(Guid obj, int type)
{
Guid realObj = (obj == Guid.Empty) ? Guid.NewGuid() : obj;
string path = string.Format(CultureInfo.InvariantCulture, ObjectTypePathTemplate, realObj.ToString("B"));
RegistryKey key = _rootKey.CreateSubKey(path);
key.SetValue("Type", type, RegistryValueType.Dword);
return realObj;
}
public override void CreateElement(Guid obj, int element)
{
string path = string.Format(CultureInfo.InvariantCulture, ElementPathTemplate, obj.ToString("B"), element);
_rootKey.CreateSubKey(path);
}
public override void DeleteObject(Guid obj)
{
string path = string.Format(CultureInfo.InvariantCulture, ObjectTypePathTemplate, obj.ToString("B"));
_rootKey.DeleteSubKeyTree(path);
}
public override void DeleteElement(Guid obj, int element)
{
string path = string.Format(CultureInfo.InvariantCulture, ElementPathTemplate, obj.ToString("B"), element);
_rootKey.DeleteSubKeyTree(path);
}
private object GetValue(Guid obj, int element)
{
string path = string.Format(CultureInfo.InvariantCulture, ElementPathTemplate, obj.ToString("B"), element);
RegistryKey key = _rootKey.OpenSubKey(path);
return key.GetValue("Element");
}
private void SetValue(Guid obj, int element, object value)
{
string path = string.Format(CultureInfo.InvariantCulture, ElementPathTemplate, obj.ToString("B"), element);
RegistryKey key = _rootKey.OpenSubKey(path);
key.SetValue("Element", value);
}
}
}
+390
View File
@@ -0,0 +1,390 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
//
// Symbolic names of BCD Elements taken from Geoff Chappell's website:
// http://www.geoffchappell.com/viewer.htm?doc=notes/windows/boot/bcd/elements.htm
//
//
namespace DiscUtils.BootConfig
{
using System;
using System.Globalization;
/// <summary>
/// Represents an element in a Boot Configuration Database object.
/// </summary>
public class Element
{
private BaseStorage _storage;
private Guid _obj;
private ApplicationType _appType;
private int _identifier;
private ElementValue _value;
internal Element(BaseStorage storage, Guid obj, ApplicationType appType, int identifier)
{
_storage = storage;
_obj = obj;
_appType = appType;
_identifier = identifier;
}
/// <summary>
/// Gets the friendly name of the element, if any.
/// </summary>
public string FriendlyName
{
get
{
return "{" + IdentifierToName(_appType, _identifier) + "}";
}
}
/// <summary>
/// Gets the class of the element.
/// </summary>
public ElementClass Class
{
get { return (ElementClass)((_identifier >> 28) & 0xF); }
}
/// <summary>
/// Gets the element's format.
/// </summary>
public ElementFormat Format
{
get { return (ElementFormat)((_identifier >> 24) & 0xF); }
}
/// <summary>
/// Gets or sets the element's value.
/// </summary>
public ElementValue Value
{
get
{
if (_value == null)
{
_value = LoadValue();
}
return _value;
}
set
{
if (Format != value.Format)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Attempt to assign {1} value to {0} format element", Format, value.Format));
}
_value = value;
WriteValue();
}
}
/// <summary>
/// Gets the element's id as a hex string.
/// </summary>
/// <returns>A hex string.</returns>
public override string ToString()
{
return _identifier.ToString("X8", CultureInfo.InvariantCulture);
}
private static string IdentifierToName(ApplicationType appType, int identifier)
{
ElementClass idClass = GetClass(identifier);
if (idClass == ElementClass.Library)
{
switch (identifier)
{
case 0x11000001: return "device";
case 0x12000002: return "path";
case 0x12000004: return "description";
case 0x12000005: return "locale";
case 0x14000006: return "inherit";
case 0x15000007: return "truncatememory";
case 0x14000008: return "recoverysequence";
case 0x16000009: return "recoveryenabled";
case 0x1700000A: return "badmemorylist";
case 0x1600000B: return "badmemoryaccess";
case 0x1500000C: return "firstmegabytepolicy";
case 0x16000010: return "bootdebug";
case 0x15000011: return "debugtype";
case 0x15000012: return "debugaddress";
case 0x15000013: return "debugport";
case 0x15000014: return "baudrate";
case 0x15000015: return "channel";
case 0x12000016: return "targetname";
case 0x16000017: return "noumex";
case 0x15000018: return "debugstart";
case 0x16000020: return "bootems";
case 0x15000022: return "emsport";
case 0x15000023: return "emsbaudrate";
case 0x12000030: return "loadoptions";
case 0x16000040: return "advancedoptions";
case 0x16000041: return "optionsedit";
case 0x15000042: return "keyringaddress";
case 0x16000046: return "graphicsmodedisabled";
case 0x15000047: return "configaccesspolicy";
case 0x16000048: return "nointegritychecks";
case 0x16000049: return "testsigning";
case 0x16000050: return "extendedinput";
case 0x15000051: return "initialconsoleinput";
}
}
else if (idClass == ElementClass.Application)
{
switch (appType)
{
case ApplicationType.FirmwareBootManager:
case ApplicationType.BootManager:
switch (identifier)
{
case 0x24000001: return "displayorder";
case 0x24000002: return "bootsequence";
case 0x23000003: return "default";
case 0x25000004: return "timeout";
case 0x26000005: return "resume";
case 0x23000006: return "resumeobject";
case 0x24000010: return "toolsdisplayorder";
case 0x26000020: return "displaybootmenu";
case 0x26000021: return "noerrordisplay";
case 0x21000022: return "bcddevice";
case 0x22000023: return "bcdfilepath";
case 0x27000030: return "customactions";
}
break;
case ApplicationType.OsLoader:
switch (identifier)
{
case 0x21000001: return "osdevice";
case 0x22000002: return "systemroot";
case 0x23000003: return "resumeobject";
case 0x26000010: return "detecthal";
case 0x22000011: return "kernel";
case 0x22000012: return "hal";
case 0x22000013: return "dbgtransport";
case 0x25000020: return "nx";
case 0x25000021: return "pae";
case 0x26000022: return "winpe";
case 0x26000024: return "nocrashautoreboot";
case 0x26000025: return "lastknowngood";
case 0x26000026: return "oslnointegritychecks";
case 0x26000027: return "osltestsigning";
case 0x26000030: return "nolowmem";
case 0x25000031: return "removememory";
case 0x25000032: return "increaseuserva";
case 0x25000033: return "perfmem";
case 0x26000040: return "vga";
case 0x26000041: return "quietboot";
case 0x26000042: return "novesa";
case 0x25000050: return "clustermodeaddressing";
case 0x26000051: return "usephysicaldestination";
case 0x25000052: return "restrictapiccluster";
case 0x26000060: return "onecpu";
case 0x25000061: return "numproc";
case 0x26000062: return "maxproc";
case 0x25000063: return "configflags";
case 0x26000070: return "usefirmwarepcisettings";
case 0x25000071: return "msi";
case 0x25000072: return "pciexpress";
case 0x25000080: return "safeboot";
case 0x26000081: return "safebootalternateshell";
case 0x26000090: return "bootlog";
case 0x26000091: return "sos";
case 0x260000A0: return "debug";
case 0x260000A1: return "halbreakpoint";
case 0x260000B0: return "ems";
case 0x250000C0: return "forcefailure";
case 0x250000C1: return "driverloadfailurepolicy";
case 0x250000E0: return "bootstatuspolicy";
}
break;
case ApplicationType.Resume:
switch (identifier)
{
case 0x21000001: return "filedevice";
case 0x22000002: return "filepath";
case 0x26000003: return "customsettings";
case 0x26000004: return "pae";
case 0x21000005: return "associatedosdevice";
case 0x26000006: return "debugoptionenabled";
}
break;
case ApplicationType.MemoryDiagnostics:
switch (identifier)
{
case 0x25000001: return "passcount";
case 0x25000002: return "testmix";
case 0x25000003: return "failurecount";
case 0x25000004: return "testtofail";
}
break;
case ApplicationType.NtLoader:
case ApplicationType.SetupLoader:
switch (identifier)
{
case 0x22000001: return "bpbstring";
}
break;
case ApplicationType.Startup:
switch (identifier)
{
case 0x26000001: return "pxesoftreboot";
case 0x22000002: return "applicationname";
}
break;
}
}
else if (idClass == ElementClass.Device)
{
switch (identifier)
{
case 0x35000001: return "ramdiskimageoffset";
case 0x35000002: return "ramdisktftpclientport";
case 0x31000003: return "ramdisksdidevice";
case 0x32000004: return "ramdisksdipath";
case 0x35000005: return "ramdiskimagelength";
case 0x36000006: return "exportascd";
case 0x35000007: return "ramdisktftpblocksize";
}
}
else if (idClass == ElementClass.Hidden)
{
switch (identifier)
{
case 0x45000001: return "devicetype";
case 0x42000002: return "apprelativepath";
case 0x42000003: return "ramdiskdevicerelativepath";
case 0x46000004: return "omitosloaderelements";
case 0x46000010: return "recoveryos";
}
}
return identifier.ToString("X8", CultureInfo.InvariantCulture);
}
private static ElementClass GetClass(int identifier)
{
return (ElementClass)((identifier >> 28) & 0xF);
}
private ElementValue LoadValue()
{
switch (Format)
{
case ElementFormat.Boolean:
return new BooleanElementValue(_storage.GetBinary(_obj, _identifier));
case ElementFormat.Device:
return new DeviceElementValue(_storage.GetBinary(_obj, _identifier));
case ElementFormat.Guid:
return new GuidElementValue(_storage.GetString(_obj, _identifier));
case ElementFormat.GuidList:
return new GuidListElementValue(_storage.GetMultiString(_obj, _identifier));
case ElementFormat.Integer:
return new IntegerElementValue(_storage.GetBinary(_obj, _identifier));
case ElementFormat.IntegerList:
return new IntegerListElementValue(_storage.GetBinary(_obj, _identifier));
case ElementFormat.String:
return new StringElementValue(_storage.GetString(_obj, _identifier));
default:
throw new NotImplementedException("Unknown element format: " + Format);
}
}
private void WriteValue()
{
switch (_value.Format)
{
case ElementFormat.Boolean:
_storage.SetBinary(_obj, _identifier, ((BooleanElementValue)_value).GetBytes());
break;
case ElementFormat.Device:
_storage.SetBinary(_obj, _identifier, ((DeviceElementValue)_value).GetBytes());
break;
case ElementFormat.GuidList:
_storage.SetMultiString(_obj, _identifier, ((GuidListElementValue)_value).GetGuidStrings());
break;
case ElementFormat.Integer:
_storage.SetBinary(_obj, _identifier, ((IntegerElementValue)_value).GetBytes());
break;
case ElementFormat.IntegerList:
_storage.SetBinary(_obj, _identifier, ((IntegerListElementValue)_value).GetBytes());
break;
case ElementFormat.Guid:
case ElementFormat.String:
_storage.SetString(_obj, _identifier, _value.ToString());
break;
default:
throw new NotImplementedException("Unknown element format: " + Format);
}
}
}
}
+55
View File
@@ -0,0 +1,55 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
/// <summary>
/// The known classes of element.
/// </summary>
public enum ElementClass
{
/// <summary>
/// Unknown class.
/// </summary>
None = 0,
/// <summary>
/// Common setting.
/// </summary>
Library = 1,
/// <summary>
/// An application setting.
/// </summary>
Application = 2,
/// <summary>
/// A device (or partition) setting.
/// </summary>
Device = 3,
/// <summary>
/// A hidden setting.
/// </summary>
Hidden = 4
}
}
+70
View File
@@ -0,0 +1,70 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
/// <summary>
/// The known formats used to store BCD values.
/// </summary>
public enum ElementFormat
{
/// <summary>
/// Unknown format.
/// </summary>
None = 0,
/// <summary>
/// A block device, or partition.
/// </summary>
Device = 1,
/// <summary>
/// A unicode string.
/// </summary>
String = 2,
/// <summary>
/// A Globally Unique Identifier (GUID).
/// </summary>
Guid = 3,
/// <summary>
/// A GUID list.
/// </summary>
GuidList = 4,
/// <summary>
/// An integer.
/// </summary>
Integer = 5,
/// <summary>
/// A boolean.
/// </summary>
Boolean = 6,
/// <summary>
/// An integer list.
/// </summary>
IntegerList = 7
}
}
+138
View File
@@ -0,0 +1,138 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Globalization;
/// <summary>
/// The value of an element.
/// </summary>
public abstract class ElementValue
{
/// <summary>
/// Gets the format of the value.
/// </summary>
public abstract ElementFormat Format { get; }
/// <summary>
/// Gets the parent object (only for Device values).
/// </summary>
public virtual Guid ParentObject
{
get { return Guid.Empty; }
}
/// <summary>
/// Gets a value representing a device (aka partition).
/// </summary>
/// <param name="parentObject">Object containing detailed information about the device.</param>
/// <param name="physicalVolume">The volume to represent.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForDevice(Guid parentObject, PhysicalVolumeInfo physicalVolume)
{
return new DeviceElementValue(parentObject, physicalVolume);
}
/// <summary>
/// Gets a value representing the logical boot device.
/// </summary>
/// <returns>The boot pseudo-device as an object.</returns>
public static ElementValue ForBootDevice()
{
return new DeviceElementValue();
}
/// <summary>
/// Gets a value representing a string value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForString(string value)
{
return new StringElementValue(value);
}
/// <summary>
/// Gets a value representing an integer value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForInteger(long value)
{
return new IntegerElementValue((ulong)value);
}
/// <summary>
/// Gets a value representing an integer list value.
/// </summary>
/// <param name="values">The value to convert.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForIntegerList(long[] values)
{
ulong[] ulValues = new ulong[values.Length];
for (int i = 0; i < values.Length; ++i)
{
ulValues[i] = (ulong)values[i];
}
return new IntegerListElementValue(ulValues);
}
/// <summary>
/// Gets a value representing a boolean value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForBoolean(bool value)
{
return new BooleanElementValue(value);
}
/// <summary>
/// Gets a value representing a GUID value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForGuid(Guid value)
{
return new GuidElementValue(value.ToString("B"));
}
/// <summary>
/// Gets a value representing a GUID list value.
/// </summary>
/// <param name="values">The value to convert.</param>
/// <returns>The value as an object.</returns>
public static ElementValue ForGuidList(Guid[] values)
{
string[] strValues = new string[values.Length];
for (int i = 0; i < values.Length; ++i)
{
strValues[i] = values[i].ToString("B");
}
return new GuidListElementValue(strValues);
}
}
}
+49
View File
@@ -0,0 +1,49 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
internal class GuidElementValue : ElementValue
{
private string _value;
public GuidElementValue(string value)
{
_value = value;
}
public override ElementFormat Format
{
get { return ElementFormat.Guid; }
}
public override string ToString()
{
if (string.IsNullOrEmpty(_value))
{
return "<none>";
}
return _value;
}
}
}
@@ -0,0 +1,60 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
internal class GuidListElementValue : ElementValue
{
private string[] _values;
public GuidListElementValue(string[] values)
{
_values = values;
}
public override ElementFormat Format
{
get { return ElementFormat.GuidList; }
}
public override string ToString()
{
if (_values == null || _values.Length == 0)
{
return "<none>";
}
string result = _values[0];
for (int i = 1; i < _values.Length; ++i)
{
result += "," + _values[i];
}
return result;
}
internal string[] GetGuidStrings()
{
return _values;
}
}
}
+54
View File
@@ -0,0 +1,54 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// Indicates the type of objects that can inherit from an object.
/// </summary>
public enum InheritType
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0x0,
/// <summary>
/// Any type of object may inherit from this object.
/// </summary>
AnyObject = 0x1,
/// <summary>
/// Only Application objects may inherit from this object.
/// </summary>
ApplicationObjects = 0x2,
/// <summary>
/// Only Device objects may inherit from this object.
/// </summary>
DeviceObjects = 0x3
}
}
@@ -0,0 +1,63 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Globalization;
internal class IntegerElementValue : ElementValue
{
private ulong _value;
public IntegerElementValue(byte[] value)
{
// Actual bytes stored may be less than 8
byte[] buffer = new byte[8];
Array.Copy(value, buffer, value.Length);
_value = Utilities.ToUInt64LittleEndian(buffer, 0);
}
public IntegerElementValue(ulong value)
{
_value = value;
}
public override ElementFormat Format
{
get { return ElementFormat.Integer; }
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0}", _value);
}
internal byte[] GetBytes()
{
byte[] bytes = new byte[8];
Utilities.WriteBytesLittleEndian(_value, bytes, 0);
return bytes;
}
}
}
@@ -0,0 +1,82 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System.Globalization;
internal class IntegerListElementValue : ElementValue
{
private ulong[] _values;
public IntegerListElementValue(byte[] value)
{
_values = new ulong[value.Length / 8];
for (int i = 0; i < _values.Length; ++i)
{
_values[i] = Utilities.ToUInt64LittleEndian(value, i * 8);
}
}
public IntegerListElementValue(ulong[] values)
{
_values = values;
}
public override ElementFormat Format
{
get { return ElementFormat.IntegerList; }
}
public override string ToString()
{
if (_values == null || _values.Length == 0)
{
return "<none>";
}
string result = string.Empty;
for (int i = 0; i < _values.Length; ++i)
{
if (i != 0)
{
result += " ";
}
result += _values[i].ToString("X16", CultureInfo.InvariantCulture);
}
return result;
}
internal byte[] GetBytes()
{
byte[] bytes = new byte[_values.Length * 8];
for (int i = 0; i < _values.Length; ++i)
{
Utilities.WriteBytesLittleEndian(_values[i], bytes, i * 8);
}
return bytes;
}
}
}
+50
View File
@@ -0,0 +1,50 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
/// <summary>
/// Enumeration of known object types.
/// </summary>
public enum ObjectType
{
/// <summary>
/// An unknown type.
/// </summary>
None = 0x0,
/// <summary>
/// An application object.
/// </summary>
Application = 0x1,
/// <summary>
/// Inheritable common settings.
/// </summary>
Inherit = 0x2,
/// <summary>
/// Device (or partition) object.
/// </summary>
Device = 0x3
}
}
+149
View File
@@ -0,0 +1,149 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Globalization;
internal class PartitionRecord : DeviceRecord
{
public int PartitionType { get; set; }
public byte[] DiskIdentity { get; set; }
public byte[] PartitionIdentity { get; set; }
public override int Size
{
get { return 0x48; }
}
public override void GetBytes(byte[] data, int offset)
{
WriteHeader(data, offset);
if (Type == 5)
{
Array.Clear(data, offset + 0x10, 0x38);
}
else if (Type == 6)
{
Utilities.WriteBytesLittleEndian(PartitionType, data, offset + 0x24);
if (PartitionType == 1)
{
Array.Copy(DiskIdentity, 0, data, offset + 0x28, 4);
Array.Copy(PartitionIdentity, 0, data, offset + 0x10, 8);
}
else if (PartitionType == 0)
{
Array.Copy(DiskIdentity, 0, data, offset + 0x28, 16);
Array.Copy(PartitionIdentity, 0, data, offset + 0x10, 16);
}
else
{
throw new NotImplementedException("Unknown partition type: " + PartitionType);
}
}
else
{
throw new NotImplementedException("Unknown device type: " + Type);
}
}
public override string ToString()
{
if (Type == 5)
{
return "<boot device>";
}
else if (Type == 6)
{
if (PartitionType == 1)
{
return string.Format(
CultureInfo.InvariantCulture,
"(disk:{0:X2}{1:X2}{2:X2}{3:X2} part-offset:{4})",
DiskIdentity[0],
DiskIdentity[1],
DiskIdentity[2],
DiskIdentity[3],
Utilities.ToUInt64LittleEndian(PartitionIdentity, 0));
}
else
{
Guid diskGuid = Utilities.ToGuidLittleEndian(DiskIdentity, 0);
Guid partitionGuid = Utilities.ToGuidLittleEndian(PartitionIdentity, 0);
return string.Format(CultureInfo.InvariantCulture, "(disk:{0} partition:{1})", diskGuid, partitionGuid);
}
}
else if (Type == 8)
{
return "custom:<unknown>";
}
else
{
return "<unknown>";
}
}
protected override void DoParse(byte[] data, int offset)
{
base.DoParse(data, offset);
if (Type == 5)
{
// Nothing to do - just empty...
}
else if (Type == 6)
{
PartitionType = Utilities.ToInt32LittleEndian(data, offset + 0x24);
if (PartitionType == 1)
{
// BIOS disk
DiskIdentity = new byte[4];
Array.Copy(data, offset + 0x28, DiskIdentity, 0, 4);
PartitionIdentity = new byte[8];
Array.Copy(data, offset + 0x10, PartitionIdentity, 0, 8);
}
else if (PartitionType == 0)
{
// GPT disk
DiskIdentity = new byte[16];
Array.Copy(data, offset + 0x28, DiskIdentity, 0, 16);
PartitionIdentity = new byte[16];
Array.Copy(data, offset + 0x10, PartitionIdentity, 0, 16);
}
else
{
throw new NotImplementedException("Unknown partition type: " + PartitionType);
}
}
else
{
throw new NotImplementedException("Unknown device type: " + Type);
}
}
}
}
+168
View File
@@ -0,0 +1,168 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
using System;
using System.Collections.Generic;
using DiscUtils.Registry;
/// <summary>
/// Represents a Boot Configuration Database store (i.e. a BCD file).
/// </summary>
public class Store
{
private BaseStorage _store;
/// <summary>
/// Initializes a new instance of the Store class.
/// </summary>
/// <param name="key">The registry key that is the root of the configuration database.</param>
public Store(RegistryKey key)
{
_store = new DiscUtilsRegistryStorage(key);
}
/// <summary>
/// Gets the objects within the store.
/// </summary>
public IEnumerable<BcdObject> Objects
{
get
{
foreach (var obj in _store.EnumerateObjects())
{
yield return new BcdObject(_store, obj);
}
}
}
/// <summary>
/// Initializes a new Boot Configuration Database.
/// </summary>
/// <param name="root">The registry key at the root of the database.</param>
/// <returns>The BCD store.</returns>
public static Store Initialize(RegistryKey root)
{
RegistryKey descKey = root.CreateSubKey("Description");
descKey.SetValue("KeyName", "BCD00000001");
root.CreateSubKey("Objects");
return new Store(root);
}
/// <summary>
/// Gets an object from the store.
/// </summary>
/// <param name="id">The identity of the object.</param>
/// <returns>The requested object, or <c>null</c>.</returns>
public BcdObject GetObject(Guid id)
{
if (_store.ObjectExists(id))
{
return new BcdObject(_store, id);
}
else
{
return null;
}
}
/// <summary>
/// Creates a specific object.
/// </summary>
/// <param name="id">The identity of the object to create.</param>
/// <param name="type">The object's type.</param>
/// <returns>The object representing the new application.</returns>
public BcdObject CreateObject(Guid id, int type)
{
_store.CreateObject(id, type);
return new BcdObject(_store, id);
}
/// <summary>
/// Creates an application object.
/// </summary>
/// <param name="imageType">The image type of the application.</param>
/// <param name="appType">The application's type.</param>
/// <returns>The object representing the new application.</returns>
public BcdObject CreateApplication(ApplicationImageType imageType, ApplicationType appType)
{
Guid obj = _store.CreateObject(Guid.NewGuid(), BcdObject.MakeApplicationType(imageType, appType));
return new BcdObject(_store, obj);
}
/// <summary>
/// Creates an application object.
/// </summary>
/// <param name="id">The identity of the object to create.</param>
/// <param name="imageType">The image type of the application.</param>
/// <param name="appType">The application's type.</param>
/// <returns>The object representing the new application.</returns>
public BcdObject CreateApplication(Guid id, ApplicationImageType imageType, ApplicationType appType)
{
Guid obj = _store.CreateObject(id, BcdObject.MakeApplicationType(imageType, appType));
return new BcdObject(_store, obj);
}
/// <summary>
/// Creates an 'inherit' object that contains common settings.
/// </summary>
/// <param name="inheritType">The type of object the settings apply to.</param>
/// <returns>The object representing the new settings.</returns>
public BcdObject CreateInherit(InheritType inheritType)
{
Guid obj = _store.CreateObject(Guid.NewGuid(), BcdObject.MakeInheritType(inheritType));
return new BcdObject(_store, obj);
}
/// <summary>
/// Creates an 'inherit' object that contains common settings.
/// </summary>
/// <param name="id">The identity of the object to create.</param>
/// <param name="inheritType">The type of object the settings apply to.</param>
/// <returns>The object representing the new settings.</returns>
public BcdObject CreateInherit(Guid id, InheritType inheritType)
{
Guid obj = _store.CreateObject(id, BcdObject.MakeInheritType(inheritType));
return new BcdObject(_store, obj);
}
/// <summary>
/// Creates a new device object, representing a partition.
/// </summary>
/// <returns>The object representing the new device.</returns>
public BcdObject CreateDevice()
{
Guid obj = _store.CreateObject(Guid.NewGuid(), 0x30000000);
return new BcdObject(_store, obj);
}
/// <summary>
/// Removes an object.
/// </summary>
/// <param name="id">The identity of the object to remove.</param>
public void RemoveObject(Guid id)
{
_store.DeleteObject(id);
}
}
}
@@ -0,0 +1,44 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.BootConfig
{
internal class StringElementValue : ElementValue
{
private string _value;
public StringElementValue(string value)
{
_value = value;
}
public override ElementFormat Format
{
get { return ElementFormat.String; }
}
public override string ToString()
{
return _value;
}
}
}
+618
View File
@@ -0,0 +1,618 @@
//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
//
// Symbolic names of BCD Elements taken from Geoff Chappell's website:
// http://www.geoffchappell.com/viewer.htm?doc=notes/windows/boot/bcd/elements.htm
//
//
namespace DiscUtils.BootConfig
{
/// <summary>
/// Enumeration of known BCD elements.
/// </summary>
public enum WellKnownElement : int
{
/// <summary>
/// Not specified.
/// </summary>
None = 0,
/// <summary>
/// Device containing the application.
/// </summary>
LibraryApplicationDevice = 0x11000001,
/// <summary>
/// Path to the application.
/// </summary>
LibraryApplicationPath = 0x12000002,
/// <summary>
/// Description of the object.
/// </summary>
LibraryDescription = 0x12000004,
/// <summary>
/// Preferred locale of the object.
/// </summary>
LibraryPreferredLocale = 0x12000005,
/// <summary>
/// Objects containing elements inherited by the object.
/// </summary>
LibraryInheritedObjects = 0x14000006,
/// <summary>
/// Upper bound on physical addresses used by Windows.
/// </summary>
LibraryTruncatePhysicalMemory = 0x15000007,
/// <summary>
/// List of objects, indicating recovery sequence.
/// </summary>
LibraryRecoverySequence = 0x14000008,
/// <summary>
/// Enables auto recovery.
/// </summary>
LibraryAutoRecoveryEnabled = 0x16000009,
/// <summary>
/// List of bad memory regions.
/// </summary>
LibraryBadMemoryList = 0x1700000A,
/// <summary>
/// Allow use of bad memory regions.
/// </summary>
LibraryAllowBadMemoryAccess = 0x1600000B,
/// <summary>
/// Policy on use of first mega-byte of physical RAM.
/// </summary>
/// <remarks>0 = UseNone, 1 = UseAll, 2 = UsePrivate.</remarks>
LibraryFirstMegaBytePolicy = 0x1500000C,
/// <summary>
/// Debugger enabled.
/// </summary>
LibraryDebuggerEnabled = 0x16000010,
/// <summary>
/// Debugger type.
/// </summary>
/// <remarks>0 = Serial, 1 = 1394, 2 = USB.</remarks>
LibraryDebuggerType = 0x15000011,
/// <summary>
/// Debugger serial port address.
/// </summary>
LibraryDebuggerSerialAddress = 0x15000012,
/// <summary>
/// Debugger serial port.
/// </summary>
LibraryDebuggerSerialPort = 0x15000013,
/// <summary>
/// Debugger serial port baud rate.
/// </summary>
LibraryDebuggerSerialBaudRate = 0x15000014,
/// <summary>
/// Debugger 1394 channel.
/// </summary>
LibraryDebugger1394Channel = 0x15000015,
/// <summary>
/// Debugger USB target name.
/// </summary>
LibraryDebuggerUsbTargetName = 0x12000016,
/// <summary>
/// Debugger ignores user mode exceptions.
/// </summary>
LibraryDebuggerIgnoreUserModeExceptions = 0x16000017,
/// <summary>
/// Debugger start policy.
/// </summary>
/// <remarks>0 = Active, 1 = AutoEnable, 2 = Disable.</remarks>
LibraryDebuggerStartPolicy = 0x15000018,
/// <summary>
/// Emergency Management System enabled.
/// </summary>
LibraryEmergencyManagementSystemEnabled = 0x16000020,
/// <summary>
/// Emergency Management System serial port.
/// </summary>
LibraryEmergencyManagementSystemPort = 0x15000022,
/// <summary>
/// Emergency Management System baud rate.
/// </summary>
LibraryEmergencyManagementSystemBaudRate = 0x15000023,
/// <summary>
/// Load options.
/// </summary>
LibraryLoadOptions = 0x12000030,
/// <summary>
/// Displays advanced options.
/// </summary>
LibraryDisplayAdvancedOptions = 0x16000040,
/// <summary>
/// Displays UI to edit advanced options.
/// </summary>
LibraryDisplayOptionsEdit = 0x16000041,
/// <summary>
/// FVE (Full Volume Encryption - aka BitLocker?) KeyRing address.
/// </summary>
LibraryFveKeyRingAddress = 0x16000042,
/// <summary>
/// Device to contain Boot Status Log.
/// </summary>
LibraryBootStatusLogDevice = 0x11000043,
/// <summary>
/// Path to Boot Status Log.
/// </summary>
LibraryBootStatusLogFile = 0x12000044,
/// <summary>
/// Whether to append to the existing Boot Status Log.
/// </summary>
LibraryBootStatusLogAppend = 0x12000045,
/// <summary>
/// Disables graphics mode.
/// </summary>
LibraryGraphicsModeDisabled = 0x16000046,
/// <summary>
/// Configure access policy.
/// </summary>
/// <remarks>0 = default, 1 = DisallowMmConfig.</remarks>
LibraryConfigAccessPolicy = 0x15000047,
/// <summary>
/// Disables integrity checks.
/// </summary>
LibraryDisableIntegrityChecks = 0x16000048,
/// <summary>
/// Allows pre-release signatures (test signing).
/// </summary>
LibraryAllowPrereleaseSignatures = 0x16000049,
/// <summary>
/// Console extended input.
/// </summary>
LibraryConsoleExtendedInput = 0x16000050,
/// <summary>
/// Initial console input.
/// </summary>
LibraryInitialConsoleInput = 0x15000051,
/// <summary>
/// Application display order.
/// </summary>
BootMgrDisplayOrder = 0x24000001,
/// <summary>
/// Application boot sequence.
/// </summary>
BootMgrBootSequence = 0x24000002,
/// <summary>
/// Default application.
/// </summary>
BootMgrDefaultObject = 0x23000003,
/// <summary>
/// User input timeout.
/// </summary>
BootMgrTimeout = 0x25000004,
/// <summary>
/// Attempt to resume from hibernated state.
/// </summary>
BootMgrAttemptResume = 0x26000005,
/// <summary>
/// The resume application.
/// </summary>
BootMgrResumeObject = 0x23000006,
/// <summary>
/// The tools display order.
/// </summary>
BootMgrToolsDisplayOrder = 0x24000010,
/// <summary>
/// Displays the boot menu.
/// </summary>
BootMgrDisplayBootMenu = 0x26000020,
/// <summary>
/// No error display.
/// </summary>
BootMgrNoErrorDisplay = 0x26000021,
/// <summary>
/// The BCD device.
/// </summary>
BootMgrBcdDevice = 0x21000022,
/// <summary>
/// The BCD file path.
/// </summary>
BootMgrBcdFilePath = 0x22000023,
/// <summary>
/// The custom actions list.
/// </summary>
BootMgrCustomActionsList = 0x27000030,
/// <summary>
/// Device containing the Operating System.
/// </summary>
OsLoaderOsDevice = 0x21000001,
/// <summary>
/// System root on the OS device.
/// </summary>
OsLoaderSystemRoot = 0x22000002,
/// <summary>
/// The resume application associated with this OS.
/// </summary>
OsLoaderAssociatedResumeObject = 0x23000003,
/// <summary>
/// Auto-detect the correct kernel &amp; HAL.
/// </summary>
OsLoaderDetectKernelAndHal = 0x26000010,
/// <summary>
/// The filename of the kernel.
/// </summary>
OsLoaderKernelPath = 0x22000011,
/// <summary>
/// The filename of the HAL.
/// </summary>
OsLoaderHalPath = 0x22000012,
/// <summary>
/// The debug transport path.
/// </summary>
OsLoaderDebugTransportPath = 0x22000013,
/// <summary>
/// NX (No-Execute) policy.
/// </summary>
/// <remarks>0 = OptIn, 1 = OptOut, 2 = AlwaysOff, 3 = AlwaysOn.</remarks>
OsLoaderNxPolicy = 0x25000020,
/// <summary>
/// PAE policy.
/// </summary>
/// <remarks>0 = default, 1 = ForceEnable, 2 = ForceDisable.</remarks>
OsLoaderPaePolicy = 0x25000021,
/// <summary>
/// WinPE mode.
/// </summary>
OsLoaderWinPeMode = 0x26000022,
/// <summary>
/// Disable automatic reboot on OS crash.
/// </summary>
OsLoaderDisableCrashAutoReboot = 0x26000024,
/// <summary>
/// Use the last known good settings.
/// </summary>
OsLoaderUseLastGoodSettings = 0x26000025,
/// <summary>
/// Disable integrity checks.
/// </summary>
OsLoaderDisableIntegrityChecks = 0x26000026,
/// <summary>
/// Allows pre-release signatures (test signing).
/// </summary>
OsLoaderAllowPrereleaseSignatures = 0x26000027,
/// <summary>
/// Loads all executables above 4GB boundary.
/// </summary>
OsLoaderNoLowMemory = 0x26000030,
/// <summary>
/// Excludes a given amount of memory from use by Windows.
/// </summary>
OsLoaderRemoveMemory = 0x25000031,
/// <summary>
/// Increases the User Mode virtual address space.
/// </summary>
OsLoaderIncreaseUserVa = 0x25000032,
/// <summary>
/// Size of buffer (in MB) for perfomance data logging.
/// </summary>
OsLoaderPerformanceDataMemory = 0x25000033,
/// <summary>
/// Uses the VGA display driver.
/// </summary>
OsLoaderUseVgaDriver = 0x26000040,
/// <summary>
/// Quiet boot.
/// </summary>
OsLoaderDisableBootDisplay = 0x26000041,
/// <summary>
/// Disables use of the VESA BIOS.
/// </summary>
OsLoaderDisableVesaBios = 0x26000042,
/// <summary>
/// Maximum processors in a single APIC cluster.
/// </summary>
OsLoaderClusterModeAddressing = 0x25000050,
/// <summary>
/// Forces the physical APIC to be used.
/// </summary>
OsLoaderUsePhysicalDestination = 0x26000051,
/// <summary>
/// The largest APIC cluster number the system can use.
/// </summary>
OsLoaderRestrictApicCluster = 0x25000052,
/// <summary>
/// Forces only the boot processor to be used.
/// </summary>
OsLoaderUseBootProcessorOnly = 0x26000060,
/// <summary>
/// The number of processors to be used.
/// </summary>
OsLoaderNumberOfProcessors = 0x25000061,
/// <summary>
/// Use maximum number of processors.
/// </summary>
OsLoaderForceMaxProcessors = 0x26000062,
/// <summary>
/// Processor specific configuration flags.
/// </summary>
OsLoaderProcessorConfigurationFlags = 0x25000063,
/// <summary>
/// Uses BIOS-configured PCI resources.
/// </summary>
OsLoaderUseFirmwarePciSettings = 0x26000070,
/// <summary>
/// Message Signalled Interrupt setting.
/// </summary>
OsLoaderMsiPolicy = 0x25000071,
/// <summary>
/// PCE Express Policy.
/// </summary>
OsLoaderPciExpressPolicy = 0x25000072,
/// <summary>
/// The safe boot option.
/// </summary>
/// <remarks>0 = Minimal, 1 = Network, 2 = DsRepair.</remarks>
OsLoaderSafeBoot = 0x25000080,
/// <summary>
/// Loads the configured alternate shell during a safe boot.
/// </summary>
OsLoaderSafeBootAlternateShell = 0x26000081,
/// <summary>
/// Enables boot log.
/// </summary>
OsLoaderBootLogInitialization = 0x26000090,
/// <summary>
/// Displays diagnostic information during boot.
/// </summary>
OsLoaderVerboseObjectLoadMode = 0x26000091,
/// <summary>
/// Enables the kernel debugger.
/// </summary>
OsLoaderKernelDebuggerEnabled = 0x260000A0,
/// <summary>
/// Causes the kernal to halt early during boot.
/// </summary>
OsLoaderDebuggerHalBreakpoint = 0x260000A1,
/// <summary>
/// Enables Windows Emergency Management System.
/// </summary>
OsLoaderEmsEnabled = 0x260000B0,
/// <summary>
/// Forces a failure on boot.
/// </summary>
OsLoaderForceFailure = 0x250000C0,
/// <summary>
/// The OS failure policy.
/// </summary>
OsLoaderDriverLoadFailurePolicy = 0x250000C1,
/// <summary>
/// The OS boot status policy.
/// </summary>
OsLoaderBootStatusPolicy = 0x250000E0,
/// <summary>
/// The device containing the hibernation file.
/// </summary>
ResumeHiberFileDevice = 0x21000001,
/// <summary>
/// The path to the hibernation file.
/// </summary>
ResumeHiberFilePath = 0x22000002,
/// <summary>
/// Allows resume loader to use custom settings.
/// </summary>
ResumeUseCustomSettings = 0x26000003,
/// <summary>
/// PAE settings for resume application.
/// </summary>
ResumePaeMode = 0x26000004,
/// <summary>
/// An MS-DOS device with containing resume application.
/// </summary>
ResumeAssociatedDosDevice = 0x21000005,
/// <summary>
/// Enables debug option.
/// </summary>
ResumeDebugOptionEnabled = 0x26000006,
/// <summary>
/// The number of iterations to run.
/// </summary>
MemDiagPassCount = 0x25000001,
/// <summary>
/// The test mix.
/// </summary>
MemDiagTestMix = 0x25000002,
/// <summary>
/// The failure count.
/// </summary>
MemDiagFailureCount = 0x25000003,
/// <summary>
/// The tests to fail.
/// </summary>
MemDiagTestToFail = 0x25000004,
/// <summary>
/// BPB string.
/// </summary>
LoaderBpbString = 0x22000001,
/// <summary>
/// Causes a soft PXE reboot.
/// </summary>
StartupPxeSoftReboot = 0x26000001,
/// <summary>
/// PXE application name.
/// </summary>
StartupPxeApplicationName = 0x22000002,
/// <summary>
/// Offset of the RAM disk image.
/// </summary>
DeviceRamDiskImageOffset = 0x35000001,
/// <summary>
/// Client port for TFTP.
/// </summary>
DeviceRamDiskTftpClientPort = 0x35000002,
/// <summary>
/// Device containing the SDI file.
/// </summary>
DeviceRamDiskSdiDevice = 0x31000003,
/// <summary>
/// Path to the SDI file.
/// </summary>
DeviceRamDiskSdiPath = 0x32000004,
/// <summary>
/// Length of the RAM disk image.
/// </summary>
DeviceRamDiskRamDiskImageLength = 0x35000005,
/// <summary>
/// Exports the image as a CD.
/// </summary>
DeviceRamDiskExportAsCd = 0x36000006,
/// <summary>
/// The TFTP transfer block size.
/// </summary>
DeviceRamDiskTftpBlockSize = 0x35000007,
/// <summary>
/// The device type.
/// </summary>
SetupDeviceType = 0x45000001,
/// <summary>
/// The application relative path.
/// </summary>
SetupAppRelativePath = 0x42000002,
/// <summary>
/// The device relative path.
/// </summary>
SetupRamDiskDeviceRelativePath = 0x42000003,
/// <summary>
/// Omit OS loader elements.
/// </summary>
SetupOmitOsLoaderElements = 0x46000004,
/// <summary>
/// Recovery OS flag.
/// </summary>
SetupRecoveryOs = 0x46000010,
}
}