Optimize the random access of the non hashed files

This commit is contained in:
Maschell 2019-04-30 14:25:29 +02:00
parent 79365a9fe6
commit fc3a604cd4
2 changed files with 5 additions and 24 deletions

View File

@ -91,7 +91,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
long streamOffset = payloadOffset;
long streamFilesize = size;
long streamFilesize = c.getEncryptedFileSize();
if (c.isHashed()) {
streamOffset = (payloadOffset / 0xFC00) * 0x10000;
long offsetInBlock = payloadOffset - ((streamOffset / 0x10000) * 0xFC00);
@ -110,16 +110,11 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
streamFilesize = curVal;
}
} else {
if (size != entry.getFileSize()) {
streamOffset = (payloadOffset / 0x8000) * 0x8000;
// We need the missing bytes of the previous blocks + the size we want to read.
streamFilesize = size;
long offsetInBlock = offset - streamOffset;
streamFilesize += offsetInBlock;
if (size != entry.getFileSize()) {
streamFilesize = size;
// We need the previous IV if we don't start at the first block.
if (payloadOffset >= 0x8000 && payloadOffset % 0x8000 == 0) {
if (payloadOffset >= 16) {
streamOffset -= 16;
streamFilesize += 16;
}

View File

@ -91,13 +91,8 @@ public class NUSDecryption extends AESDecryption {
int skipoffset = (int) (fileOffset % 0x8000);
try {
// If we are at the beginning of a block, but it's not the first one,
// we need to get the IV from the last 16 bytes of the previous block.
// while beeing paranoid to exactly read 16 bytes but not more. Reading more
// would destroy our input stream.
// The input stream has been prepared to start 16 bytes earlier on this case.
if (fileOffset >= 0x8000 && fileOffset % 0x8000 == 0) {
if (fileOffset >= 16) {
int toRead = 16;
byte[] data = new byte[toRead];
int readTotal = 0;
@ -119,15 +114,6 @@ public class NUSDecryption extends AESDecryption {
long toRead = Utils.align(filesize + 15, 16);
do {
// In case we start on the middle of a block we need to consume the "garbage" and save the
// current IV.
if (skipoffset > 0) {
int skippedBytes = StreamUtils.getChunkFromStream(inputStream, blockBuffer, overflow, skipoffset);
if (skippedBytes >= 16) {
IV = Arrays.copyOfRange(blockBuffer, skippedBytes - 16, skippedBytes);
}
skipoffset = 0;
}
int curReadSize = BLOCKSIZE;
if (toRead < BLOCKSIZE) {