Example #1
0
        public virtual void LoadDirectories(FileStream isoStream)
        {
            // change name of top level folder
            this.DirectoryRecordForRootDirectory.FileIdentifierString = String.Empty;

            // get first path record
            byte[] rootDirPathBytes = CdRom.GetSectorByLba(isoStream, this.VolumeBaseOffset, this.LocationOfOccurrenceOfTypeMPathTable, this.IsRawDump, this.LogicalBlockSize);
            rootDirPathBytes = CdRom.GetDataChunkFromSector(rootDirPathBytes, this.IsRawDump);

            // grab the directory record
            uint rootDirectoryOffset = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(rootDirPathBytes, 2, 4));

            byte[] rootDirDirectorySector = CdRom.GetSectorByLba(isoStream, this.VolumeBaseOffset, rootDirectoryOffset, this.IsRawDump, this.LogicalBlockSize);
            rootDirDirectorySector = CdRom.GetDataChunkFromSector(rootDirDirectorySector, this.IsRawDump);

            byte rootDirectoryRecordSize = rootDirDirectorySector[0];

            byte[] rootDirectoryRecord = ParseFile.ParseSimpleOffset(rootDirDirectorySector, 0, rootDirectoryRecordSize);
            this.DirectoryRecordForRootDirectory = new GreenBookCdiDirectoryRecord(rootDirectoryRecord);

            // populate this volume's directory structure
            GreenBookCdiDirectoryStructure rootDirectory =
                new GreenBookCdiDirectoryStructure(isoStream, isoStream.Name,
                                                   this.VolumeBaseOffset, this.DirectoryRecordForRootDirectory,
                                                   this.LogicalBlockSize, this.IsRawDump, this.SectorSize, null);

            this.DirectoryStructureArray.Add(rootDirectory);
        }
Example #2
0
        /// <summary>
        /// Reads a string from the stream, advancing the index accordingly
        /// </summary>
        /// <param name="length">The length of the string to be read</param>
        /// <returns>the string read from the stream</returns>
        public string ReadString(int length)
        {
            byte[] temp = new byte[length];
            _stream.Read(temp, 0, length);

            return(ByteConversion.GetString(temp));
        }
Example #3
0
        /// <summary>
        /// Reads a float from the stream, and advances the index accordingly.
        /// </summary>
        /// <returns>the next 4 bytes from the stream cast as a float</returns>
        public float ReadFloat()
        {
            byte[] temp = new byte[INTLENGTH];
            _stream.Read(temp, 0, INTLENGTH);

            return(ByteConversion.ToFloat(temp, 0));
        }
