mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Move NcaUtils
This commit is contained in:
parent
7681429c97
commit
aa153980be
21 changed files with 78 additions and 74 deletions
|
@ -1,7 +1,7 @@
|
|||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
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 OpenNca(out Nca nca, IStorage ncaStorage);
|
||||
Result VerifyAcidSignature(IFileSystem codeFileSystem, Nca nca);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using LibHac.Fs;
|
|||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.Impl;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
namespace LibHac.FsSrv.FsCreator;
|
||||
|
||||
|
@ -75,4 +75,4 @@ public class StorageOnNcaCreator : IStorageOnNcaCreator
|
|||
storage = nca.OpenStorage(fsIndex, IntegrityCheckLevel.ErrorOnInvalid);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,10 @@ using LibHac.Fs.Fsa;
|
|||
using LibHac.FsSrv.FsCreator;
|
||||
using LibHac.FsSrv.Impl;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Ncm;
|
||||
using LibHac.Os;
|
||||
using LibHac.Spl;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using LibHac.Util;
|
||||
using RightsId = LibHac.Fs.RightsId;
|
||||
using Utility = LibHac.FsSystem.Utility;
|
||||
|
@ -933,4 +933,4 @@ public readonly struct InternalProgramIdRangeForSpeedEmulation
|
|||
ProgramIdMin = min;
|
||||
ProgramIdMax = max;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,41 +2,7 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using LibHac.Common.FixedArrays;
|
||||
|
||||
namespace LibHac.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}";
|
||||
}
|
||||
}
|
||||
namespace LibHac.FsSystem;
|
||||
|
||||
public struct NcaSparseInfo
|
||||
{
|
||||
|
@ -118,4 +84,4 @@ public enum NcaFormatType
|
|||
{
|
||||
Romfs,
|
||||
Pfs0
|
||||
}
|
||||
}
|
|
@ -8,9 +8,9 @@ using LibHac.Common.Keys;
|
|||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Ncm;
|
||||
using LibHac.Ns;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using LibHac.Tools.FsSystem.Save;
|
||||
using LibHac.Tools.Ncm;
|
||||
using LibHac.Util;
|
||||
|
|
|
@ -9,10 +9,11 @@ using LibHac.Crypto;
|
|||
using LibHac.Diag;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.RomFs;
|
||||
using LibHac.Spl;
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public class Nca
|
||||
{
|
||||
|
@ -778,7 +779,7 @@ public class Nca
|
|||
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 counterVersion;
|
||||
|
@ -789,14 +790,14 @@ public class Nca
|
|||
|
||||
switch (type)
|
||||
{
|
||||
case Ncm.ContentType.Program:
|
||||
case LibHac.Ncm.ContentType.Program:
|
||||
counterType = sectionIndex + 1;
|
||||
break;
|
||||
case Ncm.ContentType.HtmlDocument:
|
||||
counterType = (int)Ncm.ContentType.HtmlDocument;
|
||||
case LibHac.Ncm.ContentType.HtmlDocument:
|
||||
counterType = (int)LibHac.Ncm.ContentType.HtmlDocument;
|
||||
break;
|
||||
case Ncm.ContentType.LegalInformation:
|
||||
counterType = (int)Ncm.ContentType.LegalInformation;
|
||||
case LibHac.Ncm.ContentType.LegalInformation:
|
||||
counterType = (int)LibHac.Ncm.ContentType.LegalInformation;
|
||||
break;
|
||||
default:
|
||||
counterType = 0;
|
||||
|
@ -828,4 +829,4 @@ public class Nca
|
|||
bool isOutOfRange = startIndex < 0 || startIndex > length || subLength < 0 || startIndex > length - subLength;
|
||||
return !isOutOfRange;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,8 +4,9 @@ using System.Diagnostics;
|
|||
using LibHac.Crypto;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem;
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public static class NcaExtensions
|
||||
{
|
||||
|
@ -195,4 +196,4 @@ public static class NcaExtensions
|
|||
|
||||
return validity;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using LibHac.FsSystem;
|
||||
|
||||
// ReSharper disable ImpureMethodCallOnReadonlyValueField
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public struct NcaFsHeader
|
||||
{
|
||||
|
@ -108,4 +109,4 @@ public struct NcaFsHeader
|
|||
[FieldOffset(0x140)] public int CounterType;
|
||||
[FieldOffset(0x144)] public int CounterVersion;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public struct NcaFsIntegrityInfoIvfc
|
||||
{
|
||||
|
@ -85,4 +85,4 @@ public struct NcaFsIntegrityInfoIvfc
|
|||
[FieldOffset(8)] public long Size;
|
||||
[FieldOffset(0x10)] public int BlockSize;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public struct NcaFsIntegrityInfoSha256
|
||||
{
|
||||
|
@ -67,4 +67,4 @@ public struct NcaFsIntegrityInfoSha256
|
|||
[FieldOffset(0)] public long Offset;
|
||||
[FieldOffset(8)] public long Size;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public struct NcaFsPatchInfo
|
||||
{
|
||||
|
@ -50,4 +50,4 @@ public struct NcaFsPatchInfo
|
|||
[FieldOffset(0x20)] public long EncryptionTreeOffset;
|
||||
[FieldOffset(0x28)] public long EncryptionTreeSize;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,9 +7,10 @@ using LibHac.Common.Keys;
|
|||
using LibHac.Crypto;
|
||||
using LibHac.Diag;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Util;
|
||||
|
||||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
public struct NcaHeader
|
||||
{
|
||||
|
@ -372,4 +373,4 @@ public enum NcaVersion
|
|||
Nca0,
|
||||
Nca0FixedKey,
|
||||
Nca0RsaOaep
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace LibHac.FsSystem.NcaUtils;
|
||||
namespace LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
internal enum NcaKeyType
|
||||
{
|
||||
|
@ -7,4 +7,4 @@ internal enum NcaKeyType
|
|||
AesCtr = 2,
|
||||
AesCtrEx = 3,
|
||||
AesCtrHw = 4
|
||||
}
|
||||
}
|
35
src/LibHac/Tools/FsSystem/NcaUtils/NcaStructs.cs
Normal file
35
src/LibHac/Tools/FsSystem/NcaUtils/NcaStructs.cs
Normal 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}";
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Ncm;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using ContentType = LibHac.Ncm.ContentType;
|
||||
|
||||
namespace LibHac.Tools.Ncm;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using LibHac;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Ncm;
|
||||
using LibHac.Tools.Fs;
|
||||
using ContentType = LibHac.Ncm.ContentType;
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Buffers.Binary;
|
|||
using System.Text;
|
||||
using LibHac;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
|
||||
namespace hactoolnet;
|
||||
|
||||
|
@ -111,4 +111,4 @@ internal static class Print
|
|||
|
||||
return Encoding.ASCII.GetString(buf);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@ using LibHac.Common;
|
|||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using static hactoolnet.Print;
|
||||
|
||||
namespace hactoolnet;
|
||||
|
|
|
@ -6,8 +6,8 @@ using LibHac.Fs;
|
|||
using LibHac.Fs.Fsa;
|
||||
using LibHac.Fs.Impl;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Npdm;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using static hactoolnet.Print;
|
||||
|
||||
namespace hactoolnet;
|
||||
|
@ -402,4 +402,4 @@ internal static class ProcessNca
|
|||
public Nca Nca;
|
||||
public Validity[] Validities = new Validity[4];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ using LibHac;
|
|||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Ns;
|
||||
using LibHac.Tools.Fs;
|
||||
using LibHac.Tools.FsSystem.Save;
|
||||
|
|
|
@ -4,8 +4,8 @@ using System.Text;
|
|||
using LibHac;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
using LibHac.Tools.Fs;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using static hactoolnet.Print;
|
||||
|
||||
namespace hactoolnet;
|
||||
|
|
Loading…
Reference in a new issue