From aa153980bee47a79031cb00a252e3d2f595bd8ed Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 18 Dec 2021 19:43:06 -0700 Subject: [PATCH] Move NcaUtils --- .../FsSrv/FsCreator/IStorageOnNcaCreator.cs | 4 +- .../FsSrv/FsCreator/StorageOnNcaCreator.cs | 4 +- src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs | 4 +- .../FsSystem/{NcaUtils => }/NcaStructs.cs | 38 +------------------ src/LibHac/Tools/Fs/SwitchFs.cs | 2 +- .../{ => Tools}/FsSystem/NcaUtils/Nca.cs | 17 +++++---- .../FsSystem/NcaUtils/NcaExtensions.cs | 5 ++- .../FsSystem/NcaUtils/NcaFsHeader.cs | 5 ++- .../NcaUtils/NcaFsIntegrityInfoIvfc.cs | 4 +- .../NcaUtils/NcaFsIntegrityInfoSha256.cs | 4 +- .../FsSystem/NcaUtils/NcaFsPatchInfo.cs | 4 +- .../FsSystem/NcaUtils/NcaHeader.cs | 5 ++- .../FsSystem/NcaUtils/NcaKeyType.cs | 4 +- .../Tools/FsSystem/NcaUtils/NcaStructs.cs | 35 +++++++++++++++++ src/LibHac/Tools/Ncm/Cnmt.cs | 2 +- src/hactoolnet/EnumStrings.cs | 2 +- src/hactoolnet/Print.cs | 4 +- src/hactoolnet/ProcessDelta.cs | 2 +- src/hactoolnet/ProcessNca.cs | 4 +- src/hactoolnet/ProcessSwitchFs.cs | 1 - src/hactoolnet/ProcessXci.cs | 2 +- 21 files changed, 78 insertions(+), 74 deletions(-) rename src/LibHac/FsSystem/{NcaUtils => }/NcaStructs.cs (61%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/Nca.cs (98%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaExtensions.cs (99%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaFsHeader.cs (97%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs (98%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs (97%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaFsPatchInfo.cs (96%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaHeader.cs (99%) rename src/LibHac/{ => Tools}/FsSystem/NcaUtils/NcaKeyType.cs (71%) create mode 100644 src/LibHac/Tools/FsSystem/NcaUtils/NcaStructs.cs diff --git a/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs b/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs index 2ab4a2d6..46378436 100644 --- a/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs @@ -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 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); -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs b/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs index 13839dc2..41e7e987 100644 --- a/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs index c71825e1..9df95997 100644 --- a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaStructs.cs b/src/LibHac/FsSystem/NcaStructs.cs similarity index 61% rename from src/LibHac/FsSystem/NcaUtils/NcaStructs.cs rename to src/LibHac/FsSystem/NcaStructs.cs index 8ef6757d..87c1e949 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaStructs.cs +++ b/src/LibHac/FsSystem/NcaStructs.cs @@ -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 -} +} \ No newline at end of file diff --git a/src/LibHac/Tools/Fs/SwitchFs.cs b/src/LibHac/Tools/Fs/SwitchFs.cs index 4957407f..3369cd02 100644 --- a/src/LibHac/Tools/Fs/SwitchFs.cs +++ b/src/LibHac/Tools/Fs/SwitchFs.cs @@ -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; diff --git a/src/LibHac/FsSystem/NcaUtils/Nca.cs b/src/LibHac/Tools/FsSystem/NcaUtils/Nca.cs similarity index 98% rename from src/LibHac/FsSystem/NcaUtils/Nca.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/Nca.cs index 71452022..c73c35fd 100644 --- a/src/LibHac/FsSystem/NcaUtils/Nca.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/Nca.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs similarity index 99% rename from src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs index 728f4bb3..42b0ed0e 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaFsHeader.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsHeader.cs similarity index 97% rename from src/LibHac/FsSystem/NcaUtils/NcaFsHeader.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaFsHeader.cs index 3c9909ff..479a4c63 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaFsHeader.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsHeader.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs similarity index 98% rename from src/LibHac/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs index b30fca98..abefe815 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsIntegrityInfoIvfc.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs similarity index 97% rename from src/LibHac/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs index 2b1663e1..2939cd03 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsIntegrityInfoSha256.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaFsPatchInfo.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsPatchInfo.cs similarity index 96% rename from src/LibHac/FsSystem/NcaUtils/NcaFsPatchInfo.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaFsPatchInfo.cs index b01ba7eb..7fc772c9 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaFsPatchInfo.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaFsPatchInfo.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaHeader.cs similarity index 99% rename from src/LibHac/FsSystem/NcaUtils/NcaHeader.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaHeader.cs index 0f53f572..4cc6ef8e 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaHeader.cs @@ -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 -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaUtils/NcaKeyType.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaKeyType.cs similarity index 71% rename from src/LibHac/FsSystem/NcaUtils/NcaKeyType.cs rename to src/LibHac/Tools/FsSystem/NcaUtils/NcaKeyType.cs index e7d58fb9..26c24b2c 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaKeyType.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaKeyType.cs @@ -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 -} +} \ No newline at end of file diff --git a/src/LibHac/Tools/FsSystem/NcaUtils/NcaStructs.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaStructs.cs new file mode 100644 index 00000000..429f9d11 --- /dev/null +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaStructs.cs @@ -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}"; + } +} \ No newline at end of file diff --git a/src/LibHac/Tools/Ncm/Cnmt.cs b/src/LibHac/Tools/Ncm/Cnmt.cs index 2933bc5a..28922c4e 100644 --- a/src/LibHac/Tools/Ncm/Cnmt.cs +++ b/src/LibHac/Tools/Ncm/Cnmt.cs @@ -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; diff --git a/src/hactoolnet/EnumStrings.cs b/src/hactoolnet/EnumStrings.cs index da0033ce..59595317 100644 --- a/src/hactoolnet/EnumStrings.cs +++ b/src/hactoolnet/EnumStrings.cs @@ -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; diff --git a/src/hactoolnet/Print.cs b/src/hactoolnet/Print.cs index 10bc6948..a7fb8b9c 100644 --- a/src/hactoolnet/Print.cs +++ b/src/hactoolnet/Print.cs @@ -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); } -} +} \ No newline at end of file diff --git a/src/hactoolnet/ProcessDelta.cs b/src/hactoolnet/ProcessDelta.cs index 83586a0b..7d965b0e 100644 --- a/src/hactoolnet/ProcessDelta.cs +++ b/src/hactoolnet/ProcessDelta.cs @@ -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; diff --git a/src/hactoolnet/ProcessNca.cs b/src/hactoolnet/ProcessNca.cs index 180ccbb9..b088a703 100644 --- a/src/hactoolnet/ProcessNca.cs +++ b/src/hactoolnet/ProcessNca.cs @@ -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]; } -} +} \ No newline at end of file diff --git a/src/hactoolnet/ProcessSwitchFs.cs b/src/hactoolnet/ProcessSwitchFs.cs index 54e50bd0..474498d3 100644 --- a/src/hactoolnet/ProcessSwitchFs.cs +++ b/src/hactoolnet/ProcessSwitchFs.cs @@ -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; diff --git a/src/hactoolnet/ProcessXci.cs b/src/hactoolnet/ProcessXci.cs index 4c60c9fc..cb2fd280 100644 --- a/src/hactoolnet/ProcessXci.cs +++ b/src/hactoolnet/ProcessXci.cs @@ -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;