From e8236e86d248db5526af79249805e3bf35b94923 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 6 Dec 2018 15:59:34 +0100 Subject: [PATCH] Fixed file offset calculation. --- src/de/mas/wiiu/jnus/entities/fst/FST.java | 12 ++++++------ src/de/mas/wiiu/jnus/entities/fst/FSTService.java | 9 ++------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/de/mas/wiiu/jnus/entities/fst/FST.java b/src/de/mas/wiiu/jnus/entities/fst/FST.java index de67a9b..eef2770 100644 --- a/src/de/mas/wiiu/jnus/entities/fst/FST.java +++ b/src/de/mas/wiiu/jnus/entities/fst/FST.java @@ -34,13 +34,13 @@ import lombok.Getter; public final class FST { @Getter private final FSTEntry root = FSTEntry.getRootFSTEntry(); - @Getter private final int unknown; + @Getter private final int sectorSize; @Getter private final int contentCount; @Getter private final Map contentFSTInfos = new HashMap<>(); private FST(int unknown, int contentCount) { - this.unknown = unknown; + this.sectorSize = unknown; this.contentCount = contentCount; } @@ -55,15 +55,15 @@ public final class FST { */ public static FST parseFST(byte[] fstData, Map contentsMappedByIndex) { if (!Arrays.equals(Arrays.copyOfRange(fstData, 0, 3), new byte[] { 0x46, 0x53, 0x54 })) { - throw new NullPointerException(); + throw new RuntimeException("Failed to parse FST"); // return null; // throw new IllegalArgumentException("Not a FST. Maybe a wrong key?"); } - int unknownValue = ByteUtils.getIntFromBytes(fstData, 0x04); + int sectorSize = ByteUtils.getIntFromBytes(fstData, 0x04); int contentCount = ByteUtils.getIntFromBytes(fstData, 0x08); - FST result = new FST(unknownValue, contentCount); + FST result = new FST(sectorSize, contentCount); int contentfst_offset = 0x20; int contentfst_size = 0x20 * contentCount; @@ -94,7 +94,7 @@ public final class FST { FSTEntry root = result.getRoot(); - FSTService.parseFST(root, fstSection, nameSection, contentsMappedByIndex, contentFSTInfos); + FSTService.parseFST(root, fstSection, nameSection, contentsMappedByIndex, contentFSTInfos, sectorSize); return result; } diff --git a/src/de/mas/wiiu/jnus/entities/fst/FSTService.java b/src/de/mas/wiiu/jnus/entities/fst/FSTService.java index d916947..9a4571e 100644 --- a/src/de/mas/wiiu/jnus/entities/fst/FSTService.java +++ b/src/de/mas/wiiu/jnus/entities/fst/FSTService.java @@ -33,7 +33,7 @@ public final class FSTService { } public static void parseFST(FSTEntry rootEntry, byte[] fstSection, byte[] namesSection, Map contentsByIndex, - Map contentsFSTByIndex) { + Map contentsFSTByIndex, int sectorSize) { int totalEntries = ByteUtils.getIntFromBytes(fstSection, 0x08); int level = 0; @@ -99,7 +99,7 @@ public final class FSTService { break; } } else { - entryParam.setFileOffset(fileOffset << 5); + entryParam.setFileOffset(fileOffset * sectorSize); entryParam.setFileSize(fileSize); parent = fstEntryToOffsetMap.get(Entry[level - 1]); @@ -114,11 +114,6 @@ public final class FSTService { if (content == null) { log.warning("Content for FST Entry not found"); } else { - - if (content.isHashed() && (content.getDecryptedFileSize() < (fileOffset << 5))) { // TODO: Figure out how this works... - entryParam.setFileOffset(fileOffset); - } - entryParam.setContent(content); ContentFSTInfo contentFSTInfo = contentsFSTByIndex.get((int) contentIndex);