mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add raw DVD reading with HL-DT-ST command (#823)
This commit is contained in:
committed by
GitHub
parent
a2c6b8961a
commit
1153a270a9
@@ -30,12 +30,19 @@
|
||||
// Copyright © 2011-2023 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.Console;
|
||||
using Aaru.Decoders.DVD;
|
||||
using Aaru.Helpers;
|
||||
|
||||
namespace Aaru.Devices;
|
||||
|
||||
public partial class Device
|
||||
{
|
||||
readonly Sector _decoding = new();
|
||||
|
||||
/// <summary>Reads a "raw" sector from DVD on HL-DT-ST drives.</summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
||||
/// <param name="buffer">Buffer where the HL-DT-ST READ DVD (RAW) response will be stored</param>
|
||||
@@ -51,15 +58,17 @@ public partial class Device
|
||||
var cdb = new byte[12];
|
||||
buffer = new byte[2064 * transferLength];
|
||||
|
||||
uint cacheDataOffset = 0x80000000 + (lba % 96 * 2064);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.HlDtStVendor;
|
||||
cdb[1] = 0x48;
|
||||
cdb[2] = 0x49;
|
||||
cdb[3] = 0x54;
|
||||
cdb[4] = 0x01;
|
||||
cdb[6] = (byte)((lba & 0xFF000000) >> 24);
|
||||
cdb[7] = (byte)((lba & 0xFF0000) >> 16);
|
||||
cdb[8] = (byte)((lba & 0xFF00) >> 8);
|
||||
cdb[9] = (byte)(lba & 0xFF);
|
||||
cdb[6] = (byte)((cacheDataOffset & 0xFF000000) >> 24);
|
||||
cdb[7] = (byte)((cacheDataOffset & 0xFF0000) >> 16);
|
||||
cdb[8] = (byte)((cacheDataOffset & 0xFF00) >> 8);
|
||||
cdb[9] = (byte)(cacheDataOffset & 0xFF);
|
||||
cdb[10] = (byte)((buffer.Length & 0xFF00) >> 8);
|
||||
cdb[11] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
@@ -70,6 +79,38 @@ public partial class Device
|
||||
|
||||
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.HL_DT_ST_READ_DVD_RAW_took_0_ms, duration);
|
||||
|
||||
if(!CheckSectorNumber(buffer, lba, transferLength))
|
||||
return true;
|
||||
|
||||
if(_decoding.Scramble(buffer, transferLength, out byte[] scrambledBuffer) != ErrorNumber.NoError)
|
||||
return true;
|
||||
|
||||
buffer = scrambledBuffer;
|
||||
return sense;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes sure the data's sector number is the one expected.
|
||||
/// </summary>
|
||||
/// <param name="buffer">Data buffer</param>
|
||||
/// <param name="firstLba">First consecutive LBA of the buffer</param>
|
||||
/// <param name="transferLength">How many blocks to in buffer</param>
|
||||
/// <returns><c>false</c> if any sector is not matching expected value, else <c>true</c></returns>
|
||||
static bool CheckSectorNumber(IReadOnlyList<byte> buffer, uint firstLba, uint transferLength)
|
||||
{
|
||||
for(int i = 0; i < transferLength; i++)
|
||||
{
|
||||
byte[] sectorBuffer =
|
||||
{
|
||||
0x0, buffer[1 + (2064 * i)], buffer[2 + (2064 * i)], buffer[3 + (2064 * i)]
|
||||
};
|
||||
|
||||
uint sectorNumber = BigEndianBitConverter.ToUInt32(sectorBuffer, 0);
|
||||
|
||||
if(sectorNumber != firstLba + i + 0x30000)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user