Core/DataStores: Allow loading encrypted sections when key is known when reading from casc storage

Closes #24456
This commit is contained in:
Shauren
2020-05-10 15:29:47 +02:00
parent 16761e1d7c
commit d889228259
6 changed files with 43 additions and 9 deletions

View File

@@ -185,7 +185,7 @@ public:
virtual uint32 GetRecordCopyCount() const = 0;
virtual uint32 GetMaxId() const = 0;
virtual DB2FileLoadInfo const* GetLoadInfo() const = 0;
virtual DB2SectionHeader const& GetSection(uint32 section) const = 0;
virtual DB2SectionHeader& GetSection(uint32 section) const = 0;
virtual bool IsSignedField(uint32 field) const = 0;
private:
@@ -225,7 +225,7 @@ public:
uint32 GetRecordCopyCount() const override;
uint32 GetMaxId() const override;
DB2FileLoadInfo const* GetLoadInfo() const override;
DB2SectionHeader const& GetSection(uint32 section) const override;
DB2SectionHeader& GetSection(uint32 section) const override;
bool IsSignedField(uint32 field) const override;
private:
@@ -284,7 +284,7 @@ public:
uint32 GetRecordCopyCount() const override;
uint32 GetMaxId() const override;
DB2FileLoadInfo const* GetLoadInfo() const override;
DB2SectionHeader const& GetSection(uint32 section) const override;
DB2SectionHeader& GetSection(uint32 section) const override;
bool IsSignedField(uint32 field) const override;
private:
@@ -961,7 +961,7 @@ DB2FileLoadInfo const* DB2FileLoaderRegularImpl::GetLoadInfo() const
return _loadInfo;
}
DB2SectionHeader const& DB2FileLoaderRegularImpl::GetSection(uint32 section) const
DB2SectionHeader& DB2FileLoaderRegularImpl::GetSection(uint32 section) const
{
return _sections[section];
}
@@ -1605,7 +1605,7 @@ DB2FileLoadInfo const* DB2FileLoaderSparseImpl::GetLoadInfo() const
return _loadInfo;
}
DB2SectionHeader const& DB2FileLoaderSparseImpl::GetSection(uint32 section) const
DB2SectionHeader& DB2FileLoaderSparseImpl::GetSection(uint32 section) const
{
return _sections[section];
}
@@ -1906,13 +1906,22 @@ bool DB2FileLoader::Load(DB2FileSource* source, DB2FileLoadInfo const* loadInfo)
for (uint32 i = 0; i < _header.SectionCount; ++i)
{
DB2SectionHeader const& section = _impl->GetSection(i);
DB2SectionHeader& section = _impl->GetSection(i);
if (section.TactId)
{
_impl->SkipEncryptedSection(i);
idTable.resize(idTable.size() + section.IdTableSize / sizeof(uint32));
continue;
switch (source->HandleEncryptedSection(section))
{
case DB2EncryptedSectionHandling::Skip:
_impl->SkipEncryptedSection(i);
idTable.resize(idTable.size() + section.IdTableSize / sizeof(uint32));
continue;
case DB2EncryptedSectionHandling::Process:
section.TactId = 0;
break;
default:
break;
}
}
if (!source->SetPosition(section.FileOffset))

View File

@@ -90,6 +90,12 @@ struct TC_COMMON_API DB2FileLoadInfo
std::string TypesString;
};
enum class DB2EncryptedSectionHandling
{
Skip,
Process
};
struct TC_COMMON_API DB2FileSource
{
virtual ~DB2FileSource();
@@ -109,6 +115,8 @@ struct TC_COMMON_API DB2FileSource
virtual int64 GetFileSize() const = 0;
virtual char const* GetFileName() const = 0;
virtual DB2EncryptedSectionHandling HandleEncryptedSection(DB2SectionHeader const& sectionHeader) const = 0;
};
class TC_COMMON_API DB2Record

View File

@@ -61,3 +61,8 @@ char const* DB2FileSystemSource::GetFileName() const
{
return _fileName.c_str();
}
DB2EncryptedSectionHandling DB2FileSystemSource::HandleEncryptedSection(DB2SectionHeader const& /*sectionHeader*/) const
{
return DB2EncryptedSectionHandling::Skip;
}

View File

@@ -31,6 +31,7 @@ struct TC_COMMON_API DB2FileSystemSource : public DB2FileSource
bool SetPosition(int64 position) override;
int64 GetFileSize() const override;
char const* GetFileName() const override;
DB2EncryptedSectionHandling HandleEncryptedSection(DB2SectionHeader const& sectionHeader) const override;
private:
std::string _fileName;

View File

@@ -21,6 +21,7 @@
DB2CascFileSource::DB2CascFileSource(std::shared_ptr<CASC::Storage const> storage, uint32 fileDataId, bool printErrors /*= true*/)
{
_storageHandle = storage;
_fileHandle.reset(storage->OpenFile(fileDataId, CASC_LOCALE_NONE, printErrors, true));
_fileName = Trinity::StringFormat("FileDataId: %u", fileDataId);
}
@@ -60,3 +61,11 @@ char const* DB2CascFileSource::GetFileName() const
{
return _fileName.c_str();
}
DB2EncryptedSectionHandling DB2CascFileSource::HandleEncryptedSection(DB2SectionHeader const& sectionHeader) const
{
if (std::shared_ptr<CASC::Storage const> storage = _storageHandle.lock())
return storage->HasTactKey(sectionHeader.TactId) ? DB2EncryptedSectionHandling::Process : DB2EncryptedSectionHandling::Skip;
return DB2EncryptedSectionHandling::Skip;
}

View File

@@ -32,8 +32,10 @@ struct DB2CascFileSource : public DB2FileSource
int64 GetFileSize() const override;
CASC::File* GetNativeHandle() const;
char const* GetFileName() const override;
DB2EncryptedSectionHandling HandleEncryptedSection(DB2SectionHeader const& sectionHeader) const override;
private:
std::weak_ptr<CASC::Storage const> _storageHandle;
std::unique_ptr<CASC::File> _fileHandle;
std::string _fileName;
};