From: Jeffrey D. <ha...@us...> - 2003-10-15 19:48:53
|
Log Message: ----------- Encrypted memloc support Added Files: ----------- /cvsroot/decaldev/source/Include: DecalKey.h Revision Data ------------- --- NEW FILE: DecalKey.h --- // DecalVersion.h // Declaration of the Decal version resource #ifndef __DECALKEY_H__ #define __DECALKEY_H__ #define DECAL_KEY "DECAL" #endif |
From: Jeffrey D. <ha...@us...> - 2003-10-15 19:49:58
|
Log Message: ----------- Encrypted memloc support Modified Files: -------------- /cvsroot/decaldev/source/DenAgent: DenAgent.cpp DenAgent.h DenAgentDlg.cpp StdAfx.h Revision Data ------------- Index: DenAgent.cpp =================================================================== RCS file: /cvsroot/decaldev/source/DenAgent/DenAgent.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- DenAgent.cpp 29 May 2003 21:30:16 -0000 1.18 +++ DenAgent.cpp 15 Oct 2003 19:46:52 -0000 1.19 @@ -245,8 +245,19 @@ { pDoc.CreateInstance ( __uuidof ( MSXML::DOMDocument ), NULL, CLSCTX_INPROC_SERVER ); pDoc->async = false; - if ( !pDoc->load ( static_cast< LPCTSTR > ( strXMLFile ) ) ) - { + BOOL bSuccess = pDoc->load( static_cast< LPCTSTR > ( strXMLFile ) ); + + if( !bSuccess ) + { + std::string szXIML; + DecryptXML( static_cast< LPCSTR >( strXMLFile ), szXML ); + + if( szXML != "" ) + bSuccess = pDoc->loadXML( _bstr_t( szXML.c_str() ) ); + } + + if( ! bSuccess ) + { CString strMessage; strMessage.FormatMessage ( IDE_NOXMLDOC, static_cast< LPCTSTR > ( strXMLFile ) ); @@ -312,6 +323,61 @@ return true; } +void CDenAgentApp::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 ); +} + bool CDenAgentApp::checkXMLVersions ( CTrayWnd* pTrayWnd ) { bool bOK = true; @@ -342,10 +408,21 @@ try { - if ( !pDoc->load ( static_cast< LPCTSTR > ( pFirst->XMLFile ) ) ) - { + BOOL bSuccess = pDoc->load( static_cast< LPCTSTR > ( pFirst->XMLFile ) ); + + if( ! bSuccess ) + { + std::string szXML; + DecryptXML( static_cast< LPCSTR >( pFirst->XMLFile ), szXML ); + + if( szXML != "" ) + bSuccess = pDoc->loadXML( _bstr_t( szXML.c_str() ) ); + } + + if( ! bSuccess ) + { CString strMessage; - strMessage.FormatMessage ( IDE_NOXMLDOC, pFirst->XMLFile ); + strMessage.FormatMessage( IDE_NOXMLDOC, pFirst->XMLFile ); ::AfxMessageBox ( strMessage, MB_ICONERROR ); pFirst->build = 0; Index: DenAgent.h =================================================================== RCS file: /cvsroot/decaldev/source/DenAgent/DenAgent.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- DenAgent.h 20 Apr 2002 20:29:52 -0000 1.6 +++ DenAgent.h 15 Oct 2003 19:46:52 -0000 1.7 @@ -17,6 +17,10 @@ class CTrayWnd; + +// the public key to unencrypt memlocs.xml +#include "..\include\DecalKey.h" + ///////////////////////////////////////////////////////////////////////////// // CDenAgentApp: // See DenAgent.cpp for the implementation of this class @@ -32,6 +36,9 @@ static bool getVersionInfo ( LPCTSTR szFilename, int &iReleaseMajor, int &iReleaseMinor, int &iBuildMajor, int &iBuildMinor ); static bool getACVersionString ( CString &strVersion ); static bool getCOMObjectDLL ( REFCLSID rclsid, CString &strFilename ); + + // decrypts xml file + static void DecryptXML( const char *szPath, std::string &szXML ); // Prepends the agent path to a filename static bool getAgentPath ( LPCTSTR szFilename, CString &strPath ); Index: DenAgentDlg.cpp =================================================================== RCS file: /cvsroot/decaldev/source/DenAgent/DenAgentDlg.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- DenAgentDlg.cpp 23 Jun 2003 04:58:21 -0000 1.36 +++ DenAgentDlg.cpp 15 Oct 2003 19:46:52 -0000 1.37 @@ -581,7 +581,17 @@ m_pDoc.CreateInstance( __uuidof( MSXML::DOMDocument ) ); m_pDoc->async = false; - if (m_pDoc->load(_bstr_t(szFilename)) == VARIANT_FALSE) + BOOL bSuccess = m_pDoc->load( _bstr_t(szFilename) ); + if( !bSuccess ) + { + std::string szXML; + CDenAgentApp::DecryptXML( static_cast< LPCSTR >( szFilename ), szXML ); + + if( szXML != "" ) + bSuccess = m_pDoc->loadXML( _bstr_t( szXML.c_str() ) ); + } + + if( !bSuccess ) return; if (strlen(pszRootElement)) { Index: StdAfx.h =================================================================== RCS file: /cvsroot/decaldev/source/DenAgent/StdAfx.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- StdAfx.h 29 May 2003 21:30:15 -0000 1.10 +++ StdAfx.h 15 Oct 2003 19:46:52 -0000 1.11 @@ -28,8 +28,9 @@ #include <atlbase.h> #include <comdef.h> +#include <atlcrypt.h> - #define _ATL_APARTMENT_THREADED +#define _ATL_APARTMENT_THREADED #include <atlbase.h> //You may derive a class from CComModule and use it if you want to override //something, but do not change the name of _Module |
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> |