📄 loader_win32.cpp
字号:
memset(&tocData,0,sizeof(tocData));
switch ( format )
{
case WIN32LOADER_TOC_CMD_TOC:
cdromReadTocEx.Format = CDROM_READ_TOC_EX_FORMAT_TOC;
cdromReadTocEx.SessionTrack = 0; // starting track number
break;
case WIN32LOADER_TOC_CMD_SESSION_INFO:
cdromReadTocEx.Format = CDROM_READ_TOC_EX_FORMAT_SESSION;
break;
case WIN32LOADER_TOC_CMD_FULL_TOC:
cdromReadTocEx.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC;
cdromReadTocEx.SessionTrack = requestedSession; // session number
break;
case WIN32LOADER_TOC_CMD_CDTEXT:
cdromReadTocEx.Format = CDROM_READ_TOC_EX_FORMAT_CDTEXT;
break;
default:
return ( WIN32LOADER_FAILURE );
break;
}
cdromReadTocEx.Msf = msf;
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_CDROM_READ_TOC_EX, // operation
&cdromReadTocEx,
sizeof(cdromReadTocEx),
tocData,
sizeof(tocData),
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgPrint(("WIN32Loader::CDROMReadTOC: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
memcpy( buffer, tocData, bufferSize );
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::ReadSubChannel Read SubChannelQ data
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::ReadSubChannel( int fMSF, int fSubQ, unsigned char bFormat, unsigned char bTrack, unsigned char *pData, unsigned long int size)
{
BOOL win32Result;
DWORD outputByteCount = 0;
CDROM_SUB_Q_DATA_FORMAT cdromSubQDataFormat;
SUB_Q_CHANNEL_DATA subQChannelData;
DbgAssert ( data != NULL );
DbgAssert ( fMSF == TRUE );
DbgAssert ( fSubQ == TRUE );
DbgAssert ( bFormat == 0x01 );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
memset(&cdromSubQDataFormat,0,sizeof(cdromSubQDataFormat));
memset(&subQChannelData,0,sizeof(subQChannelData));
cdromSubQDataFormat.Format = IOCTL_CDROM_CURRENT_POSITION;
cdromSubQDataFormat.Track = bTrack;
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_CDROM_READ_Q_CHANNEL, // operation
&cdromSubQDataFormat,
sizeof(cdromSubQDataFormat),
&subQChannelData,
sizeof(subQChannelData),
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgPrint(("WIN32Loader::ReadSubChannel: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
memset( pData,0,size);
if ( size >= 12 )
{
pData[0] = subQChannelData.CurrentPosition.FormatCode;
pData[1] = (subQChannelData.CurrentPosition.ADR << 4) | (subQChannelData.CurrentPosition.Control);
pData[2] = (subQChannelData.CurrentPosition.TrackNumber);
pData[3] = (subQChannelData.CurrentPosition.IndexNumber);
pData[4] = subQChannelData.CurrentPosition.AbsoluteAddress[0];
pData[5] = subQChannelData.CurrentPosition.AbsoluteAddress[1];
pData[6] = subQChannelData.CurrentPosition.AbsoluteAddress[2];
pData[7] = subQChannelData.CurrentPosition.AbsoluteAddress[3];
pData[8] = subQChannelData.CurrentPosition.TrackRelativeAddress[0];
pData[9] = subQChannelData.CurrentPosition.TrackRelativeAddress[1];
pData[10] = subQChannelData.CurrentPosition.TrackRelativeAddress[2];
pData[11] = subQChannelData.CurrentPosition.TrackRelativeAddress[3];
}
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::GetAgid CSS authentication
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::GetAgid( void )
{
BOOL win32Result;
DWORD outputByteCount;
DbgAssert ( data != NULL );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_DVD_START_SESSION, // operation
NULL,
0,
&data->sessionId,
sizeof(DVD_SESSION_ID),
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgPrint(("WIN32Loader::GetAgid: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::InvalidateAgid CSS authentication
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::InvalidateAgid( void )
{
BOOL win32Result;
DWORD outputByteCount;
DbgAssert ( data != NULL );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_DVD_END_SESSION, // operation
&data->sessionId,
sizeof(data->sessionId),
NULL,
0,
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgPrint(("WIN32Loader::InvalidateAgid: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::GetChallenge CSS authentication
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::GetChallenge( unsigned char pbChallengeKey[10] )
{
unsigned char keyBuffer[DVD_CHALLENGE_KEY_LENGTH];
PDVD_COPY_PROTECT_KEY pKey = NULL;
BOOL win32Result;
DWORD outputByteCount;
int index;
DbgAssert ( data != NULL );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
memset(keyBuffer,0,sizeof(keyBuffer));
pKey = (PDVD_COPY_PROTECT_KEY) &keyBuffer;
pKey->KeyLength = DVD_CHALLENGE_KEY_LENGTH;
pKey->SessionId = data->sessionId;
pKey->KeyType = DvdChallengeKey;
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_DVD_READ_KEY, // operation
&keyBuffer,
sizeof(keyBuffer),
&keyBuffer,
sizeof(keyBuffer),
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgPrint(("WIN32Loader::GetChallenge: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
for ( index = 0; index < 10; index++ )
{
pbChallengeKey[index] = pKey->KeyData[index];
}
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::SendChallenge CSS authentication
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::SendChallenge( unsigned char pbChallengeKey[10] )
{
unsigned char keyBuffer[DVD_CHALLENGE_KEY_LENGTH];
PDVD_COPY_PROTECT_KEY pKey = NULL;
BOOL win32Result;
DWORD outputByteCount;
int index;
DbgAssert ( data != NULL );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
memset(keyBuffer,0,sizeof(keyBuffer));
pKey = (PDVD_COPY_PROTECT_KEY) &keyBuffer;
pKey->KeyLength = DVD_CHALLENGE_KEY_LENGTH;
pKey->SessionId = data->sessionId;
pKey->KeyType = DvdChallengeKey;
for ( index = 0; index < 10; index++ )
{
pKey->KeyData[index] = pbChallengeKey[index];
}
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_DVD_SEND_KEY, // operation
&keyBuffer,
sizeof(keyBuffer),
NULL,
0,
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgAssert(("WIN32Loader::GetChallenge: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::GetBusKey CSS authentication
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::GetBusKey( unsigned char pbKey[5] )
{
unsigned char keyBuffer[DVD_BUS_KEY_LENGTH];
PDVD_COPY_PROTECT_KEY pKey = NULL;
BOOL win32Result;
DWORD outputByteCount;
DbgAssert ( data != NULL );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
memset(keyBuffer,0,sizeof(keyBuffer));
pKey = (PDVD_COPY_PROTECT_KEY) &keyBuffer;
pKey->KeyLength = DVD_BUS_KEY_LENGTH;
pKey->SessionId = data->sessionId;
pKey->KeyType = DvdBusKey1;
win32Result = DeviceIoControl( data->deviceHandle, // device handle
IOCTL_DVD_READ_KEY, // operation
&keyBuffer,
sizeof(keyBuffer),
&keyBuffer,
sizeof(keyBuffer),
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
if (win32Result == 0x00)
{
DbgPrint(("WIN32Loader::GetBusKey: ERROR %d\n", GetLastError() ));
data->sessionId = 0;
return ( WIN32LOADER_FAILURE );
}
memcpy(pbKey,pKey->KeyData,5);
//DbgPrint(("CSS: BUS KEY = %02x %02x %02x %02x %02x\n", pbKey[0],pbKey[1],pbKey[2],pbKey[3],pbKey[4]));
return ( WIN32LOADER_SUCCESS );
}
/**
*******************************************************************************
* WIN32Loader::SendBusKey CSS authentication
*
* @return WIN32LOADER_SUCCESS if successful, otherwise WIN32LOADER_FAILURE
*******************************************************************************/
int WIN32Loader::SendBusKey( unsigned char pbKey[5] )
{
unsigned char keyBuffer[DVD_BUS_KEY_LENGTH];
PDVD_COPY_PROTECT_KEY pKey = NULL;
BOOL win32Result;
DWORD outputByteCount;
int index;
DbgAssert ( data != NULL );
if ( data->deviceHandle == INVALID_HANDLE_VALUE )
{
return ( WIN32LOADER_FAILURE );
}
memset(keyBuffer,0,sizeof(keyBuffer));
pKey = (PDVD_COPY_PROTECT_KEY) &keyBuffer;
pKey->KeyLength = DVD_BUS_KEY_LENGTH;
pKey->SessionId = data->sessionId;
pKey->KeyType = DvdBusKey2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -