diff options
author | Strangerke | 2011-09-11 14:15:32 +0200 |
---|---|---|
committer | Strangerke | 2011-09-11 14:15:32 +0200 |
commit | 3715d6d444792fc93fe98df4f0274f0be846eed1 (patch) | |
tree | 2236eca4d006dc1f3e9a4e762f86ff361a1d5c26 /engines/cge | |
parent | 0784b7e0b4f0f19b4c5a34f7081fdbf8ce9f75d9 (diff) | |
download | scummvm-rg350-3715d6d444792fc93fe98df4f0274f0be846eed1.tar.gz scummvm-rg350-3715d6d444792fc93fe98df4f0274f0be846eed1.tar.bz2 scummvm-rg350-3715d6d444792fc93fe98df4f0274f0be846eed1.zip |
CGE: Add EncryptedStream class, remove seed parameter from XCrypt()
Diffstat (limited to 'engines/cge')
-rw-r--r-- | engines/cge/fileio.cpp | 25 | ||||
-rw-r--r-- | engines/cge/fileio.h | 8 | ||||
-rw-r--r-- | engines/cge/general.cpp | 6 | ||||
-rw-r--r-- | engines/cge/general.h | 4 |
4 files changed, 37 insertions, 6 deletions
diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index 7624eac936..87a1ffebac 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -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 diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index 65f0b953e7..68b9a26d76 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -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; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index c93cc1292b..7db61818ab 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -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) { diff --git a/engines/cge/general.h b/engines/cge/general.h index 8f997c9ae2..1793594d07 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -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); |