Example #4
0
        /// <summary>
        /// Reads the next short from the stream, and checks if it equals 'value'.
        /// </summary>
        /// <param name="value">The value to compare against the next short from the stream</param>
        /// <param name="objectID">The ID of the marker (if known)</param>
        /// <param name="objectName">The name of the object being affected</param>
        /// <param name="objectType">The type of object (if known)</param>
        /// <param name="precedingProperty">The property immediately before the invalid marker</param>
        /// <returns>true or false, depending on whether the read short is the same as the specified value</returns>
        public bool Assert(short value, ushort objectID, string objectName, string objectType,
                           string precedingProperty)
        {
            long Location = _stream.Position;

            byte[] temp = new byte[SHORTLENGTH];
            _stream.Read(temp, 0, SHORTLENGTH);

            short Value = ByteConversion.ToShort(temp, 0);

            if (Value != value)
            {
                InvalidMarkerEventArgs Args = new InvalidMarkerEventArgs(Location,
                                                                         objectID,
                                                                         objectName,
                                                                         objectType,
                                                                         precedingProperty,
                                                                         value,
                                                                         Value);

                InvalidMarkerEvent(null, Args);
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Reads a ulong from the stream, and advances the index accordingly.
        /// </summary>
        /// <returns>the next 8 bytes from the stream cast as a ulong</returns>
        public ulong ReadULong()
        {
            byte[] temp = new byte[LONGLENGTH];
            _stream.Read(temp, 0, LONGLENGTH);

            return(ByteConversion.ToULong(temp, 0));
        }
Example #6
0
        /// <summary>
        /// Reads a uint from the stream, and advances the index accordingly.
        /// </summary>
        /// <returns>the next 4 bytes from the stream cast as a uint</returns>
        public uint ReadUInt()
        {
            byte[] temp = new byte[INTLENGTH];
            _stream.Read(temp, 0, INTLENGTH);

            return(ByteConversion.ToUInt(temp, 0));
        }
Example #7
0
        /// <summary>
        /// Reads a ushort from the stream, and advances the index accordingly.
        /// </summary>
        /// <returns>the next 2 bytes from the stream cast as a ushort</returns>
        public ushort ReadUShort()
        {
            byte[] temp = new byte[SHORTLENGTH];
            _stream.Read(temp, 0, SHORTLENGTH);

            return(ByteConversion.ToUShort(temp, 0));
        }
Example #8
0
        public static int GetMpegStreamType(string path)
        {
            int mpegType = -1;

            using (FileStream fs = File.OpenRead(path))
            {
                // look for first packet
                long currentOffset = ParseFile.GetNextOffset(fs, 0, MpegStream.PacketStartBytes);

                if (currentOffset != -1)
                {
                    currentOffset += 4;
                    fs.Position    = currentOffset;
                    byte idByte = (byte)fs.ReadByte();

                    if ((int)ByteConversion.GetHighNibble(idByte) == 2)
                    {
                        mpegType = 1;
                    }
                    else if ((int)ByteConversion.GetHighNibble(idByte) == 4)
                    {
                        mpegType = 2;
                    }
                }
                else
                {
                    throw new FormatException(String.Format("Cannot find Pack Header for file: {0}{1}", Path.GetFileName(path), Environment.NewLine));
                }
            }

            return(mpegType);
        }
        public void Initialize(FileStream isoStream, long offset, bool isRawDump)
        {
            byte[] volumeIdentifierBytes;

            this.DiscBaseOffset = offset;
            this.DiscReader     = new NintendoWiiEncryptedDiscReader();

            this.WiiDiscId  = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(isoStream, this.DiscBaseOffset, 1));
            this.GameCode   = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(isoStream, this.DiscBaseOffset + 1, 2));
            this.RegionCode = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(isoStream, this.DiscBaseOffset + 3, 1));
            this.MakerCode  = ParseFile.ParseSimpleOffset(isoStream, this.DiscBaseOffset + 4, 2);

            this.IsRawDump = isRawDump;

            // get identifier
            volumeIdentifierBytes = ParseFile.ParseSimpleOffset(isoStream, this.DiscBaseOffset + 0x20, 64);
            volumeIdentifierBytes = FileUtil.ReplaceNullByteWithSpace(volumeIdentifierBytes);

            // initialize partition info
            this.InitializePartitions(isoStream);

            // initialize volumes
            this.VolumeArrayList = new ArrayList();
            this.LoadVolumes(isoStream);
        }
Example #10
0
        public Iso9660PathTableRecord(byte[] pathBytes, bool isLittleEndian)
        {
            this.LengthOfDirectoryIdentifier   = ParseFile.ParseSimpleOffset(pathBytes, 0, 1)[0];
            this.ExtendedAttributeRecordLength = ParseFile.ParseSimpleOffset(pathBytes, 1, 1)[0];

            if (isLittleEndian)
            {
                this.LocationOfExtent = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(pathBytes, 2, 4), 0);
            }
            else
            {
                this.LocationOfExtent = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(pathBytes, 2, 4));
            }
            if (isLittleEndian)
            {
                this.DirectoryNumberOfParentDirectory = BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(pathBytes, 6, 2), 0);
            }
            else
            {
                this.DirectoryNumberOfParentDirectory = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(pathBytes, 6, 2));
            }

            this.DirectoryIdentifierBytes = ParseFile.ParseSimpleOffset(pathBytes, 8, this.LengthOfDirectoryIdentifier);
            this.DirectoryIdentifier      =
                ByteConversion.GetEncodedText(this.DirectoryIdentifierBytes,
                                              ByteConversion.GetPredictedCodePageForTags(this.DirectoryIdentifierBytes));

            if (this.LengthOfDirectoryIdentifier % 2 == 1)
            {
                this.PaddingByte = ParseFile.ParseSimpleOffset(pathBytes, this.LengthOfDirectoryIdentifier + 8, 1)[0];
            }
        }
