mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-09-28 15:08:35 +02:00
llow reading disc with an given offset from a bigger file (e.g from a disk dump)
This commit is contained in:
parent
135e78feda
commit
75a280ece5
@ -46,6 +46,10 @@ public class WUDImage {
|
||||
@Getter private final WUDDiscReader WUDDiscReader;
|
||||
|
||||
public WUDImage(File file) throws IOException {
|
||||
this(file, 0);
|
||||
}
|
||||
|
||||
public WUDImage(File file, long readOffset) throws IOException {
|
||||
if (file == null || !file.exists()) {
|
||||
log.info("WUD file is null or does not exist");
|
||||
System.exit(1);
|
||||
@ -86,11 +90,11 @@ public class WUDImage {
|
||||
}
|
||||
|
||||
if (isCompressed()) {
|
||||
this.WUDDiscReader = new WUDDiscReaderCompressed(this);
|
||||
this.WUDDiscReader = new WUDDiscReaderCompressed(this, readOffset);
|
||||
} else if (isSplitted()) {
|
||||
this.WUDDiscReader = new WUDDiscReaderSplitted(this);
|
||||
this.WUDDiscReader = new WUDDiscReaderSplitted(this, readOffset);
|
||||
} else {
|
||||
this.WUDDiscReader = new WUDDiscReaderUncompressed(this);
|
||||
this.WUDDiscReader = new WUDDiscReaderUncompressed(this, readOffset);
|
||||
}
|
||||
|
||||
fileStream.close();
|
||||
|
@ -36,9 +36,16 @@ import lombok.extern.java.Log;
|
||||
@Log
|
||||
public abstract class WUDDiscReader {
|
||||
@Getter private final WUDImage image;
|
||||
@Getter private long baseOffset;
|
||||
|
||||
public WUDDiscReader(WUDImage image) {
|
||||
this(image, 0);
|
||||
}
|
||||
|
||||
public WUDDiscReader(WUDImage image, long baseOffset) {
|
||||
this.baseOffset = 0;
|
||||
this.image = image;
|
||||
this.baseOffset = baseOffset;
|
||||
}
|
||||
|
||||
public byte[] readEncryptedToByteArray(long offset, long fileoffset, long size) throws IOException {
|
||||
|
@ -27,8 +27,8 @@ import de.mas.wiiu.jnus.utils.StreamUtils;
|
||||
|
||||
public class WUDDiscReaderCompressed extends WUDDiscReader {
|
||||
|
||||
public WUDDiscReaderCompressed(WUDImage image) {
|
||||
super(image);
|
||||
public WUDDiscReaderCompressed(WUDImage image, long baseOffset) {
|
||||
super(image, baseOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,9 +39,9 @@ public class WUDDiscReaderCompressed extends WUDDiscReader {
|
||||
// make sure there is no out-of-bounds read
|
||||
WUDImageCompressedInfo info = getImage().getCompressedInfo();
|
||||
|
||||
long fileBytesLeft = info.getUncompressedSize() - offset;
|
||||
long fileBytesLeft = info.getUncompressedSize() - (offset + getBaseOffset());
|
||||
|
||||
long usedOffset = offset;
|
||||
long usedOffset = offset + getBaseOffset();
|
||||
long usedSize = size;
|
||||
|
||||
if (fileBytesLeft <= 0) {
|
||||
|
@ -32,20 +32,21 @@ public class WUDDiscReaderSplitted extends WUDDiscReader {
|
||||
public static long NUMBER_OF_FILES = 12;
|
||||
public static String WUD_SPLITTED_DEFAULT_FILEPATTERN = "game_part%d.wud";
|
||||
|
||||
public WUDDiscReaderSplitted(WUDImage image) {
|
||||
super(image);
|
||||
public WUDDiscReaderSplitted(WUDImage image, long baseOffset) {
|
||||
super(image, baseOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readEncryptedToStream(OutputStream outputStream, long offset, long size) throws IOException {
|
||||
RandomAccessFile input = getFileByOffset(offset);
|
||||
long newOffset = offset + + this.getBaseOffset();
|
||||
RandomAccessFile input = getFileByOffset(newOffset);
|
||||
|
||||
int bufferSize = 0x8000;
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
long totalread = 0;
|
||||
long curOffset = offset;
|
||||
long curOffset = newOffset;
|
||||
|
||||
int part = getFilePartByOffset(offset);
|
||||
int part = getFilePartByOffset(newOffset);
|
||||
long offsetInFile = getOffsetInFilePart(part, curOffset);
|
||||
|
||||
do {
|
||||
|
@ -26,8 +26,11 @@ import de.mas.wiiu.jnus.implementations.wud.WUDImage;
|
||||
import de.mas.wiiu.jnus.utils.StreamUtils;
|
||||
|
||||
public class WUDDiscReaderUncompressed extends WUDDiscReader {
|
||||
public WUDDiscReaderUncompressed(WUDImage image) {
|
||||
super(image);
|
||||
|
||||
|
||||
public WUDDiscReaderUncompressed(WUDImage image, long baseOffset) {
|
||||
super(image, baseOffset);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,7 +38,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader {
|
||||
|
||||
FileInputStream input = new FileInputStream(getImage().getFileHandle());
|
||||
|
||||
StreamUtils.skipExactly(input, offset);
|
||||
StreamUtils.skipExactly(input, offset + this.getBaseOffset());
|
||||
|
||||
int bufferSize = 0x8000;
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
@ -68,7 +71,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader {
|
||||
@Override
|
||||
public InputStream readEncryptedToStream(long offset, long size) throws IOException {
|
||||
FileInputStream input = new FileInputStream(getImage().getFileHandle());
|
||||
StreamUtils.skipExactly(input, offset);
|
||||
StreamUtils.skipExactly(input, offset + this.getBaseOffset());
|
||||
return input;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user