Move NcaUtils

This commit is contained in:
Alex Barney 2021-12-18 19:43:06 -07:00
parent 7681429c97
commit aa153980be
21 changed files with 78 additions and 74 deletions

View file

@ -1,7 +1,7 @@
using LibHac.Common; using LibHac.Common;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem.NcaUtils; using LibHac.Tools.FsSystem.NcaUtils;
namespace LibHac.FsSrv.FsCreator; namespace LibHac.FsSrv.FsCreator;
@ -11,4 +11,4 @@ public interface IStorageOnNcaCreator
Result CreateWithPatch(ref SharedRef<IStorage> outStorage, out NcaFsHeader fsHeader, Nca baseNca, Nca patchNca, int fsIndex, bool isCodeFs); Result CreateWithPatch(ref SharedRef<IStorage> outStorage, out NcaFsHeader fsHeader, Nca baseNca, Nca patchNca, int fsIndex, bool isCodeFs);
Result OpenNca(out Nca nca, IStorage ncaStorage); Result OpenNca(out Nca nca, IStorage ncaStorage);
Result VerifyAcidSignature(IFileSystem codeFileSystem, Nca nca); Result VerifyAcidSignature(IFileSystem codeFileSystem, Nca nca);
} }

View file

@ -5,7 +5,7 @@ using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.Impl; using LibHac.FsSystem.Impl;
using LibHac.FsSystem.NcaUtils; using LibHac.Tools.FsSystem.NcaUtils;
namespace LibHac.FsSrv.FsCreator; namespace LibHac.FsSrv.FsCreator;
@ -75,4 +75,4 @@ public class StorageOnNcaCreator : IStorageOnNcaCreator
storage = nca.OpenStorage(fsIndex, IntegrityCheckLevel.ErrorOnInvalid); storage = nca.OpenStorage(fsIndex, IntegrityCheckLevel.ErrorOnInvalid);
return Result.Success; return Result.Success;
} }
} }

View file

@ -8,10 +8,10 @@ using LibHac.Fs.Fsa;
using LibHac.FsSrv.FsCreator; using LibHac.FsSrv.FsCreator;
using LibHac.FsSrv.Impl; using LibHac.FsSrv.Impl;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Ncm; using LibHac.Ncm;
using LibHac.Os; using LibHac.Os;
using LibHac.Spl; using LibHac.Spl;
using LibHac.Tools.FsSystem.NcaUtils;
using LibHac.Util; using LibHac.Util;
using RightsId = LibHac.Fs.RightsId; using RightsId = LibHac.Fs.RightsId;
using Utility = LibHac.FsSystem.Utility; using Utility = LibHac.FsSystem.Utility;
@ -933,4 +933,4 @@ public readonly struct InternalProgramIdRangeForSpeedEmulation
ProgramIdMin = min; ProgramIdMin = min;
ProgramIdMax = max; ProgramIdMax = max;
} }
} }

View file