Example #11
0
        public static DateTime GetIsoDateTime(byte[] isoDateArray)
        {
            DateTime dateValue = new DateTime();
            string   dateString;

            if (ParseFile.CompareSegment(isoDateArray, 0, EMPTY_DATETIME))
            {
                dateValue = DateTime.MinValue;
            }
            // Easy CD Creator v4.2 (310), and maybe others,
            //  doesn't set the Grenwich Mean Time offset to zero as it should
            else if (ParseFile.CompareSegmentUsingSourceOffset(isoDateArray, 0, EMPTY_DATETIME_HACK.Length, EMPTY_DATETIME_HACK))
            {
                dateValue = DateTime.MinValue;
            }
            else
            {
                dateString = ByteConversion.GetAsciiText(isoDateArray);
                dateValue  = new DateTime(Int32.Parse(dateString.Substring(0, 4).Replace("0000", "2000")),
                                          Int16.Parse(dateString.Substring(4, 2)),
                                          Int16.Parse(dateString.Substring(6, 2)),
                                          Int16.Parse(dateString.Substring(8, 2)),
                                          Int16.Parse(dateString.Substring(10, 2)),
                                          Int16.Parse(dateString.Substring(12, 2)),
                                          Int16.Parse(dateString.Substring(14, 2)));
            }

            return(dateValue);
        }
Example #12
0
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pByteRemoverStruct,
                                              DoWorkEventArgs e)
        {
            ByteRemoverStruct taskStruct = (ByteRemoverStruct)pByteRemoverStruct;

            long startOffset;
            long endOffset;
            long removalLength = 0;

            // parse start offset
            startOffset = ByteConversion.GetLongValueFromString(taskStruct.StartOffset);

            if (taskStruct.UseEndAddress)
            {
                // parse end offset
                endOffset     = ByteConversion.GetLongValueFromString(taskStruct.EndOffset);
                removalLength = endOffset - startOffset + 1;
            }
            else if (taskStruct.UseLength)
            {
                removalLength = ByteConversion.GetLongValueFromString(taskStruct.Length);
            }
            else if (taskStruct.UseFileEnd)
            {
                FileInfo fi = new FileInfo(pPath);
                removalLength = fi.Length - startOffset;
            }

            FileUtil.RemoveChunkFromFile(pPath, startOffset, removalLength);

            this.outputBuffer.Append(String.Format("{0}{1}", Path.GetFileName(pPath), Environment.NewLine));
        }
Example #13
0
        private void BuildRomFsFile(FileStream isoStream, long ivfcOffset, long fileEntryOffset, long fileBlockOffset, long romFsDataOffset)
        {
            RomFsFileEntry file = new RomFsFileEntry();

            // Nintendo3dsCtrFile tempFile;
            byte[] nameBytes;

            // load dir
            file.ParentDirOffset = ParseFile.ReadUintLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset);
            file.SiblingOffset   = ParseFile.ReadInt32LE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 4);
            file.DataOffset      = ParseFile.ReadUlongLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 8);
            file.DataSize        = ParseFile.ReadUlongLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x10);
            file.WeirdOffset     = ParseFile.ReadUintLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x18);
            file.NameSize        = ParseFile.ReadUintLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x1C);

            // build directory name
            if (file.NameSize > 0)
            {
                nameBytes = ParseFile.ParseSimpleOffset(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x20, (int)file.NameSize);
                file.Name = ByteConversion.GetUtf16LeText(nameBytes);
            }
            else // this is root
            {
                file.Name = "NO_NAME_FOUND"; // @TODO Make this a constant
            }

            this.FileName = file.Name;
            this.Offset   = ivfcOffset + romFsDataOffset + (long)file.DataOffset;
            this.Size     = (long)file.DataSize;

            // get sibling
            this.SiblingOffset = file.SiblingOffset;
        }
Example #14
0
        public void ByteConversionToStringTest(ulong bytes, string expected)
        {
            // Set the thread culture so the current system culture don't interfere with the results
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");
            var converted = new ByteConversion(bytes);

            Assert.Equal(expected, converted.ToString());
        }
Example #15
0
        private void ComboBoxBaudRate_SelectedIndexChanged(object sender, EventArgs e)
        {
            Device device = devicesFound.Find(d => d.ID == ((ComboBox)sender).Parent.Text);

            device.BaudRateStr = (string)((ComboBox)sender).SelectedItem;

            if (device is UHFReader)
            {
                ((UHFReader)device).FBaud = ByteConversion.GetBaudRateIndexByte(device.BaudRateStr);
            }
        }
Example #16
0
        public NintendoGameCubeDirectoryRecord(byte[] directoryBytes, int OffsetBitShiftValue)
        {
            this.NameOffset = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 0, 4));

            this.FileOffset   = (long)ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 4, 4));
            this.FileOffset <<= OffsetBitShiftValue;

            this.FileSize    = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 8, 4));
            this.IsDirectory = ((this.NameOffset & 0xFF000000) != 0);

            this.NameOffset &= 0xFFFFFF;
        }
Example #17
0
        /// <summary>
        /// Reads the next long from the stream, and checks if it equals 'value'.
        /// </summary>
        /// <param name="value">The value to compare against the next long from the stream</param>
        /// <param name="failmessage">The error message to be thrown if the long does not equal value</param>
        /// <returns>true or false, depending on whether the read long is the same as the specified value</returns>
        public bool Assert(long value, string failmessage)
        {
            byte[] temp = new byte[LONGLENGTH];
            _stream.Read(temp, 0, LONGLENGTH);

            if (ByteConversion.ToLong(temp, 0) != value)
            {
                throw new AssertFailedException(failmessage);
            }

            return(true);
        }
        public NintendoWiiOpticalDiscDirectoryRecord(byte[] directoryBytes)
        {
            this.NameOffset = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 0, 4));

            this.FileOffset   = (long)ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 4, 4));
            this.FileOffset <<= 2;

            this.FileSize    = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 8, 4));
            this.IsDirectory = ((this.NameOffset & 0xFF000000) != 0);

            this.NameOffset &= 0xFFFFFF;
        }
Example #19
0
        /// <summary>
        /// Reads the next int from the stream, and checks if it equals 'value'.
        /// </summary>
        /// <param name="value">The value to compare against the next int from the stream</param>
        /// <param name="failmessage">The error message to be thrown if the int does not equal value</param>
        /// <returns>true or false, depending on whether the read byte is the same as the specified value</returns>
        public bool Assert(int value, string failmessage)
        {
            byte[] temp = new byte[INTLENGTH];
            _stream.Read(temp, 0, INTLENGTH);

            if (ByteConversion.ToInt(temp, 0) != value)
            {
                throw new AssertFailedException(failmessage);
            }

            return(true);
        }
Example #20
0
        static void Main(string[] args)
        {
            string inFilename;
            long   startOffset;
            long   blockSize;

            string fullInputPath;
            string fullOutputPath;
            string outputDirectory;
            string filePrefix;

            long currentOffset;
            long fileSize;
            uint fileCount = 0;

            if (args.Length < 3)
            {
                Console.WriteLine("Usage: snakesplit.exe <infile> <start offset> <blocksize>");
            }
            else
            {
                inFilename  = args[0];
                startOffset = ByteConversion.GetLongValueFromString(args[1]);
                blockSize   = ByteConversion.GetLongValueFromString(args[2]);

                fullInputPath   = Path.GetFullPath(inFilename);
                filePrefix      = Path.GetFileNameWithoutExtension(fullInputPath);
                outputDirectory = Path.Combine(Path.GetDirectoryName(fullInputPath), "snakesplit");

                if (File.Exists(fullInputPath))
                {
                    using (FileStream fs = File.OpenRead(fullInputPath))
                    {
                        fileSize      = fs.Length;
                        currentOffset = startOffset;

                        while (currentOffset < fileSize)
                        {
                            fullOutputPath = Path.Combine(outputDirectory, String.Format("{0}_{1}.bin", filePrefix, fileCount.ToString("X8")));
                            fileCount++;

                            ParseFile.ExtractChunkToFile(fs, currentOffset, blockSize, fullOutputPath);

                            currentOffset += blockSize;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("File Not Found: " + fullInputPath);
                }
            }
        }
Example #21
0
        public XDvdFsDirectoryRecord(byte[] directoryBytes)
        {
            this.OffsetToLeftSubTree  = (long)(BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(directoryBytes, 0x00, 2), 0) * XDvdFs.DWORD_SIZE);
            this.OffsetToRightSubTree = (long)(BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(directoryBytes, 0x02, 2), 0) * XDvdFs.DWORD_SIZE);

            this.StartingSector = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(directoryBytes, 0x04, 4), 0);
            this.EntrySize      = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(directoryBytes, 0x08, 4), 0);

            this.EntryFlags = ParseFile.ParseSimpleOffset(directoryBytes, 0x0C, 1)[0];

            this.EntryNameSize  = ParseFile.ParseSimpleOffset(directoryBytes, 0x0D, 1)[0];
            this.EntryNameBytes = ParseFile.ParseSimpleOffset(directoryBytes, 0x0E, this.EntryNameSize);
            this.EntryName      = ByteConversion.GetAsciiText(this.EntryNameBytes);
        }
Example #22
0
        protected override long GetStartOffset(Stream readStream, long currentOffset)
        {
            long startOffset = 0;

            uint seekOffsets = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(readStream, 0x86, 4));
            uint seekCount   = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(readStream, 0x8A, 4));

            if (seekOffsets > 0)
            {
                startOffset = seekOffsets + (seekCount * 0x0A);
            }

            return(startOffset);
        }
