Esempio n. 1
0
		/// <summary>
		/// calculates the complete disc hash for matching to a redump
		/// </summary>
		public uint Calculate_PSX_RedumpHash()
		{
			//a special CRC32 is used to help us match redump's DB
			SpecialCRC32 crc = new SpecialCRC32();
			byte[] buffer2352 = new byte[2352];

			var dsr = new DiscSectorReader(disc);
			dsr.Policy.DeterministicClearBuffer = false; //live dangerously

			//read all sectors for redump hash
			for (int i = 0; i < disc.Session1.LeadoutLBA; i++)
			{
				dsr.ReadLBA_2352(i, buffer2352, 0);
				crc.Add(buffer2352, 0, 2352);
			}

			return crc.Result;
		}
Esempio n. 2
0
		public static void Extract(Disc disc, string path, string filebase)
		{
			var dsr = new DiscSectorReader(disc);

			bool confirmed = false;
			var tracks = disc.Session1.Tracks;
			foreach (var track in tracks)
			{
				if (!track.IsAudio)
					continue;

				int trackLength = track.NextTrack.LBA - track.LBA;
				var waveData = new byte[trackLength * 2352];
				int startLba = track.LBA;
				for (int sector = 0; sector < trackLength; sector++)
					dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352);

				string mp3Path = string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.Number);
				if (File.Exists(mp3Path))
				{
					if (!confirmed)
					{
						var dr = MessageBox.Show("This file already exists. Do you want extraction to proceed overwriting files, or cancel the entire operation immediately?", "File already exists", MessageBoxButtons.OKCancel);
						if (dr == DialogResult.Cancel) return;
						confirmed = true;
					}
					File.Delete(mp3Path);
				}

				string tempfile = Path.GetTempFileName();

				try
				{
					File.WriteAllBytes(tempfile, waveData);
					var ffmpeg = new FFMpeg();
					ffmpeg.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path);
				}
				finally
				{
					File.Delete(tempfile);
				}
			}
		}
Esempio n. 3
0
        /// <summary>
        /// calculates the complete disc hash for matching to a redump
        /// </summary>
        public uint Calculate_PSX_RedumpHash()
        {
            //a special CRC32 is used to help us match redump's DB
            SpecialCRC32 crc = new SpecialCRC32();

            byte[] buffer2352 = new byte[2352];

            var dsr = new DiscSectorReader(disc);

            dsr.Policy.DeterministicClearBuffer = false;             //live dangerously

            //read all sectors for redump hash
            for (int i = 0; i < disc.Session1.LeadoutLBA; i++)
            {
                dsr.ReadLBA_2352(i, buffer2352, 0);
                crc.Add(buffer2352, 0, 2352);
            }

            return(crc.Result);
        }
Esempio n. 4
0
        /// <summary>
        /// calculates the hash for quick PSX Disc identification
        /// </summary>
        public uint Calculate_PSX_BizIDHash()
        {
            //notes about the hash:
            //"Arc the Lad II (J) 1.0 and 1.1 conflict up to 25 sectors (so use 26)
            //Tekken 3 (Europe) (Alt) and Tekken 3 (Europe) conflict in track 2 and 3 unfortunately, not sure what to do about this yet
            //the TOC isn't needed!
            //but it will help detect dumps with mangled TOCs which are all too common
            //
            //a possibly special CRC32 is used to help us match redump's DB elsewhere

            SpecialCRC32 crc = new SpecialCRC32();

            byte[] buffer2352 = new byte[2352];

            var dsr = new DiscSectorReader(disc)
            {
                Policy = { DeterministicClearBuffer = false }                 // live dangerously
            };

            //hash the TOC
            crc.Add((int)disc.TOC.Session1Format);
            crc.Add(disc.TOC.FirstRecordedTrackNumber);
            crc.Add(disc.TOC.LastRecordedTrackNumber);
            for (int i = 1; i <= 100; i++)
            {
                //if (disc.TOC.TOCItems[i].Exists) Console.WriteLine("{0:X8} {1:X2} {2:X2} {3:X8}", crc.Current, (int)disc.TOC.TOCItems[i].Control, disc.TOC.TOCItems[i].Exists ? 1 : 0, disc.TOC.TOCItems[i].LBATimestamp.Sector); //a little debugging
                crc.Add((int)disc.TOC.TOCItems[i].Control);
                crc.Add(disc.TOC.TOCItems[i].Exists ? 1 : 0);
                crc.Add((int)disc.TOC.TOCItems[i].LBA);
            }

            //hash first 26 sectors
            for (int i = 0; i < 26; i++)
            {
                dsr.ReadLBA_2352(i, buffer2352, 0);
                crc.Add(buffer2352, 0, 2352);
            }

            return(crc.Result);
        }
