mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
changes the CheckMemoryHashTable to Validity
This commit is contained in:
parent
13ea564aec
commit
fcb44f8a2f
4 changed files with 6 additions and 30 deletions
|
@ -12,12 +12,12 @@ namespace LibHac
|
||||||
internal const int Aes128Size = 0x10;
|
internal const int Aes128Size = 0x10;
|
||||||
internal const int Sha256DigestSize = 0x20;
|
internal const int Sha256DigestSize = 0x20;
|
||||||
|
|
||||||
public static bool CheckMemoryHashTable(byte[] data, byte[] hash)
|
public static Validity CheckMemoryHashTable(byte[] data, byte[] hash, int offset , int count)
|
||||||
{
|
{
|
||||||
bool comp = false;
|
Validity comp = Validity.Invalid ;
|
||||||
using (var _SHA = SHA256.Create())
|
using (var _SHA = SHA256.Create())
|
||||||
{
|
{
|
||||||
comp = hash.SequenceEqual(_SHA.ComputeHash(data));
|
comp = hash.SequenceEqual(_SHA.ComputeHash(data , offset , count)) ? Validity.Valid : Validity.Invalid;
|
||||||
}
|
}
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,14 +141,7 @@ namespace LibHac
|
||||||
for (int i = 0; i < NumFiles; i++)
|
for (int i = 0; i < NumFiles; i++)
|
||||||
{
|
{
|
||||||
reader.BaseStream.Position = HeaderSize + Files[i].Offset;
|
reader.BaseStream.Position = HeaderSize + Files[i].Offset;
|
||||||
if (Crypto.CheckMemoryHashTable(reader.ReadBytes((int)Files[i].HashedRegionSize), Files[i].Hash))
|
Files[i].HashValidity = Crypto.CheckMemoryHashTable(reader.ReadBytes(Files[i].HashedRegionSize), Files[i].Hash, 0, Files[i].HashedRegionSize);
|
||||||
{
|
|
||||||
Files[i].HashValidity = Validity.Valid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Files[i].HashValidity = Validity.Invalid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibHac.Savefile
|
namespace LibHac.Savefile
|
||||||
|
@ -81,21 +80,12 @@ namespace LibHac.Savefile
|
||||||
MetaMapEntries[i] = new MapEntry(reader);
|
MetaMapEntries[i] = new MapEntry(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderHashValidity = ValidateHeaderHash();
|
HeaderHashValidity = Crypto.CheckMemoryHashTable(Data, Layout.Hash, 0x300, 0x3d00);
|
||||||
SignatureValidity = ValidateSignature(keyset);
|
SignatureValidity = ValidateSignature(keyset);
|
||||||
|
|
||||||
logger?.LogMessage($"Header hash is {HeaderHashValidity}");
|
logger?.LogMessage($"Header hash is {HeaderHashValidity}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Validity ValidateHeaderHash()
|
|
||||||
{
|
|
||||||
using (SHA256 sha256 = SHA256.Create())
|
|
||||||
{
|
|
||||||
var hash = sha256.ComputeHash(Data, 0x300, 0x3d00);
|
|
||||||
return hash.SequenceEqual(Layout.Hash) ? Validity.Valid : Validity.Invalid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Validity ValidateSignature(Keyset keyset)
|
private Validity ValidateSignature(Keyset keyset)
|
||||||
{
|
{
|
||||||
var calculatedCmac = new byte[0x10];
|
var calculatedCmac = new byte[0x10];
|
||||||
|
|
|
@ -134,14 +134,7 @@ namespace LibHac
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.BaseStream.Position = PartitionFsHeaderAddress;
|
reader.BaseStream.Position = PartitionFsHeaderAddress;
|
||||||
|
PartitionFsHeaderValidity = Crypto.CheckMemoryHashTable(reader.ReadBytes((int)PartitionFsHeaderSize), PartitionFsHeaderHash, 0, (int)PartitionFsHeaderSize);
|
||||||
if (Crypto.CheckMemoryHashTable(reader.ReadBytes((int)PartitionFsHeaderSize), PartitionFsHeaderHash)) {
|
|
||||||
PartitionFsHeaderValidity = Validity.Valid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PartitionFsHeaderValidity = Validity.Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue