From: Jeffrey D. <ha...@us...> - 2003-10-15 21:15:19
|
Log Message: ----------- Encrypted memloc support Modified Files: -------------- /cvsroot/decaldev/source/Decal: ACHooks.cpp ACHooks.h Decal.vcproj StdAfx.h Revision Data ------------- Index: ACHooks.cpp =================================================================== RCS file: /cvsroot/decaldev/source/Decal/ACHooks.cpp,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- ACHooks.cpp 8 Oct 2003 20:56:10 -0000 1.67 +++ ACHooks.cpp 15 Oct 2003 19:45:48 -0000 1.68 @@ -20,8 +20,6 @@ */ #define BSTRT(x) (_Unnamed = L##x, _Unnamed) - - ///////////////////////////////////////////////////////////////////////////// cACHooks* cACHooks::s_pACHooks = NULL; long g_lObjectDestroyedProc = 0; @@ -178,6 +176,15 @@ pMemLocDoc->async = false; VARIANT_BOOL bSuccess = pMemLocDoc->load( szPath ); + if( ! bSuccess ) + { + std::string szXML; + DecryptXML( szPath, szXML ); + + if( szXML != "" ) + bSuccess = pMemLocDoc->loadXML( _bstr_t( szXML.c_str() ) ); + } + if( bSuccess ) { MSXML::IXMLDOMElementPtr pNode = pMemLocDoc->selectSingleNode( BSTRT( "locations" ) ); @@ -860,6 +867,61 @@ if( m_bIdQueueRef ) m_pIdQueue.Release(); +} + +void cACHooks::DecryptXML( const char *szPath, std::string &szXML ) +{ + if( szPath == NULL ) + { + szXML = ""; + return; + } + + FILE *f = fopen( szPath, "rb" ); + if( f == NULL ) + { + szXML = ""; + return; + } + + szXML.clear(); + unsigned char szBuffer[1025]; + + try + { + CCryptProv crypt; + if( crypt.Initialize( PROV_RSA_FULL, "Decal_Memlocs", MS_DEF_PROV ) == NTE_BAD_KEYSET ) + crypt.Initialize( PROV_RSA_FULL, "Decal_Memlocs", MS_DEF_PROV, CRYPT_NEWKEYSET ); + + CCryptMD5Hash hash; + hash.Initialize( crypt ); + hash.AddString( DECAL_KEY ); + + CCryptDerivedKey key; + key.Initialize( crypt, hash ); + + DWORD dwDecLen = 0; + + while( ! feof(f) ) + { + memset( szBuffer, 0, sizeof( szBuffer ) ); + dwDecLen = fread( szBuffer, 1, 1024, f ); + key.Decrypt( feof(f), (BYTE *) szBuffer, &dwDecLen ); + szXML += (char *)szBuffer; + } + + key.Destroy(); + hash.Destroy(); + crypt.Release(); + } + + catch( ... ) + { + // crap... + szXML = ""; + } + + fclose( f ); } STDMETHODIMP cACHooks::SetDecal( IUnknown *pDecal ) Index: ACHooks.h =================================================================== RCS file: /cvsroot/decaldev/source/Decal/ACHooks.h,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- ACHooks.h 9 Sep 2003 03:08:32 -0000 1.47 +++ ACHooks.h 15 Oct 2003 19:45:48 -0000 1.48 @@ -9,6 +9,9 @@ #include "DecalManager.h" #include "DecalCP.h" +// the public key to unencrypt memlocs.xml +#include "..\include\DecalKey.h" + // .NET vs VC6.0 Compiler Config #if _MSC_VER > 1200 // .NET #import "..\Include\Inject.tlb" @@ -95,6 +98,7 @@ private: long* GetCs(long offs=0) ; + void DecryptXML( const char *szPath, std::string &szXML ); long m_Hooks ; typedef std::map< std::string, sMemoryLocation > LocMap; @@ -342,4 +346,4 @@ STDMETHOD(SendMessageByMask)(LONG lMask, BSTR szMessage); }; -#endif // __ACHOOKS_H_ \ No newline at end of file +#endif // __ACHOOKS_H_ Index: Decal.vcproj =================================================================== RCS file: /cvsroot/decaldev/source/Decal/Decal.vcproj,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Decal.vcproj 19 Jun 2003 22:04:03 -0000 1.3 +++ Decal.vcproj 15 Oct 2003 19:45:48 -0000 1.4 @@ -932,6 +932,9 @@ RelativePath="..\Include\DecalImpl.h"> </File> <File + RelativePath="..\Include\DecalKey.h"> + </File> + <File RelativePath="DecalManager.h"> </File> <File Index: StdAfx.h =================================================================== RCS file: /cvsroot/decaldev/source/Decal/StdAfx.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- StdAfx.h 29 May 2003 20:50:36 -0000 1.6 +++ StdAfx.h 15 Oct 2003 19:45:48 -0000 1.7 @@ -23,6 +23,8 @@ #include <atlcom.h> #include <comdef.h> +#include <atlcrypt.h> + #include <ddraw.h> #include <d3d.h> |