diff --git a/DiscImageCreator/DiscImageCreator.cpp b/DiscImageCreator/DiscImageCreator.cpp index 5ec5f46..c42f3a6 100644 --- a/DiscImageCreator/DiscImageCreator.cpp +++ b/DiscImageCreator/DiscImageCreator.cpp @@ -173,13 +173,13 @@ int execForDumping(PEXEC_TYPE pExecType, PEXT_ARG pExtArg, _TCHAR* pszFullPath, hash.uiMax = 1; // .bin } else if (*pExecType == bd) { - hash.uiMax = 2; // PIC.bin, .iso + hash.uiMax = 2; // PIC.bin, .iso } else if (*pExecType == dvd || *pExecType == sacd) { - hash.uiMax = 3; // PFI.bin, DMI.bin, .iso + hash.uiMax = 3; // PFI.bin, DMI.bin, .iso or .raw } else if (*pExecType == xbox) { - hash.uiMax = 4; // SS.bin, PFI.bin, DMI.bin, .iso + hash.uiMax = 4; // SS.bin, PFI.bin, DMI.bin, .iso } hash.pHashChunk = (PHASH_CHUNK)calloc(hash.uiMax, sizeof(HASH_CHUNK)); if (!hash.pHashChunk) { @@ -393,7 +393,7 @@ int execForDumping(PEXEC_TYPE pExecType, PEXT_ARG pExtArg, _TCHAR* pszFullPath, if (pExtArg->byFix) { pDisc->DVD.fixNum = s_uiFix; } - bRet = ReadDVDRaw(pExtArg, pDevice, pDisc, pszFullPath); + bRet = ReadDVDRaw(pExtArg, pDevice, pDisc, pszFullPath, &hash); if (pExtArg->byFix && bRet > 6) { s_uiFix = (UINT)bRet; } diff --git a/DiscImageCreator/execScsiCmdforDVD.cpp b/DiscImageCreator/execScsiCmdforDVD.cpp index 51edd03..58f55a5 100644 --- a/DiscImageCreator/execScsiCmdforDVD.cpp +++ b/DiscImageCreator/execScsiCmdforDVD.cpp @@ -628,7 +628,8 @@ BOOL ReadDVDRaw( PEXT_ARG pExtArg, PDEVICE pDevice, PDISC pDisc, - LPCTSTR pszFullPath + LPCTSTR pszFullPath, + PHASH pHash ) { //#define TEST_WII #ifdef TEST_WII @@ -641,8 +642,9 @@ BOOL ReadDVDRaw( memcpy(szMode, _T("rb+"), 3); } + _TCHAR szFnameAndExt[_MAX_FNAME + _MAX_EXT] = {}; _TCHAR pszOutPath[_MAX_PATH] = {}; - if (NULL == (fp = CreateOrOpenFile(pszFullPath, NULL, pszOutPath, NULL, NULL, _T(".raw"), szMode, 0, 0))) { + if (NULL == (fp = CreateOrOpenFile(pszFullPath, NULL, pszOutPath, szFnameAndExt, NULL, _T(".raw"), szMode, 0, 0))) { OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__); return FALSE; } @@ -848,6 +850,7 @@ BOOL ReadDVDRaw( OutputString("\n"); #endif } + CalcInit(&pHash->pHashChunk[pHash->uiIndex].md5, &pHash->pHashChunk[pHash->uiIndex].sha); #ifdef _WIN32 INT direction = SCSI_IOCTL_DATA_IN; @@ -955,7 +958,7 @@ BOOL ReadDVDRaw( } if (bCheckSectorNum) { nRereadNum = 0; - fwrite(lpBuf, sizeof(BYTE), rawWriteSize, fp); + WriteBufWithCalc(lpBuf, dwSectorSize * memBlkSize, transferLen.AsULong, fp, pHash); sectorNum += transferAndMemSize; } else { @@ -1075,6 +1078,9 @@ BOOL ReadDVDRaw( FreeAndNull(pBuf); FcloseAndNull(fp); + _tcsncpy(pHash->pHashChunk[pHash->uiIndex].szFnameAndExt, szFnameAndExt, sizeof(szFnameAndExt)); + pHash->pHashChunk[pHash->uiIndex].ui64FileSize = (UINT64)(DVD_RAW_SECTOR_SIZE * pDisc->SCSI.nAllLength); + if (bRet && IsNintendoDisc(pDisc) && IsSupported0xE7(pDevice)) { _TCHAR str[_MAX_PATH * 3] = {}; if (GetUnscCmd(str, pszOutPath)) { diff --git a/DiscImageCreator/execScsiCmdforDVD.h b/DiscImageCreator/execScsiCmdforDVD.h index 59a224e..2d857de 100644 --- a/DiscImageCreator/execScsiCmdforDVD.h +++ b/DiscImageCreator/execScsiCmdforDVD.h @@ -48,7 +48,8 @@ BOOL ReadDVDRaw( PEXT_ARG pExtArg, PDEVICE pDevice, PDISC pDisc, - LPCTSTR pszFullPath + LPCTSTR pszFullPath, + PHASH pHash ); BOOL ReadDiscStructure( diff --git a/DiscImageCreator/forwardDeclaration.h b/DiscImageCreator/forwardDeclaration.h index dc778f7..f3e883f 100644 --- a/DiscImageCreator/forwardDeclaration.h +++ b/DiscImageCreator/forwardDeclaration.h @@ -22,6 +22,7 @@ #define DRIVE_PRODUCT_ID_SIZE (16) #define DRIVE_VERSION_ID_SIZE (4) +#define NOT_USE_SIZE (0) #define DISC_MAIN_DATA_SIZE (2048) #define CD_RAW_READ_C2_294_SIZE (294) #define CD_RAW_SECTOR_SIZE (2352) diff --git a/DiscImageCreator/xml.cpp b/DiscImageCreator/xml.cpp index ba57ec4..5a1c228 100644 --- a/DiscImageCreator/xml.cpp +++ b/DiscImageCreator/xml.cpp @@ -32,6 +32,7 @@ BOOL OutputHash( #else XMLElement* pWriter, #endif + PEXT_ARG pExtArg, _TCHAR* pszFullPath, DWORD dwBytesPerSector, LPCTSTR szExt, @@ -46,7 +47,7 @@ BOOL OutputHash( SHA1Context sha = {}; UINT64 ui64FileSize = 0; - if (pHash->uiMax == 0) { + if (pHash->uiMax == 0 || (pExtArg->byRawDump && !_tcsncmp(szExt, _T(".iso"), 4))) { // for CD _TCHAR szOutPath[_MAX_PATH] = {}; FILE* fp = NULL; @@ -65,16 +66,9 @@ BOOL OutputHash( } ui64FileSize = GetFileSize64(0, fp); - UINT uiSectorSizeOne = 0; - if (dwBytesPerSector) { - uiSectorSizeOne = (UINT)dwBytesPerSector; - } - else { - uiSectorSizeOne = CD_RAW_SECTOR_SIZE; - } + UINT64 ui64SectorSizeAll = ui64FileSize / (UINT64)dwBytesPerSector; - UINT64 ui64SectorSizeAll = ui64FileSize / (UINT64)uiSectorSizeOne; - if (ui64FileSize >= uiSectorSizeOne) { + if (ui64FileSize >= dwBytesPerSector) { CalcInit(&md5, &sha); BYTE data[CD_RAW_SECTOR_SIZE] = {}; @@ -82,11 +76,11 @@ BOOL OutputHash( OutputString("Hashing: %s\n", szFnameAndExt); // TODO: This code can more speed up! if reduce calling fread() for (UINT64 i = 1; i <= ui64SectorSizeAll; i++) { - if (fread(data, sizeof(BYTE), uiSectorSizeOne, fp) < uiSectorSizeOne) { - OutputErrorString("Failed to read: read size %u [F:%s][L:%d]\n", uiSectorSizeOne, _T(__FUNCTION__), __LINE__); + if (fread(data, sizeof(BYTE), dwBytesPerSector, fp) < dwBytesPerSector) { + OutputErrorString("Failed to read: read size %lu [F:%s][L:%d]\n", dwBytesPerSector, _T(__FUNCTION__), __LINE__); return FALSE; }; - nRet = CalcHash(&crc32, &md5, &sha, data, uiSectorSizeOne); + nRet = CalcHash(&crc32, &md5, &sha, data, dwBytesPerSector); if (!nRet) { break; } @@ -112,6 +106,7 @@ BOOL OutputHash( if (CalcEnd(&md5, &sha, digest, Message_Digest)) { if (!_tcsncmp(szExt, _T(".scm"), 4) || !_tcsncmp(szExt, _T(".img"), 4) || + !_tcsncmp(szExt, _T(".raw"), 4) || find_last_string(szFnameAndExt, _T("_SS.bin")) || find_last_string(szFnameAndExt, _T("_PFI.bin")) || find_last_string(szFnameAndExt, _T("_DMI.bin")) || @@ -239,7 +234,7 @@ BOOL OutputRomElement( PHASH pHash ) { if (*pExecType == fd || *pExecType == disk) { - if (!OutputHash(pWriter, pszFullPath, pDisc->dwBytesPerSector, _T(".bin"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, pszFullPath, pDisc->dwBytesPerSector, _T(".bin"), 1, 1, FALSE, pHash)) { return FALSE; } } @@ -252,7 +247,7 @@ BOOL OutputRomElement( OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__); return FALSE; } - if (!OutputHash(pWriter, szPath, pDisc->dwBytesPerSector, _T(".bin"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, szPath, NOT_USE_SIZE, _T(".bin"), 1, 1, FALSE, pHash)) { return FALSE; } } @@ -263,7 +258,7 @@ BOOL OutputRomElement( OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__); return FALSE; } - if (!OutputHash(pWriter, szPath, pDisc->dwBytesPerSector, _T(".bin"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, szPath, NOT_USE_SIZE, _T(".bin"), 1, 1, FALSE, pHash)) { return FALSE; } @@ -273,7 +268,7 @@ BOOL OutputRomElement( OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__); return FALSE; } - if (!OutputHash(pWriter, szPath, pDisc->dwBytesPerSector, _T(".bin"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, szPath, NOT_USE_SIZE, _T(".bin"), 1, 1, FALSE, pHash)) { return FALSE; } } @@ -284,15 +279,15 @@ BOOL OutputRomElement( OutputLastErrorNumAndString(_T(__FUNCTION__), __LINE__); return FALSE; } - if (!OutputHash(pWriter, szPath, pDisc->dwBytesPerSector, _T(".bin"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, szPath, NOT_USE_SIZE, _T(".bin"), 1, 1, FALSE, pHash)) { return FALSE; } } - if (!OutputHash(pWriter, pszFullPath, pDisc->dwBytesPerSector, _T(".iso"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, pszFullPath, DISC_MAIN_DATA_SIZE, _T(".iso"), 1, 1, FALSE, pHash)) { return FALSE; } if (pExtArg->byRawDump) { - if (!OutputHash(pWriter, pszFullPath, pDisc->dwBytesPerSector, _T(".raw"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, pszFullPath, NOT_USE_SIZE, _T(".raw"), 1, 1, FALSE, pHash)) { return FALSE; } } @@ -302,16 +297,16 @@ BOOL OutputRomElement( OutputDiscLog(OUTPUT_DHYPHEN_PLUS_STR("Hash(Whole image)")); if (pDisc->SCSI.trkType == TRACK_TYPE::dataExist || pDisc->SCSI.trkType == TRACK_TYPE::pregapDataIn1stTrack) { - if (!OutputHash(pWriter, pszFullPath, pDisc->dwBytesPerSector, _T(".scm"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, pszFullPath, CD_RAW_SECTOR_SIZE, _T(".scm"), 1, 1, FALSE, pHash)) { return FALSE; } } - if (!OutputHash(pWriter, pszFullPath, pDisc->dwBytesPerSector, _T(".img"), 1, 1, FALSE, pHash)) { + if (!OutputHash(pWriter, pExtArg, pszFullPath, CD_RAW_SECTOR_SIZE, _T(".img"), 1, 1, FALSE, pHash)) { return FALSE; } } for (UCHAR i = pDisc->SCSI.toc.FirstTrack; i <= pDisc->SCSI.toc.LastTrack; i++) { - if (!OutputHash(pWriter, pszFullPath, pDisc->dwBytesPerSector, _T(".bin"), i, pDisc->SCSI.toc.LastTrack, bDesync, pHash)) { + if (!OutputHash(pWriter, pExtArg, pszFullPath, CD_RAW_SECTOR_SIZE, _T(".bin"), i, pDisc->SCSI.toc.LastTrack, bDesync, pHash)) { return FALSE; } } diff --git a/DiscImageCreator/xml.h b/DiscImageCreator/xml.h index 36065f4..5fa5233 100644 --- a/DiscImageCreator/xml.h +++ b/DiscImageCreator/xml.h @@ -19,21 +19,6 @@ using namespace tinyxml2; #endif -BOOL OutputHash( -#ifdef _WIN32 - CComPtr pWriter, -#else - XMLElement* pWriter, -#endif - _TCHAR* pszFullPath, - DWORD dwBytesPerSector, - LPCTSTR szExt, - UCHAR uiTrack, - UCHAR uiLastTrack, - BOOL bDesync, - PHASH pHash -); - BOOL ReadWriteDat( PEXEC_TYPE pExecType, PEXT_ARG pExtArg,