mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Remove old classes
This commit is contained in:
parent
e1b9f9b935
commit
75dafd9cbe
8 changed files with 24 additions and 96 deletions
|
@ -19,7 +19,7 @@ namespace LibHac
|
||||||
|
|
||||||
public Bktr(Stream patchRomfs, Stream baseRomfs, NcaSection section)
|
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");
|
Patch = patchRomfs ?? throw new NullReferenceException($"{nameof(patchRomfs)} cannot be null");
|
||||||
Base = baseRomfs ?? throw new NullReferenceException($"{nameof(baseRomfs)} cannot be null");
|
Base = baseRomfs ?? throw new NullReferenceException($"{nameof(baseRomfs)} cannot be null");
|
||||||
|
|
||||||
|
|
|
@ -371,21 +371,19 @@ namespace LibHac
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
long size = 0;
|
long size = 0;
|
||||||
|
|
||||||
switch (sect.Type)
|
switch (sect.Header.HashType)
|
||||||
{
|
{
|
||||||
case SectionType.Invalid:
|
case NcaHashType.Sha256:
|
||||||
break;
|
|
||||||
case SectionType.Pfs0:
|
|
||||||
offset = sect.Header.Sha256Info.HashTableOffset;
|
offset = sect.Header.Sha256Info.HashTableOffset;
|
||||||
size = sect.Header.Sha256Info.HashTableSize;
|
size = sect.Header.Sha256Info.HashTableSize;
|
||||||
break;
|
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;
|
offset = sect.Header.IvfcInfo.LevelHeaders[0].LogicalOffset;
|
||||||
size = 1 << sect.Header.IvfcInfo.LevelHeaders[0].BlockSizePower;
|
size = 1 << sect.Header.IvfcInfo.LevelHeaders[0].BlockSizePower;
|
||||||
break;
|
break;
|
||||||
case SectionType.Bktr:
|
|
||||||
CheckBktrKey(sect);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream stream = OpenSection(index, true, IntegrityCheckLevel.None);
|
Stream stream = OpenSection(index, true, IntegrityCheckLevel.None);
|
||||||
|
@ -395,7 +393,7 @@ namespace LibHac
|
||||||
stream.Read(hashTable, 0, hashTable.Length);
|
stream.Read(hashTable, 0, hashTable.Length);
|
||||||
|
|
||||||
sect.MasterHashValidity = Crypto.CheckMemoryHashTable(hashTable, expected, 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()
|
public void Dispose()
|
||||||
|
|
|
@ -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 class BktrPatchInfo
|
||||||
{
|
{
|
||||||
public BktrHeader RelocationHeader;
|
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
|
public enum ProgramPartitionType
|
||||||
{
|
{
|
||||||
Code,
|
Code,
|
||||||
|
|
|
@ -68,29 +68,6 @@ namespace LibHac
|
||||||
Hfs0
|
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 class PfsHeader
|
||||||
{
|
{
|
||||||
public string Magic;
|
public string Magic;
|
||||||
|
|
|
@ -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 class RomfsExtensions
|
||||||
{
|
{
|
||||||
public static void Extract(this Romfs romfs, string outDir, IProgressReport logger = null)
|
public static void Extract(this Romfs romfs, string outDir, IProgressReport logger = null)
|
||||||
|
|
10
README.md
10
README.md
|
@ -15,9 +15,10 @@ hactoolnet is an example program that uses LibHac. It is used in a similar manne
|
||||||
Usage: hactoolnet.exe [options...] <path>
|
Usage: hactoolnet.exe [options...] <path>
|
||||||
Options:
|
Options:
|
||||||
-r, --raw Keep raw data, don't unpack.
|
-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.
|
-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.
|
--titlekeys <file> Load title keys from an external file.
|
||||||
NCA options:
|
NCA options:
|
||||||
--section0 <file> Specify Section 0 file path.
|
--section0 <file> Specify Section 0 file path.
|
||||||
|
@ -53,6 +54,8 @@ Package1 options:
|
||||||
--outdir <dir> Specify Package1 directory path.
|
--outdir <dir> Specify Package1 directory path.
|
||||||
Package2 options:
|
Package2 options:
|
||||||
--outdir <dir> Specify Package2 directory path.
|
--outdir <dir> Specify Package2 directory path.
|
||||||
|
INI1 options:
|
||||||
|
--outdir <dir> Specify INI1 directory path.
|
||||||
Switch FS options:
|
Switch FS options:
|
||||||
--sdseed <seed> Set console unique seed for SD card NAX0 encryption.
|
--sdseed <seed> Set console unique seed for SD card NAX0 encryption.
|
||||||
--listapps List application info.
|
--listapps List application info.
|
||||||
|
@ -64,10 +67,13 @@ Switch FS options:
|
||||||
--romfs <file> Specify RomFS directory path. (--title must be specified)
|
--romfs <file> Specify RomFS directory path. (--title must be specified)
|
||||||
--romfsdir <dir> 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.
|
--savedir <dir> Specify save file directory path.
|
||||||
|
-y, --verify Verify all titles, or verify a single title if --title is set.
|
||||||
Savefile options:
|
Savefile options:
|
||||||
--outdir <dir> Specify directory path to save contents to.
|
--outdir <dir> Specify directory path to save contents to.
|
||||||
--debugoutdir <dir> Specify directory path to save intermediate data to for debugging.
|
--debugoutdir <dir> Specify directory path to save intermediate data to for debugging.
|
||||||
--sign Sign the save file. (Requires device_key in key file)
|
--sign Sign the save file. (Requires device_key in key file)
|
||||||
|
Keygen options:
|
||||||
|
--outdir <dir> Specify directory path to save key files to.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
|
@ -198,6 +198,7 @@ namespace hactoolnet
|
||||||
sb.AppendLine(" --romfs <file> Specify RomFS directory path. (--title must be specified)");
|
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(" --romfsdir <dir> Specify RomFS directory path. (--title must be specified)");
|
||||||
sb.AppendLine(" --savedir <dir> Specify save file directory path.");
|
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("Savefile options:");
|
||||||
sb.AppendLine(" --outdir <dir> Specify directory path to save contents to.");
|
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.");
|
sb.AppendLine(" --debugoutdir <dir> Specify directory path to save intermediate data to for debugging.");
|
||||||
|
|
|
@ -160,16 +160,13 @@ namespace hactoolnet
|
||||||
PrintItem(sb, colLen, " Partition Type:", sect.IsExefs ? "ExeFS" : sect.Type.ToString());
|
PrintItem(sb, colLen, " Partition Type:", sect.IsExefs ? "ExeFS" : sect.Type.ToString());
|
||||||
PrintItem(sb, colLen, " Section CTR:", sect.Header.Ctr);
|
PrintItem(sb, colLen, " Section CTR:", sect.Header.Ctr);
|
||||||
|
|
||||||
switch (sect.Type)
|
switch (sect.Header.HashType)
|
||||||
{
|
{
|
||||||
case SectionType.Pfs0:
|
case NcaHashType.Sha256:
|
||||||
PrintPfs0(sect);
|
PrintSha256Hash(sect);
|
||||||
break;
|
break;
|
||||||
case SectionType.Romfs:
|
case NcaHashType.Ivfc:
|
||||||
PrintRomfs(sect);
|
PrintIvfcHash(sect);
|
||||||
break;
|
|
||||||
case SectionType.Bktr:
|
|
||||||
PrintRomfs(sect);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sb.AppendLine(" Unknown/invalid superblock!");
|
sb.AppendLine(" Unknown/invalid superblock!");
|
||||||
|
@ -178,7 +175,7 @@ namespace hactoolnet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintPfs0(NcaSection sect)
|
void PrintSha256Hash(NcaSection sect)
|
||||||
{
|
{
|
||||||
Sha256Info hashInfo = sect.Header.Sha256Info;
|
Sha256Info hashInfo = sect.Header.Sha256Info;
|
||||||
|
|
||||||
|
@ -192,7 +189,7 @@ namespace hactoolnet
|
||||||
PrintItem(sb, colLen, " PFS0 Size:", $"0x{hashInfo.DataSize:x12}");
|
PrintItem(sb, colLen, " PFS0 Size:", $"0x{hashInfo.DataSize:x12}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintRomfs(NcaSection sect)
|
void PrintIvfcHash(NcaSection sect)
|
||||||
{
|
{
|
||||||
IvfcHeader ivfcInfo = sect.Header.IvfcInfo;
|
IvfcHeader ivfcInfo = sect.Header.IvfcInfo;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue