//////////////////////////////////////////////////////////////////////////////////////////////////
//
// Title: SAMA
// Compiler: Microsoft Visual Studio .NET 2003
// Creation Date: 2007/08/12
// Description: XML parser
//
// Authors: Jacky Zhou, zyx040404@163.com
//
//////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <algorithm>
#include <Shlobj.h>
#include <ShObjIdl.h>
#include <PROCESS.H>
#include "SAMA.h"
#include "SAMALog/ILogger.h"
#include "SAMALog/LoggerImpl.h"
#include "SAMARegularString/IStringMatchService.h"
#include "SAMARegularString/StringMatchServiceImpl.h"
#include "SAMARegistry/IRegistryKnob.h"
#include "SAMARegistry/RegistryKnobImpl.h"
#include "SAMAXML/IXMLParser.h"
#include "SAMAXML/XMLParserImpl.h"
#include "SAMAScanFile/IScanFile.h"
#include "SAMAScanFile/ScanFileImpl.h"
#include "SAMAResource/ResourceImpl.h"
#include "dbgw/IDBGW.h"
#include "dbgw/DBGWImpl.h"
#include "MD5/md5.h"
using namespace std;
static CResourceImpl l_Resource;
//------------------------------------------------------------------------------------------------------
// GetSAMAVersion
//------------------------------------------------------------------------------------------------------
SAMA_API float GetSAMAVersion()
{
return 2.0;
}
//------------------------------------------------------------------------------------------------------
// FileSizeK
//------------------------------------------------------------------------------------------------------
__int64 FileSizeK(DWORD high, DWORD low)
{
__int64 k = 0;
if (high != 0)
{
k = high;
k <<= 22; // shift left 32 since high order, then right 10 to divide by 1024
}
k += (low / 1024);
return k;
}
//------------------------------------------------------------------------------------------------------
// GetFileSize
//------------------------------------------------------------------------------------------------------
__int64 GetFileSize(const TSTRING & sFullFileName, WIN32_FIND_DATA & win32FindData)
{
__int64 i64FileSize = 0;
if (win32FindData.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)
{
__int64 i64ActualSize = 0;
DWORD dwActualSizeLow = 0;
DWORD dwActualSizeHigh = 0;
dwActualSizeLow = GetCompressedFileSize(sFullFileName.c_str(), &dwActualSizeHigh);
if (dwActualSizeHigh > 0)
{
i64ActualSize = dwActualSizeHigh;
i64ActualSize <<= 32;
}
i64ActualSize += dwActualSizeLow;
i64FileSize = (i64ActualSize / 1024);
}
else
i64FileSize = max(FileSizeK(win32FindData.nFileSizeHigh, win32FindData.nFileSizeLow), 1);
return i64FileSize;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
//******************************************************************************************************
// structs definition
//******************************************************************************************************
enum SCAN_FILE_ERROR
{
HF_error,
HF_continue,
HF_done
};
//******************************************************************************************************
// classes
//******************************************************************************************************
//------------------------------------------------------------------------------------------------------
// CreateILogger
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateILogger()
{
CLoggerImpl * pRK = new CLoggerImpl();
return static_cast<void *> (pRK);
}
//------------------------------------------------------------------------------------------------------
// CreateIRegistryKnob
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIRegistryKnob()
{
CRegistryKnobImpl* pRK = new CRegistryKnobImpl();
return static_cast<void *> (pRK);
}
//------------------------------------------------------------------------------------------------------
// CreateIStringMatchService
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIStringMatchService()
{
CStringMatchServiceImpl* pSMS = new CStringMatchServiceImpl();
return static_cast<void *> (pSMS);
}
//------------------------------------------------------------------------------------------------------
// CreateIXMLParser
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIXMLParser()
{
CXMLParser* pXMLParser = new CXMLParser();
return static_cast<void *> (pXMLParser);
}
//------------------------------------------------------------------------------------------------------
// CreateIScanFile
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIScanFile()
{
CScanFileImpl* pScanFile = new CScanFileImpl();
return static_cast<void *> (pScanFile);
}
//------------------------------------------------------------------------------------------------------
// CreateIResource
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIResource()
{
CResourceImpl* pResource = new CResourceImpl();
return static_cast<void *> (pResource);
}
//------------------------------------------------------------------------------------------------------
// CreateIDBGW
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIDBGW()
{
CDBGWImpl* pDBGW = new CDBGWImpl();
return static_cast<void *> (pDBGW);
}
//------------------------------------------------------------------------------------------------------
// CreateIMD5
//------------------------------------------------------------------------------------------------------
SAMA_API void * CreateIMD5()
{
CMD5* pMD5 = new CMD5();
return static_cast<void *> (pMD5);
}
//******************************************************************************************************
// string functions
//******************************************************************************************************
//------------------------------------------------------------------------------------------------------
// CompareStringWithoutCase
//------------------------------------------------------------------------------------------------------
SAMA_API int CompareStringWithoutCase(const TSTRING & s1, const TSTRING & s2)
{
return _tcsicmp (s1.c_str(), s2.c_str());
}
//------------------------------------------------------------------------------------------------------
// FindStringWithoutCase
//------------------------------------------------------------------------------------------------------
SAMA_API size_t FindStringWithoutCase(const TSTRING & s1, const TSTRING & s2)
{
TSTRING sLower1 = stolower(s1);
TSTRING sLower2 = stolower(s2);
return sLower1.find(sLower2);
}
//------------------------------------------------------------------------------------------------------
// stoupper
//------------------------------------------------------------------------------------------------------
SAMA_API TSTRING stoupper(const TSTRING & s)
{
TSTRING upper(s);
for(size_t i=0; i<s.length(); i++)
upper[i] = _totupper(upper[i]);
return upper;
}
//---------------------------------------------------------------------------------