public static WUDInfo createAndLoad(WUDDiscReader discReader, byte[] titleKey) { WUDInfo result = new WUDInfo(titleKey, discReader); byte[] PartitionTocBlock = discReader.readDecryptedToByteArray(Settings.WIIU_DECRYPTED_AREA_OFFSET, 0, 0x8000, titleKey, null); // verify DiscKey before proceeding byte[] copy = new byte[4]; Array.ConstrainedCopy(PartitionTocBlock, 0, copy, 0, 4); if (!ArraysEqual(copy, DECRYPTED_AREA_SIGNATURE)) { //MessageBox.Show("Decryption of PartitionTocBlock failed"); return(null); } Dictionary <string, WUDPartition> partitions = readPartitions(result, PartitionTocBlock); result.partitions.Clear(); foreach (var v in partitions) { result.partitions.Add(v.Key, v.Value); } return(result); }
public override MemoryStream getInputStreamFromContent(Content content, long fileOffsetBlock) { WUDDiscReader discReader = getDiscReader(); long offset = getOffsetInWUD(content) + fileOffsetBlock; return(discReader.readEncryptedToInputStream(offset, content.encryptedFileSize)); }
private static byte[] getFSTEntryAsByte(String filename, WUDPartition partition, FST fst, WUDDiscReader discReader, byte[] key) { FSTEntry entry = getEntryByName(fst.root, filename); ContentFSTInfo info = fst.contentFSTInfos[((int)entry.contentFSTID)]; // Calculating the IV ByteBuffer byteBuffer = ByteBuffer.allocate(0x10); byteBuffer.position(0x08); long l = entry.fileOffset >> 16; byte[] ar = BitConverter.GetBytes(l); byte[] IV = new byte[0x10];//= copybyteBuffer.putLong(entry.fileOffset >> 16).ToArray(); Array.ConstrainedCopy(ar, 0, IV, 0x08, 0x08); return(discReader.readDecryptedToByteArray(Settings.WIIU_DECRYPTED_AREA_OFFSET + (long)partition.partitionOffset + (long)info.getOffset(), entry.fileOffset, (int)entry.fileSize, key, IV)); }
public WUDImage(FileInfo file) { if (file == null || !file.Exists) { //MessageBox.Show("WUD file is null or does not exist"); //System.exit(1); } fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); BinaryReader br1 = new BinaryReader(fileStream); br1.BaseStream.Seek(0, SeekOrigin.Begin); byte[] wuxheader = new byte[WUDImageCompressedInfo.WUX_HEADER_SIZE]; int n = br1.Read(wuxheader, 0, WUDImageCompressedInfo.WUX_HEADER_SIZE); WUDImageCompressedInfo compressedInfo = new WUDImageCompressedInfo(wuxheader); if (compressedInfo.isWUX()) { //MessageBox.Show("Image is compressed"); this.isCompressed = true; this.isSplitted = false; Dictionary <int, long> indexTable = new Dictionary <int, long>(); long offsetIndexTable = compressedInfo.offsetIndexTable; br1.BaseStream.Seek(offsetIndexTable, SeekOrigin.Begin); byte[] tableData = new byte[(int)(compressedInfo.indexTableEntryCount * 0x04)]; br1.Read(tableData, 0, tableData.Length); int cur_offset = 0x00; for (long i = 0; i < compressedInfo.indexTableEntryCount; i++) { indexTable[(int)i] = BitConverter.ToInt32(tableData, (int)cur_offset); cur_offset += 0x04; } compressedInfo.indexTable = indexTable; this.compressedInfo = compressedInfo; } else { this.isCompressed = false; if (file.Name.Equals(String.Format(WUDDiscReaderSplitted.WUD_SPLITTED_DEFAULT_FILEPATTERN, 1)) && (file.Length == WUDDiscReaderSplitted.WUD_SPLITTED_FILE_SIZE)) { this.isSplitted = true; //MessageBox.Show("Image is splitted"); } else { //MessageBox.Show("Image is not splitted"); this.isSplitted = false; } } if (isCompressed) { this.WUDDiscReader = new WUDDiscReaderCompressed(this); } else if (isSplitted) { this.WUDDiscReader = new WUDDiscReaderSplitted(this); } else { this.WUDDiscReader = new WUDDiscReaderUncompressed(this); } fileStream.Close(); this.fileHandle = file; }
public WUDInfo(byte[] titleKey, WUDDiscReader discReader) { // TODO: Complete member initialization this.titleKey = titleKey; this.WUDDiscReader = discReader; }