Пример #1
0
        static void Run(Options o)
        {
            IDiscToc toc = null;

            if (o.PerformTests)
            {
                toc = TestData.ReadToc(o.Device);
            }
            else
            {
                toc = CdRom.ReadToc(o.Device);
            }
            if (o.All || o.PrintToc)
            {
                Console.WriteLine($"first: {toc.StartTrack}");
                Console.WriteLine($"last: {toc.EndTrack}");
                foreach (var e in toc.TrackEntries)
                {
                    Console.WriteLine("track: {0,3} lba: {1,9} {5:00}:{6:00}:{7:00} adr: {2} control: {3} mode: {4}",
                                      e.TrackNumber, e.Lba, e.Adr, e.Control, e.Mode, e.M, e.S, e.F);
                }
                var l = toc.LeadOutEntry;
                Console.WriteLine("track:lout lba: {0,9} {3:00}:{4:00}:{5:00} adr: {1} control: {2}",
                                  l.Lba, l.Adr, l.Control, l.M, l.S, l.F);
            }

            if (o.All || o.PrintFreeDbDiscID)
            {
                var freeDbDiscID = new FreeDbDiscID();
                var fingerprint  = freeDbDiscID.GetFingerprint(toc);
                Console.WriteLine("FreeDB DISC ID:\r\n {0}", fingerprint);
                var s       = new FreeDBService();
                var results = s.Query(fingerprint);
                foreach (var r in results)
                {
                    Console.WriteLine($"{r.Category} {r.Discid} {r.Artist} / {r.Title}");
                    var data = s.Read(r);
                    foreach (var track in data.Tracks)
                    {
                        Console.WriteLine("T{0:00} - {1}", track.Number, track.Title);
                    }
                }
            }

            if (o.All || o.PrintMusicBrainzDiscID)
            {
                var musicBrainzDiscID = new MusicBrainzDiscID();
                Console.WriteLine("MusicBrainz DISC ID:\r\n {0}", musicBrainzDiscID.GetFingerprint(toc));
            }
        }