Example #23
0
        public CriAcbFile(FileStream fs, long offset, bool includeCueIdInFileName)
        {
            // initialize UTF
            this.Initialize(fs, offset);

            // initialize ACB specific items
            this.InitializeCueList(fs);
            this.InitializeCueNameToWaveformMap(fs, includeCueIdInFileName);

            // initialize internal AWB
            if (this.InternalAwbFileSize > 0)
            {
                if (CriAfs2Archive.IsCriAfs2Archive(fs, (long)this.InternalAwbFileOffset))
                {
                    this.InternalAwb = new CriAfs2Archive(fs, (long)this.InternalAwbFileOffset);
                }
                else if (CriCpkArchive.IsCriCpkArchive(fs, (long)this.InternalAwbFileOffset))
                {
                    this.InternalCpk = new CriCpkArchive();
                    this.InternalCpk.Initialize(fs, (long)this.InternalAwbFileOffset, true);
                }
            }

            // initialize external AWB

            // @TODO: This isn't correct for files with CPKs
            if ((this.StreamAwbAfs2HeaderSize > 0) ||
                (!ByteConversion.IsZeroFilledByteArray(this.StreamAwbHash)))
            {
                // get external file name
                this.StreamfilePath = this.GetStreamfilePath();

                // get file type
                using (FileStream awbFs = File.Open(this.StreamfilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    // AWB
                    if (CriAfs2Archive.IsCriAfs2Archive(awbFs, 0))
                    {
                        this.ExternalAwb = new CriAfs2Archive(awbFs, 0);
                    }
                    // CPK
                    else if (CriCpkArchive.IsCriCpkArchive(awbFs, 0))
                    {
                        this.ExternalCpk = new CriCpkArchive();
                        this.ExternalCpk.Initialize(awbFs, 0, true);
                    }
                }
            }
        }
Example #24
0
        public void Initialize(FileStream isoStream, long offset, bool isRawDump)
        {
            byte[] volumeIdentifierBytes;
            byte[] imageDateBytes;
            string imageDateString;

            this.VolumeBaseOffset        = offset;
            this.IsRawDump               = isRawDump;
            this.VolumeType              = VolumeDataType.Data;
            this.DirectoryStructureArray = new ArrayList();

            // get identifier
            volumeIdentifierBytes = ParseFile.ParseSimpleOffset(isoStream, this.VolumeBaseOffset + 0x20, 64);
            volumeIdentifierBytes = FileUtil.ReplaceNullByteWithSpace(volumeIdentifierBytes);
            this.VolumeIdentifier = ByteConversion.GetEncodedText(volumeIdentifierBytes, ByteConversion.GetPredictedCodePageForTags(volumeIdentifierBytes)).Trim();;

            // get date
            imageDateBytes  = ParseFile.ParseSimpleOffset(isoStream, this.VolumeBaseOffset + 0x2440, 0xA);
            imageDateString = ByteConversion.GetAsciiText(imageDateBytes);

            try
            {
                this.ImageCreationTime = new DateTime(int.Parse(imageDateString.Substring(0, 4)),
                                                      int.Parse(imageDateString.Substring(5, 2)),
                                                      int.Parse(imageDateString.Substring(8, 2)));
            }
            catch (Exception)
            {
                this.ImageCreationTime = new DateTime();
            }

            // set bit shift for GC or WII
            if (this.IsGameCubeDisc(isoStream))
            {
                this.OffsetBitShiftValue = 0;
                this.FormatDescription   = NintendoGameCube.FORMAT_DESCRIPTION_STRING;
            }
            else
            {
                this.OffsetBitShiftValue = 2;
                this.FormatDescription   = NintendoWiiOpticalDisc.FORMAT_DESCRIPTION_STRING_DECRYPTED;
            }

            // get offset of file table
            this.RootDirectoryOffset   = (long)ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(isoStream, this.VolumeBaseOffset + 0x424, 4));
            this.RootDirectoryOffset <<= this.OffsetBitShiftValue;

            this.LoadDirectories(isoStream);
        }
Example #25
0
        private void loadGenhFileForEditing()
        {
            ListBoxFileInfoObject listBoxFile;

            if (lbFiles.SelectedIndices.Count == 1)
            {
                listBoxFile = (ListBoxFileInfoObject)this.lbFiles.SelectedItem;
                string editPath = listBoxFile.FilePath;

                if (GenhUtil.IsGenhFile(editPath))
                {
                    using (FileStream fs = File.OpenRead(editPath))
                    {
                        Genh itemToEdit = new Genh();
                        itemToEdit.Initialize(fs, editPath);

                        // Set initial values
                        GenhCreationStruct gcStruct = GenhUtil.GetGenhCreationStruct(itemToEdit);
                        this.setGenhParameters(gcStruct);

                        // set loop radio button
                        if ((String.IsNullOrEmpty(gcStruct.LoopStart)) ||
                            (gcStruct.LoopStart.Equals(Genh.EMPTY_SAMPLE_COUNT)))
                        {
                            if (this.cbNoLoops.Checked == true)
                            {
                                this.cbNoLoops.Checked = false; // do this to trigger event if already checked.
                            }

                            this.cbNoLoops.Checked = true;


                            // for some formats (MPEG, XMA, FFMPEG) I cannot calculate the exact number of samples,
                            //    so copy current loop end to total samples.  However, do not overwrite if it exists.
                            if (String.IsNullOrWhiteSpace(this.tbTotalSamples.Text) ||
                                ByteConversion.GetLongValueFromString(this.tbTotalSamples.Text) == 0)
                            {
                                this.tbTotalSamples.Text = ByteConversion.GetLongValueFromString(gcStruct.LoopEnd) > 0 ? gcStruct.LoopEnd : "0";
                            }
                        }
                        else
                        {
                            this.cbManualEntry.Checked = true;
                        }
                    }
                }
            }
        }
