Skip to content

Commit

Permalink
MT32: Add SHA1 file digest checking in getROMInfo()
Browse files Browse the repository at this point in the history
This ensures that the capabilities of the detected ROM files are
set properly from the list of known ROMs. This is mostly needed
for the extra samples of the CM32-L ROMs
  • Loading branch information
bluegr committed Dec 28, 2015
1 parent f6e42a7 commit 908d2f3
Show file tree
Hide file tree
Showing 3 changed files with 702 additions and 4 deletions.
22 changes: 18 additions & 4 deletions audio/softsynth/mt32/ROMInfo.cpp
Expand Up @@ -17,6 +17,7 @@

//#include <cstring>
#include "ROMInfo.h"
#include "sha1/sha1.h"

namespace MT32Emu {

Expand Down Expand Up @@ -52,14 +53,27 @@ static const ROMInfo *getKnownROMInfoFromList(unsigned int index) {
return ROM_INFOS[index];
}

static void getSHA1(Common::File *file, char *fileDigest) {
size_t fileSize = file->size();
byte *data = new byte[fileSize];
file->read(data, fileSize);
file->seek(0);
SHA1 sha1;
uint intDigest[5];
sha1.Input((const char *)data, fileSize);
if (sha1.Result(intDigest))
sprintf(fileDigest, "%08x%08x%08x%08x%08x", intDigest[0], intDigest[1], intDigest[2], intDigest[3], intDigest[4]);
delete[] data;
}

const ROMInfo* ROMInfo::getROMInfo(Common::File *file) {
size_t fileSize = file->size();
// We haven't added the SHA1 checksum code in ScummVM, as the file size
// suffices for our needs for now.
//const char *fileDigest = file->getSHA1();
char fileDigest[41]; // Includes terminator char
getSHA1(file, fileDigest);

for (int i = 0; getKnownROMInfoFromList(i) != NULL; i++) {
const ROMInfo *romInfo = getKnownROMInfoFromList(i);
if (fileSize == romInfo->fileSize /*&& !strcmp(fileDigest, romInfo->sha1Digest)*/) {
if (fileSize == romInfo->fileSize && !strcmp(fileDigest, romInfo->sha1Digest)) {
return romInfo;
}
}
Expand Down

0 comments on commit 908d2f3

Please sign in to comment.