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