2018-06-23 04:02:19 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace libhac
|
|
|
|
|
{
|
|
|
|
|
public class Cnmt
|
|
|
|
|
{
|
|
|
|
|
public ulong TitleId { get; set; }
|
2018-07-01 22:12:59 +02:00
|
|
|
|
public TitleVersion TitleVersion { get; set; }
|
2018-06-23 04:02:19 +02:00
|
|
|
|
public TitleType Type { get; set; }
|
|
|
|
|
public byte FieldD { get; set; }
|
|
|
|
|
public int TableOffset { get; set; }
|
|
|
|
|
public int ContentEntryCount { get; set; }
|
|
|
|
|
public int MetaEntryCount { get; set; }
|
|
|
|
|
|
|
|
|
|
public CnmtContentEntry[] ContentEntries { get; set; }
|
2018-07-01 22:12:59 +02:00
|
|
|
|
public CnmtMetaEntry[] MetaEntries { get; set; }
|
|
|
|
|
|
|
|
|
|
public ulong ApplicationTitleId { get; set; }
|
|
|
|
|
public ulong PatchTitleId { get; set; }
|
|
|
|
|
public TitleVersion MinimumSystemVersion { get; }
|
|
|
|
|
public TitleVersion MinimumApplicationVersion { get; }
|
2018-06-23 04:02:19 +02:00
|
|
|
|
|
|
|
|
|
public Cnmt(Stream file)
|
|
|
|
|
{
|
|
|
|
|
using (var reader = new BinaryReader(file))
|
|
|
|
|
{
|
|
|
|
|
TitleId = reader.ReadUInt64();
|
2018-07-01 22:12:59 +02:00
|
|
|
|
var version = reader.ReadUInt32();
|
2018-06-23 04:02:19 +02:00
|
|
|
|
Type = (TitleType)reader.ReadByte();
|
2018-07-01 22:12:59 +02:00
|
|
|
|
TitleVersion = new TitleVersion(version, Type < TitleType.Application);
|
2018-06-23 04:02:19 +02:00
|
|
|
|
FieldD = reader.ReadByte();
|
|
|
|
|
TableOffset = reader.ReadUInt16();
|
|
|
|
|
ContentEntryCount = reader.ReadUInt16();
|
|
|
|
|
MetaEntryCount = reader.ReadUInt16();
|
|
|
|
|
file.Position += 12;
|
2018-07-01 22:12:59 +02:00
|
|
|
|
|
|
|
|
|
switch (Type)
|
|
|
|
|
{
|
|
|
|
|
case TitleType.Application:
|
2018-07-02 20:16:38 +02:00
|
|
|
|
ApplicationTitleId = TitleId;
|
2018-07-01 22:12:59 +02:00
|
|
|
|
PatchTitleId = reader.ReadUInt64();
|
|
|
|
|
MinimumSystemVersion = new TitleVersion(reader.ReadUInt32(), true);
|
|
|
|
|
break;
|
|
|
|
|
case TitleType.Patch:
|
|
|
|
|
ApplicationTitleId = reader.ReadUInt64();
|
|
|
|
|
MinimumSystemVersion = new TitleVersion(reader.ReadUInt32(), true);
|
|
|
|
|
break;
|
|
|
|
|
case TitleType.AddOnContent:
|
|
|
|
|
ApplicationTitleId = reader.ReadUInt64();
|
|
|
|
|
MinimumApplicationVersion = new TitleVersion(reader.ReadUInt32());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.Position = 0x20 + TableOffset;
|
2018-06-23 04:02:19 +02:00
|
|
|
|
|
|
|
|
|
ContentEntries = new CnmtContentEntry[ContentEntryCount];
|
2018-07-01 22:12:59 +02:00
|
|
|
|
MetaEntries = new CnmtMetaEntry[MetaEntryCount];
|
2018-06-23 04:02:19 +02:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ContentEntryCount; i++)
|
|
|
|
|
{
|
|
|
|
|
ContentEntries[i] = new CnmtContentEntry(reader);
|
|
|
|
|
}
|
2018-07-01 22:12:59 +02:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < MetaEntryCount; i++)
|
|
|
|
|
{
|
|
|
|
|
MetaEntries[i] = new CnmtMetaEntry(reader);
|
|
|
|
|
}
|
2018-06-23 04:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CnmtContentEntry
|
|
|
|
|
{
|
|
|
|
|
public byte[] Hash { get; set; }
|
|
|
|
|
public byte[] NcaId { get; set; }
|
|
|
|
|
public long Size { get; set; }
|
|
|
|
|
public CnmtContentType Type { get; set; }
|
|
|
|
|
|
|
|
|
|
public CnmtContentEntry(BinaryReader reader)
|
|
|
|
|
{
|
|
|
|
|
Hash = reader.ReadBytes(0x20);
|
|
|
|
|
NcaId = reader.ReadBytes(0x10);
|
|
|
|
|
Size = reader.ReadUInt32();
|
|
|
|
|
Size |= ((long)reader.ReadUInt16() << 32);
|
|
|
|
|
Type = (CnmtContentType)reader.ReadByte();
|
|
|
|
|
reader.BaseStream.Position += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-01 22:12:59 +02:00
|
|
|
|
public class CnmtMetaEntry
|
|
|
|
|
{
|
|
|
|
|
public ulong TitleId { get; }
|
|
|
|
|
public TitleVersion Version { get; }
|
|
|
|
|
public CnmtContentType Type { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CnmtMetaEntry(BinaryReader reader)
|
|
|
|
|
{
|
|
|
|
|
TitleId = reader.ReadUInt64();
|
|
|
|
|
Version = new TitleVersion(reader.ReadUInt32(), true);
|
|
|
|
|
Type = (CnmtContentType)reader.ReadByte();
|
|
|
|
|
reader.BaseStream.Position += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-23 04:02:19 +02:00
|
|
|
|
public enum CnmtContentType
|
|
|
|
|
{
|
|
|
|
|
Meta,
|
|
|
|
|
Program,
|
|
|
|
|
Data,
|
|
|
|
|
Control,
|
|
|
|
|
OfflineManualHtml,
|
|
|
|
|
LegalHtml,
|
|
|
|
|
UpdatePatch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum TitleType
|
|
|
|
|
{
|
|
|
|
|
SystemProgram = 1,
|
2018-07-01 22:12:59 +02:00
|
|
|
|
SystemData,
|
2018-06-23 04:02:19 +02:00
|
|
|
|
SystemUpdate,
|
2018-07-01 22:12:59 +02:00
|
|
|
|
BootImagePackage,
|
|
|
|
|
BootImagePackageSafe,
|
2018-06-25 21:01:24 +02:00
|
|
|
|
Application = 0x80,
|
|
|
|
|
Patch,
|
2018-06-23 04:02:19 +02:00
|
|
|
|
AddOnContent,
|
|
|
|
|
DeltaTitle
|
|
|
|
|
}
|
|
|
|
|
}
|