Remove old classes

This commit is contained in:
Alex Barney 2018-10-12 21:06:21 -05:00
parent e1b9f9b935
commit 75dafd9cbe
8 changed files with 24 additions and 96 deletions

View file

@ -19,7 +19,7 @@ namespace LibHac
public Bktr(Stream patchRomfs, Stream baseRomfs, NcaSection section)
{
if (section.Type != SectionType.Bktr) throw new ArgumentException("Section is not of type BKTR");
if (section.Header.EncryptionType != NcaEncryptionType.AesCtrEx) throw new ArgumentException("Section is not of type BKTR");
Patch = patchRomfs ?? throw new NullReferenceException($"{nameof(patchRomfs)} cannot be null");
Base = baseRomfs ?? throw new NullReferenceException($"{nameof(baseRomfs)} cannot be null");

View file

@ -371,21 +371,19 @@ namespace LibHac
long offset = 0;
long size = 0;
switch (sect.Type)
switch (sect.Header.HashType)
{
case SectionType.Invalid:
break;
case SectionType.Pfs0:
case NcaHashType.Sha256:
offset = sect.Header.Sha256Info.HashTableOffset;
size = sect.Header.Sha256Info.HashTableSize;
break;
case SectionType.Romfs:
case NcaHashType.Ivfc when sect.Header.EncryptionType == NcaEncryptionType.AesCtrEx:
CheckBktrKey(sect);
break;
case NcaHashType.Ivfc:
offset = sect.Header.IvfcInfo.LevelHeaders[0].LogicalOffset;
size = 1 << sect.Header.IvfcInfo.LevelHeaders[0].BlockSizePower;
break;
case SectionType.Bktr:
CheckBktrKey(sect);
return;
}
Stream stream = OpenSection(index, true, IntegrityCheckLevel.None);
@ -395,7 +393,7 @@ namespace LibHac
stream.Read(hashTable, 0, hashTable.Length);
sect.MasterHashValidity = Crypto.CheckMemoryHashTable(hashTable, expected, 0, hashTable.Length);
if (sect.Type == SectionType.Romfs) sect.Header.IvfcInfo.LevelHeaders[0].HashValidity = sect.MasterHashValidity;
if (sect.Header.HashType == NcaHashType.Ivfc) sect.Header.IvfcInfo.LevelHeaders[0].HashValidity = sect.MasterHashValidity;
}
public void Dispose()

View file

