CGE: Add EncryptedStream class, remove seed parameter from XCrypt()

This commit is contained in:
Strangerke 2011-09-11 14:15:32 +02:00
parent 0784b7e0b4
commit 3715d6d444
4 changed files with 37 additions and 6 deletions

View File

@ -61,7 +61,7 @@ uint16 IoHand::read(void *buf, uint16 len) {
if (!bytesRead)
error("Read %s - %d bytes", _file->getName(), len);
if (_crypt)
_seed = _crypt(buf, len, kCryptSeed);
_seed = _crypt(buf, len);
return bytesRead;
}
@ -378,4 +378,27 @@ long VFile::seek(long pos) {
return (_bufMark = _begMark + pos);
}
/*-----------------------------------------------------------------------
* EncryptedStream
*-----------------------------------------------------------------------*/
EncryptedStream::EncryptedStream(const char *name) {
debugC(3, kCGEDebugFile, "EncryptedStream::EncryptedStream(%s)", name);
_error = false;
if (_dat->_error || _cat->_error)
error("Bad volume data");
BtKeypack *kp = _cat->find(name);
if (scumm_stricmp(kp->_key, name) != 0)
_error = true;
_dat->_file->seek(kp->_mark);
byte *dataBuffer = (byte *)malloc(kp->_size);
_dat->_file->read(dataBuffer, kp->_size);
XCrypt(dataBuffer, kp->_size);
_readStream = new Common::MemoryReadStream(dataBuffer, kp->_size, DisposeAfterUse::YES);
}
EncryptedStream::~EncryptedStream() {
}
} // End of namespace CGE

View File

@ -147,6 +147,14 @@ public:
long seek(long pos);
};
class EncryptedStream {
public:
bool _error;
EncryptedStream(const char *name);
~EncryptedStream();
Common::SeekableReadStream *_readStream;
};
extern CFile *_dat;
extern BtFile *_cat;

View File

@ -31,13 +31,13 @@
namespace CGE {
uint16 XCrypt(void *buf, uint16 siz, uint16 seed) {
uint16 XCrypt(void *buf, uint16 siz) {
byte *b = static_cast<byte *>(buf);
for (uint16 i = 0; i < siz; i++)
*b++ ^= seed;
*b++ ^= kCryptSeed;
return seed;
return kCryptSeed;
}
char *mergeExt(char *buf, const char *name, const char *ext) {

View File

@ -45,9 +45,9 @@ struct Dac {
uint8 _b;
};
typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed);
typedef uint16 Crypt(void *buf, uint16 siz);
uint16 XCrypt(void *buf, uint16 siz, uint16 seed);
uint16 XCrypt(void *buf, uint16 siz);
int takeEnum(const char **tab, const char *text);
uint16 chkSum(void *m, uint16 n);
char *mergeExt(char *buf, const char *name, const char *ext);