Skip to content

Commit

Permalink
- added: support multiple files in C2ErrorProtect.txt (MAX 16 files)
Browse files Browse the repository at this point in the history
- fixed: format code of DVD-R and DVD+R
- fixed: checking lead-out of subQ channel
- changed: func name of Xbox related
  • Loading branch information
saramibreak committed Nov 10, 2019
1 parent 3f3d448 commit 05fda7d
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 133 deletions.
18 changes: 16 additions & 2 deletions DiscImageCreator/DiscImageCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int exec(_TCHAR* argv[], PEXEC_TYPE pExecType, PEXT_ARG pExtArg, _TCHAR* pszFull
if (pExtArg->byScanProtectViaFile) {
device.dwTimeOutValue = pExtArg->dwTimeoutNum;
GetFilenameToSkipError(pExtArg->FILE.readError);
GetFilenameToFixError(pExtArg->FILE.edceccError);
GetFilenameToFixError(pExtArg->FILE.c2Error);
}
else {
device.dwTimeOutValue = DEFAULT_SPTD_TIMEOUT_VAL;
Expand Down Expand Up @@ -389,6 +389,7 @@ int exec(_TCHAR* argv[], PEXEC_TYPE pExecType, PEXT_ARG pExtArg, _TCHAR* pszFull
}
}
if (discData.SCSI.wCurrentMedia == ProfileDvdRam ||
discData.SCSI.wCurrentMedia == ProfileDvdPlusR ||
discData.SCSI.wCurrentMedia == ProfileHDDVDRam) {
ReadTOC(pExtArg, pExecType, &device, &discData);
}
Expand Down Expand Up @@ -421,7 +422,11 @@ int exec(_TCHAR* argv[], PEXEC_TYPE pExecType, PEXT_ARG pExtArg, _TCHAR* pszFull
else {
CONST size_t bufSize = 5;
_TCHAR szBuf[bufSize] = {};
#ifdef _WIN32
_sntprintf(szBuf, bufSize, _T("%c:\\*"), device.byDriveLetter);
#else
_sntprintf(szBuf, bufSize, _T("%s/*"), device.drivepath);
#endif
szBuf[4] = 0;
UINT64 uiDiscSize = 0;
bRet = GetDiscSize(szBuf, &uiDiscSize);
Expand Down Expand Up @@ -528,6 +533,7 @@ int exec(_TCHAR* argv[], PEXEC_TYPE pExecType, PEXT_ARG pExtArg, _TCHAR* pszFull
}

// custom _tsplitpath implementation to preserve dots in path
#if 0
void splitPath(const _TCHAR* path, _TCHAR* drive, _TCHAR* dir, _TCHAR* fname, _TCHAR* ext)
{
if(path == NULL)
Expand Down Expand Up @@ -586,14 +592,18 @@ void splitPath(const _TCHAR* path, _TCHAR* drive, _TCHAR* dir, _TCHAR* fname, _T
ext[n] = TEXT('\0');
}
}

#endif
int printAndSetPath(_TCHAR* szPathFromArg, _TCHAR* pszFullPath)
{
if (!GetCurrentDirectory(sizeof(s_szCurrentdir) / sizeof(s_szCurrentdir[0]), s_szCurrentdir)) {
OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__);
return FALSE;
}
#if 0
splitPath(szPathFromArg, s_szDrive, s_szDir, s_szFname, s_szExt);
#else
_tsplitpath(szPathFromArg, s_szDrive, s_szDir, s_szFname, s_szExt);
#endif

if (!s_szDrive[0] || !s_szDir[0]) {
_tcsncpy(pszFullPath, s_szCurrentdir, _MAX_PATH);
Expand Down Expand Up @@ -622,7 +632,11 @@ int printAndSetPath(_TCHAR* szPathFromArg, _TCHAR* pszFullPath)
OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__);
return FALSE;
}
#if 0
splitPath(pszFullPath, s_szDrive, s_szDir, NULL, NULL);
#else
_tsplitpath(pszFullPath, s_szDrive, s_szDir, s_szFname, NULL);
#endif
if (s_szExt[0] && _tcslen(pszFullPath) + _tcslen(s_szExt) < _MAX_PATH) {
_tcsncat(pszFullPath, s_szExt, _tcslen(s_szExt));
}
Expand Down
33 changes: 25 additions & 8 deletions DiscImageCreator/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,18 @@ BOOL IsValidSecuRomSector(

BOOL IsValidProtectedSector(
PDISC pDisc,
INT nLBA
INT nLBA,
INT idx
) {
BOOL bRet = FALSE;
if ((pDisc->PROTECT.byExist && pDisc->PROTECT.ERROR_SECTOR.nExtentPos <= nLBA &&
nLBA <= pDisc->PROTECT.ERROR_SECTOR.nExtentPos + pDisc->PROTECT.ERROR_SECTOR.nSectorSize) ||
((pDisc->PROTECT.byExist == microids || pDisc->PROTECT.byExist == datelAlt)
&& pDisc->PROTECT.ERROR_SECTOR.nExtentPos2nd <= nLBA &&
nLBA <= pDisc->PROTECT.ERROR_SECTOR.nExtentPos2nd + pDisc->PROTECT.ERROR_SECTOR.nSectorSize2nd)) {
bRet = TRUE;
if (pDisc->PROTECT.byExist != c2Err) {
if ((pDisc->PROTECT.byExist && pDisc->PROTECT.ERROR_SECTOR.nExtentPos[idx] <= nLBA &&
nLBA <= pDisc->PROTECT.ERROR_SECTOR.nExtentPos[idx] + pDisc->PROTECT.ERROR_SECTOR.nSectorSize[idx]) ||
(pDisc->PROTECT.byExist == datelAlt
&& pDisc->PROTECT.ERROR_SECTOR.nExtentPos2nd <= nLBA &&
nLBA <= pDisc->PROTECT.ERROR_SECTOR.nExtentPos2nd + pDisc->PROTECT.ERROR_SECTOR.nSectorSize2nd)) {
bRet = TRUE;
}
}
return bRet;
}
Expand Down Expand Up @@ -529,7 +532,9 @@ BOOL IsValidSafeDiscSector(

BOOL IsValidIntentionalC2error(
PDISC pDisc,
PDISC_PER_SECTOR pDiscPerSector
PDISC_PER_SECTOR pDiscPerSector,
INT nLBA,
INT idx
) {
BOOL bRet = FALSE;
if (pDisc->PROTECT.byExist == codelock ||
Expand All @@ -538,6 +543,10 @@ BOOL IsValidIntentionalC2error(
IsValidSafeDiscSector(pDisc, pDiscPerSector)) {
bRet = TRUE;
}
else if (pDisc->PROTECT.byExist == c2Err && pDisc->PROTECT.ERROR_SECTOR.nExtentPos[idx] <= nLBA &&
nLBA <= pDisc->PROTECT.ERROR_SECTOR.nExtentPos[idx] + pDisc->PROTECT.ERROR_SECTOR.nSectorSize[idx]) {
bRet = TRUE;
}
return bRet;
}

Expand Down Expand Up @@ -1256,7 +1265,11 @@ BOOL AnalyzeIfoFile(
BOOL bRet = TRUE;
CONST size_t bufSize = 25;
_TCHAR szBuf[bufSize] = {};
#ifdef _WIN32
_sntprintf(szBuf, bufSize, _T("%c:\\VIDEO_TS\\VIDEO_TS.IFO"), pDevice->byDriveLetter);
#else
_sntprintf(szBuf, bufSize, _T("%s/VIDEO_TS/VIDEO_TS.IFO"), pDevice->drivepath);
#endif

if (PathFileExists(szBuf)) {
_TCHAR szFnameAndExt[_MAX_FNAME] = {};
Expand Down Expand Up @@ -1293,7 +1306,11 @@ BOOL AnalyzeIfoFile(
}
INT nPgcCnt = 0;
for (WORD w = 1; w <= wNumOfTitleSets; w++) {
#ifdef _WIN32
_sntprintf(szBuf, bufSize, _T("%c:\\VIDEO_TS\\VTS_%02d_0.IFO"), pDevice->byDriveLetter, w);
#else
_sntprintf(szBuf, bufSize, _T("%s/VIDEO_TS/VTS_%02d_0.IFO"), pDevice->drivepath, w);
#endif
if (PathFileExists(szBuf)) {
FILE* fpVts = CreateOrOpenFile(szBuf, NULL, NULL, szFnameAndExt, NULL, _T(".IFO"), _T("rb"), 0, 0);
if (!fpVts) {
Expand Down
7 changes: 5 additions & 2 deletions DiscImageCreator/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ BOOL IsValidSecuRomSector(

BOOL IsValidProtectedSector(
PDISC pDisc,
INT nLBA
INT nLBA,
INT idx
);

BOOL IsValidSafeDiscSector(
Expand All @@ -102,7 +103,9 @@ BOOL IsValidSafeDiscSector(

BOOL IsValidIntentionalC2error(
PDISC pDisc,
PDISC_PER_SECTOR pDiscPerSector
PDISC_PER_SECTOR pDiscPerSector,
INT nLBA,
INT idx
);

BOOL IsCheckingSubChannel(
Expand Down
4 changes: 2 additions & 2 deletions DiscImageCreator/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef enum _TRACK_TYPE {
// https://www.cdmediaworld.com/hardware/cdrom/cd_protections.shtml
typedef enum _PROTECT_TYPE_CD {
no,
cdidx,
cds300,
codelock,
datel,
Expand All @@ -96,8 +97,7 @@ typedef enum _PROTECT_TYPE_CD {
smartE,
ripGuard,
physicalErr,
edcEccErr,
microids
c2Err
} PROTECT_TYPE_CD, *PPROTECT_TYPE_CD;

typedef enum _PROTECT_TYPE_DVD {
Expand Down
69 changes: 43 additions & 26 deletions DiscImageCreator/execScsiCmdforCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ BOOL ProcessReadCD(
}

if (pExtArg->byFua || pDisc->SUB.nCorruptCrcH == 1 || pDisc->SUB.nCorruptCrcL == 1) {
if (!IsValidProtectedSector(pDisc, nLBA) &&
!IsValidIntentionalC2error(pDisc, pDiscPerSector) &&
if (!IsValidProtectedSector(pDisc, nLBA, GetReadErrorFileIdx(pExtArg, pDisc, nLBA)) &&
!IsValidIntentionalC2error(pDisc, pDiscPerSector, nLBA, GetC2ErrorFileIdx(pExtArg, pDisc, nLBA)) &&
!pDiscPerSector->bLibCrypt && !pDiscPerSector->bSecuRom) {
FlushDriveCache(pExtArg, pDevice, nLBA);
// SynchronizeCache(pExtArg, pDevice);
Expand Down Expand Up @@ -303,7 +303,7 @@ BOOL ProcessReadCD(
if (pExtArg->byC2 && pDevice->FEATURE.byC2ErrorData) {
bRet = ContainsC2Error(pDevice, pDiscPerSector->data.current, &pDiscPerSector->uiC2errorNum, TRUE);
}
if (!IsValidProtectedSector(pDisc, nLBA)) {
if (!IsValidProtectedSector(pDisc, nLBA, GetReadErrorFileIdx(pExtArg, pDisc, nLBA))) {
if (pDiscPerSector->data.next != NULL && 1 <= pExtArg->uiSubAddionalNum) {
if (!(pDevice->byAsusDrive && pDisc->SCSI.nAllLength - 1 <= nLBA)) {
ExecReadCDForC2(pExecType, pExtArg, pDevice, lpCmd,
Expand Down Expand Up @@ -620,7 +620,7 @@ BOOL ReadCDForRereadingSectorType2(
}

INT ExecEccEdc(
BYTE byScanProtectViaFile,
PEXT_ARG pExtArg,
_DISC::_PROTECT protect,
LPCTSTR pszImgPath,
_DISC::_PROTECT::_ERROR_SECTOR errorSector
Expand All @@ -629,12 +629,12 @@ INT ExecEccEdc(
CONST INT nStrSize = _MAX_PATH * 2 + nCmdSize;
_TCHAR str[nStrSize] = {};
_TCHAR cmd[nCmdSize] = { _T("check") };
INT nStartLBA = errorSector.nExtentPos;
INT nEndLBA = errorSector.nExtentPos + errorSector.nSectorSize;
if (byScanProtectViaFile) {
INT nStartLBA = errorSector.nExtentPos[0];
INT nEndLBA = errorSector.nExtentPos[0] + errorSector.nSectorSize[0];
if (pExtArg->byScanProtectViaFile) {
if (protect.byExist == safeDisc || protect.byExist == safeDiscLite ||
protect.byExist == codelock || protect.byExist == datel ||
protect.byExist == datelAlt) {
protect.byExist == datelAlt || protect.byExist == c2Err) {
_tcsncpy(cmd, _T("fix"), sizeof(cmd) / sizeof(cmd[0]));
}
}
Expand All @@ -643,7 +643,27 @@ INT ExecEccEdc(
OutputString(_T("Exec %s\n"), str);
ret = _tsystem(str);
}
if (protect.byExist == microids || protect.byExist == datelAlt) {
if (protect.byExist == physicalErr) {
for (INT i = 1; i < pExtArg->FILE.readErrCnt; i++) {
nStartLBA = errorSector.nExtentPos[i];
nEndLBA = errorSector.nExtentPos[i] + errorSector.nSectorSize[i];
if (GetEccEdcCmd(str, nStrSize, cmd, pszImgPath, nStartLBA, nEndLBA)) {
OutputString(_T("Exec %s\n"), str);
ret = _tsystem(str);
}
}
}
else if (protect.byExist == c2Err) {
for (INT i = 1; i < pExtArg->FILE.c2ErrCnt; i++) {
nStartLBA = errorSector.nExtentPos[i];
nEndLBA = errorSector.nExtentPos[i] + errorSector.nSectorSize[i];
if (GetEccEdcCmd(str, nStrSize, cmd, pszImgPath, nStartLBA, nEndLBA)) {
OutputString(_T("Exec %s\n"), str);
ret = _tsystem(str);
}
}
}
else if (protect.byExist == datelAlt) {
nStartLBA = errorSector.nExtentPos2nd;
nEndLBA = errorSector.nExtentPos2nd + errorSector.nSectorSize2nd;
if (GetEccEdcCmd(str, nStrSize, cmd, pszImgPath, nStartLBA, nEndLBA)) {
Expand Down Expand Up @@ -721,7 +741,7 @@ BOOL ProcessDescramble(
return FALSE;
}
if (pExtArg->byBe) {
ExecEccEdc(pExtArg->byScanProtectViaFile, pDisc->PROTECT, pszNewPath, pDisc->PROTECT.ERROR_SECTOR);
ExecEccEdc(pExtArg, pDisc->PROTECT, pszNewPath, pDisc->PROTECT.ERROR_SECTOR);
}
}
else {
Expand All @@ -739,7 +759,7 @@ BOOL ProcessDescramble(
}
DescrambleMainChannelAll(pExtArg, pDisc, scrambled_table, fpImg);
FcloseAndNull(fpImg);
ExecEccEdc(pExtArg->byScanProtectViaFile, pDisc->PROTECT, pszImgPath, pDisc->PROTECT.ERROR_SECTOR);
ExecEccEdc(pExtArg, pDisc->PROTECT, pszImgPath, pDisc->PROTECT.ERROR_SECTOR);
}
return TRUE;
}
Expand Down Expand Up @@ -932,8 +952,8 @@ BOOL ReadCDAll(
}
}
else if (pDisc->PROTECT.byExist == laserlock || pDisc->PROTECT.byExist == proring ||
pDisc->PROTECT.byExist == physicalErr || pDisc->PROTECT.byExist == microids) {
if (IsValidProtectedSector(pDisc, nLBA - 1)) {
pDisc->PROTECT.byExist == physicalErr) {
if (IsValidProtectedSector(pDisc, nLBA - 1, GetReadErrorFileIdx(pExtArg, pDisc, nLBA))) {
ProcessReturnedContinue(pExecType, pExtArg, pDevice, pDisc
, pDiscPerSector, nLBA, nMainDataType, padByUsr55, fpImg, fpSub, fpC2);
nLBA++;
Expand Down Expand Up @@ -975,7 +995,7 @@ BOOL ReadCDAll(
OutputLogA(standardError | fileC2Error,
" LBA[%06d, %#07x] Detected C2 error %d bit\n", nLBA, nLBA, pDiscPerSector->uiC2errorNum);
if (pExtArg->byC2 && pDevice->FEATURE.byC2ErrorData) {
if (!(IsValidProtectedSector(pDisc, nLBA) && IsValidIntentionalC2error(pDisc, pDiscPerSector))) {
if (!(IsValidIntentionalC2error(pDisc, pDiscPerSector, nLBA, GetC2ErrorFileIdx(pExtArg, pDisc, nLBA)))) {
pDisc->MAIN.lpAllLBAOfC2Error[pDisc->MAIN.nC2ErrorCnt++] = nLBA;
}
}
Expand Down Expand Up @@ -1057,7 +1077,7 @@ BOOL ReadCDAll(
, pDiscPerSector->data.current, CD_RAW_SECTOR_SIZE);
}
if (pDisc->SUB.nSubChannelOffset) {
if (!IsValidProtectedSector(pDisc, nLBA)) {
if (!IsValidProtectedSector(pDisc, nLBA, GetReadErrorFileIdx(pExtArg, pDisc, nLBA))) {
if (2 <= pExtArg->uiSubAddionalNum) {
memcpy(pDiscPerSector->subcode.nextNext
, pDiscPerSector->subcode.next, CD_RAW_READ_SUBCODE_SIZE);
Expand Down Expand Up @@ -1400,8 +1420,7 @@ BOOL ReadCDForSwap(
OutputLogA(standardError | fileC2Error,
"\rLBA[%06d, %#07x] Detected C2 error %d bit\n", nLBA, nLBA, pDiscPerSector->uiC2errorNum);
if (pExtArg->byC2 && pDevice->FEATURE.byC2ErrorData) {
if (!(IsValidProtectedSector(pDisc, nLBA) && (pDisc->PROTECT.byExist == codelock
|| IsValidSafeDiscSector(pDisc, pDiscPerSector)))) {
if (!(IsValidIntentionalC2error(pDisc, pDiscPerSector, nLBA, GetC2ErrorFileIdx(pExtArg, pDisc, nLBA)))) {
pDisc->MAIN.lpAllLBAOfC2Error[pDisc->MAIN.nC2ErrorCnt++] = nLBA;
}
}
Expand Down Expand Up @@ -1905,8 +1924,7 @@ BOOL ReadCDPartial(
OutputLogA(standardError | fileC2Error,
" LBA[%06d, %#07x] Detected C2 error %d bit\n", nLBA, nLBA, pDiscPerSector->uiC2errorNum);
if (pExtArg->byC2 && pDevice->FEATURE.byC2ErrorData) {
if (!(IsValidProtectedSector(pDisc, nLBA) && (pDisc->PROTECT.byExist == codelock
|| IsValidSafeDiscSector(pDisc, pDiscPerSector)))) {
if (!(IsValidIntentionalC2error(pDisc, pDiscPerSector, nLBA, GetC2ErrorFileIdx(pExtArg, pDisc, nLBA)))) {
pDisc->MAIN.lpAllLBAOfC2Error[pDisc->MAIN.nC2ErrorCnt++] = nLBA;
}
}
Expand All @@ -1922,8 +1940,7 @@ BOOL ReadCDPartial(
}
else if (pDiscPerSector->bReturnCode == RETURNED_CONTINUE) {
if (pDisc->PROTECT.byExist != physicalErr && (!bForceSkip || !bForceSkip2)) {
if (pDisc->PROTECT.byExist == proring || pDisc->PROTECT.byExist == laserlock ||
pDisc->PROTECT.byExist == microids) {
if (pDisc->PROTECT.byExist == proring || pDisc->PROTECT.byExist == laserlock) {
if (!bForceSkip) {
for (UINT i = 0; i < pExtArg->uiSkipSectors; i++) {
ProcessReturnedContinue(pExecType, pExtArg, pDevice, pDisc, pDiscPerSector
Expand Down Expand Up @@ -2020,7 +2037,7 @@ BOOL ReadCDPartial(
, pDiscPerSector->data.current, CD_RAW_SECTOR_SIZE);
}
if (pDisc->SUB.nSubChannelOffset) {
if (!IsValidProtectedSector(pDisc, nLBA)) {
if (!IsValidProtectedSector(pDisc, nLBA, GetReadErrorFileIdx(pExtArg, pDisc, nLBA))) {
if (2 <= pExtArg->uiSubAddionalNum) {
memcpy(pDiscPerSector->subcode.nextNext, pDiscPerSector->subcode.next, CD_RAW_READ_SUBCODE_SIZE);
}
Expand Down Expand Up @@ -2219,17 +2236,17 @@ BOOL ReadCDPartial(
FcloseAndNull(fpBin);
}
if (pExtArg->byScanProtectViaFile) {
pDisc->PROTECT.ERROR_SECTOR.nExtentPos = nStart;
pDisc->PROTECT.ERROR_SECTOR.nSectorSize = nEnd - nStart;
pDisc->PROTECT.ERROR_SECTOR.nExtentPos[0] = nStart;
pDisc->PROTECT.ERROR_SECTOR.nSectorSize[0] = nEnd - nStart;
}
ExecEccEdc(pExtArg->byScanProtectViaFile, pDisc->PROTECT, pszPath, pDisc->PROTECT.ERROR_SECTOR);
ExecEccEdc(pExtArg, pDisc->PROTECT, pszPath, pDisc->PROTECT.ERROR_SECTOR);
}
else if (*pExecType == gd) {
_TCHAR pszImgPath[_MAX_PATH] = {};
if (!DescrambleMainChannelForGD(pszPath, pszImgPath)) {
throw FALSE;
}
ExecEccEdc(pExtArg->byScanProtectViaFile, pDisc->PROTECT, pszImgPath, pDisc->PROTECT.ERROR_SECTOR);
ExecEccEdc(pExtArg, pDisc->PROTECT, pszImgPath, pDisc->PROTECT.ERROR_SECTOR);
if (!CreateBinCueForGD(pDisc, pszPath)) {
throw FALSE;
}
Expand Down
8 changes: 4 additions & 4 deletions DiscImageCreator/execScsiCmdforCDCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,8 @@ BOOL ReadCDForScanningProtectViaSector(
aBuf[nOfs + 4] == 0 && aBuf[nOfs + 5] == 0xff && aBuf[nOfs + 6] == 0 && aBuf[nOfs + 7] == 0xff &&
aBuf[nOfs + 8] == 0 && aBuf[nOfs + 9] == 0xff && aBuf[nOfs + 10] == 0 && aBuf[nOfs + 11] == 0xff) {
OutputLogA(standardOut | fileDisc, "\nDetected ProtectCD VOB. It begins from %d sector", nLBA);
pDisc->PROTECT.ERROR_SECTOR.nExtentPos = nLBA;
pDisc->PROTECT.ERROR_SECTOR.nSectorSize = pDisc->SCSI.nAllLength - nLBA - 1;
pDisc->PROTECT.ERROR_SECTOR.nExtentPos[0] = nLBA;
pDisc->PROTECT.ERROR_SECTOR.nSectorSize[0] = pDisc->SCSI.nAllLength - nLBA - 1;
pDisc->PROTECT.byExist = protectCDVOB;
pExtArg->byScanProtectViaFile = pExtArg->byScanProtectViaSector;
break;
Expand Down Expand Up @@ -1509,9 +1509,9 @@ BOOL ExecCheckingByteOrder(
return FALSE;
}
BYTE lpCmd[CDB12GENERIC_LENGTH] = {};
pExtArg->byBe = TRUE;
// pExtArg->byBe = TRUE;
SetReadDiscCommand(NULL, pExtArg, pDevice, 1, c2, sub, lpCmd, FALSE);
pExtArg->byBe = FALSE;
// pExtArg->byBe = FALSE;

BOOL bRet = TRUE;
if (!ExecReadCD(pExtArg, pDevice, lpCmd, 0, lpBuf
Expand Down
Loading

0 comments on commit 05fda7d

Please sign in to comment.