From bd49c3201234f447a4fc951ea652532d973c07b1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 14 Nov 2013 23:13:38 +0000 Subject: Encryption: gathering all things together, part I git-svn-id: http://svn.miranda-ng.org/main/trunk@6910 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/commonheaders.h | 1 + plugins/Db3x_mmap/src/dbcache.cpp | 16 +++++----------- plugins/Db3x_mmap/src/dbintf.cpp | 28 ++++++---------------------- plugins/Db3x_mmap/src/dbintf.h | 5 ++++- 4 files changed, 16 insertions(+), 34 deletions(-) (limited to 'plugins/Db3x_mmap/src') diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h index d122b08d1e..12286e83d6 100644 --- a/plugins/Db3x_mmap/src/commonheaders.h +++ b/plugins/Db3x_mmap/src/commonheaders.h @@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "database.h" #include "dbintf.h" diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp index 874a3b733e..8862c7192f 100644 --- a/plugins/Db3x_mmap/src/dbcache.cpp +++ b/plugins/Db3x_mmap/src/dbcache.cpp @@ -26,15 +26,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void CDb3Mmap::Map() { m_hMap = CreateFileMapping(m_hDbFile, NULL, PAGE_READWRITE, 0, m_dwFileSize, NULL); - - if (m_hMap) - { + if (m_hMap) { m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, FILE_MAP_ALL_ACCESS/*FILE_MAP_WRITE*/, 0, 0 ,0); if (!m_pDbCache) DatabaseCorruption( _T("%s (MapViewOfFile failed. Code: %d)")); } - else - DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)")); + else DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)")); } void CDb3Mmap::ReMap(DWORD needed) @@ -43,18 +40,15 @@ void CDb3Mmap::ReMap(DWORD needed) log3("remapping %d + %d (file end: %d)",m_dwFileSize,needed,m_dbHeader.ofsFileEnd); - if (needed > m_ChunkSize) - { + if (needed > m_ChunkSize) { if (needed + m_dwFileSize > m_dbHeader.ofsFileEnd + m_ChunkSize) DatabaseCorruption( _T("%s (Too large increment)")); - else - { + else { DWORD x = m_dbHeader.ofsFileEnd/m_ChunkSize; m_dwFileSize = (x+1)*m_ChunkSize; } } - else - m_dwFileSize += m_ChunkSize; + else m_dwFileSize += m_ChunkSize; // FlushViewOfFile(m_pDbCache, 0); UnmapViewOfFile(m_pDbCache); diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 0888e8c7f9..caaa1e5a74 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -58,7 +58,7 @@ CDb3Base::CDb3Base(const TCHAR *tszFileName) : m_ChunkSize = sinf.dwAllocationGranularity; m_codePage = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0); - m_hModHeap = HeapCreate(0,0,0); + m_hModHeap = HeapCreate(0, 0, 0); } CDb3Base::~CDb3Base() @@ -71,12 +71,15 @@ CDb3Base::~CDb3Base() m_lOfs.destroy(); // destroy map - KillTimer(NULL,m_flushBuffersTimerId); + KillTimer(NULL, m_flushBuffersTimerId); if (m_pDbCache) { FlushViewOfFile(m_pDbCache, 0); UnmapViewOfFile(m_pDbCache); } + if (m_crypto) + m_crypto->destroy(); + if (m_hMap) CloseHandle(m_hMap); @@ -114,6 +117,7 @@ int CDb3Base::Load(bool bSkipInit) if ( !bSkipInit) { if (InitCache()) return 1; if (InitModuleNames()) return 1; + if (InitCrypt()) return 1; m_bReadOnly = false; @@ -142,26 +146,6 @@ STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet) DBFlush(1); } -void CDb3Base::EncodeCopyMemory(void *dst, void *src, size_t size) -{ - MoveMemory(dst, src, size); -} - -void CDb3Base::DecodeCopyMemory(void *dst, void *src, size_t size) -{ - MoveMemory(dst, src, size); -} - -void CDb3Base::EncodeDBWrite(DWORD ofs, void *src, int size) -{ - DBWrite(ofs, src, size); -} - -void CDb3Base::DecodeDBWrite(DWORD ofs, void *src, int size) -{ - DBWrite(ofs, src, size); -} - /////////////////////////////////////////////////////////////////////////////// // MIDatabaseChecker diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 152e8613b2..80f1d32790 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -204,6 +204,7 @@ protected: virtual int InitCache(void) = 0; protected: + int InitCrypt(void); virtual void EncodeCopyMemory(void *dst, void *src, size_t size); virtual void DecodeCopyMemory(void *dst, void *src, size_t size); virtual void EncodeDBWrite(DWORD ofs, void *src, int size); @@ -223,7 +224,9 @@ protected: DBHeader m_dbHeader; DWORD m_ChunkSize; bool m_safetyMode, m_bReadOnly; - + + MICryptoEngine *m_crypto; + //////////////////////////////////////////////////////////////////////////// // database stuff public: -- cgit v1.2.3