ctr_test_tools/TwlBkpCheck/Windows/TWLBackupBlock/TmdReserved.cs
n2460 f26671db85 TwlBkpCheck/Windows:ヘッダ情報の更新(今までのは Legacy としてクラス分け)
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_test_tools@27 6b0af911-cb57-b745-895f-eec5701120e1
2011-10-19 08:51:52 +00:00

83 lines
2.5 KiB
C#

using System;
using System.IO;
using System.Diagnostics;
namespace TwlBackupBlock
{
/// <summary>
/// ヘッダブロック中のTMDReserved。
/// Normal, Legacy 共に共通。
/// </summary>
public class TmdReserved
{
private const int TMD_RESERVED_SIZE = 62;
public const int RESERVED8_SIZE = 3;
public const int PARENTAL_CONTROL_SIZE = 16;
public const int RESERVED_SIZE = 30;
public UInt32 publicSaveSize;
public UInt32 privateSaveSize;
public UInt32 reserved32;
public Byte flags;
public readonly Byte[] reserved8;
public readonly Byte[] parentalControl;
public readonly Byte[] reserved;
public TmdReserved()
{
reserved8 = new Byte[RESERVED8_SIZE];
parentalControl = new Byte[PARENTAL_CONTROL_SIZE];
reserved = new Byte[RESERVED_SIZE];
}
public byte[] GetBytes()
{
byte[] bytes = new byte[TMD_RESERVED_SIZE];
using (var ms = new MemoryStream(bytes))
using (var bw = new BinaryWriter(ms))
{
bw.Write(publicSaveSize);
bw.Write(privateSaveSize);
bw.Write(reserved32);
bw.Write(flags);
bw.Write(reserved8);
bw.Write(parentalControl);
bw.Write(reserved);
Debug.Assert(ms.Position == TMD_RESERVED_SIZE);
}
return bytes;
}
public void SetBytes(byte[] bytes)
{
if (bytes == null)
{
throw new ArgumentNullException("bytes");
}
if (bytes.Length != TMD_RESERVED_SIZE)
{
string message = string.Format("bytes.Length != {0} (bytes.Length:{1})", TMD_RESERVED_SIZE, bytes.Length);
throw new ArgumentException("bytes", message);
}
using (var ms = new MemoryStream(bytes))
using (var br = new ExtBinaryReader(ms))
{
br.Read(ref publicSaveSize);
br.Read(ref privateSaveSize);
br.Read(ref reserved32);
br.Read(ref flags);
br.Read(reserved8);
br.Read(parentalControl);
br.Read(reserved);
Debug.Assert(ms.Position == TMD_RESERVED_SIZE);
}
}
}
}