@ -148,32 +148,6 @@ namespace LibHac
}
}
public class RomfsSuperblock
{
public IvfcHeader IvfcHeader;
public RomfsSuperblock(BinaryReader reader)
{
IvfcHeader = new IvfcHeader(reader);
reader.BaseStream.Position += 0x58;
}
}
public class BktrSuperblock
{
public IvfcHeader IvfcHeader;
public BktrHeader RelocationHeader;
public BktrHeader SubsectionHeader;
public BktrSuperblock(BinaryReader reader)
{
IvfcHeader = new IvfcHeader(reader);
reader.BaseStream.Position += 0x18;
RelocationHeader = new BktrHeader(reader);
SubsectionHeader = new BktrHeader(reader);
}
}
public class BktrPatchInfo
{
public BktrHeader RelocationHeader;
@ -304,18 +278,6 @@ namespace LibHac
}
}
public class Pfs0Section
{
public PfsSuperblock Superblock { get; set; }
public Validity Validity { get; set; }
}
public class RomfsSection
{
public RomfsSuperblock Superblock { get; set; }
public IvfcLevel[] IvfcLevels { get; set; } = new IvfcLevel[Romfs.IvfcMaxLevel];
}
public enum ProgramPartitionType
{
Code,

View file

@ -68,29 +68,6 @@ namespace LibHac
Hfs0
}
public class PfsSuperblock
{
public byte[] MasterHash; /* SHA-256 hash of the hash table. */
public int BlockSize; /* In bytes. */
public uint Always2;
public long HashTableOffset; /* Normally zero. */
public long HashTableSize;
public long Pfs0Offset;
public long Pfs0Size;
public PfsSuperblock(BinaryReader reader)
{
MasterHash = reader.ReadBytes(0x20);
BlockSize = reader.ReadInt32();
Always2 = reader.ReadUInt32();
HashTableOffset = reader.ReadInt64();
HashTableSize = reader.ReadInt64();
Pfs0Offset = reader.ReadInt64();
Pfs0Size = reader.ReadInt64();
reader.BaseStream.Position += 0xF0;
}
}
public class PfsHeader
{
public string Magic;

View file

@ -143,19 +143,6 @@ namespace LibHac
}
}
public class IvfcLevel
{
public long DataOffset { get; set; }
public long DataSize { get; set; }
public long HashOffset { get; set; }
public long HashSize { get; set; }
public long HashBlockSize { get; set; }
public long HashBlockCount { get; set; }
public Validity HashValidity { get; set; }
}
public static class RomfsExtensions
{
public static void Extract(this Romfs romfs, string outDir, IProgressReport logger = null)

View file

@ -15,9 +15,10 @@ hactoolnet is an example program that uses LibHac. It is used in a similar manne
Usage: hactoolnet.exe [options...] <path>
Options:
-r, --raw Keep raw data, don't unpack.
-y, --verify Verify hashes.
-y, --verify Verify all hashes in the input file.
-h, --enablehash Enable hash checks when reading the input file.
-k, --keyset Load keys from an external file.
-t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, switchfs, save, keygen]
-t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, ini1, kip1, switchfs, save, keygen]
--titlekeys <file> Load title keys from an external file.
NCA options:
--section0 <file> Specify Section 0 file path.
@ -53,6 +54,8 @@ Package1 options:
--outdir <dir> Specify Package1 directory path.
Package2 options:
--outdir <dir> Specify Package2 directory path.
INI1 options:
--outdir <dir> Specify INI1 directory path.
Switch FS options:
--sdseed <seed> Set console unique seed for SD card NAX0 encryption.
--listapps List application info.
@ -64,10 +67,13 @@ Switch FS options:
--romfs <file> Specify RomFS directory path. (--title must be specified)
--romfsdir <dir> Specify RomFS directory path. (--title must be specified)
--savedir <dir> Specify save file directory path.
-y, --verify Verify all titles, or verify a single title if --title is set.
Savefile options:
--outdir <dir> Specify directory path to save contents to.
--debugoutdir <dir> Specify directory path to save intermediate data to for debugging.
--sign Sign the save file. (Requires device_key in key file)
Keygen options:
--outdir <dir> Specify directory path to save key files to.
```
## Examples

View file

@ -198,6 +198,7 @@ namespace hactoolnet
sb.AppendLine(" --romfs <file> Specify RomFS directory path. (--title must be specified)");
sb.AppendLine(" --romfsdir <dir> Specify RomFS directory path. (--title must be specified)");
sb.AppendLine(" --savedir <dir> Specify save file directory path.");
sb.AppendLine(" -y, --verify Verify all titles, or verify a single title if --title is set.");
sb.AppendLine("Savefile options:");
sb.AppendLine(" --outdir <dir> Specify directory path to save contents to.");
sb.AppendLine(" --debugoutdir <dir> Specify directory path to save intermediate data to for debugging.");

View file

@ -160,16 +160,13 @@ namespace hactoolnet
PrintItem(sb, colLen, " Partition Type:", sect.IsExefs ? "ExeFS" : sect.Type.ToString());
PrintItem(sb, colLen, " Section CTR:", sect.Header.Ctr);
switch (sect.Type)
switch (sect.Header.HashType)
{
case SectionType.Pfs0:
PrintPfs0(sect);
case NcaHashType.Sha256:
PrintSha256Hash(sect);
break;
case SectionType.Romfs:
PrintRomfs(sect);
break;
case SectionType.Bktr:
PrintRomfs(sect);
case NcaHashType.Ivfc:
PrintIvfcHash(sect);
break;
default:
sb.AppendLine(" Unknown/invalid superblock!");
@ -178,7 +175,7 @@ namespace hactoolnet
}
}
void PrintPfs0(NcaSection sect)
void PrintSha256Hash(NcaSection sect)
{
Sha256Info hashInfo = sect.Header.Sha256Info;
@ -192,7 +189,7 @@ namespace hactoolnet
PrintItem(sb, colLen, " PFS0 Size:", $"0x{hashInfo.DataSize:x12}");
}
void PrintRomfs(NcaSection sect)
void PrintIvfcHash(NcaSection sect)
{
IvfcHeader ivfcInfo = sect.Header.IvfcInfo;