mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-25 09:26:55 +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()) {
|
||||
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) {
|
||||
if (c.isUNKNWNFlag1Set()) {
|
||||
log.info("Hash doesn't match. But file is optional. Don't worry.");
|
||||
|
@ -276,8 +276,8 @@ public class NUSDecryption extends AESDecryption {
|
||||
return output;
|
||||
}
|
||||
|
||||
public boolean decryptStreams(InputStream inputStream, OutputStream outputStream, long offset, long size, Content content, Optional<byte[]> h3HashHashed)
|
||||
throws IOException, CheckSumWrongException, NoSuchAlgorithmException {
|
||||
public boolean decryptStreams(InputStream inputStream, OutputStream outputStream, long offset, long size, Content content, Optional<byte[]> h3HashHashed,
|
||||
boolean partial) throws IOException, CheckSumWrongException, NoSuchAlgorithmException {
|
||||
|
||||
short contentIndex = (short) content.getIndex();
|
||||
|
||||
@ -290,11 +290,8 @@ public class NUSDecryption extends AESDecryption {
|
||||
decryptFileStreamHashed(inputStream, outputStream, offset, size, (short) contentIndex, h3);
|
||||
} else {
|
||||
byte[] h3Hash = content.getSHA2Hash();
|
||||
// We want to check if we read the whole file or just a part of it.
|
||||
// There should be only one actual file inside a non-hashed content.
|
||||
// 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) {
|
||||
// Ignore the h3hash if we don't read the whole file.
|
||||
if (partial) {
|
||||
h3Hash = null;
|
||||
}
|
||||
decryptFileStream(inputStream, outputStream, offset, size, (short) contentIndex, h3Hash, encryptedFileSize);
|
||||
|
Loading…
Reference in New Issue
Block a user