@ -2,41 +2,7 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using LibHac.Common.FixedArrays; using LibHac.Common.FixedArrays;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.FsSystem;
public class TitleVersion
{
public uint Version { get; }
public int Major { get; }
public int Minor { get; }
public int Patch { get; }
public int Revision { get; }
public TitleVersion(uint version, bool isSystemTitle = false)
{
Version = version;
if (isSystemTitle)
{
Revision = (int)(version & ((1 << 16) - 1));
Patch = (int)((version >> 16) & ((1 << 4) - 1));
Minor = (int)((version >> 20) & ((1 << 6) - 1));
Major = (int)((version >> 26) & ((1 << 6) - 1));
}
else
{
Revision = (byte)version;
Patch = (byte)(version >> 8);
Minor = (byte)(version >> 16);
Major = (byte)(version >> 24);
}
}
public override string ToString()
{
return $"{Major}.{Minor}.{Patch}.{Revision}";
}
}
public struct NcaSparseInfo public struct NcaSparseInfo
{ {
@ -118,4 +84,4 @@ public enum NcaFormatType
{ {
Romfs, Romfs,
Pfs0 Pfs0
} }

View file

@ -8,9 +8,9 @@ using LibHac.Common.Keys;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Ncm; using LibHac.Ncm;
using LibHac.Ns; using LibHac.Ns;
using LibHac.Tools.FsSystem.NcaUtils;
using LibHac.Tools.FsSystem.Save; using LibHac.Tools.FsSystem.Save;
using LibHac.Tools.Ncm; using LibHac.Tools.Ncm;
using LibHac.Util; using LibHac.Util;

View file

@ -9,10 +9,11 @@ using LibHac.Crypto;
using LibHac.Diag; using LibHac.Diag;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.FsSystem.RomFs; using LibHac.FsSystem.RomFs;
using LibHac.Spl; using LibHac.Spl;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public class Nca public class Nca
{ {
@ -778,7 +779,7 @@ public class Nca
return Header.VerifySignature1(KeySet.NcaHeaderSigningKeyParams[0].Modulus); return Header.VerifySignature1(KeySet.NcaHeaderSigningKeyParams[0].Modulus);
} }
internal void GenerateAesCounter(int sectionIndex, Ncm.ContentType type, int minorVersion) internal void GenerateAesCounter(int sectionIndex, LibHac.Ncm.ContentType type, int minorVersion)
{ {
int counterType; int counterType;
int counterVersion; int counterVersion;
@ -789,14 +790,14 @@ public class Nca
switch (type) switch (type)
{ {
case Ncm.ContentType.Program: case LibHac.Ncm.ContentType.Program:
counterType = sectionIndex + 1; counterType = sectionIndex + 1;
break; break;
case Ncm.ContentType.HtmlDocument: case LibHac.Ncm.ContentType.HtmlDocument:
counterType = (int)Ncm.ContentType.HtmlDocument; counterType = (int)LibHac.Ncm.ContentType.HtmlDocument;
break; break;
case Ncm.ContentType.LegalInformation: case LibHac.Ncm.ContentType.LegalInformation:
counterType = (int)Ncm.ContentType.LegalInformation; counterType = (int)LibHac.Ncm.ContentType.LegalInformation;
break; break;
default: default:
counterType = 0; counterType = 0;
@ -828,4 +829,4 @@ public class Nca
bool isOutOfRange = startIndex < 0 || startIndex > length || subLength < 0 || startIndex > length - subLength; bool isOutOfRange = startIndex < 0 || startIndex > length || subLength < 0 || startIndex > length - subLength;
return !isOutOfRange; return !isOutOfRange;
} }
} }

View file

@ -4,8 +4,9 @@ using System.Diagnostics;
using LibHac.Crypto; using LibHac.Crypto;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public static class NcaExtensions public static class NcaExtensions
{ {
@ -195,4 +196,4 @@ public static class NcaExtensions
return validity; return validity;
} }
} }

View file

@ -1,10 +1,11 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using LibHac.FsSystem;
// ReSharper disable ImpureMethodCallOnReadonlyValueField // ReSharper disable ImpureMethodCallOnReadonlyValueField
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public struct NcaFsHeader public struct NcaFsHeader
{ {
@ -108,4 +109,4 @@ public struct NcaFsHeader
[FieldOffset(0x140)] public int CounterType; [FieldOffset(0x140)] public int CounterType;
[FieldOffset(0x144)] public int CounterVersion; [FieldOffset(0x144)] public int CounterVersion;
} }
} }

View file

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public struct NcaFsIntegrityInfoIvfc public struct NcaFsIntegrityInfoIvfc
{ {
@ -85,4 +85,4 @@ public struct NcaFsIntegrityInfoIvfc
[FieldOffset(8)] public long Size; [FieldOffset(8)] public long Size;
[FieldOffset(0x10)] public int BlockSize; [FieldOffset(0x10)] public int BlockSize;
} }
} }

View file

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public struct NcaFsIntegrityInfoSha256 public struct NcaFsIntegrityInfoSha256
{ {
@ -67,4 +67,4 @@ public struct NcaFsIntegrityInfoSha256
[FieldOffset(0)] public long Offset; [FieldOffset(0)] public long Offset;
[FieldOffset(8)] public long Size; [FieldOffset(8)] public long Size;
} }
} }

View file

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public struct NcaFsPatchInfo public struct NcaFsPatchInfo
{ {
@ -50,4 +50,4 @@ public struct NcaFsPatchInfo
[FieldOffset(0x20)] public long EncryptionTreeOffset; [FieldOffset(0x20)] public long EncryptionTreeOffset;
[FieldOffset(0x28)] public long EncryptionTreeSize; [FieldOffset(0x28)] public long EncryptionTreeSize;
} }
} }

View file