Пример #2
0
        public static IVolume[] GetDataVolumes(string pPath, long startingOffset)
        {
            ArrayList volumeList = new ArrayList();

            // read the file, scanning for identifying bytes
            using (FileStream fs = File.OpenRead(pPath))
            {
                long currentOffset = startingOffset;
                long fileSize      = fs.Length;

                byte[] sectorBytes;
                byte[] sectorDataBytes;
                byte[] volumeIdBytes;
                byte[] secondaryHeaderBytes;

                bool isRawFormat = false;
                int  sectorSize  = 0x800;
                // CdSectorType mode;

                //----------------------
                // check for sync bytes
                //----------------------
                byte[] syncCheckBytes = ParseFile.ParseSimpleOffset(fs, 0, CdRom.SYNC_BYTES.Length);

                if (ParseFile.CompareSegment(syncCheckBytes, 0, CdRom.SYNC_BYTES))
                {
                    isRawFormat = true;
                    sectorSize  = 0x930;
                }

                while (currentOffset < fileSize)
                {
                    // get sector
                    sectorBytes = ParseFile.ParseSimpleOffset(fs, currentOffset, sectorSize);

                    // get data bytes from sector
                    sectorDataBytes = CdRom.GetDataChunkFromSector(sectorBytes, isRawFormat);

                    // get header bytes
                    volumeIdBytes = ParseFile.ParseSimpleOffset(sectorDataBytes, 0, MAX_ID_BYTES_LENGTH);

                    //----------
                    // ISO 9660
                    //----------
                    if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0, Iso9660.VOLUME_DESCRIPTOR_IDENTIFIER.Length, Iso9660.VOLUME_DESCRIPTOR_IDENTIFIER))
                    {
                        Iso9660Volume isoVolume;
                        isoVolume = new Iso9660Volume();
                        isoVolume.Initialize(fs, currentOffset, isRawFormat);
                        volumeList.Add((IVolume)isoVolume);

                        if ((isoVolume.Directories.Length == 1) &&
                            (isoVolume.Directories[0].SubDirectories.Length == 0) &&
                            ((isoVolume.Directories[0].Files.Length == 0) ||
                             ((isoVolume.Directories[0].Files.Length == 1) && (isoVolume.Directories[0].Files[0].FileName.Equals(XDvdFs.XGD3_WARNING_FILE_NAME)))
                            )
                            )
                        {
                            // possible empty/dummy volume (XBOX)
                            currentOffset += sectorSize;
                        }
                        else
                        {
                            currentOffset = isoVolume.VolumeBaseOffset + ((long)isoVolume.VolumeSpaceSize * (long)sectorSize);
                        }
                    }
                    //-----------------
                    // Green Book CD-I
                    //-----------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0, GreenBookCdi.VOLUME_DESCRIPTOR_IDENTIFIER.Length, GreenBookCdi.VOLUME_DESCRIPTOR_IDENTIFIER))
                    {
                        GreenBookCdiVolume isoVolume;
                        isoVolume = new GreenBookCdiVolume();
                        isoVolume.Initialize(fs, currentOffset, isRawFormat);
                        volumeList.Add((IVolume)isoVolume);

                        break;
                    }

                    //-----------------------
                    // XDVDFS (XBOX/XBOX360)
                    //-----------------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0, XDvdFs.STANDARD_IDENTIFIER.Length, XDvdFs.STANDARD_IDENTIFIER))
                    {
                        if (isRawFormat)
                        {
                            throw new FormatException("Raw dumps not supported for XDVDFS (XBOX/XBOX360) format.");
                        }
                        else
                        {
                            XDvdFsVolume isoVolume;
                            isoVolume = new XDvdFsVolume();
                            isoVolume.Initialize(fs, currentOffset, isRawFormat);
                            volumeList.Add((IVolume)isoVolume);

                            // XDVDFS should be the last volume
                            break;
                        }
                    }

                    //---------------
                    // PANASONIC 3DO
                    //---------------
                    else if ((ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0, Panasonic3do.STANDARD_IDENTIFIER.Length, Panasonic3do.STANDARD_IDENTIFIER)) ||
                             (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0, Panasonic3do.STANDARD_IDENTIFIER2.Length, Panasonic3do.STANDARD_IDENTIFIER2)) ||
                             (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0, Panasonic3do.STANDARD_IDENTIFIER2.Length, Panasonic3do.STANDARD_IDENTIFIER3)))
                    {
                        Panasonic3doVolume isoVolume;
                        isoVolume = new Panasonic3doVolume();
                        isoVolume.Initialize(fs, currentOffset, isRawFormat);
                        volumeList.Add((IVolume)isoVolume);

                        // should be the last volume
                        break;
                    }

                    //-------------------
                    // NINTENDO GAMECUBE
                    //-------------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)NintendoGameCube.IDENTIFIER_OFFSET, NintendoGameCube.STANDARD_IDENTIFIER.Length, NintendoGameCube.STANDARD_IDENTIFIER))
                    {
                        NintendoGameCubeVolume isoVolume;
                        isoVolume = new NintendoGameCubeVolume();
                        isoVolume.Initialize(fs, currentOffset, isRawFormat);
                        volumeList.Add((IVolume)isoVolume);

                        // should be the last volume
                        break;
                    }

                    //--------------
                    // NINTENDO WII
                    //--------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)NintendoWiiOpticalDisc.IDENTIFIER_OFFSET, NintendoWiiOpticalDisc.STANDARD_IDENTIFIER.Length, NintendoWiiOpticalDisc.STANDARD_IDENTIFIER))
                    {
                        if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, 0x60, 1, Constants.NullByteArray))
                        {
                            NintendoWiiOpticalDisc wiiDisc = new NintendoWiiOpticalDisc();
                            wiiDisc.Initialize(fs, currentOffset, isRawFormat);

                            foreach (NintendoWiiOpticalDiscVolume isoVolume in wiiDisc.Volumes)
                            {
                                volumeList.Add((IVolume)isoVolume);
                            }

                            break;
                        }
                        else // Decrypted WII ISO
                        {
                            NintendoGameCubeVolume isoVolume;
                            isoVolume = new NintendoGameCubeVolume();
                            isoVolume.Initialize(fs, currentOffset, isRawFormat);
                            volumeList.Add((IVolume)isoVolume);
                        }
                        // should be the last volume
                        break;
                    }

                    //------------------------
                    // MS STFS Package (XBLA)
                    //------------------------
                    //
                    // @TODO: Currently Broken
                    //
                    //else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)MicrosoftSTFS.IDENTIFIER_OFFSET, MicrosoftSTFS.STANDARD_IDENTIFIER.Length, MicrosoftSTFS.STANDARD_IDENTIFIER))
                    //{
                    //    MicrosoftSTFSVolume isoVolume;
                    //    isoVolume = new MicrosoftSTFSVolume();
                    //    isoVolume.Initialize(fs, currentOffset, isRawFormat);
                    //    volumeList.Add((IVolume)isoVolume);

                    //    // should be the last volume
                    //    break;
                    //}

                    //------------------------
                    // NINTENDO U8 ARCHIVE
                    //------------------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)NintendoU8Archive.IDENTIFIER_OFFSET, NintendoU8Archive.STANDARD_IDENTIFIER.Length, NintendoU8Archive.STANDARD_IDENTIFIER))
                    {
                        NintendoU8Archive isoVolume;
                        isoVolume = new NintendoU8Archive(fs.Name);
                        isoVolume.Initialize(fs, currentOffset, isRawFormat);
                        volumeList.Add((IVolume)isoVolume);

                        // should be the last volume
                        break;
                    }

                    //-----------------
                    // NINTENDO WIIU
                    //-----------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)NintendoWiiUOpticalDisc.IDENTIFIER_OFFSET, NintendoWiiUOpticalDisc.STANDARD_IDENTIFIER.Length, NintendoWiiUOpticalDisc.STANDARD_IDENTIFIER))
                    {
                        NintendoWiiUOpticalDisc wiiUDisc = new NintendoWiiUOpticalDisc();
                        wiiUDisc.Initialize(fs, currentOffset, isRawFormat);

                        foreach (NintendoWiiUOpticalDiscVolume isoVolume in wiiUDisc.Volumes)
                        {
                            volumeList.Add((IVolume)isoVolume);
                        }

                        break;
                    }


                    //-----------------
                    // NINTENDO 3DS
                    //-----------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)Nintendo3dsCtr.IDENTIFIER_OFFSET, Nintendo3dsCtr.STANDARD_IDENTIFIER.Length, Nintendo3dsCtr.STANDARD_IDENTIFIER))
                    {
                        Nintendo3dsCtr ctr = new Nintendo3dsCtr(fs.Name);

                        foreach (Nintendo3dsNcchContainer isoVolume in ctr.Volumes)
                        {
                            volumeList.Add((IVolume)isoVolume);
                        }

                        break;
                    }

                    //------------------------
                    // CRI CPK ARCHIVE
                    //------------------------
                    else if (ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)CriCpkArchive.IDENTIFIER_OFFSET, CriCpkArchive.STANDARD_IDENTIFIER.Length, CriCpkArchive.STANDARD_IDENTIFIER))
                    {
                        CriCpkArchive isoVolume;
                        isoVolume = new CriCpkArchive();
                        isoVolume.Initialize(fs, currentOffset, isRawFormat);
                        volumeList.Add((IVolume)isoVolume);

                        // should be the last volume
                        break;
                    }

                    //-----------------------------
                    // PS VITA (MICROSOFT EXFAT FILE SYSTEM)
                    //-----------------------------
                    else if ((ParseFile.CompareSegmentUsingSourceOffset(volumeIdBytes, (int)SonyPsVitaCartridge.IDENTIFIER_OFFSET, SonyPsVitaCartridge.STANDARD_IDENTIFIER.Length, SonyPsVitaCartridge.STANDARD_IDENTIFIER)))
                    {
                        secondaryHeaderBytes = ParseFile.ParseSimpleOffset(fs, currentOffset + SonyPsVitaCartridge.EXFAT_HEADER_OFFSET, (int)(MicrosoftExFatFileSystem.STANDARD_IDENTIFIER.Length + MicrosoftExFatFileSystem.IDENTIFIER_OFFSET));

                        if (ParseFile.CompareSegmentUsingSourceOffset(secondaryHeaderBytes,
                                                                      (int)MicrosoftExFatFileSystem.IDENTIFIER_OFFSET,
                                                                      MicrosoftExFatFileSystem.STANDARD_IDENTIFIER.Length,
                                                                      MicrosoftExFatFileSystem.STANDARD_IDENTIFIER))
                        {
                            MicrosoftExFatVolume isoVolume;
                            isoVolume = new MicrosoftExFatVolume();
                            isoVolume.Initialize(fs, currentOffset + SonyPsVitaCartridge.EXFAT_HEADER_OFFSET, isRawFormat);
                            volumeList.Add((IVolume)isoVolume);

                            break;
                        }
                    }

                    else
                    {
                        currentOffset += sectorSize;
                    }
                }
            }

            return((IVolume[])volumeList.ToArray(typeof(IVolume)));
        }