Skip to content

Commit

Permalink
Change alignment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
saltukkos committed Aug 17, 2018
1 parent 457158f commit 18ebe75
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions BiosPatcher/Models/PatchingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class PatchingModel
private const int DataLengthOffset = 0x18;
private const int CheckSumOffset = 0x44;
private const int HeaderLength = 0x100;
private const int ChecksumDivider = 0x40;
private const int ChecksumLittleByte = 0x40;
private const int CopyrightOffset = 0x564;

//Copyright 1996-1999, all rights reserved Insyde Software Corp.
Expand Down Expand Up @@ -149,16 +149,16 @@ public string Patch()
var dataLength = 2 * BitConverterLittleEndian.ReadInt(newImage, DataLengthOffset);
var checksum = CheckSumCalculator.Calculate(newImage, HeaderLength, dataLength);

var modulo = checksum % ChecksumDivider;
var modulo = (checksum - ChecksumLittleByte) % 256;
if (modulo != 0)
{
newImage[CopyrightOffset + CopyrightString.Length - 2] = 0;
newImage[CopyrightOffset + CopyrightString.Length - 1] =
(byte) (CopyrightString[CopyrightString.Length - 2] + ChecksumDivider - modulo);
unchecked ((byte) (CopyrightString[CopyrightString.Length - 2] - modulo));
}

var correctedChecksum = CheckSumCalculator.Calculate(newImage, HeaderLength, dataLength);
if (correctedChecksum % ChecksumDivider != 0)
if (correctedChecksum % 256 != ChecksumLittleByte)
{
return "Internal error";
}
Expand Down Expand Up @@ -202,7 +202,7 @@ private bool CheckInputCorrect()
var actualChecksum = CheckSumCalculator.Calculate(_image, HeaderLength, dataLength);
var writtenChecksum = BitConverterLittleEndian.ReadInt(_image, CheckSumOffset);

if (actualChecksum != writtenChecksum || actualChecksum % ChecksumDivider != 0)
if (actualChecksum != writtenChecksum || actualChecksum % 256 != ChecksumLittleByte)
{
LastError = FileSignatureDiffersFromSupportedBios;
return false;
Expand Down

0 comments on commit 18ebe75

Please sign in to comment.