mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Validate save header hash
This commit is contained in:
parent
9bd55e19a6
commit
83323b58c3
1 changed files with 30 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace libhac.Savefile
|
||||
{
|
||||
|
@ -13,8 +14,14 @@ namespace libhac.Savefile
|
|||
public MapEntry[] FileMapEntries { get; set; }
|
||||
public MapEntry[] MetaMapEntries { get; set; }
|
||||
|
||||
public Header(BinaryReader reader)
|
||||
public byte[] Data { get; }
|
||||
|
||||
public Header(BinaryReader reader, IProgressReport logger = null)
|
||||
{
|
||||
reader.BaseStream.Position = 0;
|
||||
Data = reader.ReadBytes(0x4000);
|
||||
reader.BaseStream.Position = 0;
|
||||
|
||||
Cmac = reader.ReadBytes(0x10);
|
||||
|
||||
reader.BaseStream.Position = 0x100;
|
||||
|
@ -38,6 +45,18 @@ namespace libhac.Savefile
|
|||
{
|
||||
MetaMapEntries[i] = new MapEntry(reader);
|
||||
}
|
||||
|
||||
var hashStatus = ValidateHeaderHash() ? "valid" : "invalid";
|
||||
logger?.LogMessage($"Header hash is {hashStatus}");
|
||||
}
|
||||
|
||||
private bool ValidateHeaderHash()
|
||||
{
|
||||
using (SHA256 sha256 = SHA256.Create())
|
||||
{
|
||||
var hash = sha256.ComputeHash(Data, 0x300, 0x3d00);
|
||||
return Util.ArraysEqual(hash, Layout.Hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,11 +81,11 @@ namespace libhac.Savefile
|
|||
public long JournalDataSizeA { get; set; }
|
||||
public long JournalDataSizeB { get; set; }
|
||||
public long SizeReservedArea { get; set; }
|
||||
public long OffsetL1Bitmap0 { get; set; }
|
||||
public long OffsetL1Bitmap1 { get; set; }
|
||||
public long SizeL1Bitmap { get; set; }
|
||||
public long MasterHashOffset { get; set; }
|
||||
public long FieldC8 { get; set; }
|
||||
public long L1BitmapOffset0 { get; set; }
|
||||
public long L1BitmapOffset1 { get; set; }
|
||||
public long L1BitmapSize { get; set; }
|
||||
public long MasterHashOffset0 { get; set; }
|
||||
public long MasterHashOffset1 { get; set; }
|
||||
public long MasterHashSize { get; set; }
|
||||
public long OffsetJournalTable { get; set; }
|
||||
public long SizeJournalTable { get; set; }
|
||||
|
@ -107,11 +126,11 @@ namespace libhac.Savefile
|
|||
JournalDataSizeA = reader.ReadInt64();
|
||||
JournalDataSizeB = reader.ReadInt64();
|
||||
SizeReservedArea = reader.ReadInt64();
|
||||
OffsetL1Bitmap0 = reader.ReadInt64();
|
||||
OffsetL1Bitmap1 = reader.ReadInt64();
|
||||
SizeL1Bitmap = reader.ReadInt64();
|
||||
MasterHashOffset = reader.ReadInt64();
|
||||
FieldC8 = reader.ReadInt64();
|
||||
L1BitmapOffset0 = reader.ReadInt64();
|
||||
L1BitmapOffset1 = reader.ReadInt64();
|
||||
L1BitmapSize = reader.ReadInt64();
|
||||
MasterHashOffset0 = reader.ReadInt64();
|
||||
MasterHashOffset1 = reader.ReadInt64();
|
||||
MasterHashSize = reader.ReadInt64();
|
||||
OffsetJournalTable = reader.ReadInt64();
|
||||
SizeJournalTable = reader.ReadInt64();
|
||||
|
|
Loading…
Reference in a new issue