Add method to get only the user data from a CD Mode 2 sector.

This commit is contained in:
2020-01-11 22:25:34 +00:00
parent 1856c6ddb4
commit 3c5b8db654
2 changed files with 39 additions and 90 deletions

View File

@@ -32,8 +32,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
namespace DiscImageChef.Decoders.CD
{
@@ -207,94 +207,42 @@ namespace DiscImageChef.Decoders.CD
return scrambled;
}
// public static byte[] GetUserDataFromMode2(byte[] data)
// {
// byte[] sector;
//
// DiscImageChef.Checksums.CdChecksums.
// EccInit();
//
// if(sectorPrefixDdt == null) sectorPrefixDdt = new uint[imageInfo.Sectors];
//
// sector = new byte[2328];
// if(ArrayHelpers.ArrayIsNullOrEmpty(data))
// {
// sectorPrefixDdt[sectorAddress] = (uint)CdFixFlags.NotDumped;
// return WriteSector(sector, sectorAddress);
// }
//
// prefixCorrect = true;
//
// if(data[0x00] != 0x00 || data[0x01] != 0xFF || data[0x02] != 0xFF || data[0x03] != 0xFF ||
// data[0x04] != 0xFF || data[0x05] != 0xFF || data[0x06] != 0xFF || data[0x07] != 0xFF ||
// data[0x08] != 0xFF || data[0x09] != 0xFF || data[0x0A] != 0xFF || data[0x0B] != 0x00 ||
// data[0x0F] != 0x02) prefixCorrect = false;
//
// if(prefixCorrect)
// {
// minute = (data[0x0C] >> 4) * 10 + (data[0x0C] & 0x0F);
// second = (data[0x0D] >> 4) * 10 + (data[0x0D] & 0x0F);
// frame = (data[0x0E] >> 4) * 10 + (data[0x0E] & 0x0F);
// storedLba = minute * 60 * 75 + second * 75 + frame - 150;
// prefixCorrect = storedLba == (int)sectorAddress;
// }
//
// if(prefixCorrect) sectorPrefixDdt[sectorAddress] = (uint)CdFixFlags.Correct;
// else
// {
// if((sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) > 0)
// sectorPrefixMs.Position =
// ((sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16;
// else sectorPrefixMs.Seek(0, SeekOrigin.End);
//
// sectorPrefixDdt[sectorAddress] = (uint)(sectorPrefixMs.Position / 16 + 1);
//
// sectorPrefixMs.Write(data, 0, 16);
// }
//
// if(mode2Subheaders == null) mode2Subheaders = new byte[imageInfo.Sectors * 8];
//
// bool correctEcc = SuffixIsCorrectMode2(data);
// bool correctEdc = false;
//
// if(correctEcc)
// {
// uint computedEdc = ComputeEdc(0, data, 0x808, 0x10);
// uint edc = BitConverter.ToUInt32(data, 0x818);
// correctEdc = computedEdc == edc;
// }
// else
// {
// uint computedEdc = ComputeEdc(0, data, 0x91C, 0x10);
// uint edc = BitConverter.ToUInt32(data, 0x92C);
// correctEdc = computedEdc == edc;
// }
//
// if(correctEcc && correctEdc)
// {
// sector = new byte[2048];
// if(sectorSuffixDdt == null) sectorSuffixDdt = new uint[imageInfo.Sectors];
// sectorSuffixDdt[sectorAddress] = (uint)CdFixFlags.Mode2Form1Ok;
// Array.Copy(data, 24, sector, 0, 2048);
// }
// else if(correctEdc)
// {
// sector = new byte[2324];
// if(sectorSuffixDdt == null) sectorSuffixDdt = new uint[imageInfo.Sectors];
// sectorSuffixDdt[sectorAddress] = (uint)CdFixFlags.Mode2Form2Ok;
// Array.Copy(data, 24, sector, 0, 2324);
// }
// else if(BitConverter.ToUInt32(data, 0x92C) == 0)
// {
// sector = new byte[2324];
// if(sectorSuffixDdt == null) sectorSuffixDdt = new uint[imageInfo.Sectors];
// sectorSuffixDdt[sectorAddress] = (uint)CdFixFlags.Mode2Form2NoCrc;
// Array.Copy(data, 24, sector, 0, 2324);
// }
// else Array.Copy(data, 24, sector, 0, 2328);
//
// Array.Copy(data, 16, mode2Subheaders, (int)sectorAddress * 8, 8);
// return WriteSector(sector, sectorAddress);
// }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte[] GetUserDataFromMode2(byte[] data)
{
if(data.Length != 2352 &&
data.Length != 2336)
return data;
int pos = 0;
if(data.Length == 2352)
{
if(data[0] != 0x00 ||
data[1] != 0xFF ||
data[2] != 0xFF ||
data[3] != 0xFF ||
data[4] != 0xFF ||
data[5] != 0xFF ||
data[6] != 0xFF ||
data[7] != 0xFF ||
data[8] != 0xFF ||
data[9] != 0xFF ||
data[10] != 0xFF ||
data[11] != 0x00 ||
data[15] != 0x02)
return data;
pos = 16;
}
int len = (data[pos + 2] & 0x20) == 0x20 ? 2324 : 2048;
pos += 8;
byte[] sector = new byte[len];
Array.Copy(data, pos, sector, 0, len);
return sector;
}
}
}