mirror of
https://github.com/Maschell/JNUSLib.git
synced 2025-02-21 10:32:03 +01:00
Fix the hash calculation for some files in "non hashed" .app files
This commit is contained in:
parent
e046031dd2
commit
659b408a59
@ -80,6 +80,7 @@ public class NUSDecryption extends AESDecryption {
|
|||||||
|
|
||||||
int inBlockBuffer;
|
int inBlockBuffer;
|
||||||
long written = 0;
|
long written = 0;
|
||||||
|
long writtenFallback = 0;
|
||||||
|
|
||||||
ByteArrayBuffer overflow = new ByteArrayBuffer(BLOCKSIZE);
|
ByteArrayBuffer overflow = new ByteArrayBuffer(BLOCKSIZE);
|
||||||
|
|
||||||
@ -101,12 +102,21 @@ public class NUSDecryption extends AESDecryption {
|
|||||||
|
|
||||||
if (sha1 != null && sha1fallback != null) {
|
if (sha1 != null && sha1fallback != null) {
|
||||||
sha1.update(output, 0, toWrite);
|
sha1.update(output, 0, toWrite);
|
||||||
sha1fallback.update(output, 0, toWrite);
|
|
||||||
|
// In some cases it's using the hash of the whole .app file instead of the part
|
||||||
|
// that's been actually used.
|
||||||
|
long toFallback = inBlockBuffer;
|
||||||
|
if (writtenFallback + toFallback > expectedSizeForHash) {
|
||||||
|
toFallback = expectedSizeForHash - writtenFallback;
|
||||||
|
}
|
||||||
|
sha1fallback.update(output, 0, (int) toFallback);
|
||||||
|
writtenFallback += toFallback;
|
||||||
}
|
}
|
||||||
} while (inBlockBuffer == BLOCKSIZE);
|
} while (inBlockBuffer == BLOCKSIZE);
|
||||||
|
|
||||||
if (sha1 != null && sha1fallback != null) {
|
if (sha1 != null && sha1fallback != null) {
|
||||||
long missingInHash = expectedSizeForHash - written;
|
|
||||||
|
long missingInHash = expectedSizeForHash - writtenFallback;
|
||||||
if (missingInHash > 0) {
|
if (missingInHash > 0) {
|
||||||
sha1fallback.update(new byte[(int) missingInHash]);
|
sha1fallback.update(new byte[(int) missingInHash]);
|
||||||
}
|
}
|
||||||
@ -118,6 +128,7 @@ public class NUSDecryption extends AESDecryption {
|
|||||||
outputStream.close();
|
outputStream.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
throw new CheckSumWrongException("hash checksum failed", calculated_hash1, expected_hash);
|
throw new CheckSumWrongException("hash checksum failed", calculated_hash1, expected_hash);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// log.warning("Hash DOES match saves output stream.");
|
// log.warning("Hash DOES match saves output stream.");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user