mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-05 07:45:11 +01:00
Optimize the random access of the non hashed files
This commit is contained in:
parent
79365a9fe6
commit
fc3a604cd4
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user