Esempio n. 5
0
        // gets an identifying hash. hashes the first 512 sectors of
        // the first data track on the disc.
        //TODO - this is a very platform-specific thing. hashing the TOC may be faster and be just as effective. so, rename it appropriately
        public string OldHash()
        {
            byte[]           buffer = new byte[512 * 2352];
            DiscSectorReader dsr    = new DiscSectorReader(disc);

            foreach (var track in disc.Session1.Tracks)
            {
                if (track.IsAudio)
                {
                    continue;
                }

                int lba_len = Math.Min(track.NextTrack.LBA, 512);
                for (int s = 0; s < 512 && s < lba_len; s++)
                {
                    dsr.ReadLBA_2352(track.LBA + s, buffer, s * 2352);
                }

                return(buffer.HashMD5(0, lba_len * 2352));
            }
            return("no data track found");
        }
Esempio n. 6
0
		/// <summary>
		/// calculates the hash for quick PSX Disc identification
		/// </summary>
		public uint Calculate_PSX_BizIDHash()
		{
			//notes about the hash:
			//"Arc the Lad II (J) 1.0 and 1.1 conflict up to 25 sectors (so use 26)
			//Tekken 3 (Europe) (Alt) and Tekken 3 (Europe) conflict in track 2 and 3 unfortunately, not sure what to do about this yet
			//the TOC isn't needed!
			//but it will help detect dumps with mangled TOCs which are all too common
			//
			//a possibly special CRC32 is used to help us match redump's DB elsewhere

			SpecialCRC32 crc = new SpecialCRC32();
			byte[] buffer2352 = new byte[2352];

			var dsr = new DiscSectorReader(disc);
			dsr.Policy.DeterministicClearBuffer = false; //live dangerously

			//hash the TOC
			crc.Add((int)disc.TOC.Session1Format);
			crc.Add(disc.TOC.FirstRecordedTrackNumber);
			crc.Add(disc.TOC.LastRecordedTrackNumber);
			for (int i = 1; i <= 100; i++)
			{
				//if (disc.TOC.TOCItems[i].Exists) Console.WriteLine("{0:X8} {1:X2} {2:X2} {3:X8}", crc.Current, (int)disc.TOC.TOCItems[i].Control, disc.TOC.TOCItems[i].Exists ? 1 : 0, disc.TOC.TOCItems[i].LBATimestamp.Sector); //a little debugging
				crc.Add((int)disc.TOC.TOCItems[i].Control);
				crc.Add(disc.TOC.TOCItems[i].Exists ? 1 : 0);
				crc.Add((int)disc.TOC.TOCItems[i].LBA);
			}

			//hash first 26 sectors
			for (int i = 0; i < 26; i++)
			{
				dsr.ReadLBA_2352(i, buffer2352, 0);
				crc.Add(buffer2352, 0, 2352);
			}

			return crc.Result;
		}
Esempio n. 7
0
		// gets an identifying hash. hashes the first 512 sectors of 
		// the first data track on the disc.
		//TODO - this is a very platform-specific thing. hashing the TOC may be faster and be just as effective. so, rename it appropriately
		public string OldHash()
		{
			byte[] buffer = new byte[512 * 2352];
			DiscSectorReader dsr = new DiscSectorReader(disc);
			foreach (var track in disc.Session1.Tracks)
			{
				if (track.IsAudio)
					continue;

				int lba_len = Math.Min(track.NextTrack.LBA, 512);
				for (int s = 0; s < 512 && s < lba_len; s++)
					dsr.ReadLBA_2352(track.LBA + s, buffer, s * 2352);

				return buffer.HashMD5(0, lba_len * 2352);
			}
			return "no data track found";
		}