diff --git a/LibHac/Crypto.cs b/LibHac/Crypto.cs index 115ae84e..342b4417 100644 --- a/LibHac/Crypto.cs +++ b/LibHac/Crypto.cs @@ -13,15 +13,12 @@ namespace LibHac public static bool CheckMemoryHashTable(byte[] data, byte[] hash) { - bool comp = false; - using (var _SHA = SHA256.Create()) + using (SHA256 sha = SHA256.Create()) { - comp = Util.ArraysEqual(hash, _SHA.ComputeHash(data)); + return Util.ArraysEqual(hash, sha.ComputeHash(data)); } - return comp; } - public static void DecryptEcb(byte[] key, byte[] src, int srcIndex, byte[] dest, int destIndex, int length) { using (var aes = Aes.Create()) diff --git a/LibHac/Lz4.cs b/LibHac/Lz4.cs index cfb49551..cb4583cf 100644 --- a/LibHac/Lz4.cs +++ b/LibHac/Lz4.cs @@ -1,78 +1,80 @@ +// https://github.com/Ryujinx/Ryujinx/blob/0254a84f90ea03037be15b8fd1f9e0a4be5577e9/Ryujinx.HLE/Loaders/Compression/Lz4.cs + using System; -namespace Ryujinx.HLE.Loaders.Compression +namespace LibHac { - static class Lz4 + public static class Lz4 { - public static byte[] Decompress(byte[] Cmp, int DecLength) + public static byte[] Decompress(byte[] cmp, int decLength) { - byte[] Dec = new byte[DecLength]; + byte[] dec = new byte[decLength]; - int CmpPos = 0; - int DecPos = 0; + int cmpPos = 0; + int decPos = 0; - int GetLength(int Length) + int GetLength(int length) { - byte Sum; + byte sum; - if (Length == 0xf) + if (length == 0xf) { do { - Length += (Sum = Cmp[CmpPos++]); + length += (sum = cmp[cmpPos++]); } - while (Sum == 0xff); + while (sum == 0xff); } - return Length; + return length; } do { - byte Token = Cmp[CmpPos++]; + byte token = cmp[cmpPos++]; - int EncCount = (Token >> 0) & 0xf; - int LitCount = (Token >> 4) & 0xf; + int encCount = (token >> 0) & 0xf; + int litCount = (token >> 4) & 0xf; - //Copy literal chunck - LitCount = GetLength(LitCount); + //Copy literal chunk + litCount = GetLength(litCount); - Buffer.BlockCopy(Cmp, CmpPos, Dec, DecPos, LitCount); + Buffer.BlockCopy(cmp, cmpPos, dec, decPos, litCount); - CmpPos += LitCount; - DecPos += LitCount; + cmpPos += litCount; + decPos += litCount; - if (CmpPos >= Cmp.Length) + if (cmpPos >= cmp.Length) { break; } - //Copy compressed chunck - int Back = Cmp[CmpPos++] << 0 | - Cmp[CmpPos++] << 8; + //Copy compressed chunk + int back = cmp[cmpPos++] << 0 | + cmp[cmpPos++] << 8; - EncCount = GetLength(EncCount) + 4; + encCount = GetLength(encCount) + 4; - int EncPos = DecPos - Back; + int encPos = decPos - back; - if (EncCount <= Back) + if (encCount <= back) { - Buffer.BlockCopy(Dec, EncPos, Dec, DecPos, EncCount); + Buffer.BlockCopy(dec, encPos, dec, decPos, encCount); - DecPos += EncCount; + decPos += encCount; } else { - while (EncCount-- > 0) + while (encCount-- > 0) { - Dec[DecPos++] = Dec[EncPos++]; + dec[decPos++] = dec[encPos++]; } } } - while (CmpPos < Cmp.Length && - DecPos < Dec.Length); + while (cmpPos < cmp.Length && + decPos < dec.Length); - return Dec; + return dec; } } } \ No newline at end of file diff --git a/LibHac/Nso.cs b/LibHac/Nso.cs index c777c12b..555cc7b3 100644 --- a/LibHac/Nso.cs +++ b/LibHac/Nso.cs @@ -1,7 +1,6 @@ using System.Collections; using System.IO; using LibHac.Streams; -using Ryujinx.HLE.Loaders.Compression; namespace LibHac { diff --git a/LibHac/Pfs.cs b/LibHac/Pfs.cs index 90dfda57..83290b13 100644 --- a/LibHac/Pfs.cs +++ b/LibHac/Pfs.cs @@ -141,7 +141,7 @@ namespace LibHac for (int i = 0; i < NumFiles; i++) { reader.BaseStream.Position = HeaderSize + Files[i].Offset; - if (Crypto.CheckMemoryHashTable(reader.ReadBytes((int)Files[i].HashedRegionSize), Files[i].Hash)) + if (Crypto.CheckMemoryHashTable(reader.ReadBytes(Files[i].HashedRegionSize), Files[i].Hash)) { Files[i].HashValidity = Validity.Valid; } diff --git a/LibHac/Savefile/Header.cs b/LibHac/Savefile/Header.cs index 5f841805..17c95bdf 100644 --- a/LibHac/Savefile/Header.cs +++ b/LibHac/Savefile/Header.cs @@ -30,7 +30,7 @@ namespace LibHac.Savefile public byte[] Data { get; } - public Header(Keyset keyset, BinaryReader reader, IProgressReport logger = null) + public Header(Keyset keyset, BinaryReader reader) { reader.BaseStream.Position = 0; Data = reader.ReadBytes(0x4000); diff --git a/LibHac/Savefile/Savefile.cs b/LibHac/Savefile/Savefile.cs index c483c021..f0e87977 100644 --- a/LibHac/Savefile/Savefile.cs +++ b/LibHac/Savefile/Savefile.cs @@ -41,13 +41,13 @@ namespace LibHac.Savefile public DirectoryEntry[] Directories { get; private set; } private Dictionary FileDict { get; } - public Savefile(Keyset keyset, Stream file, bool enableIntegrityChecks, IProgressReport logger = null) + public Savefile(Keyset keyset, Stream file, bool enableIntegrityChecks) { SavefileSource = new SharedStreamSource(file); using (var reader = new BinaryReader(SavefileSource.CreateStream(), Encoding.Default, true)) { - Header = new Header(keyset, reader, logger); + Header = new Header(keyset, reader); FsLayout layout = Header.Layout; FileRemap = new RemapStream( diff --git a/LibHac/XciHeader.cs b/LibHac/XciHeader.cs index a6d367e4..9f524bef 100644 --- a/LibHac/XciHeader.cs +++ b/LibHac/XciHeader.cs @@ -64,7 +64,7 @@ namespace LibHac public Validity SignatureValidity { get; set; } - public Validity PartitionFsHeaderValidity { get; set; } = Validity.Unchecked; + public Validity PartitionFsHeaderValidity { get; set; } public XciHeader(Keyset keyset, Stream stream) { diff --git a/hactoolnet/ProcessKip.cs b/hactoolnet/ProcessKip.cs index 7051b138..08de8e0b 100644 --- a/hactoolnet/ProcessKip.cs +++ b/hactoolnet/ProcessKip.cs @@ -10,6 +10,7 @@ namespace hactoolnet using (var file = new FileStream(ctx.Options.InFile, FileMode.Open, FileAccess.Read)) { var kip = new Kip(file); + kip.OpenRawFile(); } } diff --git a/hactoolnet/ProcessSave.cs b/hactoolnet/ProcessSave.cs index 23abf048..81487cd9 100644 --- a/hactoolnet/ProcessSave.cs +++ b/hactoolnet/ProcessSave.cs @@ -14,7 +14,7 @@ namespace hactoolnet { using (var file = new FileStream(ctx.Options.InFile, FileMode.Open, FileAccess.ReadWrite)) { - var save = new Savefile(ctx.Keyset, file, ctx.Options.EnableHash, ctx.Logger); + var save = new Savefile(ctx.Keyset, file, ctx.Options.EnableHash); if (ctx.Options.OutDir != null) {