Skip to content

Commit

Permalink
- fixed: forgot .raw hashing when added #108 (2022-01-27) (closed #148)
Browse files Browse the repository at this point in the history
  • Loading branch information
saramibreak committed Sep 13, 2022
1 parent 035de4b commit bb05d98
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 46 deletions.
8 changes: 4 additions & 4 deletions DiscImageCreator/DiscImageCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 9 additions & 3 deletions DiscImageCreator/execScsiCmdforDVD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion DiscImageCreator/execScsiCmdforDVD.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ BOOL ReadDVDRaw(
PEXT_ARG pExtArg,
PDEVICE pDevice,
PDISC pDisc,
LPCTSTR pszFullPath
LPCTSTR pszFullPath,
PHASH pHash
);

BOOL ReadDiscStructure(
Expand Down
1 change: 1 addition & 0 deletions DiscImageCreator/forwardDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 18 additions & 23 deletions DiscImageCreator/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BOOL OutputHash(
#else
XMLElement* pWriter,
#endif
PEXT_ARG pExtArg,
_TCHAR* pszFullPath,
DWORD dwBytesPerSector,
LPCTSTR szExt,
Expand All @@ -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;
Expand All @@ -65,28 +66,21 @@ 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] = {};
int nRet = TRUE;
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;
}
Expand All @@ -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")) ||
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
15 changes: 0 additions & 15 deletions DiscImageCreator/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,6 @@
using namespace tinyxml2;
#endif

BOOL OutputHash(
#ifdef _WIN32
CComPtr<IXmlWriter> 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,
Expand Down

0 comments on commit bb05d98

Please sign in to comment.