@ -7,9 +7,10 @@ using LibHac.Common.Keys;
using LibHac.Crypto; using LibHac.Crypto;
using LibHac.Diag; using LibHac.Diag;
using LibHac.Fs; using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Util; using LibHac.Util;
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
public struct NcaHeader public struct NcaHeader
{ {
@ -372,4 +373,4 @@ public enum NcaVersion
Nca0, Nca0,
Nca0FixedKey, Nca0FixedKey,
Nca0RsaOaep Nca0RsaOaep
} }

View file

@ -1,4 +1,4 @@
namespace LibHac.FsSystem.NcaUtils; namespace LibHac.Tools.FsSystem.NcaUtils;
internal enum NcaKeyType internal enum NcaKeyType
{ {
@ -7,4 +7,4 @@ internal enum NcaKeyType
AesCtr = 2, AesCtr = 2,
AesCtrEx = 3, AesCtrEx = 3,
AesCtrHw = 4 AesCtrHw = 4
} }

View file

@ -0,0 +1,35 @@
namespace LibHac.Tools.FsSystem.NcaUtils;
public class TitleVersion
{
public uint Version { get; }
public int Major { get; }
public int Minor { get; }
public int Patch { get; }
public int Revision { get; }
public TitleVersion(uint version, bool isSystemTitle = false)
{
Version = version;
if (isSystemTitle)
{
Revision = (int)(version & ((1 << 16) - 1));
Patch = (int)((version >> 16) & ((1 << 4) - 1));
Minor = (int)((version >> 20) & ((1 << 6) - 1));
Major = (int)((version >> 26) & ((1 << 6) - 1));
}
else
{
Revision = (byte)version;
Patch = (byte)(version >> 8);
Minor = (byte)(version >> 16);
Major = (byte)(version >> 24);
}
}
public override string ToString()
{
return $"{Major}.{Minor}.{Patch}.{Revision}";
}
}

View file

@ -1,7 +1,7 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using LibHac.FsSystem.NcaUtils;
using LibHac.Ncm; using LibHac.Ncm;
using LibHac.Tools.FsSystem.NcaUtils;
using ContentType = LibHac.Ncm.ContentType; using ContentType = LibHac.Ncm.ContentType;
namespace LibHac.Tools.Ncm; namespace LibHac.Tools.Ncm;

View file

@ -1,6 +1,6 @@
using LibHac; using LibHac;
using LibHac.Fs; using LibHac.Fs;
using LibHac.FsSystem.NcaUtils; using LibHac.FsSystem;
using LibHac.Ncm; using LibHac.Ncm;
using LibHac.Tools.Fs; using LibHac.Tools.Fs;
using ContentType = LibHac.Ncm.ContentType; using ContentType = LibHac.Ncm.ContentType;

View file

@ -3,7 +3,7 @@ using System.Buffers.Binary;
using System.Text; using System.Text;
using LibHac; using LibHac;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils; using LibHac.Tools.FsSystem.NcaUtils;
namespace hactoolnet; namespace hactoolnet;
@ -111,4 +111,4 @@ internal static class Print
return Encoding.ASCII.GetString(buf); return Encoding.ASCII.GetString(buf);
} }
} }

View file

@ -6,8 +6,8 @@ using LibHac.Common;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Tools.FsSystem; using LibHac.Tools.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils;
using static hactoolnet.Print; using static hactoolnet.Print;
namespace hactoolnet; namespace hactoolnet;

View file

@ -6,8 +6,8 @@ using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.Fs.Impl; using LibHac.Fs.Impl;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Npdm; using LibHac.Npdm;
using LibHac.Tools.FsSystem.NcaUtils;
using static hactoolnet.Print; using static hactoolnet.Print;
namespace hactoolnet; namespace hactoolnet;
@ -402,4 +402,4 @@ internal static class ProcessNca
public Nca Nca; public Nca Nca;
public Validity[] Validities = new Validity[4]; public Validity[] Validities = new Validity[4];
} }
} }

View file

@ -8,7 +8,6 @@ using LibHac;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.Fs.Fsa;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Ns; using LibHac.Ns;
using LibHac.Tools.Fs; using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem.Save; using LibHac.Tools.FsSystem.Save;

View file

@ -4,8 +4,8 @@ using System.Text;
using LibHac; using LibHac;
using LibHac.Fs; using LibHac.Fs;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Tools.Fs; using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem.NcaUtils;
using static hactoolnet.Print; using static hactoolnet.Print;
namespace hactoolnet; namespace hactoolnet;