Example #26
0
        private byte[] RemoveAudioInfoFromThpHeader(byte[] dirtyThpHeader)
        {
            byte[] dataBytes;
            byte[] fourEmptyBytes = new byte[] { 0x00, 0x00, 0x00, 0x00 };

            // clear max audio samples
            Array.Copy(fourEmptyBytes, 0, dirtyThpHeader, 0xC, 4);

            // reset components
            Array.Copy(fourEmptyBytes, 0, dirtyThpHeader, this.ComponentDataOffset, 4);
            dirtyThpHeader[this.ComponentDataOffset + 3] = 0x01;
            dirtyThpHeader[this.ComponentDataOffset + 4] = 0x00; // set to video
            dirtyThpHeader[this.ComponentDataOffset + 5] = 0xFF;

            // add video details in case it was the second component
            dataBytes = ByteConversion.GetBytesBigEndian(this.Width);
            Array.Copy(dataBytes, 0, dirtyThpHeader, 0x44, 4);

            dataBytes = ByteConversion.GetBytesBigEndian(this.Height);
            Array.Copy(dataBytes, 0, dirtyThpHeader, 0x48, 4);

            if (this.Version == ThpVersion.Version11)
            {
                dataBytes = ByteConversion.GetBytesBigEndian(this.Unknown);
                Array.Copy(dataBytes, 0, dirtyThpHeader, 0x4C, 4);
            }

            // remove audio component details
            if (this.ContainsAudio)
            {
                if (this.Version == ThpVersion.Version10)
                {
                    for (int i = 0x4C; i < this.FirstFrameOffset; i++)
                    {
                        dirtyThpHeader[i] = 0;
                    }
                }
                else // version 1.1
                {
                    for (int i = 0x50; i < this.FirstFrameOffset; i++)
                    {
                        dirtyThpHeader[i] = 0;
                    }
                }
            }

            return(dirtyThpHeader);
        }
Example #27
0
        private void ParseComponents(FileStream thpStream)
        {
            this.ComponentCount = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, this.ComponentDataOffset, 4));

            byte componentType;
            long componentDetailsOffset = this.ComponentDataOffset + 4 + 0x10;

            // load components
            for (int i = 0; i < this.ComponentCount; i++)
            {
                componentType = ParseFile.ParseSimpleOffset(thpStream, this.ComponentDataOffset + 4 + (i * 1), 1)[0];

                if (componentType == VIDEO_COMPONENT)
                {
                    this.Width  = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset, 4));
                    this.Height = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset + 4, 4));

                    if (this.Version == ThpVersion.Version11)
                    {
                        this.Unknown            = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset + 8, 4));
                        componentDetailsOffset += 0xC;
                    }
                    else
                    {
                        this.Unknown            = 0;
                        componentDetailsOffset += 0x8;
                    }
                }
                else if (componentType == AUDIO_COMPONENT)
                {
                    this.NumberOfChannels = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset, 4));
                    this.Frequency        = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset + 4, 4));
                    this.NumberOfSamples  = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset + 8, 4));

                    if (this.Version == ThpVersion.Version11)
                    {
                        this.NumberOfAudioBlocksPerFrame = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(thpStream, componentDetailsOffset + 0xC, 4));
                        componentDetailsOffset          += 0x10;
                    }
                    else
                    {
                        this.NumberOfAudioBlocksPerFrame = 1; // 1 audio chunk per frame
                        componentDetailsOffset          += 0xC;
                    }
                }
            }
        }
