Solution refactoring and restructuring, removed Boost dependency, removed unused tools
This commit is contained in:
1603
src/EterPack/EterPack.cpp
Normal file
1603
src/EterPack/EterPack.cpp
Normal file
File diff suppressed because it is too large
Load Diff
248
src/EterPack/EterPack.h
Normal file
248
src/EterPack/EterPack.h
Normal file
@ -0,0 +1,248 @@
|
||||
#ifndef __INC_ETERPACKLIB_ETERPACK_H__
|
||||
#define __INC_ETERPACKLIB_ETERPACK_H__
|
||||
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../EterBase/MappedFile.h"
|
||||
|
||||
#ifndef MAKEFOURCC
|
||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||
((DWORD)(BYTE) (ch0 ) | ((DWORD)(BYTE) (ch1) << 8) | \
|
||||
((DWORD)(BYTE) (ch2) << 16) | ((DWORD)(BYTE) (ch3) << 24))
|
||||
#endif
|
||||
|
||||
|
||||
//#define CHECKSUM_CHECK_MD5
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
namespace eterpack
|
||||
{
|
||||
const DWORD c_PackCC = MAKEFOURCC('E', 'P', 'K', 'D');
|
||||
const DWORD c_IndexCC = MAKEFOURCC('E', 'P', 'K', 'D');
|
||||
const DWORD c_Version = 2;
|
||||
// FourCC + Version + m_indexCount
|
||||
const DWORD c_HeaderSize = sizeof(DWORD) + sizeof(DWORD) + sizeof(long);
|
||||
};
|
||||
|
||||
enum EEterPackTypes
|
||||
{
|
||||
DBNAME_MAX_LEN = 255,
|
||||
FILENAME_MAX_LEN = 160,
|
||||
FREE_INDEX_BLOCK_SIZE = 32768,
|
||||
FREE_INDEX_MAX_SIZE = 512,
|
||||
DATA_BLOCK_SIZE = 256,
|
||||
|
||||
COMPRESSED_TYPE_NONE = 0,
|
||||
COMPRESSED_TYPE_COMPRESS = 1,
|
||||
COMPRESSED_TYPE_SECURITY = 2,
|
||||
COMPRESSED_TYPE_PANAMA = 3,
|
||||
COMPRESSED_TYPE_HYBRIDCRYPT = 4,
|
||||
COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB = 5,
|
||||
COMPRESSED_TYPE_COUNT = 6,
|
||||
};
|
||||
|
||||
#pragma pack(push, 4)
|
||||
typedef struct SEterPackIndex
|
||||
{
|
||||
long id;
|
||||
char filename[FILENAME_MAX_LEN + 1];
|
||||
DWORD filename_crc;
|
||||
long real_data_size;
|
||||
long data_size;
|
||||
#ifdef CHECKSUM_CHECK_MD5
|
||||
BYTE MD5Digest[16];
|
||||
#else
|
||||
DWORD data_crc;
|
||||
#endif
|
||||
long data_position;
|
||||
char compressed_type;
|
||||
} TEterPackIndex;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef std::unordered_map<DWORD, TEterPackIndex *> TDataPositionMap;
|
||||
typedef std::list<TEterPackIndex *> TFreeIndexList;
|
||||
|
||||
|
||||
class CEterPack;
|
||||
|
||||
class CEterFileDict
|
||||
{
|
||||
public:
|
||||
struct Item
|
||||
{
|
||||
Item() : pkPack(NULL), pkInfo(NULL) {}
|
||||
|
||||
CEterPack* pkPack;
|
||||
TEterPackIndex* pkInfo;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
BUCKET_SIZE = 16,
|
||||
};
|
||||
|
||||
typedef std::unordered_multimap<DWORD, Item> TDict;
|
||||
|
||||
public:
|
||||
void InsertItem(CEterPack* pkPack, TEterPackIndex* pkInfo);
|
||||
void UpdateItem(CEterPack* pkPack, TEterPackIndex* pkInfo);
|
||||
|
||||
Item* GetItem(DWORD dwFileNameHash, const char* c_pszFileName);
|
||||
|
||||
const TDict& GetDict() const
|
||||
{
|
||||
return m_dict;
|
||||
}
|
||||
|
||||
private:
|
||||
TDict m_dict;
|
||||
};
|
||||
|
||||
class EterPackPolicy_CSHybridCrypt;
|
||||
|
||||
class CEterPack
|
||||
{
|
||||
public:
|
||||
CEterPack();
|
||||
virtual ~CEterPack();
|
||||
|
||||
void Destroy();
|
||||
bool Create(CEterFileDict& rkFileDict, const char * dbname, const char * pathName, bool bReadOnly = true, const BYTE* iv = NULL);
|
||||
bool DecryptIV(DWORD dwPanamaKey);
|
||||
|
||||
const std::string& GetPathName();
|
||||
const char * GetDBName();
|
||||
|
||||
//THEMIDA
|
||||
bool Get(CMappedFile & mappedFile, const char * filename, LPCVOID * data);
|
||||
//THEMIDA
|
||||
bool Get2(CMappedFile & mappedFile, const char * filename, TEterPackIndex* index, LPCVOID * data);
|
||||
|
||||
|
||||
//THEMIDA
|
||||
bool Put(const char * filename, const char * sourceFilename, BYTE packType, const std::string& strRelateMapName);
|
||||
//THEMIDA
|
||||
bool Put(const char * filename, LPCVOID data, long len, BYTE packType);
|
||||
|
||||
bool Delete(const char * filename);
|
||||
|
||||
bool Extract();
|
||||
|
||||
long GetFragmentSize();
|
||||
|
||||
bool IsExist(const char * filename);
|
||||
|
||||
TDataPositionMap & GetIndexMap();
|
||||
|
||||
bool EncryptIndexFile();
|
||||
bool DecryptIndexFile();
|
||||
|
||||
DWORD DeleteUnreferencedData(); // <20><EFBFBD><EEB0B3> <20><><EFBFBD><EFBFBD> <20>Ǿ<EFBFBD><C7BE><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ѵ<EFBFBD>.
|
||||
|
||||
bool GetNames(std::vector<std::string>* retNames);
|
||||
|
||||
EterPackPolicy_CSHybridCrypt* GetPackPolicy_HybridCrypt() const;
|
||||
|
||||
private:
|
||||
bool __BuildIndex(CEterFileDict& rkFileDict, bool bOverwirte=false);
|
||||
|
||||
bool CreateIndexFile();
|
||||
TEterPackIndex * FindIndex(const char * filename);
|
||||
long GetNewIndexPosition(CFileBase& file);
|
||||
TEterPackIndex * NewIndex(CFileBase& file, const char * filename, long size);
|
||||
void WriteIndex(CFileBase& file, TEterPackIndex * index);
|
||||
int GetFreeBlockIndex(long size);
|
||||
void PushFreeIndex(TEterPackIndex * index);
|
||||
|
||||
bool CreateDataFile();
|
||||
long GetNewDataPosition(CFileBase& file);
|
||||
bool ReadData(CFileBase& file, TEterPackIndex * index, LPVOID data, long maxsize);
|
||||
bool WriteData(CFileBase& file, TEterPackIndex * index, LPCVOID data);
|
||||
bool WriteNewData(CFileBase& file, TEterPackIndex * index, LPCVOID data);
|
||||
|
||||
bool Delete(TEterPackIndex * pIndex);
|
||||
|
||||
protected:
|
||||
CMappedFile m_file;
|
||||
|
||||
char* m_file_data;
|
||||
unsigned m_file_size;
|
||||
|
||||
long m_indexCount;
|
||||
bool m_bEncrypted;
|
||||
|
||||
char m_dbName[DBNAME_MAX_LEN+1];
|
||||
char m_indexFileName[MAX_PATH+1];
|
||||
TEterPackIndex * m_indexData;
|
||||
long m_FragmentSize;
|
||||
bool m_bReadOnly;
|
||||
bool m_bDecrypedIV;
|
||||
|
||||
std::unordered_map<DWORD, DWORD> m_map_indexRefCount;
|
||||
TDataPositionMap m_DataPositionMap;
|
||||
TFreeIndexList m_FreeIndexList[FREE_INDEX_MAX_SIZE + 1]; // MAX <20><> <20>\<EFBFBD><EFBCBC> <20>ϹǷ<CFB9> + 1 ũ<>⸸ŭ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
|
||||
std::string m_stDataFileName;
|
||||
std::string m_stPathName;
|
||||
|
||||
|
||||
EterPackPolicy_CSHybridCrypt* m_pCSHybridCryptPolicy;
|
||||
|
||||
private:
|
||||
void __CreateFileNameKey_Panama(const char * filename, BYTE * key, unsigned int keySize);
|
||||
bool __Decrypt_Panama(const char* filename, const BYTE* data, SIZE_T dataSize, CLZObject& zObj);
|
||||
bool __Encrypt_Panama(const char* filename, const BYTE* data, SIZE_T dataSize, CLZObject& zObj);
|
||||
std::string m_stIV_Panama;
|
||||
|
||||
//private:
|
||||
// bool m_bIsDataLoaded;
|
||||
// // <20>׳<EFBFBD> time_t<5F><74> <20><><EFBFBD><EFBFBD>, 32bit time_t<5F><74> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
||||
// // CEterPack<63><6B> size<7A><65> <20><><EFBFBD><EFBFBD> size - 4<><34> <20>ν<EFBFBD><CEBD>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD><DFBB><EFBFBD> <20><> <20>ִ<EFBFBD>.
|
||||
// __time64_t m_tLastAccessTime;
|
||||
//public:
|
||||
// __time64_t GetLastAccessTime() { return m_tLastAccessTime; }
|
||||
// void UpdateLastAccessTime();
|
||||
// void ClearDataMemoryMap();
|
||||
|
||||
#ifdef CHECKSUM_CHECK_MD5
|
||||
void GenerateMD5Hash( BYTE* pData, int nLength, IN OUT MD5_CTX& context );
|
||||
#endif
|
||||
};
|
||||
|
||||
class CMakePackLog
|
||||
{
|
||||
public:
|
||||
static CMakePackLog& GetSingleton();
|
||||
|
||||
public:
|
||||
CMakePackLog();
|
||||
~CMakePackLog();
|
||||
|
||||
void SetFileName(const char* c_szFileName);
|
||||
|
||||
void Writef(const char* c_szFormat, ...);
|
||||
void Writenf(const char* c_szFormat, ...);
|
||||
void Write(const char* c_szBuf);
|
||||
|
||||
void WriteErrorf(const char* c_szFormat, ...);
|
||||
void WriteErrornf(const char* c_szFormat, ...);
|
||||
void WriteError(const char* c_szBuf);
|
||||
|
||||
void FlushError();
|
||||
|
||||
private:
|
||||
void __Write(const char* c_szBuf, int nBufLen);
|
||||
void __WriteError(const char* c_szBuf, int nBufLen);
|
||||
bool __IsLogMode();
|
||||
|
||||
private:
|
||||
FILE* m_fp;
|
||||
FILE* m_fp_err;
|
||||
|
||||
std::string m_stFileName;
|
||||
std::string m_stErrorFileName;
|
||||
};
|
||||
|
||||
#endif
|
380
src/EterPack/EterPack.vcxproj
Normal file
380
src/EterPack/EterPack.vcxproj
Normal file
@ -0,0 +1,380 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Distribute|Win32">
|
||||
<Configuration>Distribute</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="MfcDebug|Win32">
|
||||
<Configuration>MfcDebug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="MfcRelease|Win32">
|
||||
<Configuration>MfcRelease</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="VTune|Win32">
|
||||
<Configuration>VTune</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<ProjectName>EterPack</ProjectName>
|
||||
<ProjectGuid>{4950BA04-3877-4F66-BCA0-60E00DE3770B}</ProjectGuid>
|
||||
<RootNamespace>EterPack</RootNamespace>
|
||||
<SccProjectName>Perforce Project</SccProjectName>
|
||||
<SccLocalPath>.</SccLocalPath>
|
||||
<SccProvider>MSSCCI:Perforce SCM</SccProvider>
|
||||
<Keyword>MFCProj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>17.0.32203.90</_ProjectFileVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
|
||||
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">
|
||||
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
|
||||
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">
|
||||
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<VcpkgUseStatic>true</VcpkgUseStatic>
|
||||
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
|
||||
<VcpkgUseStatic>true</VcpkgUseStatic>
|
||||
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<VcpkgUseStatic>true</VcpkgUseStatic>
|
||||
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<PrecompiledHeaderOutputFile>.\Distribute/EterPack.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerOutput>All</AssemblerOutput>
|
||||
<AssemblerListingLocation>.\Distribute/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\Distribute/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\Distribute/</ProgramDataBaseFileName>
|
||||
<BrowseInformation />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)Extern\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
||||
<PrecompiledHeader />
|
||||
<PrecompiledHeaderOutputFile>.\MfcRelease/EterPack.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerOutput>All</AssemblerOutput>
|
||||
<AssemblerListingLocation>.\MfcRelease/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\MfcRelease/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\MfcRelease/</ProgramDataBaseFileName>
|
||||
<BrowseInformation />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<OutputFile>.\MfcRelease\EterPack.lib</OutputFile>
|
||||
<AdditionalLibraryDirectories>../../extern/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalOptions>/Gs %(AdditionalOptions)</AdditionalOptions>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<PrecompiledHeaderOutputFile>.\VTune/EterPack.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerOutput>All</AssemblerOutput>
|
||||
<AssemblerListingLocation>.\VTune/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\VTune/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\VTune/</ProgramDataBaseFileName>
|
||||
<BrowseInformation />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<CompileAs>Default</CompileAs>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<OutputFile>.\VTune\EterPack.lib</OutputFile>
|
||||
<AdditionalLibraryDirectories>../../extern/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
||||
<PrecompiledHeader />
|
||||
<PrecompiledHeaderOutputFile>.\MfcDebug/EterPack.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>.\MfcDebug/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\MfcDebug/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\MfcDebug/</ProgramDataBaseFileName>
|
||||
<BrowseInformation />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<OutputFile>.\MfcDebug\EterPack.lib</OutputFile>
|
||||
<AdditionalLibraryDirectories>../../extern/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<PrecompiledHeaderOutputFile>.\Release/EterPack.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>.\Release/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\Release/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\Release/</ProgramDataBaseFileName>
|
||||
<BrowseInformation />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>../../extern/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeader />
|
||||
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>.\Debug/EterPack.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\Debug/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
|
||||
<BrowseInformation />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
<IgnoreStandardIncludePath>true</IgnoreStandardIncludePath>
|
||||
</ResourceCompile>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>../../extern/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EterPack.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EterPackCursor.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EterPackManager.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EterPackPolicy_CSHybridCrypt.cpp" />
|
||||
<ClCompile Include="md5.c" />
|
||||
<ClCompile Include="StdAfx.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="EterPack.h" />
|
||||
<ClInclude Include="EterPackCursor.h" />
|
||||
<ClInclude Include="EterPackManager.h" />
|
||||
<ClInclude Include="EterPackPolicy_CSHybridCrypt.h" />
|
||||
<ClInclude Include="Inline.h" />
|
||||
<ClInclude Include="md5.h" />
|
||||
<ClInclude Include="StdAfx.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
56
src/EterPack/EterPack.vcxproj.filters
Normal file
56
src/EterPack/EterPack.vcxproj.filters
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{28cbe5da-8a6f-41ba-81a5-785c7db06420}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{c156ef19-8b61-496c-a499-8bf66e9ca80d}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EterPack.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EterPackCursor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EterPackManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EterPackPolicy_CSHybridCrypt.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="md5.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StdAfx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="EterPack.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EterPackCursor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EterPackManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EterPackPolicy_CSHybridCrypt.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inline.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="md5.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
59
src/EterPack/EterPackCursor.cpp
Normal file
59
src/EterPack/EterPackCursor.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPackCursor.h"
|
||||
#include "Inline.h"
|
||||
|
||||
CEterPackCursor::CEterPackCursor(CEterPack* pack) : m_pPack(pack), m_pData(NULL), m_ReadPoint(0)
|
||||
{
|
||||
}
|
||||
|
||||
CEterPackCursor::~CEterPackCursor()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
bool CEterPackCursor::Open(const char* filename)
|
||||
{
|
||||
assert(m_pPack != NULL);
|
||||
|
||||
char tmpFilename[MAX_PATH + 1];
|
||||
strncpy(tmpFilename, filename, MAX_PATH);
|
||||
inlineConvertPackFilename(tmpFilename);
|
||||
|
||||
if (!m_pPack->Get(m_file, tmpFilename, &m_pData))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEterPackCursor::Close()
|
||||
{
|
||||
m_file.Destroy();
|
||||
m_pData = NULL;
|
||||
m_ReadPoint = 0;
|
||||
}
|
||||
|
||||
void CEterPackCursor::Seek(long offset)
|
||||
{
|
||||
m_ReadPoint = max(0, min(Size(), offset));
|
||||
}
|
||||
|
||||
bool CEterPackCursor::Read(LPVOID data, long size)
|
||||
{
|
||||
if (m_file.IsNull())
|
||||
return false;
|
||||
|
||||
if (m_ReadPoint + size > Size())
|
||||
return false;
|
||||
|
||||
memcpy(data, (char*) m_pData + m_ReadPoint, size);
|
||||
m_ReadPoint += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
long CEterPackCursor::Size()
|
||||
{
|
||||
if (m_file.IsNull())
|
||||
return 0;
|
||||
|
||||
return m_file.Size();
|
||||
}
|
25
src/EterPack/EterPackCursor.h
Normal file
25
src/EterPack/EterPackCursor.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __INC_ETERPACKCURSOR_H__
|
||||
#define __INC_ETERPACKCURSOR_H__
|
||||
|
||||
#include "EterPack.h"
|
||||
|
||||
class CEterPackCursor
|
||||
{
|
||||
public:
|
||||
CEterPackCursor(CEterPack * pack);
|
||||
~CEterPackCursor();
|
||||
|
||||
bool Open(const char* filename);
|
||||
void Close();
|
||||
void Seek(long offset);
|
||||
bool Read(LPVOID data, long size);
|
||||
long Size();
|
||||
|
||||
private:
|
||||
CEterPack * m_pPack;
|
||||
CMappedFile m_file;
|
||||
LPCVOID m_pData;
|
||||
long m_ReadPoint;
|
||||
};
|
||||
|
||||
#endif
|
618
src/EterPack/EterPackManager.cpp
Normal file
618
src/EterPack/EterPackManager.cpp
Normal file
@ -0,0 +1,618 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <io.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "EterPackManager.h"
|
||||
#include "EterPackPolicy_CSHybridCrypt.h"
|
||||
|
||||
#include "../eterBase/Debug.h"
|
||||
#include "../eterBase/CRC32.h"
|
||||
|
||||
#define PATH_ABSOLUTE_YMIRWORK1 "d:/ymir work/"
|
||||
#define PATH_ABSOLUTE_YMIRWORK2 "d:\\ymir work\\"
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
#include <ThemidaSDK.h>
|
||||
#endif
|
||||
|
||||
|
||||
CEterPack* CEterPackManager::FindPack(const char* c_szPathName)
|
||||
{
|
||||
std::string strFileName;
|
||||
|
||||
if (0 == ConvertFileName(c_szPathName, strFileName))
|
||||
{
|
||||
return &m_RootPack;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (TEterPackMap::iterator itor = m_DirPackMap.begin(); itor != m_DirPackMap.end(); ++itor)
|
||||
{
|
||||
const std::string & c_rstrName = itor->first;
|
||||
CEterPack * pEterPack = itor->second;
|
||||
|
||||
if (CompareName(c_rstrName.c_str(), c_rstrName.length(), strFileName.c_str()))
|
||||
{
|
||||
return pEterPack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEterPackManager::SetCacheMode()
|
||||
{
|
||||
m_isCacheMode=true;
|
||||
}
|
||||
|
||||
void CEterPackManager::SetRelativePathMode()
|
||||
{
|
||||
m_bTryRelativePath = true;
|
||||
}
|
||||
|
||||
|
||||
// StringPath std::string <20><><EFBFBD><EFBFBD>
|
||||
int CEterPackManager::ConvertFileName(const char * c_szFileName, std::string & rstrFileName)
|
||||
{
|
||||
rstrFileName = c_szFileName;
|
||||
stl_lowers(rstrFileName);
|
||||
|
||||
int iCount = 0;
|
||||
|
||||
for (DWORD i = 0; i < rstrFileName.length(); ++i)
|
||||
{
|
||||
if (rstrFileName[i] == '/')
|
||||
++iCount;
|
||||
else if (rstrFileName[i] == '\\')
|
||||
{
|
||||
rstrFileName[i] = '/';
|
||||
++iCount;
|
||||
}
|
||||
}
|
||||
|
||||
return iCount;
|
||||
}
|
||||
|
||||
bool CEterPackManager::CompareName(const char * c_szDirectoryName, DWORD /*dwLength*/, const char * c_szFileName)
|
||||
{
|
||||
const char * c_pszSrc = c_szDirectoryName;
|
||||
const char * c_pszCmp = c_szFileName;
|
||||
|
||||
while (*c_pszSrc)
|
||||
{
|
||||
if (*(c_pszSrc++) != *(c_pszCmp++))
|
||||
return false;
|
||||
|
||||
if (!*c_pszCmp)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEterPackManager::LoadStaticCache(const char* c_szFileName)
|
||||
{
|
||||
if (!m_isCacheMode)
|
||||
return;
|
||||
|
||||
std::string strFileName;
|
||||
if (0 == ConvertFileName(c_szFileName, strFileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length());
|
||||
|
||||
std::unordered_map<DWORD, SCache>::iterator f = m_kMap_dwNameKey_kCache.find(dwFileNameHash);
|
||||
if (m_kMap_dwNameKey_kCache.end() != f)
|
||||
return;
|
||||
|
||||
CMappedFile kMapFile;
|
||||
const void* c_pvData;
|
||||
if (!Get(kMapFile, c_szFileName, &c_pvData))
|
||||
return;
|
||||
|
||||
SCache kNewCache;
|
||||
kNewCache.m_dwBufSize = kMapFile.Size();
|
||||
kNewCache.m_abBufData = new BYTE[kNewCache.m_dwBufSize];
|
||||
memcpy(kNewCache.m_abBufData, c_pvData, kNewCache.m_dwBufSize);
|
||||
m_kMap_dwNameKey_kCache.insert(std::unordered_map<DWORD, SCache>::value_type(dwFileNameHash, kNewCache));
|
||||
}
|
||||
|
||||
CEterPackManager::SCache* CEterPackManager::__FindCache(DWORD dwFileNameHash)
|
||||
{
|
||||
std::unordered_map<DWORD, SCache>::iterator f=m_kMap_dwNameKey_kCache.find(dwFileNameHash);
|
||||
if (m_kMap_dwNameKey_kCache.end()==f)
|
||||
return NULL;
|
||||
|
||||
return &f->second;
|
||||
}
|
||||
|
||||
void CEterPackManager::__ClearCacheMap()
|
||||
{
|
||||
std::unordered_map<DWORD, SCache>::iterator i;
|
||||
|
||||
for (i = m_kMap_dwNameKey_kCache.begin(); i != m_kMap_dwNameKey_kCache.end(); ++i)
|
||||
delete [] i->second.m_abBufData;
|
||||
|
||||
m_kMap_dwNameKey_kCache.clear();
|
||||
}
|
||||
|
||||
struct TimeChecker
|
||||
{
|
||||
TimeChecker(const char* name) : name(name)
|
||||
{
|
||||
baseTime = timeGetTime();
|
||||
}
|
||||
~TimeChecker()
|
||||
{
|
||||
printf("load %s (%d)\n", name, timeGetTime() - baseTime);
|
||||
}
|
||||
|
||||
const char* name;
|
||||
DWORD baseTime;
|
||||
};
|
||||
|
||||
bool CEterPackManager::Get(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
|
||||
{
|
||||
//TimeChecker timeChecker(c_szFileName);
|
||||
//Logf(1, "Load %s\n", c_szFileName);
|
||||
|
||||
if (m_iSearchMode == SEARCH_FILE_FIRST)
|
||||
{
|
||||
if (GetFromFile(rMappedFile, c_szFileName, pData))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetFromPack(rMappedFile, c_szFileName, pData);
|
||||
}
|
||||
|
||||
if (GetFromPack(rMappedFile, c_szFileName, pData))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetFromFile(rMappedFile, c_szFileName, pData);
|
||||
}
|
||||
|
||||
struct FinderLock
|
||||
{
|
||||
FinderLock(CRITICAL_SECTION& cs) : p_cs(&cs)
|
||||
{
|
||||
EnterCriticalSection(p_cs);
|
||||
}
|
||||
|
||||
~FinderLock()
|
||||
{
|
||||
LeaveCriticalSection(p_cs);
|
||||
}
|
||||
|
||||
CRITICAL_SECTION* p_cs;
|
||||
};
|
||||
|
||||
bool CEterPackManager::GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
|
||||
{
|
||||
FinderLock lock(m_csFinder);
|
||||
|
||||
static std::string strFileName;
|
||||
|
||||
if (0 == ConvertFileName(c_szFileName, strFileName))
|
||||
{
|
||||
return m_RootPack.Get(rMappedFile, strFileName.c_str(), pData);
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length());
|
||||
SCache* pkCache = __FindCache(dwFileNameHash);
|
||||
|
||||
if (pkCache)
|
||||
{
|
||||
rMappedFile.Link(pkCache->m_dwBufSize, pkCache->m_abBufData);
|
||||
return true;
|
||||
}
|
||||
|
||||
CEterFileDict::Item* pkFileItem = m_FileDict.GetItem(dwFileNameHash, strFileName.c_str());
|
||||
|
||||
if (pkFileItem)
|
||||
if (pkFileItem->pkPack)
|
||||
{
|
||||
bool r = pkFileItem->pkPack->Get2(rMappedFile, strFileName.c_str(), pkFileItem->pkInfo, pData);
|
||||
//pkFileItem->pkPack->ClearDataMemoryMap();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
TraceError("CANNOT_FIND_PACK_FILE [%s]", strFileName.c_str());
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const time_t g_tCachingInterval = 10; // 10<31><30>
|
||||
void CEterPackManager::ArrangeMemoryMappedPack()
|
||||
{
|
||||
//time_t curTime = time(NULL);
|
||||
//CEterFileDict::TDict dict = m_FileDict.GetDict();
|
||||
//for (CEterFileDict::TDict::iterator it = dict.begin(); it != dict.end(); ++it)
|
||||
//{
|
||||
// CEterFileDict::Item &rFileItem = it->second;
|
||||
// CEterPack* pkPack = rFileItem.pkPack;
|
||||
// if (pkPack)
|
||||
// {
|
||||
// if (curTime - pkPack->GetLastAccessTime() > g_tCachingInterval)
|
||||
// {
|
||||
// pkPack->ClearDataMemoryMap();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
bool CEterPackManager::GetFromFile(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
|
||||
{
|
||||
#ifndef _DEBUG
|
||||
//const char *pcExt = strchr(c_szFileName, '.');
|
||||
//if (pcExt &&
|
||||
// _strnicmp(pcExt, ".py", 3) == 0 && // python <20><>ũ<EFBFBD><C5A9>Ʈ <20><>
|
||||
// stricmp(c_szFileName, "logininfo.py") != 0 && // <20>α<EFBFBD><CEB1><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴϰ<C6B4>
|
||||
// strnicmp(c_szFileName, "locale", 6) != 0
|
||||
// )
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
#endif
|
||||
|
||||
//if(m_bTryRelativePath) {
|
||||
// if (strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK1, strlen(PATH_ABSOLUTE_YMIRWORK1)) == 0 || strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK2, strlen(PATH_ABSOLUTE_YMIRWORK2)) == 0) {
|
||||
// if(rMappedFile.Create(c_szFileName+strlen(PATH_ABSOLUTE_YMIRWORK1), pData, 0, 0))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
return rMappedFile.Create(c_szFileName, pData, 0, 0) ? true : false;
|
||||
}
|
||||
|
||||
bool CEterPackManager::isExistInPack(const char * c_szFileName)
|
||||
{
|
||||
std::string strFileName;
|
||||
|
||||
if (0 == ConvertFileName(c_szFileName, strFileName))
|
||||
{
|
||||
return m_RootPack.IsExist(strFileName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length());
|
||||
CEterFileDict::Item* pkFileItem = m_FileDict.GetItem(dwFileNameHash, strFileName.c_str());
|
||||
|
||||
if (pkFileItem)
|
||||
if (pkFileItem->pkPack)
|
||||
return pkFileItem->pkPack->IsExist(strFileName.c_str());
|
||||
}
|
||||
|
||||
// NOTE : <20><>ġ <20>Ǵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ٸ<EFBFBD> false - [levites]
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEterPackManager::isExist(const char * c_szFileName)
|
||||
{
|
||||
if (m_iSearchMode == SEARCH_PACK_FIRST)
|
||||
{
|
||||
if (isExistInPack(c_szFileName))
|
||||
return true;
|
||||
|
||||
return _access(c_szFileName, 0) == 0 ? true : false;
|
||||
}
|
||||
|
||||
//if(m_bTryRelativePath) {
|
||||
// if (strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK1, strlen(PATH_ABSOLUTE_YMIRWORK1)) == 0 || strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK2, strlen(PATH_ABSOLUTE_YMIRWORK2)) == 0) {
|
||||
// if(access(c_szFileName+strlen(PATH_ABSOLUTE_YMIRWORK1), 0) == 0)
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (_access(c_szFileName, 0) == 0)
|
||||
return true;
|
||||
|
||||
return isExistInPack(c_szFileName);
|
||||
}
|
||||
|
||||
|
||||
void CEterPackManager::RegisterRootPack(const char * c_szName)
|
||||
{
|
||||
if (!m_RootPack.Create(m_FileDict, c_szName, ""))
|
||||
{
|
||||
TraceError("%s: Pack file does not exist", c_szName);
|
||||
}
|
||||
}
|
||||
|
||||
const char * CEterPackManager::GetRootPackFileName()
|
||||
{
|
||||
return m_RootPack.GetDBName();
|
||||
}
|
||||
|
||||
bool CEterPackManager::DecryptPackIV(DWORD dwPanamaKey)
|
||||
{
|
||||
TEterPackMap::iterator itor = m_PackMap.begin();
|
||||
while (itor != m_PackMap.end())
|
||||
{
|
||||
itor->second->DecryptIV(dwPanamaKey);
|
||||
itor++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEterPackManager::RegisterPackWhenPackMaking(const char * c_szName, const char * c_szDirectory, CEterPack* pPack)
|
||||
{
|
||||
m_PackMap.insert(TEterPackMap::value_type(c_szName, pPack));
|
||||
m_PackList.push_front(pPack);
|
||||
|
||||
m_DirPackMap.insert(TEterPackMap::value_type(c_szDirectory, pPack));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CEterPackManager::RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV)
|
||||
{
|
||||
CEterPack * pEterPack = NULL;
|
||||
{
|
||||
TEterPackMap::iterator itor = m_PackMap.find(c_szName);
|
||||
|
||||
if (m_PackMap.end() == itor)
|
||||
{
|
||||
bool bReadOnly = true;
|
||||
|
||||
pEterPack = new CEterPack;
|
||||
if (pEterPack->Create(m_FileDict, c_szName, c_szDirectory, bReadOnly, c_pbIV))
|
||||
{
|
||||
m_PackMap.insert(TEterPackMap::value_type(c_szName, pEterPack));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
Tracef("The eterpack doesn't exist [%s]\n", c_szName);
|
||||
#endif
|
||||
delete pEterPack;
|
||||
pEterPack = NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pEterPack = itor->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (c_szDirectory && c_szDirectory[0] != '*')
|
||||
{
|
||||
TEterPackMap::iterator itor = m_DirPackMap.find(c_szDirectory);
|
||||
if (m_DirPackMap.end() == itor)
|
||||
{
|
||||
m_PackList.push_front(pEterPack);
|
||||
m_DirPackMap.insert(TEterPackMap::value_type(c_szDirectory, pEterPack));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEterPackManager::SetSearchMode(bool bPackFirst)
|
||||
{
|
||||
m_iSearchMode = bPackFirst ? SEARCH_PACK_FIRST : SEARCH_FILE_FIRST;
|
||||
}
|
||||
|
||||
int CEterPackManager::GetSearchMode()
|
||||
{
|
||||
return m_iSearchMode;
|
||||
}
|
||||
|
||||
CEterPackManager::CEterPackManager() : m_bTryRelativePath(false), m_iSearchMode(SEARCH_FILE_FIRST), m_isCacheMode(false)
|
||||
{
|
||||
InitializeCriticalSection(&m_csFinder);
|
||||
}
|
||||
|
||||
CEterPackManager::~CEterPackManager()
|
||||
{
|
||||
__ClearCacheMap();
|
||||
|
||||
TEterPackMap::iterator i = m_PackMap.begin();
|
||||
TEterPackMap::iterator e = m_PackMap.end();
|
||||
while (i != e)
|
||||
{
|
||||
delete i->second;
|
||||
i++;
|
||||
}
|
||||
DeleteCriticalSection(&m_csFinder);
|
||||
}
|
||||
|
||||
void CEterPackManager::RetrieveHybridCryptPackKeys(const BYTE *pStream)
|
||||
{
|
||||
////dump file format
|
||||
//total packagecnt (4byte)
|
||||
// for packagecntpackage
|
||||
// db name hash ( stl.h stringhash )
|
||||
// extension cnt( 4byte)
|
||||
// for extension cnt
|
||||
// ext hash ( stl.h stringhash )
|
||||
// key-16byte
|
||||
// iv-16byte
|
||||
int iMemOffset = 0;
|
||||
|
||||
int iPackageCnt;
|
||||
DWORD dwPackageNameHash;
|
||||
|
||||
memcpy( &iPackageCnt, pStream + iMemOffset, sizeof(int) );
|
||||
iMemOffset += sizeof(iPackageCnt);
|
||||
|
||||
for( int i = 0; i < iPackageCnt; ++i )
|
||||
{
|
||||
int iRecvedCryptKeySize = 0;
|
||||
memcpy( &iRecvedCryptKeySize, pStream + iMemOffset, sizeof(iRecvedCryptKeySize) );
|
||||
iRecvedCryptKeySize -= sizeof(dwPackageNameHash); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> key stream<61><6D><EFBFBD><EFBFBD> filename hash<73><68> <20><><EFBFBD>ԵǾ<D4B5> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>, hash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ŭ <20><><EFBFBD><EFBFBD>.
|
||||
iMemOffset += sizeof(iRecvedCryptKeySize);
|
||||
|
||||
memcpy( &dwPackageNameHash, pStream + iMemOffset, sizeof(dwPackageNameHash) );
|
||||
iMemOffset += sizeof(dwPackageNameHash);
|
||||
|
||||
TEterPackMap::const_iterator cit;
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
|
||||
if( dwPackageNameHash == stringhash().GetHash(noPathName) )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pCryptPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
int iHavedCryptKeySize = pCryptPolicy->ReadCryptKeyInfoFromStream( pStream + iMemOffset );
|
||||
if (iRecvedCryptKeySize != iHavedCryptKeySize)
|
||||
{
|
||||
TraceError("CEterPackManager::RetrieveHybridCryptPackKeys cryptokey length of file(%s) is not matched. received(%d) != haved(%d)", noPathName.c_str(), iRecvedCryptKeySize, iHavedCryptKeySize);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
iMemOffset += iRecvedCryptKeySize;
|
||||
}
|
||||
}
|
||||
|
||||
void CEterPackManager::RetrieveHybridCryptPackSDB( const BYTE* pStream )
|
||||
{
|
||||
//cnt
|
||||
//for cnt
|
||||
//DWORD dwPackageIdentifier;
|
||||
//DWORD dwFileIdentifier;
|
||||
//std::vector<BYTE> vecSDBStream;
|
||||
int iReadOffset = 0;
|
||||
int iSDBInfoCount = 0;
|
||||
|
||||
memcpy( &iSDBInfoCount, pStream+iReadOffset, sizeof(int) );
|
||||
iReadOffset += sizeof(int);
|
||||
|
||||
for( int i = 0; i < iSDBInfoCount; ++i )
|
||||
{
|
||||
DWORD dwPackgeIdentifier;
|
||||
memcpy( &dwPackgeIdentifier, pStream+iReadOffset, sizeof(DWORD) );
|
||||
iReadOffset += sizeof(DWORD);
|
||||
|
||||
TEterPackMap::const_iterator cit;
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
|
||||
if( dwPackgeIdentifier == stringhash().GetHash(noPathName) )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pCryptPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
iReadOffset += pCryptPolicy->ReadSupplementatyDataBlockFromStream( pStream+iReadOffset );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CEterPackManager::WriteHybridCryptPackInfo(const char* pFileName)
|
||||
{
|
||||
//NOTE : this file format contains a little bit of redundant data.
|
||||
//however it`s better for seperating cryptkey & supplementary data block.
|
||||
|
||||
//dump file format
|
||||
|
||||
//SDB data offset(4)
|
||||
|
||||
// about cryptkey
|
||||
//total packagecnt (4byte)
|
||||
// for packagecnt
|
||||
// db name hash 4byte( stl.h stringhash )
|
||||
// extension cnt( 4byte)
|
||||
// for extension cnt
|
||||
// ext hash ( stl.h stringhash )
|
||||
// key-16byte
|
||||
// iv-16byte
|
||||
|
||||
//about SDB data
|
||||
//total packagecnt (4byte)
|
||||
// for packagecnt
|
||||
// db name hash 4byte( stl.h stringhash ) +child node size(4byte)
|
||||
// sdb file cnt( 4byte )
|
||||
// for sdb file cnt
|
||||
// filename hash ( stl.h stringhash )
|
||||
// related map name size(4), relate map name
|
||||
// sdb block size( 1byte )
|
||||
// sdb blocks
|
||||
|
||||
CFileBase keyFile;
|
||||
|
||||
if( !keyFile.Create( pFileName, CFileBase::FILEMODE_WRITE) )
|
||||
{
|
||||
//TODO : write log
|
||||
return;
|
||||
}
|
||||
|
||||
int iKeyPackageCount = 0;
|
||||
|
||||
//write later ( SDB Offset & PackageCnt for Key )
|
||||
keyFile.SeekCur(2*sizeof(int));
|
||||
|
||||
TEterPackMap::const_iterator cit;
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
if( !pPolicy || !pPolicy->IsContainingCryptKey() )
|
||||
continue;
|
||||
|
||||
iKeyPackageCount++;
|
||||
|
||||
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
|
||||
|
||||
DWORD dwPackNamehash = stringhash().GetHash(noPathName);
|
||||
|
||||
CMakePackLog::GetSingleton().Writef("CEterPackManager::WriteHybridCryptPackInfo PackName : %s, Hash : %x", noPathName.c_str(), dwPackNamehash);
|
||||
keyFile.Write( &dwPackNamehash, sizeof(DWORD) );
|
||||
|
||||
pPolicy->WriteCryptKeyToFile( keyFile );
|
||||
}
|
||||
|
||||
//Write SDB Data
|
||||
int iSDBDataOffset = keyFile.GetPosition();
|
||||
int iSDBPackageCnt = 0;
|
||||
|
||||
//Write SDB PackageCnt Later
|
||||
keyFile.SeekCur(sizeof(int));
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
if( !pPolicy || !pPolicy->IsContainingSDBFile() )
|
||||
continue;
|
||||
|
||||
iSDBPackageCnt++;
|
||||
|
||||
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
|
||||
|
||||
DWORD dwPackNamehash = stringhash().GetHash(noPathName);
|
||||
keyFile.Write( &dwPackNamehash, sizeof(DWORD) );
|
||||
|
||||
int iSDBSizeWriteOffset = keyFile.GetPosition();
|
||||
keyFile.SeekCur(sizeof(int));
|
||||
|
||||
pPolicy->WriteSupplementaryDataBlockToFile( keyFile );
|
||||
int iSDBSizeAfterWrite = keyFile.GetPosition();
|
||||
|
||||
keyFile.Seek(iSDBSizeWriteOffset);
|
||||
|
||||
int iSDBSize = iSDBSizeAfterWrite-(iSDBSizeWriteOffset+4);
|
||||
keyFile.Write( &iSDBSize, sizeof(int) );
|
||||
|
||||
keyFile.Seek(iSDBSizeAfterWrite);
|
||||
}
|
||||
|
||||
//write sdb data start offset & package cnt
|
||||
keyFile.Seek(0);
|
||||
keyFile.Write( &iSDBDataOffset, sizeof(int));
|
||||
keyFile.Write( &iKeyPackageCount, sizeof(int));
|
||||
|
||||
keyFile.Seek(iSDBDataOffset);
|
||||
keyFile.Write( &iSDBPackageCnt, sizeof(int));
|
||||
|
||||
keyFile.Close();
|
||||
}
|
96
src/EterPack/EterPackManager.h
Normal file
96
src/EterPack/EterPackManager.h
Normal file
@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <unordered_map>
|
||||
#include "../eterBase/Singleton.h"
|
||||
#include "../eterBase/Stl.h"
|
||||
|
||||
#include "EterPack.h"
|
||||
|
||||
class CEterPackManager : public CSingleton<CEterPackManager>
|
||||
{
|
||||
public:
|
||||
struct SCache
|
||||
{
|
||||
BYTE* m_abBufData;
|
||||
DWORD m_dwBufSize;
|
||||
};
|
||||
public:
|
||||
enum ESearchModes
|
||||
{
|
||||
SEARCH_FILE_FIRST,
|
||||
SEARCH_PACK_FIRST
|
||||
};
|
||||
|
||||
typedef std::list<CEterPack*> TEterPackList;
|
||||
typedef std::unordered_map<std::string, CEterPack*, stringhash> TEterPackMap;
|
||||
|
||||
public:
|
||||
CEterPackManager();
|
||||
virtual ~CEterPackManager();
|
||||
|
||||
void SetCacheMode();
|
||||
void SetRelativePathMode();
|
||||
|
||||
void LoadStaticCache(const char* c_szFileName);
|
||||
|
||||
void SetSearchMode(bool bPackFirst);
|
||||
int GetSearchMode();
|
||||
|
||||
//THEMIDA
|
||||
bool Get(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
|
||||
|
||||
//THEMIDA
|
||||
bool GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
|
||||
|
||||
//THEMIDA
|
||||
bool GetFromFile(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
|
||||
bool isExist(const char * c_szFileName);
|
||||
bool isExistInPack(const char * c_szFileName);
|
||||
|
||||
bool RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV = NULL);
|
||||
void RegisterRootPack(const char * c_szName);
|
||||
bool RegisterPackWhenPackMaking(const char * c_szName, const char * c_szDirectory, CEterPack* pPack);
|
||||
|
||||
|
||||
bool DecryptPackIV(DWORD key);
|
||||
|
||||
const char * GetRootPackFileName();
|
||||
|
||||
//for hybridcrypt
|
||||
//THEMIDA
|
||||
void WriteHybridCryptPackInfo(const char* pFileName);
|
||||
|
||||
//THEMIDA
|
||||
void RetrieveHybridCryptPackKeys( const BYTE* pStream );
|
||||
//THEMIDA
|
||||
void RetrieveHybridCryptPackSDB( const BYTE* pStream );
|
||||
|
||||
// <20><DEB8> <20><><EFBFBD>ε<EFBFBD> <20>ѵ<EFBFBD> <20><><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD> <20>͵<EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
public:
|
||||
void ArrangeMemoryMappedPack();
|
||||
|
||||
protected:
|
||||
int ConvertFileName(const char * c_szFileName, std::string & rstrFileName); // StringPath std::string <20><><EFBFBD><EFBFBD>
|
||||
bool CompareName(const char * c_szDirectoryName, DWORD iLength, const char * c_szFileName);
|
||||
|
||||
CEterPack* FindPack(const char* c_szPathName);
|
||||
|
||||
SCache* __FindCache(DWORD dwFileNameHash);
|
||||
void __ClearCacheMap();
|
||||
|
||||
protected:
|
||||
bool m_bTryRelativePath;
|
||||
bool m_isCacheMode;
|
||||
int m_iSearchMode;
|
||||
|
||||
CEterFileDict m_FileDict;
|
||||
CEterPack m_RootPack;
|
||||
TEterPackList m_PackList;
|
||||
TEterPackMap m_PackMap;
|
||||
TEterPackMap m_DirPackMap;
|
||||
|
||||
std::unordered_map<DWORD, SCache> m_kMap_dwNameKey_kCache;
|
||||
|
||||
CRITICAL_SECTION m_csFinder;
|
||||
};
|
503
src/EterPack/EterPackPolicy_CSHybridCrypt.cpp
Normal file
503
src/EterPack/EterPackPolicy_CSHybridCrypt.cpp
Normal file
@ -0,0 +1,503 @@
|
||||
#include "Stdafx.h"
|
||||
#include "EterPackPolicy_CSHybridCrypt.h"
|
||||
#include "../EterBase/Stl.h"
|
||||
#include "../EterBase/FileName.h"
|
||||
#include "../EterBase/FileBase.h"
|
||||
#include "../EterBase/Crc32.h"
|
||||
#include "../EterBase/lzo.h"
|
||||
#include "../EterBase/Random.h"
|
||||
#include <cryptopp/modes.h>
|
||||
#include <cryptopp/osrng.h>
|
||||
|
||||
using namespace CryptoPP;
|
||||
|
||||
#define CIPHER_MODE CTR_Mode
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
#include <ThemidaSDK.h>
|
||||
#endif
|
||||
//Cipher
|
||||
//Block Size
|
||||
//Key Length
|
||||
//
|
||||
//Default Minimum Maximum
|
||||
//AES(Rijndael) 16 16 16 32
|
||||
//Blowfish 8 16 0 56
|
||||
//Camellia 16 16 16 32
|
||||
//CAST-128 8 16 5 16
|
||||
//CAST-256 16 16 16 32
|
||||
//DES 8 8 8 8
|
||||
//DES-EDE2 8 16 16 16
|
||||
//DES-EDE3 8 24 24 24
|
||||
//DES-XEX3 8 24 24 24
|
||||
//GOST 8 32 32 32
|
||||
//IDEA 8 16 16 16
|
||||
//MARS 16 16 16 56
|
||||
//RC2 8 16 1 128
|
||||
//RC5 8 16 0 255
|
||||
//RC6 16 16 0 255
|
||||
//SAFER-K 8 16 8 16
|
||||
//SAFER-SK 8 16 8 16
|
||||
//Serpent 16 16 1 32
|
||||
//SHACAL-2 32 16 1 64
|
||||
//SHARK-E 8 16 1 16
|
||||
//SKIPJACK 8 10 1 10
|
||||
//3-Way 12 12 1 12
|
||||
//Twofish 16 16 0 32
|
||||
//XTEA 8 16 1 16
|
||||
|
||||
inline std::string GetFileExt( std::string& rfileName )
|
||||
{
|
||||
stl_lowers(rfileName);
|
||||
return CFileNameHelper::GetExtension(rfileName);
|
||||
}
|
||||
|
||||
EterPackPolicy_CSHybridCrypt::~EterPackPolicy_CSHybridCrypt()
|
||||
{
|
||||
m_mapHybridCryptKey.clear();
|
||||
m_mapSDBMap.clear();
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::IsContainingCryptKey() const
|
||||
{
|
||||
return (m_mapHybridCryptKey.size() > 0) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GenerateCryptKey( std::string& rfileName )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
//make lower & extract ext
|
||||
std::string extName = GetFileExt(rfileName);
|
||||
stl_lowers(extName);
|
||||
|
||||
DWORD dwExtHash = stringhash().GetHash(extName);
|
||||
|
||||
TCSHybridCryptKeyMap::const_iterator cit = m_mapHybridCryptKey.find( dwExtHash );
|
||||
|
||||
if( cit != m_mapHybridCryptKey.end() )
|
||||
{
|
||||
//TODO : log already registered
|
||||
return false;
|
||||
}
|
||||
|
||||
static AutoSeededRandomPool rnd;
|
||||
|
||||
TCSHybridCryptKey info;
|
||||
{
|
||||
rnd.GenerateBlock( &(info.uEncryptKey.key[0]), sizeof(info.uEncryptKey) );
|
||||
rnd.GenerateBlock( &(info.uEncryptIV.iv[0]), sizeof(info.uEncryptIV) );
|
||||
|
||||
//for test
|
||||
/* memset( &info.uEncryptKey.key, 0x10, sizeof(info.uEncryptKey) );
|
||||
memset( &info.uEncryptIV.iv, 0x10, sizeof(info.uEncryptIV) ); */
|
||||
}
|
||||
m_mapHybridCryptKey[dwExtHash] = info;
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GetPerFileCryptKey( std::string& rfileName, eHybridCipherAlgorithm& eAlgorithm, TEncryptKey& key, TEncryptIV& iv )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
std::string fileNamelower = rfileName;
|
||||
stl_lowers(fileNamelower);
|
||||
|
||||
std::string extName = GetFileExt(fileNamelower);
|
||||
|
||||
TCSHybridCryptKeyMap::const_iterator cit = m_mapHybridCryptKey.find( stringhash().GetHash(extName));
|
||||
|
||||
if( cit == m_mapHybridCryptKey.end() )
|
||||
{
|
||||
//TODO : log no file ext info
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwfileNameCrc = GetCRC32(fileNamelower.c_str(), fileNamelower.size());
|
||||
|
||||
//make file specific algorithm & key & iv
|
||||
eAlgorithm = (eHybridCipherAlgorithm)(dwfileNameCrc % Num_Of_Ciphers);
|
||||
|
||||
::memcpy(key.key, cit->second.uEncryptKey.key, sizeof(key) );
|
||||
::memcpy(iv.iv, cit->second.uEncryptIV.iv, sizeof(iv) );
|
||||
|
||||
|
||||
//Themida Warning
|
||||
for( int i = 0; i < (sizeof(key)/sizeof(dwfileNameCrc)); ++i)
|
||||
{
|
||||
*((DWORD*)key.key + i) ^= dwfileNameCrc;
|
||||
}
|
||||
for( int i = 0; i < (sizeof(iv)/sizeof(dwfileNameCrc)); ++i)
|
||||
{
|
||||
*((DWORD*)iv.iv + i) ^= dwfileNameCrc;
|
||||
}
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::EncryptMemory( std::string& rfileName, IN const BYTE* pSrcData, IN int iSrcLen, OUT CLZObject& zObj )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
eHybridCipherAlgorithm eAlgorithm;
|
||||
TEncryptKey key;
|
||||
TEncryptIV iv;
|
||||
|
||||
if( !GetPerFileCryptKey( rfileName, eAlgorithm, key, iv ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// start cipher
|
||||
std::string strCipher;
|
||||
//NOTE : ciphered stream size could be different from original size if you choose diffrent cipher mode & algorithm
|
||||
//( i.e ECB or CBC mode )
|
||||
strCipher.reserve(iSrcLen);
|
||||
|
||||
if( eAlgorithm == e_Cipher_Camellia )
|
||||
{
|
||||
// Encryptor
|
||||
CIPHER_MODE<Camellia>::Encryption Encryptor;
|
||||
Encryptor.SetKeyWithIV(key.keyCamellia, sizeof(key.keyCamellia), iv.ivCamellia, sizeof(iv.ivCamellia));
|
||||
|
||||
ArraySource(pSrcData, iSrcLen, true,
|
||||
new StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(strCipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_Twofish )
|
||||
{
|
||||
// Encryptor
|
||||
CIPHER_MODE<Twofish>::Encryption Encryptor;
|
||||
Encryptor.SetKeyWithIV(key.keyTwofish, sizeof(key.keyTwofish), iv.ivTwofish, sizeof(iv.ivTwofish));
|
||||
|
||||
ArraySource(pSrcData, iSrcLen, true,
|
||||
new StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(strCipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_XTEA )
|
||||
{
|
||||
// Encryptor
|
||||
CIPHER_MODE<XTEA>::Encryption Encryptor;
|
||||
Encryptor.SetKeyWithIV(key.keyXTEA, sizeof(key.keyXTEA), iv.ivXTEA, sizeof(iv.ivXTEA));
|
||||
|
||||
ArraySource(pSrcData, iSrcLen, true,
|
||||
new StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(strCipher)));
|
||||
}
|
||||
|
||||
if (strCipher.length() != iSrcLen)
|
||||
{
|
||||
//TODO: size error log
|
||||
return false;
|
||||
}
|
||||
|
||||
zObj.AllocBuffer(iSrcLen);
|
||||
memcpy(zObj.GetBuffer(), strCipher.c_str(), strCipher.length() );
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::DecryptMemory( std::string& rfilename, IN const BYTE* pEncryptedData, IN int iEncryptedLen, OUT CLZObject& zObj )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
eHybridCipherAlgorithm eAlgorithm;
|
||||
TEncryptKey key;
|
||||
TEncryptIV iv;
|
||||
|
||||
if( !GetPerFileCryptKey( rfilename, eAlgorithm, key, iv ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// start decipher
|
||||
std::string strDecipher;
|
||||
//NOTE : ciphered stream size could be different from original size if you choose diffrent cipher mode & algorithm
|
||||
//( i.e ECB or CBC mode )
|
||||
strDecipher.reserve(iEncryptedLen);
|
||||
|
||||
if( eAlgorithm == e_Cipher_Camellia )
|
||||
{
|
||||
// Decryptor
|
||||
CIPHER_MODE<Camellia>::Decryption Decryptor;
|
||||
Decryptor.SetKeyWithIV(key.keyCamellia, sizeof(key.keyCamellia), iv.ivCamellia, sizeof(iv.ivCamellia));
|
||||
|
||||
ArraySource(pEncryptedData, iEncryptedLen, true,
|
||||
new StreamTransformationFilter(Decryptor, new CryptoPP::StringSink(strDecipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_Twofish )
|
||||
{
|
||||
// Decryptor
|
||||
CIPHER_MODE<Twofish>::Decryption Decryptor;
|
||||
Decryptor.SetKeyWithIV(key.keyTwofish, sizeof(key.keyTwofish), iv.ivTwofish, sizeof(iv.ivTwofish));
|
||||
|
||||
ArraySource(pEncryptedData, iEncryptedLen, true,
|
||||
new StreamTransformationFilter(Decryptor, new CryptoPP::StringSink(strDecipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_XTEA )
|
||||
{
|
||||
// Decryptor
|
||||
CIPHER_MODE<XTEA>::Decryption Decryptor;
|
||||
Decryptor.SetKeyWithIV(key.keyXTEA, sizeof(key.keyXTEA), iv.ivXTEA, sizeof(iv.ivXTEA));
|
||||
|
||||
ArraySource(pEncryptedData, iEncryptedLen, true,
|
||||
new StreamTransformationFilter(Decryptor, new CryptoPP::StringSink(strDecipher)));
|
||||
}
|
||||
|
||||
|
||||
if (strDecipher.length() != iEncryptedLen)
|
||||
{
|
||||
//TODO: size error log
|
||||
return false;
|
||||
}
|
||||
|
||||
zObj.AllocBuffer(iEncryptedLen);
|
||||
memcpy(zObj.GetBuffer(), strDecipher.c_str(), strDecipher.length() );
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EterPackPolicy_CSHybridCrypt::WriteCryptKeyToFile( CFileBase& rFile )
|
||||
{
|
||||
// ext cnt 4byte
|
||||
// for ext hash ( crc32 )
|
||||
// key-16byte
|
||||
// iv-16byte
|
||||
|
||||
DWORD dwCryptKeySize = m_mapHybridCryptKey.size();
|
||||
rFile.Write( &dwCryptKeySize, sizeof(DWORD) );
|
||||
|
||||
TCSHybridCryptKeyMap::const_iterator cit;
|
||||
for( cit = m_mapHybridCryptKey.begin(); cit != m_mapHybridCryptKey.end(); ++cit )
|
||||
{
|
||||
DWORD extNamehash = cit->first;
|
||||
const TCSHybridCryptKey& CryptKey = cit->second;
|
||||
|
||||
rFile.Write( &extNamehash, sizeof(DWORD) );
|
||||
rFile.Write( CryptKey.uEncryptKey.key, sizeof(TEncryptKey) );
|
||||
rFile.Write( CryptKey.uEncryptIV.iv, sizeof(TEncryptIV) );
|
||||
}
|
||||
}
|
||||
|
||||
int EterPackPolicy_CSHybridCrypt::ReadCryptKeyInfoFromStream( IN const BYTE* pStream )
|
||||
{
|
||||
int iStreamOffset = 0;
|
||||
|
||||
DWORD dwCryptoInfoSize;
|
||||
memcpy(&dwCryptoInfoSize, pStream, sizeof(DWORD) );
|
||||
iStreamOffset += sizeof(DWORD);
|
||||
|
||||
DWORD dwExtHash;
|
||||
|
||||
m_mapHybridCryptKey.clear();
|
||||
|
||||
for( int i = 0; i < dwCryptoInfoSize; ++i )
|
||||
{
|
||||
memcpy(&dwExtHash, pStream + iStreamOffset, sizeof(DWORD) );
|
||||
iStreamOffset += sizeof(DWORD);
|
||||
|
||||
TCSHybridCryptKey info;
|
||||
{
|
||||
memcpy(info.uEncryptKey.key, pStream + iStreamOffset, sizeof(TEncryptKey) );
|
||||
iStreamOffset += sizeof(TEncryptKey);
|
||||
|
||||
memcpy(info.uEncryptIV.iv, pStream + iStreamOffset, sizeof(TEncryptIV) );
|
||||
iStreamOffset += sizeof(TEncryptIV);
|
||||
}
|
||||
|
||||
m_mapHybridCryptKey[dwExtHash] = info;
|
||||
}
|
||||
|
||||
return iStreamOffset;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GenerateSupplementaryDataBlock(std::string& rfilename, const std::string& strMapName, IN const BYTE* pSrcData, IN int iSrcLen, OUT LPBYTE& pDestData, OUT int& iDestLen )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
std::string fileNamelower = rfilename;
|
||||
stl_lowers( fileNamelower );
|
||||
|
||||
DWORD dwFileNameHash = stringhash().GetHash(fileNamelower);
|
||||
TSupplementaryDataBlockMap::const_iterator cit = m_mapSDBMap.find( dwFileNameHash );
|
||||
|
||||
if( cit != m_mapSDBMap.end() )
|
||||
{
|
||||
//TODO : log already registered
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO : Find Better Method for deciding SDB Postion & Size
|
||||
|
||||
//prevent stream copy duplication
|
||||
TSupplementaryDataBlockInfo info;
|
||||
m_mapSDBMap[dwFileNameHash] = info;
|
||||
|
||||
std::string& strRelatedMapName = m_mapSDBMap[dwFileNameHash].strRelatedMapName;
|
||||
std::vector<BYTE>& sdbVector = m_mapSDBMap[dwFileNameHash].vecStream;
|
||||
|
||||
|
||||
//fill the data!!
|
||||
{
|
||||
strRelatedMapName = strMapName;
|
||||
|
||||
int iSDBSize = random_range( 64, 128 );
|
||||
|
||||
if( iSrcLen < iSDBSize )
|
||||
{
|
||||
iSDBSize = iSrcLen - 1;
|
||||
if( iSDBSize <= 0 )
|
||||
{
|
||||
//TODO : is there 1byte file exist???
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sdbVector.resize( iSDBSize );
|
||||
|
||||
iDestLen = iSrcLen - iSDBSize;
|
||||
pDestData = (LPBYTE)pSrcData;
|
||||
|
||||
memcpy( &sdbVector[0], pDestData + iDestLen, iSDBSize );
|
||||
}
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GetSupplementaryDataBlock( std::string& rfilename, OUT LPBYTE& pSDB, OUT int& iSDBSize )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
std::string fileNamelower = rfilename;
|
||||
stl_lowers( fileNamelower );
|
||||
|
||||
DWORD dwFileNameHash = stringhash().GetHash(fileNamelower);
|
||||
TSupplementaryDataBlockMap::const_iterator cit = m_mapSDBMap.find( dwFileNameHash );
|
||||
|
||||
if( cit == m_mapSDBMap.end() )
|
||||
{
|
||||
//TODO : log already registered
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<BYTE>& vecSDB = cit->second.vecStream;
|
||||
|
||||
iSDBSize = vecSDB.size();
|
||||
|
||||
if(iSDBSize <= 0)
|
||||
{
|
||||
pSDB = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
pSDB = (BYTE*)&vecSDB[0];
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::IsContainingSDBFile() const
|
||||
{
|
||||
return m_mapSDBMap.size() > 0 ? true : false;
|
||||
}
|
||||
|
||||
void EterPackPolicy_CSHybridCrypt::WriteSupplementaryDataBlockToFile( CFileBase& rFile )
|
||||
{
|
||||
//about SDB data
|
||||
// sdb file cnt( 4byte )
|
||||
// for sdb file cnt
|
||||
// filename hash ( stl.h stringhash )
|
||||
// related map name size(4), relate map name
|
||||
// sdb block size( 1byte )
|
||||
// sdb blocks
|
||||
|
||||
DWORD dwSDBMapSize = m_mapSDBMap.size();
|
||||
rFile.Write( &dwSDBMapSize, sizeof(DWORD) );
|
||||
|
||||
TSupplementaryDataBlockMap::const_iterator cit;
|
||||
for( cit = m_mapSDBMap.begin(); cit != m_mapSDBMap.end(); ++cit )
|
||||
{
|
||||
DWORD dwFileNamehash = cit->first;
|
||||
rFile.Write( &dwFileNamehash, sizeof(DWORD) );
|
||||
|
||||
const std::string strRelatedMapName = cit->second.strRelatedMapName;
|
||||
DWORD dwMapNameSize = strRelatedMapName.size();
|
||||
rFile.Write( &dwMapNameSize, sizeof(DWORD) );
|
||||
rFile.Write( strRelatedMapName.c_str(), dwMapNameSize );
|
||||
|
||||
const std::vector<BYTE>& sdbVector = cit->second.vecStream;
|
||||
BYTE bSDBSize = (BYTE)(sdbVector.size());
|
||||
|
||||
rFile.Write( &bSDBSize, sizeof(bSDBSize) );
|
||||
if( bSDBSize > 0 )
|
||||
rFile.Write( &sdbVector[0], bSDBSize );
|
||||
}
|
||||
}
|
||||
|
||||
int EterPackPolicy_CSHybridCrypt::ReadSupplementatyDataBlockFromStream( IN const BYTE* pStream )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
//DWORD dwFileIdentifier;
|
||||
//std::vector<BYTE> vecSDBStream;
|
||||
|
||||
DWORD dwFileNameHash;
|
||||
BYTE bSDBSize;
|
||||
int iStreamOffset = 0;
|
||||
|
||||
memcpy(&dwFileNameHash, pStream + iStreamOffset, sizeof(DWORD) );
|
||||
iStreamOffset += sizeof(DWORD);
|
||||
|
||||
memcpy(&bSDBSize, pStream + iStreamOffset, sizeof(BYTE) );
|
||||
iStreamOffset += sizeof(BYTE);
|
||||
|
||||
// NOTE : related map name isn`t required in client. so we don`t recv it from stream to reduce packet size.
|
||||
TSupplementaryDataBlockInfo info;
|
||||
{
|
||||
info.vecStream.resize( bSDBSize );
|
||||
memcpy(&info.vecStream[0], pStream + iStreamOffset, bSDBSize );
|
||||
iStreamOffset += bSDBSize;
|
||||
|
||||
m_mapSDBMap[dwFileNameHash] = info;
|
||||
}
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return iStreamOffset;
|
||||
}
|
94
src/EterPack/EterPackPolicy_CSHybridCrypt.h
Normal file
94
src/EterPack/EterPackPolicy_CSHybridCrypt.h
Normal file
@ -0,0 +1,94 @@
|
||||
#ifndef __INC_ETERPACKLIB_ETERPACKPOLICY_CSHYBRIDCRYPT_H__
|
||||
#define __INC_ETERPACKLIB_ETERPACKPOLICY_CSHYBRIDCRYPT_H__
|
||||
|
||||
#include <unordered_map>
|
||||
#include <cryptopp/cryptlib.h>
|
||||
#include <cryptopp/camellia.h>
|
||||
#include <cryptopp/twofish.h>
|
||||
#include <cryptopp/tea.h>
|
||||
|
||||
enum eHybridCipherAlgorithm
|
||||
{
|
||||
e_Cipher_Camellia,
|
||||
e_Cipher_Twofish,
|
||||
e_Cipher_XTEA,
|
||||
Num_Of_Ciphers
|
||||
};
|
||||
|
||||
|
||||
class CFileBase;
|
||||
class CLZObject;
|
||||
|
||||
//THEMIDA
|
||||
class EterPackPolicy_CSHybridCrypt
|
||||
{
|
||||
public:
|
||||
~EterPackPolicy_CSHybridCrypt();
|
||||
|
||||
bool GenerateCryptKey( std::string& rfileName );
|
||||
bool EncryptMemory( std::string& rfilename, IN const BYTE* pSrcData, IN int iSrcLen, OUT CLZObject& zObj );
|
||||
bool DecryptMemory( std::string& rfilename, IN const BYTE* pSrcData, IN int iSrcLen, OUT CLZObject& zObj );
|
||||
bool IsContainingCryptKey() const;
|
||||
|
||||
//Supplementary Data Block (SDB)
|
||||
bool GenerateSupplementaryDataBlock(std::string& rfilename, const std::string& strMapName, IN const BYTE* pSrcData, IN int iSrcLen, OUT LPBYTE& pDestData, OUT int& iDestLen );
|
||||
bool GetSupplementaryDataBlock( std::string& rfilename, OUT LPBYTE& pSDB, OUT int& iSDBSize );
|
||||
bool IsContainingSDBFile() const;
|
||||
|
||||
// Read/Write IO
|
||||
void WriteCryptKeyToFile( CFileBase& rFile );
|
||||
int ReadCryptKeyInfoFromStream( IN const BYTE* pStream );
|
||||
|
||||
void WriteSupplementaryDataBlockToFile( CFileBase& rFile );
|
||||
int ReadSupplementatyDataBlockFromStream( IN const BYTE* pStream );
|
||||
|
||||
protected:
|
||||
|
||||
typedef union UEncryptKey
|
||||
{
|
||||
BYTE key[16];
|
||||
BYTE keyCamellia[ CryptoPP::Camellia::DEFAULT_KEYLENGTH];
|
||||
BYTE keyTwofish [ CryptoPP::Twofish::DEFAULT_KEYLENGTH];
|
||||
BYTE keyXTEA [ CryptoPP::XTEA::DEFAULT_KEYLENGTH];
|
||||
|
||||
} TEncryptKey;
|
||||
|
||||
typedef union UEncryptIV
|
||||
{
|
||||
BYTE iv[16];
|
||||
BYTE ivCamellia [ CryptoPP::Camellia::BLOCKSIZE];
|
||||
BYTE ivTwofish [ CryptoPP::Twofish::BLOCKSIZE];
|
||||
BYTE ivXTEA [ CryptoPP::XTEA::BLOCKSIZE];
|
||||
|
||||
} TEncryptIV;
|
||||
|
||||
|
||||
typedef struct SCSHybridCryptKey
|
||||
{
|
||||
TEncryptKey uEncryptKey;
|
||||
TEncryptIV uEncryptIV;
|
||||
|
||||
} TCSHybridCryptKey;
|
||||
|
||||
typedef std::unordered_map<DWORD, TCSHybridCryptKey> TCSHybridCryptKeyMap;
|
||||
TCSHybridCryptKeyMap m_mapHybridCryptKey;
|
||||
|
||||
typedef struct SSupplementaryDataBlockInfo
|
||||
{
|
||||
std::string strRelatedMapName;
|
||||
std::vector<BYTE> vecStream;
|
||||
|
||||
} TSupplementaryDataBlockInfo;
|
||||
|
||||
typedef std::unordered_map<DWORD, TSupplementaryDataBlockInfo> TSupplementaryDataBlockMap; //key filename hash
|
||||
TSupplementaryDataBlockMap m_mapSDBMap;
|
||||
|
||||
private:
|
||||
bool GetPerFileCryptKey( std::string& rfileName, eHybridCipherAlgorithm& eAlgorithm, TEncryptKey& key, TEncryptIV& iv );
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __INC_ETERPACKLIB_ETERPACKPOLICY_CSHYBRIDCRYPT_H__
|
34
src/EterPack/Inline.h
Normal file
34
src/EterPack/Inline.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef __INC_ETERPACK_INLINE_H__
|
||||
#define __INC_ETERPACK_INLINE_H__
|
||||
|
||||
inline void inlinePathCreate(const char* path)
|
||||
{
|
||||
char dir[64];
|
||||
const char* p, *k;
|
||||
|
||||
p = path + 3;
|
||||
|
||||
while (NULL != (k = strchr(p, '/')))
|
||||
{
|
||||
memset(dir, 0, sizeof(dir));
|
||||
strncpy(dir, path, k - path);
|
||||
CreateDirectory(dir, NULL);
|
||||
p = k + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void inlineConvertPackFilename(char* name)
|
||||
{
|
||||
char * p = name;
|
||||
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
else
|
||||
*p = (int) tolower(*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
2
src/EterPack/StdAfx.cpp
Normal file
2
src/EterPack/StdAfx.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "stdafx.h"
|
||||
|
9
src/EterPack/StdAfx.h
Normal file
9
src/EterPack/StdAfx.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
//#include <crtdbg.h>
|
||||
#include <windows.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "../eterBase/StdAfx.h"
|
1033
src/EterPack/md5.c
Normal file
1033
src/EterPack/md5.c
Normal file
File diff suppressed because it is too large
Load Diff
128
src/EterPack/md5.h
Normal file
128
src/EterPack/md5.h
Normal file
@ -0,0 +1,128 @@
|
||||
#ifndef __INC_ETERPACKLIB_MD5_H__
|
||||
#define __INC_ETERPACKLIB_MD5_H__
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** md5.h -- header file for implementation of MD5 **
|
||||
|
||||
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
|
||||
|
||||
** Created: 2/17/90 RLR **
|
||||
|
||||
** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
|
||||
|
||||
** Revised (for MD5): RLR 4/27/91 **
|
||||
|
||||
** -- G modified to have y&~z instead of y&z **
|
||||
|
||||
** -- FF, GG, HH modified to add in last register done **
|
||||
|
||||
** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
|
||||
|
||||
** -- distinct additive constant for each step **
|
||||
|
||||
** -- round 4 added, working mod 7 **
|
||||
|
||||
***********************************************************************
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
|
||||
|
||||
** **
|
||||
|
||||
** License to copy and use this software is granted provided that **
|
||||
|
||||
** it is identified as the "RSA Data Security, Inc. MD5 Message- **
|
||||
|
||||
** Digest Algorithm" in all material mentioning or referencing this **
|
||||
|
||||
** software or this function. **
|
||||
|
||||
** **
|
||||
|
||||
** License is also granted to make and use derivative works **
|
||||
|
||||
** provided that such works are identified as "derived from the RSA **
|
||||
|
||||
** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
|
||||
|
||||
** material mentioning or referencing the derived work. **
|
||||
|
||||
** **
|
||||
|
||||
** RSA Data Security, Inc. makes no representations concerning **
|
||||
|
||||
** either the merchantability of this software or the suitability **
|
||||
|
||||
** of this software for any particular purpose. It is provided "as **
|
||||
|
||||
** is" without express or implied warranty of any kind. **
|
||||
|
||||
** **
|
||||
|
||||
** These notices must be retained in any copies of any part of this **
|
||||
|
||||
** documentation and/or software. **
|
||||
|
||||
***********************************************************************
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* typedef a 32-bit type */
|
||||
|
||||
typedef unsigned long int UINT4;
|
||||
|
||||
|
||||
|
||||
/* Data structure for MD5 (Message-Digest) computation */
|
||||
|
||||
typedef struct {
|
||||
|
||||
UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
|
||||
|
||||
UINT4 buf[4]; /* scratch buffer */
|
||||
|
||||
unsigned char in[64]; /* input buffer */
|
||||
|
||||
unsigned char digest[16]; /* actual digest after MD5Final call */
|
||||
|
||||
} MD5_CTX;
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void MD5Init (MD5_CTX *);
|
||||
|
||||
void MD5Update (MD5_CTX *,unsigned char *,unsigned int);
|
||||
|
||||
void MD5Final (MD5_CTX *);
|
||||
|
||||
void MD5Transform(UINT4 *,UINT4 *);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** End of md5.h **
|
||||
|
||||
******************************** (cut) ********************************
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user