void FindFiles(LPWSTR path,const LPWSTR *fileMasks,DWORD fileMasksCount,DWORD flags,FINDFILEPROC findFileProc,void *data,HANDLE stopEvent,DWORD subfolderDelay,DWORD foundedDelay) { WCHAR curPath[MAX_PATH]; WIN32_FIND_DATAW wfd; HANDLE handle; if ((_PathCombine(curPath,path,L"*")) && ((handle=FindFirstFileW(curPath,&wfd)) != INVALID_HANDLE_VALUE)) { do { if ((stopEvent != NULL) && (WaitForSingleObject(stopEvent,0) != WAIT_TIMEOUT)) break; if (!IsDotsName(wfd.cFileName)) { if (((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (flags & FFFLAG_SEARCH_FOLDERS)) || ((!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) && (flags & FFFLAG_SEARCH_FILES))) { for (DWORD i=0; i < fileMasksCount; i++) { if (PathMatchSpecW(wfd.cFileName,fileMasks[i]) != FALSE) { if (!findFileProc(path,&wfd,data)) goto END; if (flags & FFFLAG_DELETE) { WCHAR filePath[MAX_PATH]; if (_PathCombine(filePath,path,wfd.cFileName)) { SetFileAttributesW(filePath,FILE_ATTRIBUTE_NORMAL); DeleteFileW(filePath); } } if (foundedDelay) Sleep(foundedDelay); break; } } } if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && flags & FFFLAG_RECURSIVE) { if (_PathCombine(curPath,path,wfd.cFileName)) { if (subfolderDelay) Sleep(subfolderDelay); FindFiles(curPath,fileMasks,fileMasksCount,flags,findFileProc,data,stopEvent,subfolderDelay,foundedDelay); } } } } while (FindNextFileW(handle,&wfd) != FALSE); END: FindClose(handle); } return; }
/************************************************************************** * IShellBrowserImpl_ICommDlgBrowser_IncludeObject */ static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface, IShellView * ppshv, LPCITEMIDLIST pidl) { FileOpenDlgInfos *fodInfos; ULONG ulAttr; STRRET str; WCHAR szPathW[MAX_PATH]; IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface); TRACE("(%p)\n", This); fodInfos = get_filedlg_infoptr(This->hwndOwner); ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK; IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr); if( (ulAttr & SFGAO_HIDDEN) || /* hidden */ !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */ return S_FALSE; /* always include directories and links */ if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK)) return S_OK; /* if the application takes care of including the item we are done */ if(fodInfos->ofnInfos->Flags & OFN_ENABLEINCLUDENOTIFY && send_includeitem_notification(This->hwndOwner, pidl)) return S_OK; /* Check if there is a mask to apply if not */ if(!fodInfos->ShellInfos.lpstrCurrentFilter || !fodInfos->ShellInfos.lpstrCurrentFilter[0]) return S_OK; if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str))) { if (COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)) { if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter)) return S_OK; } } return S_FALSE; }
int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) { wchar_t *pat = NULL; wchar_t *name = NULL; BOOL match; (void) __flags; name = c_utf8_string_to_locale(__name); pat = c_utf8_string_to_locale(__pattern); match = PathMatchSpecW(name, pat); c_free_locale_string(pat); c_free_locale_string(name); if(match) return 0; else return 1; }
/************************************************************************** * IShellBrowserImpl_ICommDlgBrowser_IncludeObject */ static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface, IShellView * ppshv, LPCITEMIDLIST pidl) { FileOpenDlgInfos *fodInfos; ULONG ulAttr; STRRET str; WCHAR szPathW[MAX_PATH]; IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface); TRACE("(%p)\n", This); fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr); ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK; IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr); if( (ulAttr & SFGAO_HIDDEN) /* hidden */ | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */ return S_FALSE; /* always include directories and links */ if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK)) return S_OK; /* Check if there is a mask to apply if not */ if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter)) return S_OK; if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str))) { if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl))) { if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter)) return S_OK; } } return S_FALSE; }
BOOL WINAPI is_specialdll(UINT_PTR callerAddress,LPCWSTR dll_file) { BOOL ret = FALSE; HMODULE hCallerModule = NULL; if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)callerAddress, &hCallerModule)) { WCHAR szModuleName[VALUE_LEN+1] = {0}; if ( GetModuleFileNameW(hCallerModule, szModuleName, VALUE_LEN) ) { if ( StrChrW(dll_file,L'*') || StrChrW(dll_file,L'?') ) { if ( PathMatchSpecW(szModuleName, dll_file) ) { ret = TRUE; } } else if ( stristrW(szModuleName, dll_file) ) { ret = TRUE; } } } return ret; }
// // Searches files by several patterns // VOID FilesScanExW( LPWSTR path, const LPWSTR* fileMasks, LONG fileMasksCount, DWORD flags, FINDFILEPROC findFileProc, PVOID data, HANDLE stopEvent, DWORD subfolderDelay, DWORD foundedDelay ) { WCHAR curPath[MAX_PATH]; WIN32_FIND_DATAW wfd; HANDLE hFind; BOOL fbExit = FALSE; int i; if(FilesPathCombineW(curPath, path, L"*") && (hFind = FindFirstFileW(curPath, &wfd)) != INVALID_HANDLE_VALUE) { do { // stop? if(stopEvent != NULL && WaitForSingleObject(stopEvent, 0) != WAIT_TIMEOUT){ break; } if(!FilesIsDotsNameW(wfd.cFileName)) { // check pattern if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && flags & FFFLAG_SEARCH_FOLDERS) || (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && flags & FFFLAG_SEARCH_FILES)) { for( i = 0; i < fileMasksCount; i++) { if( PathMatchSpecW(wfd.cFileName, fileMasks[i]) != FALSE) { if(!findFileProc(path, &wfd, data)){ fbExit = TRUE; // exit while loop break; } if(foundedDelay != 0) { Sleep(foundedDelay); } break; } } } // recursive scan if(!fbExit && ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (flags & FFFLAG_RECURSIVE))) { if(FilesPathCombineW(curPath, path, wfd.cFileName)) { if(subfolderDelay != 0) { Sleep(subfolderDelay); } FilesScanExW(curPath, fileMasks, fileMasksCount, flags, findFileProc, data, stopEvent, subfolderDelay, foundedDelay); } } } // if(!FilesIsDotsNameW(wfd.cFileName)) }while( !fbExit && (FindNextFileW(hFind, &wfd) != FALSE)); FindClose(hFind); } // if(FilesPathCombineW(... }
BOOL WINAPI in_whitelist(LPCWSTR lpfile) { WCHAR *moz_processes[] = {L"", L"plugin-container.exe", L"plugin-hang-ui.exe", L"webapprt-stub.exe", L"webapp-uninstaller.exe",L"WSEnable.exe",L"uninstall\\helper.exe", L"crashreporter.exe",L"CommandExecuteHandler.exe",L"maintenanceservice.exe", L"maintenanceservice_installer.exe",L"updater.exe" }; static WCHAR white_list[EXCLUDE_NUM][VALUE_LEN+1]; int i = sizeof(moz_processes)/sizeof(moz_processes[0]); LPCWSTR pname = lpfile; BOOL ret = FALSE; if (lpfile[0] == L'"') { pname = &lpfile[1]; } /* 遍历白名单一次,只需遍历一次 */ ret = stristrW(white_list[1],L"plugin-container.exe") != NULL; if ( !ret ) { /* firefox目录下进程的路径 */ int num; WCHAR temp[VALUE_LEN+1]; GetModuleFileNameW(NULL,temp,VALUE_LEN); wcsncpy(white_list[0],(LPCWSTR)temp,VALUE_LEN); PathRemoveFileSpecW(temp); for(num=1; num<i; ++num) { _snwprintf(white_list[num],VALUE_LEN,L"%ls\\%ls", temp, moz_processes[num]); } ret = foreach_section(L"whitelist", &white_list[num], EXCLUDE_NUM-num); } if ( (ret = !ret) == FALSE ) { /* 核对白名单 */ for ( i=0; i<EXCLUDE_NUM ; i++ ) { if (wcslen(white_list[i]) == 0) { continue; } if ( StrChrW(white_list[i],L'*') || StrChrW(white_list[i],L'?') ) { if ( PathMatchSpecW(pname,white_list[i]) ) { ret = TRUE; break; } } else if (white_list[i][1] != L':') { PathToCombineW(white_list[i],VALUE_LEN); } if (_wcsnicmp(white_list[i],pname,wcslen(white_list[i]))==0) { ret = TRUE; break; } } } return ret; }
/************************************************************************* * PathMatchSpec [SHELL32.46] */ BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask) { if (SHELL_OsIsUnicode()) return PathMatchSpecW( name, mask ); return PathMatchSpecA( name, mask ); }