Example #28
0
        public static bool checkIfTextIsParsableAsLong(string textToCheck, string labelValue)
        {
            bool isParsableNumber = true;

            if (!String.IsNullOrEmpty(textToCheck))
            {
                try
                {
                    long tempValue = ByteConversion.GetLongValueFromString(textToCheck);
                }
                catch (Exception)
                {
                    MessageBox.Show(String.Format("Cannot convert \"{0}\" to a number: <{1}>", labelValue, textToCheck), "Conversion Error.");
                    isParsableNumber = false;
                }
            }

            return(isParsableNumber);
        }
        public void Initialize(FileStream isoStream, long offset, bool isRawDump)
        {
            byte[] volumeIdentifierBytes;
            byte[] imageDateBytes;
            string imageDateString;

            this.IsRawDump = isRawDump;
            this.DirectoryStructureArray = new ArrayList();

            this.FormatDescription = NintendoWiiOpticalDisc.FORMAT_DESCRIPTION_STRING;
            this.VolumeType        = VolumeDataType.Data;

            // get identifier
            volumeIdentifierBytes = DiscReader.GetBytes(isoStream, this.VolumeBaseOffset,
                                                        this.DataOffset, 0x20, 64, this.PartitionKey);
            volumeIdentifierBytes = FileUtil.ReplaceNullByteWithSpace(volumeIdentifierBytes);
            this.VolumeIdentifier = ByteConversion.GetEncodedText(volumeIdentifierBytes, ByteConversion.GetPredictedCodePageForTags(volumeIdentifierBytes)).Trim();;

            // get date
            imageDateBytes = DiscReader.GetBytes(isoStream, this.VolumeBaseOffset,
                                                 this.DataOffset, 0x2440, 0xA, this.PartitionKey);
            imageDateString = ByteConversion.GetAsciiText(imageDateBytes);

            try
            {
                this.ImageCreationTime = new DateTime(int.Parse(imageDateString.Substring(0, 4)),
                                                      int.Parse(imageDateString.Substring(5, 2)),
                                                      int.Parse(imageDateString.Substring(8, 2)));
            }
            catch (Exception)
            {
                this.ImageCreationTime = new DateTime();
            }

            // get offset of file table
            this.RootDirectoryOffset = (long)ByteConversion.GetUInt32BigEndian(DiscReader.GetBytes(isoStream, this.VolumeBaseOffset,
                                                                                                   this.DataOffset, 0x424, 4, this.PartitionKey));
            this.RootDirectoryOffset <<= 2;

            this.LoadDirectories(isoStream);
        }
Example #30
0
        private byte[] RemoveVideoInfoFromThpHeader(byte[] dirtyThpHeader)
        {
            byte[] dataBytes;
            byte[] fourEmptyBytes = new byte[] { 0x00, 0x00, 0x00, 0x00 };

            // reset components
            Array.Copy(fourEmptyBytes, 0, dirtyThpHeader, this.ComponentDataOffset, 4);
            dirtyThpHeader[this.ComponentDataOffset + 3] = 0x01;
            dirtyThpHeader[this.ComponentDataOffset + 4] = 0x01; // set to audio
            dirtyThpHeader[this.ComponentDataOffset + 5] = 0xFF;

            // add audio details in case it was the second component
            dataBytes = ByteConversion.GetBytesBigEndian(this.NumberOfChannels);
            Array.Copy(dataBytes, 0, dirtyThpHeader, 0x44, 4);

            dataBytes = ByteConversion.GetBytesBigEndian(this.Frequency);
            Array.Copy(dataBytes, 0, dirtyThpHeader, 0x48, 4);

            dataBytes = ByteConversion.GetBytesBigEndian(this.NumberOfSamples);
            Array.Copy(dataBytes, 0, dirtyThpHeader, 0x4C, 4);

            if (this.Version == ThpVersion.Version11)
            {
                dataBytes = ByteConversion.GetBytesBigEndian(this.NumberOfAudioBlocksPerFrame);
                Array.Copy(dataBytes, 0, dirtyThpHeader, 0x50, 4);

                for (int i = 0x54; i < this.FirstFrameOffset; i++)
                {
                    dirtyThpHeader[i] = 0;
                }
            }
            else
            {
                for (int i = 0x50; i < this.FirstFrameOffset; i++)
                {
                    dirtyThpHeader[i] = 0;
                }
            }

            return(dirtyThpHeader);
        }