public void initialize(byte[] pBytes) { // int _titleLength; // int _pdxLength; // Title this.titleLength = ParseFile.GetSegmentLength(pBytes, 0, TITLE_TERMINATOR); if (this.titleLength > 0) { title = VGMToolbox.util.ByteConversion.GetJapaneseEncodedText(ParseFile.ParseSimpleOffset(pBytes, 0, this.titleLength)); } // PDX this.pdxOffset = this.titleLength + TITLE_TERMINATOR.Length; this.pdxLength = ParseFile.GetSegmentLength(pBytes, (this.titleLength + TITLE_TERMINATOR.Length), PDX_TERMINATOR); if (this.pdxLength > 0) { pdxFileName = VGMToolbox.util.ByteConversion.GetJapaneseEncodedText(ParseFile.ParseSimpleOffset(pBytes, (this.titleLength + TITLE_TERMINATOR.Length), this.pdxLength)); } this.dataOffset = this.titleLength + TITLE_TERMINATOR.Length + this.pdxLength + PDX_TERMINATOR.Length; this.dataLength = (int)(pBytes.Length - this.dataOffset); }
private void parseAuthChunk() { foreach (ChunkStruct c in chunks) { if (ParseFile.CompareSegment(c.chunkIdentifier, 0, AUTH_SIGNATURE)) { System.Text.Encoding enc = System.Text.Encoding.ASCII; byte[] authBlock; int offset = 0; int labelLength; if (offset < c.chunkData.Length) { labelLength = ParseFile.GetSegmentLength(c.chunkData, offset, NULL_TERMINATOR); authBlock = ParseFile.ParseSimpleOffset(c.chunkData, offset, labelLength); songName = enc.GetString(authBlock); songNameBytes = authBlock; offset += labelLength + 1; } if (offset < c.chunkData.Length) { labelLength = ParseFile.GetSegmentLength(c.chunkData, offset, NULL_TERMINATOR); authBlock = ParseFile.ParseSimpleOffset(c.chunkData, offset, labelLength); songArtist = enc.GetString(authBlock); songArtistBytes = authBlock; offset += labelLength + 1; } if (offset < c.chunkData.Length) { labelLength = ParseFile.GetSegmentLength(c.chunkData, offset, NULL_TERMINATOR); authBlock = ParseFile.ParseSimpleOffset(c.chunkData, offset, labelLength); songCopyright = enc.GetString(authBlock); songCopyrightBytes = authBlock; offset += labelLength + 1; } if (offset < c.chunkData.Length) { labelLength = ParseFile.GetSegmentLength(c.chunkData, offset, NULL_TERMINATOR); authBlock = ParseFile.ParseSimpleOffset(c.chunkData, offset, labelLength); nsfRipper = enc.GetString(authBlock); nsfRipperBytes = authBlock; offset += labelLength + 1; } } } }
private void parseTrackLabelsChunk() { foreach (ChunkStruct c in chunks) { if (ParseFile.CompareSegment(c.chunkIdentifier, 0, TRACK_LABELS_SIGNATURE)) { System.Text.Encoding enc = System.Text.Encoding.ASCII; int offset = 0; while (offset < c.chunkData.Length) { int labelLength = ParseFile.GetSegmentLength(c.chunkData, offset, NULL_TERMINATOR); byte[] trackLabel = ParseFile.ParseSimpleOffset(c.chunkData, offset, labelLength); this.trackLabels.Add(enc.GetString(trackLabel)); offset += labelLength + 1; } } } }
private void initializeTagHash(Stream pStream) { System.Text.Encoding enc = System.Text.Encoding.ASCII; tagHash.Add("S98 Version", enc.GetString(this.version)); // Song Name if (BitConverter.ToUInt32(this.songNameOffset, 0) != 0) { Int32 songOffset = BitConverter.ToInt32(this.songNameOffset, 0); Int32 songLength = ParseFile.GetSegmentLength(pStream, songOffset, new byte[] { 0x00 }); byte[] songName = ParseFile.ParseSimpleOffset(pStream, songOffset, songLength); tagHash.Add("Song Name", enc.GetString(songName)); tagHash.Add("Uncompressed Data Size", "0x" + BitConverter.ToInt32(this.compressing, 0).ToString("X2")); tagHash.Add("Offset [Song Name]", "0x" + BitConverter.ToInt32(this.songNameOffset, 0).ToString("X2")); } // Offsets tagHash.Add("Offset [Dump Data]", "0x" + BitConverter.ToInt32(this.dumpDataOffset, 0).ToString("X2")); tagHash.Add("Offset [Loop Point]", "0x" + BitConverter.ToInt32(this.loopPointOffset, 0).ToString("X2")); }
public void getSymbRecord(Stream pStream, int pSectionOffset, int pSubSectionOffset, ref byte[][] pSymbFileNames, ref SdatSymbolRec pSdatSymbolRec) { if (pSubSectionOffset > 0) { pSdatSymbolRec = new SdatSymbolRec(); pSdatSymbolRec.nCount = ParseFile.ParseSimpleOffset(pStream, pSectionOffset + pSubSectionOffset + SYMB_ENTRY_NUM_FILES_OFFSET, SYMB_ENTRY_NUM_FILES_LENGTH); int subRecordCount = BitConverter.ToInt32(pSdatSymbolRec.nCount, 0); pSymbFileNames = new byte[subRecordCount][]; pSdatSymbolRec.nEntryOffsets = new byte[subRecordCount][]; for (int i = 1; i <= subRecordCount; i++) { pSdatSymbolRec.nEntryOffsets[i - 1] = ParseFile.ParseSimpleOffset(pStream, pSectionOffset + pSubSectionOffset + SYMB_ENTRY_NUM_FILES_OFFSET + (SYMB_ENTRY_FILE_NAME_SIZE * i), SYMB_ENTRY_NUM_FILES_LENGTH); int fileOffset = BitConverter.ToInt32(pSdatSymbolRec.nEntryOffsets[i - 1], 0); if (fileOffset > 0) { int fileLength = ParseFile.GetSegmentLength(pStream, pSectionOffset + fileOffset, NULL_BYTE_ARRAY); pSymbFileNames[i - 1] = ParseFile.ParseSimpleOffset(pStream, pSectionOffset + fileOffset, fileLength); } else { pSymbFileNames[i - 1] = null; } } } }
public void Initialize(Stream pStream, string pFilePath) { this.filePath = pFilePath; // Title this.titleLength = ParseFile.GetSegmentLength(pStream, 0, TITLE_TERMINATOR); if (this.titleLength > 0) { this.titleBytes = ParseFile.ParseSimpleOffset(pStream, 0, this.titleLength); this.title = VGMToolbox.util.ByteConversion.GetJapaneseEncodedText(this.titleBytes); } // PDX this.pdxOffset = this.titleLength + TITLE_TERMINATOR.Length; this.pdxLength = ParseFile.GetSegmentLength(pStream, this.pdxOffset, PDX_TERMINATOR); if (this.pdxLength > 0) { this.pdxBytes = ParseFile.ParseSimpleOffset(pStream, this.pdxOffset, this.pdxLength); this.pdxFileName = VGMToolbox.util.ByteConversion.GetJapaneseEncodedText(this.pdxBytes); string pdxExtension = Path.GetExtension(this.pdxFileName); if (pdxExtension.Equals(String.Empty)) { this.pdxFileName += PDX_FILE_EXTENSION; } } this.initializeTagHash(); this.dataOffset = this.titleLength + TITLE_TERMINATOR.Length + this.pdxLength + PDX_TERMINATOR.Length; this.dataLength = (int)(pStream.Length - this.dataOffset); this.dataBytes = ParseFile.ParseSimpleOffset(pStream, this.dataOffset, this.dataLength); }
public static void RenameFileUsingInternalName(string path, long offset, int length, byte[] terminatorBytes, bool maintainFileExtension) { string destinationDirectory = Path.GetDirectoryName(path); string destinationFile; string originalExtension; int nameLength; byte[] nameByteArray; using (FileStream fs = File.OpenRead(path)) { if (terminatorBytes != null) { nameLength = ParseFile.GetSegmentLength(fs, (int)offset, terminatorBytes); } else { nameLength = length; } if (nameLength < 1) { throw new ArgumentOutOfRangeException("Name Length", "Name Length is less than 1."); } if (maintainFileExtension) { originalExtension = Path.GetExtension(path); } nameByteArray = ParseFile.ParseSimpleOffset(fs, offset, nameLength); destinationFile = ByteConversion.GetAsciiText(FileUtil.ReplaceNullByteWithSpace(nameByteArray)).Trim(); destinationFile = Path.Combine(destinationDirectory, destinationFile); if (maintainFileExtension) { originalExtension = Path.GetExtension(path); destinationFile = Path.ChangeExtension(destinationFile, originalExtension); } } // try to copy using the new name if (!path.Equals(destinationFile)) { try { if (!Directory.Exists(Path.GetDirectoryName(destinationFile))) { Directory.CreateDirectory(Path.GetDirectoryName(destinationFile)); } if (File.Exists(destinationFile)) { string[] sameNamedFiles = Directory.GetFiles(Path.GetDirectoryName(destinationFile), Path.GetFileNameWithoutExtension(destinationFile) + "*"); // rename to prevent overwrite destinationFile = Path.Combine(Path.GetDirectoryName(destinationFile), String.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(destinationFile), sameNamedFiles.Length.ToString("D4"), Path.GetExtension(destinationFile))); } File.Copy(path, destinationFile); File.Delete(path); } catch (Exception ex) { throw new Exception(ex.Message, ex); } } }
private void parseDirectoryRecord( FileStream isoStream, NintendoGameCubeDirectoryRecord directoryRecord, DateTime creationDateTime, long baseOffset, long rootDirectoryOffset, long directoryOffset, long nameTableOffset, string parentDirectory, int offsetBitShiftValue) { long directoryRecordEndOffset; long newDirectoryEndOffset; long currentOffset = baseOffset + directoryOffset; int itemNameSize; byte[] itemNameBytes; string itemName; NintendoGameCubeDirectoryRecord newDirectoryRecord; NintendoGameCubeDirectoryStructure newDirectory; NintendoGameCubeFileStructure newFile; directoryRecordEndOffset = rootDirectoryOffset + (directoryRecord.FileSize * 0xC); currentOffset += 0xC; while (currentOffset < directoryRecordEndOffset) { newDirectoryRecord = new NintendoGameCubeDirectoryRecord(ParseFile.ParseSimpleOffset(isoStream, currentOffset, 0xC), offsetBitShiftValue); itemNameSize = ParseFile.GetSegmentLength(isoStream, (int)(nameTableOffset + newDirectoryRecord.NameOffset), Constants.NullByteArray); itemNameBytes = ParseFile.ParseSimpleOffset(isoStream, nameTableOffset + newDirectoryRecord.NameOffset, itemNameSize); itemName = ByteConversion.GetEncodedText(itemNameBytes, ByteConversion.GetPredictedCodePageForTags(itemNameBytes)); if (!newDirectoryRecord.IsDirectory) { newFile = new NintendoGameCubeFileStructure(parentDirectory, this.SourceFilePath, itemName, baseOffset, newDirectoryRecord.FileOffset, newDirectoryRecord.FileSize, creationDateTime); this.FileArray.Add(newFile); currentOffset += 0xC; } else { newDirectory = new NintendoGameCubeDirectoryStructure(isoStream, isoStream.Name, newDirectoryRecord, creationDateTime, baseOffset, rootDirectoryOffset, currentOffset, nameTableOffset, itemName, parentDirectory, offsetBitShiftValue); this.SubDirectoryArray.Add(newDirectory); newDirectoryEndOffset = rootDirectoryOffset + (newDirectoryRecord.FileSize * 0xC); currentOffset = newDirectoryEndOffset; } } }
private void parseDirectoryRecord( FileStream isoStream, NintendoWiiOpticalDiscDirectoryRecord directoryRecord, DateTime creationDateTime, long baseOffset, long dataSectionOffset, long rootDirectoryOffset, long directoryOffset, long nameTableOffset, string parentDirectory, NintendoWiiEncryptedDiscReader discReader, byte[] partitionKey) { long directoryRecordEndOffset; long newDirectoryEndOffset; long currentOffset = directoryOffset; int itemNameSize; byte[] itemNameBytes; string itemName; byte[] newDirectoryRecordBytes; NintendoWiiOpticalDiscDirectoryRecord newDirectoryRecord; NintendoWiiOpticalDiscDirectoryStructure newDirectory; NintendoWiiOpticalDiscFileStructure newFile; directoryRecordEndOffset = rootDirectoryOffset + (directoryRecord.FileSize * 0xC); currentOffset += 0xC; while (currentOffset < directoryRecordEndOffset) { newDirectoryRecordBytes = discReader.GetBytes(isoStream, baseOffset, dataSectionOffset, currentOffset, 0xC, partitionKey); newDirectoryRecord = new NintendoWiiOpticalDiscDirectoryRecord(newDirectoryRecordBytes); itemNameBytes = discReader.GetBytes(isoStream, baseOffset, dataSectionOffset, nameTableOffset + newDirectoryRecord.NameOffset, 512, partitionKey); itemNameSize = ParseFile.GetSegmentLength(itemNameBytes, 0, Constants.NullByteArray); itemNameBytes = discReader.GetBytes(isoStream, baseOffset, dataSectionOffset, nameTableOffset + newDirectoryRecord.NameOffset, itemNameSize, partitionKey); itemName = ByteConversion.GetEncodedText(itemNameBytes, ByteConversion.GetPredictedCodePageForTags(itemNameBytes)); if (!newDirectoryRecord.IsDirectory) { newFile = new NintendoWiiOpticalDiscFileStructure(parentDirectory, this.SourceFilePath, itemName, baseOffset, dataSectionOffset, newDirectoryRecord.FileOffset, newDirectoryRecord.FileSize, creationDateTime, discReader, partitionKey); this.FileArray.Add(newFile); currentOffset += 0xC; } else { newDirectory = new NintendoWiiOpticalDiscDirectoryStructure(isoStream, isoStream.Name, newDirectoryRecord, creationDateTime, baseOffset, dataSectionOffset, rootDirectoryOffset, currentOffset, nameTableOffset, itemName, parentDirectory, discReader, partitionKey); this.SubDirectoryArray.Add(newDirectory); newDirectoryEndOffset = rootDirectoryOffset + (newDirectoryRecord.FileSize * 0xC); currentOffset = newDirectoryEndOffset; } } }