mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-22 07:59:19 +01:00
Check partial file reads on a different location
This commit is contained in:
parent
995d548c11
commit
5a57d42c52
@ -146,7 +146,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
|
|||||||
if (c.isHashed()) {
|
if (c.isHashed()) {
|
||||||
h3HashedOpt = dataProvider.getContentH3Hash(c);
|
h3HashedOpt = dataProvider.getContentH3Hash(c);
|
||||||
}
|
}
|
||||||
return nusdecryption.decryptStreams(in, outputStream, fileOffset, fileSize, c, h3HashedOpt);
|
return nusdecryption.decryptStreams(in, outputStream, fileOffset, fileSize, c, h3HashedOpt, fileSize == entry.getFileSize());
|
||||||
} catch (CheckSumWrongException e) {
|
} catch (CheckSumWrongException e) {
|
||||||
if (c.isUNKNWNFlag1Set()) {
|
if (c.isUNKNWNFlag1Set()) {
|
||||||
log.info("Hash doesn't match. But file is optional. Don't worry.");
|
log.info("Hash doesn't match. But file is optional. Don't worry.");
|
||||||
|
@ -276,8 +276,8 @@ public class NUSDecryption extends AESDecryption {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean decryptStreams(InputStream inputStream, OutputStream outputStream, long offset, long size, Content content, Optional<byte[]> h3HashHashed)
|
public boolean decryptStreams(InputStream inputStream, OutputStream outputStream, long offset, long size, Content content, Optional<byte[]> h3HashHashed,
|
||||||
throws IOException, CheckSumWrongException, NoSuchAlgorithmException {
|
boolean partial) throws IOException, CheckSumWrongException, NoSuchAlgorithmException {
|
||||||
|
|
||||||
short contentIndex = (short) content.getIndex();
|
short contentIndex = (short) content.getIndex();
|
||||||
|
|
||||||
@ -290,11 +290,8 @@ public class NUSDecryption extends AESDecryption {
|
|||||||
decryptFileStreamHashed(inputStream, outputStream, offset, size, (short) contentIndex, h3);
|
decryptFileStreamHashed(inputStream, outputStream, offset, size, (short) contentIndex, h3);
|
||||||
} else {
|
} else {
|
||||||
byte[] h3Hash = content.getSHA2Hash();
|
byte[] h3Hash = content.getSHA2Hash();
|
||||||
// We want to check if we read the whole file or just a part of it.
|
// Ignore the h3hash if we don't read the whole file.
|
||||||
// There should be only one actual file inside a non-hashed content.
|
if (partial) {
|
||||||
// But it could also contain a directory, so we need to filter.
|
|
||||||
long fstFileSize = content.getEntries().stream().filter(f -> !f.isDir()).findFirst().map(f -> f.getFileSize()).orElse(0L);
|
|
||||||
if (size > 0 && size < fstFileSize) {
|
|
||||||
h3Hash = null;
|
h3Hash = null;
|
||||||
}
|
}
|
||||||
decryptFileStream(inputStream, outputStream, offset, size, (short) contentIndex, h3Hash, encryptedFileSize);
|
decryptFileStream(inputStream, outputStream, offset, size, (short) contentIndex, h3Hash, encryptedFileSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user