int strnatcmp(const TCHAR *psz1, const TCHAR *psz2) { int ai, bi; TCHAR ca, cb; int fractional, result; __try{ TCHAR a [MAX_PATH]; TCHAR b [MAX_PATH]; memset(a, 0, MAX_PATH); memset(b, 0, MAX_PATH); _tcscpy_s(a, MAX_PATH, psz1); _tcscpy_s(b, MAX_PATH, psz2); _tcslwr_s(a, MAX_PATH); _tcslwr_s(b, MAX_PATH); ai = bi = 0; while (1) { ca = a[ai]; cb = b[bi]; /* skip over leading spaces or zeros */ while (_is_meaningless_char(ca)) ca = a[++ai]; while (_is_meaningless_char(cb)) cb = b[++bi]; /* process run of digits */ if (_istdigit(ca) && _istdigit(cb)) { fractional = (ca == '0' || cb == '0'); if (fractional) { if ((result = compare_left(a + ai, b + bi)) != 0) return result; } else { if ((result = compare_right(a + ai, b + bi)) != 0) return result; } } if (!ca && !cb) { /* The strings compare the same. Perhaps the caller will want to call strcmp to break the tie. */ return 0; } if (ca < cb) return -1; else if (ca > cb) return +1; ++ai; ++bi; } }__except(EXCEPTION_EXECUTE_HANDLER){} return 0; }
static bool CheckFilter(const TCHAR *str,const TCHAR *filter) { TCHAR tstr[80]={0},tfilter[80]={0}; _tcsncpy_s(tstr,sizeof(tstr)/sizeof(TCHAR),str,_TRUNCATE); _tcsncpy_s(tfilter,sizeof(tfilter)/sizeof(TCHAR),filter,_TRUNCATE); _tcslwr_s(tstr,sizeof(tstr)/sizeof(TCHAR)); _tcslwr_s(tfilter,sizeof(tfilter)/sizeof(TCHAR)); if(_tcsstr(tstr,tfilter)) return TRUE; else return FALSE; }
TCHAR * _tcsstr_nocase ( const TCHAR * str1, const TCHAR * str2 ) { TCHAR *cp = (TCHAR *) str1; TCHAR *s1, *s2; if ( !*str2 ) return((TCHAR *)str1); while (*cp) { s1 = cp; s2 = (TCHAR *) str2; while ( *s1 && *s2 ) { TCHAR szCmp [3] = { *s1, *s2, _T('\0') }; _tcslwr_s (szCmp, 3); if ( szCmp[0]-szCmp[1] ) break; s1++, s2++; } if (!*s2) return(cp); cp++; } return(NULL); }
bool ExtInfoManager::IsValidImageFileExt(const TCHAR * szFilename) { TCHAR szExt[MAX_PATH] = { 0, }; SplitPath(szFilename, NULL,0, NULL,0 , NULL,0 , szExt,MAX_PATH); if ( _tcslen(szExt) < 2 ) return false; TCHAR szLowerExt[MAX_PATH] = { 0, }; _tcsncpy_s(szLowerExt, szExt, min(_tcslen(szExt)+1, MAX_PATH)); _tcslwr_s(szLowerExt); const TCHAR * szExtOnly = szLowerExt + 1; std::vector < ExtSetting >::iterator it, endit = m_extConnect.end(); bool bFound = false; for ( it = m_extConnect.begin(); it != endit; ++it ) { if ( _tcscmp(szExtOnly, it->m_strExt.c_str()) == 0 ) { bFound = true; } } return bFound; }
// Library entry point. When you register a browser helper object, it will be // looaded by both IE and Windows Explorer. We want nothing to do with Windows // Explorer, so we refuse to load when it calls us. BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved ) { TCHAR pszLoader[MAX_PATH]; OpenLog(); switch (dwReason) { case DLL_PROCESS_ATTACH: hDllModule = hModule; DllRegisterServer(); GetModuleFileName(NULL, pszLoader, MAX_PATH); _tcslwr_s(pszLoader, MAX_PATH); if (_tcsstr(pszLoader, _T("explorer.exe"))) { return FALSE; } ActiveScriptSite_CreateFactory(); OnDocument_CreateFactory(hModule); ObjectWithSite_CreateFactory(); ScriptContext_CreateFactory(); Observable_CreateFactory(); hDllModule = hModule; break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; } return TRUE; }
STDMETHODIMP_(BOOL) CStatistic::SendStatUrlExWithSigned( LPCWSTR lpszType, LPCWSTR lpszAction, BOOL bUseThread /*= TRUE*/, StatUrlSendStateCallback stateCallback /*= NULL*/) { if (!lpszType || !lpszAction) return FALSE; CString strUrl = SIGN_STATS_URL; ReplacePlaceholders(strUrl, lpszType, lpszAction); CString strSignParam = SIGN_PARAM; ReplacePlaceholders(strSignParam, lpszType, lpszAction); Utf8 u8(strSignParam); const char * pszParam = u8.AsSz(); BYTE md5[16] = {}; WCHAR szMd5[MAX_PATH] = {}; CCommonAlgorithm::MakeBuffMd5((LPVOID)pszParam, u8.Len8() - 1, md5);/// -'0' CCommonAlgorithm::ConvertMD5SumToChar(md5, szMd5, MAX_PATH); _tcslwr_s(szMd5); if (strUrl.Find(URL_SIGN) > 0) { strUrl.Replace(URL_SIGN, szMd5); } return DownloadFile(strUrl, NULL, bUseThread, 0, stateCallback); }
BOOL IEHistoryLog::GetLog( Json::Value &log_value ) { CComPtr<IUrlHistoryStg2> history; CComPtr<IEnumSTATURL> enum_staturl; STATURL url = {0}; url.cbSize = sizeof(url); std::map<CString, int> url_map; if(FAILED(CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg2, (void**)&history))) { return FALSE; } if(FAILED(history->EnumUrls(&enum_staturl))) { return FALSE; } enum_staturl->Reset(); CString url_str; ULONG fetched = 0; while(SUCCEEDED(enum_staturl->Next(1, &url, &fetched))) { if(fetched == 0) { break; } if (url.pwcsUrl) { if (_wcsnicmp(url.pwcsUrl, L"http", 4) == 0) { URL_COMPONENTS url_component = {0}; url_component.dwStructSize = sizeof(url_component); TCHAR host_name[INTERNET_MAX_HOST_NAME_LENGTH] = {0}; url_component.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH; url_component.lpszHostName = host_name; InternetCrackUrl(url.pwcsUrl, wcslen(url.pwcsUrl), ICU_DECODE, &url_component); _tcslwr_s(host_name); url_map[host_name]++; } } if (url.pwcsTitle) { CoTaskMemFree(url.pwcsTitle); url.pwcsTitle = NULL; } if (url.pwcsUrl) { CoTaskMemFree(url.pwcsUrl); url.pwcsUrl = NULL; } } for (std::map<CString, int>::iterator it = url_map.begin(); it != url_map.end(); ++it) { Json::Value item; item["host_name"] = CT2A(it->first.GetString()).m_psz; item["count"] = it->second; log_value.append(item); } return TRUE; }
XPropHero::xPROP* XPropHero::GetpProp( LPCTSTR szIdentifier ) { TCHAR szBuff[ 256 ]; _tcscpy_s( szBuff, szIdentifier ); _tcslwr_s( szBuff ); map<_tstring, xPROP*>::iterator itor; itor = m_mapData.find( szBuff ); if( itor == m_mapData.end() ) return NULL; // 못찾았으면 널 리턴 xPROP* pProp = (*itor).second; XBREAK( pProp == NULL ); // 위에서 find로 검사했기때문에 NULL나와선 안됨. return pProp; }
BOOL WINAPI KDumpModuleAnalyzer::FindExceptionModule( PTSTR ModuleName, DWORD64 ModuleBase, ULONG ModuleSize, PVOID UserContext ) { BOOL bResult =false; BOOL bRetCode =false; KDumpModuleInfo *pDumpModuleInfo = NULL; KG_PROCESS_ERROR(ModuleName); KG_PROCESS_ERROR(UserContext); pDumpModuleInfo = (KDumpModuleInfo *)UserContext; #ifdef OPEN_LOG_AND_BREAK KLogPrintf( "FindExceptionModule=>Name:%s\tBase:%p\tSize:%lld\tSearch:%llp", ModuleName, ModuleBase, ModuleSize, pDumpModuleInfo->dwStackAddress ); #endif bRetCode = pDumpModuleInfo->dwStackAddress >= ModuleBase && pDumpModuleInfo->dwStackAddress <= ModuleBase + ModuleSize; KG_PROCESS_ERROR(bRetCode); pDumpModuleInfo->dwModuleBase = ModuleBase; TCHAR *pSlash = _tcsrchr(ModuleName, _T('\\')); if (!pSlash) pSlash = ModuleName; else pSlash++; _tcsncpy(pDumpModuleInfo->szModuleName, pSlash, sizeof(pDumpModuleInfo->szModuleName) / sizeof(pDumpModuleInfo->szModuleName[0])); pDumpModuleInfo->szModuleName[sizeof(pDumpModuleInfo->szModuleName) / sizeof(pDumpModuleInfo->szModuleName[0]) - 1] = _T('\0'); _tcslwr_s(pDumpModuleInfo->szModuleName, sizeof(pDumpModuleInfo->szModuleName) / sizeof(pDumpModuleInfo->szModuleName[0])); pDumpModuleInfo->nFindDumpModuleFlag = true; bResult = TRUE; Exit0: return !bResult; }
bool FindFileExt(LPCTSTR pstrPath, LPCTSTR pstrExtFilter) { if (! pstrPath || ! pstrExtFilter) { return false; } TCHAR szExt[_MAX_EXT] = _T(""); _tsplitpath_s(pstrPath, NULL, 0, NULL, 0, NULL, 0, szExt, _MAX_EXT); _tcslwr_s(szExt, _MAX_EXT); if(_tcslen(szExt)) { _tcscat_s(szExt, _MAX_EXT, _T(";")); // .mo不符合条件,由于会匹配到.mov,所以在后面加上【;】来判断是否完全匹配 return NULL != _tcsstr(pstrExtFilter, szExt); } return false; }
///////////////////////////////////////////////////////////////////////////// // This function performs case-insensitive search that makes unnecessary case conversions LPCTSTR _tcsistr(LPCTSTR ptszStr1, LPCTSTR ptszStr2) { LPCTSTR cp(ptszStr1); LPCTSTR s1; LPCTSTR s2; if (!*ptszStr2) { return ptszStr1; } while (*cp) { s1 = cp; s2 = ptszStr2; while (*s1 && *s2) { TCHAR szCmp [3] = { *s1, *s2, _T('\0') }; #if _MSC_VER >= 1400 _tcslwr_s (szCmp, sizeof(szCmp)); #else _tcslwr (szCmp); #endif if ( szCmp[0]-szCmp[1] ) break; s1++, s2++; } if (!*s2) { return(cp); } cp++; } return(NULL); }
BOOL ParameterCheck(int argc, _TCHAR* argv[], UINT & loop_times, DWORD & ms_between_loop, BOOL & enable_logs, TCHAR * p_command_buf, ULONG command_buf_size) // loop -cmd "dir *.exe" -times 5 -sleep 2 -log // loop -c "dir *.exe" -t 5 -s 2 -l // loop dir *.exe { assert(argv); assert(p_command_buf); BOOL result = FALSE; loop_times = 0; ms_between_loop = 1000; enable_logs = FALSE; dbgtprintf(_T("%d parameter(s)\n"), argc - 1 ); for(int i = 0; i< argc; i++) { dbgtprintf(_T("%s\n"),argv[i]); } if ( 1 == argc ) { // Do nothing here, To Invoke PrintUsage(argv[0]); } else { int len = _tcsnlen(argv[1],CMD_OPTION_LENGTH); dbgtprintf(_T("len of argv[1] = %d\n"), len); if ( 0 < len ) { _tcslwr_s(argv[1], len+1); //_tcsdup } else { // do nothing } if ( 0 == _tcsncmp(OPTION_CMD,argv[1], _tcslen(OPTION_CMD)) || 0 == _tcsncmp(OPTION_C,argv[1],_tcslen(OPTION_C)) || 0 == _tcsncmp(OPTION_TIMES,argv[1], _tcslen(OPTION_TIMES)) || 0 == _tcsncmp(OPTION_T,argv[1],_tcslen(OPTION_T)) || 0 == _tcsncmp(OPTION_SLEEP,argv[1], _tcslen(OPTION_SLEEP)) || 0 == _tcsncmp(OPTION_S,argv[1],_tcslen(OPTION_S)) || 0 == _tcsncmp(OPTION_LOG,argv[1], _tcslen(OPTION_LOG)) || 0 == _tcsncmp(OPTION_L,argv[1],_tcslen(OPTION_L)) ) { dbgtprintf(_T("Parameters Mode.\n")); int iExpectedParameters = 0; BOOL bGetCmdFromOpt = FALSE; BOOL bGetTimesFromOpt = FALSE; BOOL bGetSleepFromOpt = FALSE; BOOL bGetLogFromOpt = FALSE; result = TRUE; for( int i = 1; i < argc; i++ ) { int len = _tcsnlen(argv[i],CMD_OPTION_LENGTH); dbgtprintf(_T("len of argv[%d] = %d"), i, len); if ( 0 < len ) { _tcslwr_s(argv[i], len+1); //_tcsdup } else { // do nothing } if ( !bGetCmdFromOpt && ( 0 == _tcsncmp(OPTION_CMD,argv[i], _tcslen(OPTION_CMD)) || 0 == _tcsncmp(OPTION_C, argv[i], _tcslen(OPTION_C)) ) ) { dbgtprintf(_T("Get Command From Option\n")); if ( i + 1 < argc && !IsPureSpace(argv[i+1], CMD_PARAMETER_LENGTH_LIMIT) && _tcsnlen(argv[i+1], CMD_PARAMETER_LENGTH_LIMIT) > 0 ) { dbgtprintf(_T("Command Length, %d\n"), _tcsnlen(argv[i+1], CMD_PARAMETER_LENGTH_LIMIT)); bGetCmdFromOpt = TRUE; iExpectedParameters += 2; ULONG position = 0; _stprintf_s(p_command_buf, command_buf_size-position-1, _T("%s "), BASE_CMD); position += _tcsnlen(BASE_CMD, CMD_PARAMETER_LENGTH_LIMIT) + 1; _stprintf_s(p_command_buf + position, command_buf_size-position-1, _T("%s"), argv[i+1]); dbgtprintf(_T("Command: %s\n"),p_command_buf); } else { bGetCmdFromOpt = FALSE; result = FALSE; _tprintf(_T("Invalid \"command\" Parameter!\n") ); } } else if ( !bGetTimesFromOpt && ( 0 == _tcsncmp(OPTION_TIMES,argv[i], _tcslen(OPTION_TIMES)) || 0 == _tcsncmp(OPTION_T, argv[i], _tcslen(OPTION_T)) ) ) { dbgtprintf(_T("Get Times From Option\n")); if ( i + 1 < argc && IsPureDigital(argv[i+1], CMD_PARAMETER_LENGTH_LIMIT) ) { bGetTimesFromOpt = TRUE; iExpectedParameters += 2; // to-do loop_times = _tcstoul(argv[i+1], NULL, 10 ); if ( loop_times >= TIMES_MIN && loop_times <= TIMES_MAX ) { dbgtprintf(_T("Times: %d\n"), loop_times); } else { result = FALSE; _tprintf(_T("Invalid Range of \"times\" Parameter!\n")); } } else { bGetTimesFromOpt = FALSE; result = FALSE; _tprintf(_T("Invalid \"times\" Parameter!\n")); } } else if ( !bGetSleepFromOpt && ( 0 == _tcsncmp(OPTION_SLEEP, argv[i], _tcslen(OPTION_SLEEP)) || 0 == _tcsncmp(OPTION_S, argv[i], _tcslen(OPTION_S)) ) ) { dbgtprintf(_T("Get Sleep From Option\n")); if ( i + 1 < argc && IsPureDigital(argv[i+1], CMD_PARAMETER_LENGTH_LIMIT) ) { bGetSleepFromOpt = TRUE; iExpectedParameters += 2; // to-do DWORD s_between_loop = _tcstoul(argv[i+1], NULL, 10 ); if (s_between_loop >= SLEEP_MIN && s_between_loop <= SLEEP_MAX) { ms_between_loop = s_between_loop * 1000; dbgtprintf(_T("Sleep: %d\n"),ms_between_loop); } else { result = FALSE; _tprintf(_T("Invalid Range of \"sleep\" Parameter!\n")); } } else { bGetSleepFromOpt = FALSE; result = FALSE; _tprintf(_T("Invalid \"sleep\" Parameter!\n")); } } else if ( !bGetLogFromOpt && ( 0 == _tcsncmp(OPTION_LOG, argv[i], _tcslen(OPTION_LOG)) || 0 == _tcsncmp(OPTION_L, argv[i], _tcslen(OPTION_L)) ) ) { dbgtprintf(_T("Get Log From Option\n")); bGetLogFromOpt = TRUE; enable_logs = TRUE; iExpectedParameters++; } else { dbgtprintf(_T("Other parameters from command line: %s\n"), argv[i]); } if ( FALSE == result ) { break; } } if ( result == TRUE && FALSE == bGetCmdFromOpt ) { result = FALSE; _tprintf(_T("The \"cmd\" Parameter is Mandantory!\n") ); } if ( result == TRUE && iExpectedParameters != argc - 1) { result = FALSE; dbgtprintf(_T("iExpectedParameters = %d, argc - 1 = %d\n"), iExpectedParameters, argc - 1); _tprintf(_T("Too many parameters!\n"), iExpectedParameters, argc - 1); } } else { result = TRUE; dbgtprintf(_T("Always Loop Mode.\n")); dbgtprintf(_T("%p, %p\n"), p_command_buf, p_command_buf+1); ULONG position = 0; for(int i = 0; i < argc; i++) { if( 0 == i ) { dbgtprintf(_T("s,%d\n"),i); _stprintf_s(p_command_buf + position, command_buf_size-position-1, _T("%s "), BASE_CMD); position += _tcsnlen(BASE_CMD, CMD_PARAMETER_LENGTH_LIMIT) + 1; dbgtprintf(_T("e,%d\n"),i); } else { dbgtprintf(_T("s,%d\n"),i); dbgtprintf(_T("%s\n"),argv[i]); _stprintf_s(p_command_buf + position, command_buf_size-position-1, _T("%s "), argv[i]); position += _tcsnlen(argv[i], CMD_PARAMETER_LENGTH_LIMIT) + 1; dbgtprintf(_T("e,%d\n"),i); } } dbgtprintf(_T("Command: %s\n"),p_command_buf); } } return result; }
/*----------------------------------------------------------------------------- Close any dialog windows that may be open -----------------------------------------------------------------------------*/ void CurlBlastDlg::CloseDialogs(void) { TCHAR szTitle[1025]; // make sure wptdriver isn't doing a software install bool installing = false; HWND hWptDriver = ::FindWindow(_T("wptdriver_wnd"), NULL); if (hWptDriver) { if (::GetWindowText(hWptDriver, szTitle, _countof(szTitle))) { CString title = szTitle; title.MakeLower(); if (title.Find(_T(" software")) >= 0) installing = true; } } // if there are any explorer windows open, disable this code (for local debugging and other work) if( !installing && !::FindWindow(_T("CabinetWClass"), NULL ) ) { HWND hDesktop = ::GetDesktopWindow(); HWND hWnd = ::GetWindow(hDesktop, GW_CHILD); TCHAR szClass[100]; CArray<HWND> hDlg; const TCHAR * szKeepOpen[] = { _T("urlblast") , _T("url blast") , _T("task manager") , _T("aol pagetest") , _T("choose file") , _T("network delay simulator") , _T("shut down windows") , _T("vmware") , _T("security essentials") }; // build a list of dialogs to close while(hWnd) { if(hWnd != m_hWnd) { if(::IsWindowVisible(hWnd)) if(::GetClassName(hWnd, szClass, 100)) if((!lstrcmp(szClass,_T("#32770"))||!lstrcmp(szClass,_T("Internet Explorer_Server")))) // check window title for all classes { bool bKill = true; // make sure it is not in our list of windows to keep if(::GetWindowText( hWnd, szTitle, 1024)) { log.Trace(_T("Killing Dialog: %s"), szTitle); _tcslwr_s(szTitle, _countof(szTitle)); for(int i = 0; i < _countof(szKeepOpen) && bKill; i++) { if(_tcsstr(szTitle, szKeepOpen[i])) bKill = false; } // do we have to terminate the process that owns it? if( !lstrcmp(szTitle, _T("server busy")) ) { log.Trace(_T("Terminating process")); DWORD pid; GetWindowThreadProcessId(hWnd, &pid); HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid); if( hProcess ) { TerminateProcess(hProcess, 0); CloseHandle(hProcess); } } } if(bKill) hDlg.Add(hWnd); } } hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); } // close all of the dialogs for(int i = 0; i < hDlg.GetSize(); i++) { //see if there is an OK button HWND hOk = ::FindWindowEx(hDlg[i], 0, 0, _T("OK")); if( hOk ) { int id = ::GetDlgCtrlID(hOk); if( !id ) id = IDOK; ::PostMessage(hDlg[i],WM_COMMAND,id,0); } else ::PostMessage(hDlg[i],WM_CLOSE,0,0); } } }
/*----------------------------------------------------------------------------- Kill any processes that we need closed -----------------------------------------------------------------------------*/ void TerminateProcs(void) { HWND hDesktop = ::GetDesktopWindow(); HWND hWnd = ::GetWindow(hDesktop, GW_CHILD); TCHAR szTitle[1025]; const TCHAR * szClose[] = { _T("urlblast") , _T("url blast") , _T("internet explorer") , _T("pagetest") }; // Send close messages to everything while(hWnd) { if(::IsWindowVisible(hWnd)) { if(::GetWindowText( hWnd, szTitle, 1024)) { bool bKill = false; _tcslwr_s(szTitle, _countof(szTitle)); for(int i = 0; i < _countof(szClose) && !bKill; i++) { if(_tcsstr(szTitle, szClose[i])) bKill = true; } if( bKill ) ::PostMessage(hWnd,WM_CLOSE,0,0); } } hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); } // go through and kill any procs that are still running // (wait long enough for them to exit gracefully first) const TCHAR * procs[] = { _T("urlblast.exe") , _T("iexplore.exe") , _T("pagetest.exe") }; // let our process kill processes from other users HANDLE hToken; if( OpenProcessToken( GetCurrentProcess() , TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY , &hToken) ) { TOKEN_PRIVILEGES tp; if( LookupPrivilegeValue( NULL , SE_DEBUG_NAME, &tp.Privileges[0].Luid ) ) { tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges( hToken , FALSE , &tp , 0 , (PTOKEN_PRIVILEGES) 0 , 0 ) ; } CloseHandle(hToken); } // go through and kill any matching procs WTS_PROCESS_INFO * proc = NULL; DWORD count = 0; if( WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, &proc, &count) ) { for( DWORD i = 0; i < count; i++ ) { TCHAR * file = proc[i].pProcessName; bool kill = false; for(int j = 0; j < _countof(procs) && !kill; j++) { if( !lstrcmpi(PathFindFileName(proc[i].pProcessName), procs[j]) ) kill = true; } if( kill ) { HANDLE hProc = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, FALSE, proc[i].ProcessId); if( hProc ) { // give it 2 minutes to exit on it's own if( WaitForSingleObject(hProc, 120000) != WAIT_OBJECT_0 ) TerminateProcess(hProc, 0); CloseHandle(hProc); } } } WTSFreeMemory(proc); } }