mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Code style naming fixes
This commit is contained in:
parent
56115ace39
commit
372370db82
9 changed files with 45 additions and 46 deletions
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.IO;
|
||||
using LibHac.Streams;
|
||||
using Ryujinx.HLE.Loaders.Compression;
|
||||
|
||||
namespace LibHac
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -41,13 +41,13 @@ namespace LibHac.Savefile
|
|||
public DirectoryEntry[] Directories { get; private set; }
|
||||
private Dictionary<string, FileEntry> 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(
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue