aboutsummaryrefslogtreecommitdiff
path: root/engines/zvision/zfsArchive.cpp
diff options
context:
space:
mode:
authorrichiesams2013-06-12 22:06:05 -0500
committerrichiesams2013-08-04 13:31:42 -0500
commitef37f14d539d417a1a4506c5c09df1409700aa30 (patch)
tree5aece099c5ef8cfbc3e0d23daa1f310e865696a5 /engines/zvision/zfsArchive.cpp
parent179f5de49897a723b2605a0fed18980ce144f68c (diff)
downloadscummvm-rg350-ef37f14d539d417a1a4506c5c09df1409700aa30.tar.gz
scummvm-rg350-ef37f14d539d417a1a4506c5c09df1409700aa30.tar.bz2
scummvm-rg350-ef37f14d539d417a1a4506c5c09df1409700aa30.zip
ZVISION: Add xor encryption handling to ZfsArchive class
Diffstat (limited to 'engines/zvision/zfsArchive.cpp')
-rw-r--r--engines/zvision/zfsArchive.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp
index a3111d7705..59e65f1713 100644
--- a/engines/zvision/zfsArchive.cpp
+++ b/engines/zvision/zfsArchive.cpp
@@ -55,16 +55,17 @@ ZfsArchive::~ZfsArchive() {
}
void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) {
- ZfsHeader header;
-
// Don't do a straight struct cast since we can't guarantee endianness
- header.magic = stream->readUint32LE();
- header.unknown1 = stream->readUint32LE();
- header.unknown2 = stream->readUint32LE();
- header.filesPerBlock = stream->readUint32LE();
- header.fileCount = stream->readUint32LE();
- header.xorKey = stream->readUint32LE();
- header.fileSectionOffset = stream->readUint32LE();
+ _header.magic = stream->readUint32LE();
+ _header.unknown1 = stream->readUint32LE();
+ _header.maxNameLength = stream->readUint32LE();
+ _header.filesPerBlock = stream->readUint32LE();
+ _header.fileCount = stream->readUint32LE();
+ _header.xorKey[0] = stream->readByte();
+ _header.xorKey[1] = stream->readByte();
+ _header.xorKey[2] = stream->readByte();
+ _header.xorKey[3] = stream->readByte();
+ _header.fileSectionOffset = stream->readUint32LE();
uint32 nextOffset;
@@ -73,7 +74,7 @@ void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) {
nextOffset = stream->readUint32LE();
// Read in each entry header
- for (int i = 0; i < header.filesPerBlock; i++) {
+ for (int i = 0; i < _header.filesPerBlock; i++) {
ZfsEntryHeader entryHeader;
entryHeader.name = readEntryName(stream);
@@ -135,10 +136,18 @@ Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::
byte* buffer = new byte[entryHeader->size];
zfsArchive.read(buffer, entryHeader->size);
+ // Decrypt the data in place
+ if (_header.xorKey != 0)
+ unXor(buffer, entryHeader->size, _header.xorKey);
return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES);
}
+void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const {
+ for (uint32 i = 0; i < length; i++)
+ buffer[i] ^= xorKey[i % 4];
+}
+
} // End namespace ZVision