bool operator()(const FILE_TO_ADD& a,const FILE_TO_ADD& b){ //sort by ext int ret=stricmp(PathFindExtension(a.relativePath.c_str()),PathFindExtension(b.relativePath.c_str())); if(ret==0){ //sort by path if ext is same return stricmp(a.relativePath.c_str(),b.relativePath.c_str())<0; }else{ return ret<0; } }
FileType FileWatcherBaseWindows::platformFileType(std::string filename) { if(FileExtensions.find(wstring_to_utf8(PathFindExtension( utf8_to_wstring(filename).c_str() ))) != FileExtensions.end()) { return FileExtensions.at(wstring_to_utf8(PathFindExtension(utf8_to_wstring(filename).c_str()))); } else return FileType::ftFILE; }
BOOL IsImage(const TCHAR *szFileName) { static const TCHAR *IMAGE_EXTS[] = {_T("bmp"),_T("ico"), _T("gif"),_T("jpg"),_T("exf"),_T("png"),_T("tif"),_T("wmf"),_T("emf"),_T("tiff") }; TCHAR *ext; int i = 0; ext = PathFindExtension(szFileName); if(ext == NULL || (ext + 1) == NULL) { return FALSE; } ext++; for(i = 0; i < SIZEOF_ARRAY(IMAGE_EXTS); i++) { if(lstrcmpi(ext, IMAGE_EXTS[i]) == 0) { return TRUE; } } return FALSE; }
static int GetPrivateProfilePath(TCHAR *ini_file) { int ret = -1; // Allocate string buffers TCHAR *process_path = new TCHAR[FILE_PATH_MAX]; if (!process_path) goto EXIT; // Initliaze string buffers. memset(process_path, 0, sizeof(TCHAR) * FILE_PATH_MAX); // Get the full path name of the running process. DWORD dwRet = GetModuleFileName(NULL, process_path, sizeof(TCHAR) * FILE_PATH_MAX); if (dwRet == 0) goto EXIT; // Generate the ini file path. _tcscpy_s(ini_file, FILE_PATH_MAX, process_path); TCHAR *pExt = PathFindExtension(ini_file); _tcscpy_s(pExt, 5, _T(".ini")); ret = 0; EXIT: SAFE_DELETE_ARRAY(process_path); return ret; }
/// Initialization of the decryption process /// /// @param archive Archive /// u32 CHimesyo::OnInitDecrypt(CArcFile* archive) { const SFileInfo* file_info = archive->GetOpenFileInfo(); LPCTSTR file_ext = PathFindExtension(file_info->name); if (lstrcmp(file_ext, _T(".dll")) == 0 || file_info->name == _T("startup.tjs")) { // Files we don't decode SetDecryptRequirement(false); return 0; } // Size to decrypt if (lstrcmp(file_ext, _T(".ks")) != 0 && lstrcmp(file_ext, _T(".tjs")) != 0 && lstrcmp(file_ext, _T(".asd")) != 0) { SetDecryptSize(256); } // Decryption key m_change_decrypt_key = 0; return file_info->key ^ 0x03020100 ^ 0xFFFFFFFF; }
BOOL CChordEaseDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace) { CString ext(PathFindExtension(lpszPathName)); if (!ext.CompareNoCase(LEAD_SHEET_EXT)) // if lead sheet extension lpszPathName = NULL; // force SaveAs to native file extension return CDocument::DoSave(lpszPathName, bReplace); }
void CMainDlg::OnAdd() { int nCount = m_wndAccountListView.GetItemCount(); nCount++; TCHAR szRowIndex[20]={0}; _itot(nCount,szRowIndex,10); TCHAR szFilter[] = _T("Pdf Files (*.Pdf)\0*.Pdf\0All Files (*.*)\0*.*\0\0"); CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter,this->m_hWnd); WCHAR strBuffer[65535] = {0}; dlg.m_ofn.lpstrFile = strBuffer; dlg.m_ofn.nMaxFile = 65535; TCHAR infilename[MAX_PATH]={0}; if(dlg.DoModal() == IDOK ) { CString strbuf; TCHAR* pFilePath =NULL; TCHAR szFileDirectory[MAX_PATH]={0}; pFilePath = dlg.m_ofn.lpstrFile; _tcscpy(szFileDirectory,pFilePath); TCHAR* szFileTitle = dlg.m_ofn.lpstrFileTitle; PathRemoveFileSpec(szFileDirectory); TCHAR* szExt = PathFindExtension(pFilePath); int nSize = GetContextFileSize(pFilePath); TCHAR szSize[MAX_PATH]={0}; _stprintf(szSize,_T("%dK"),nSize); int nItem = m_wndAccountListView.Append(szRowIndex,NULL,0,LISTITEM_CHECKBOX); m_wndAccountListView.AppendSubItem(nItem,szFileTitle); m_wndAccountListView.AppendSubItem(nItem,szFileDirectory); m_wndAccountListView.AppendSubItem(nItem,szExt); m_wndAccountListView.AppendSubItem(nItem,szSize); } }
BOOL fileAutoRename(PSTR szName,DWORD dwName) { char szPath[_MAX_PATH]; char szTemp[_MAX_PATH]; char szExt[_MAX_PATH]; PSTR pName,pExt,pOrd; DWORD dwOrd; HANDLE hFile; //not exist ? if (INVALID_HANDLE_VALUE != (hFile=CreateFile(szName,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))){ CloseHandle(hFile); return TRUE; } strcpyN(szPath,sizeof(szPath),szName); pName = PathFindFileName(szPath); pExt = PathFindExtension(pName); strcpyN(szExt,sizeof(szExt),pExt); pOrd = pExt - 1; for(;;pOrd++){ if (*pOrd < '0' || *pOrd > '9') break; } pOrd++; dwOrd = atoi(pOrd); pOrd[0] = 0; for(;dwOrd<INT_MAX-1;dwOrd++){ strcpyV(szTemp,sizeof(szTemp),"%s%d%s",szPath,dwOrd,szExt); if (INVALID_HANDLE_VALUE != (hFile=CreateFile(szTemp,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))){ CloseHandle(hFile); strcpyN(szName,dwName,szTemp); return TRUE; } } return FALSE; }
void CZlib::DecompressFile(CArcFile* archive) { SFileInfo* file_info = archive->GetOpenFileInfo(); // Ensure buffer std::vector<u8> z_buf(file_info->sizeCmp); std::vector<u8> buf(file_info->sizeOrg); // zlib Decompression archive->Read(z_buf.data(), z_buf.size()); Decompress(buf.data(), &file_info->sizeOrg, z_buf.data(), z_buf.size()); if (lstrcmp(PathFindExtension(file_info->name), _T(".bmp")) == 0) { CImage image; image.Init(archive, buf.data()); image.Write(file_info->sizeOrg); } else { // Output archive->OpenFile(); archive->WriteFile(buf.data(), file_info->sizeOrg); } }
void CKaiDoc::OnFileSave() { // TODO: Add your command handler code here if (pco_Doc_->b_IsImported()) { OnFileSaveAs(); return; } CString cstr_path = GetPathName(); if (!cstr_path.IsEmpty()) { CString cstr_ext = PathFindExtension (cstr_path); SetPathName (CString (cstr_path.Left (cstr_path.GetLength() - cstr_ext.GetLength())) + _T(".kai")); } else { SetTitle (pco_Doc_->str_Title_.data()); } CDocument::OnFileSave(); if (IsModified()) { SetTitle (CString (pco_Doc_->str_Title_.data()) + _T("*")); } }
BOOL CLZSS::Decomp(CArcFile* pclArc, DWORD dwDicSize, DWORD dwDicPtr, DWORD dwLengthOffset) { SFileInfo* pstFileInfo = pclArc->GetOpenFileInfo(); // Read DWORD dwSrcSize = pstFileInfo->sizeCmp; YCMemory<BYTE> clmSrc(dwSrcSize); pclArc->Read(&clmSrc[0], dwSrcSize); // Buffer allocation for extraction DWORD dwDstSize = pstFileInfo->sizeOrg; YCMemory<BYTE> clmDst(dwDstSize); // Decompression Decomp(&clmDst[0], dwDstSize, &clmSrc[0], dwSrcSize, dwDicSize, dwDicPtr, dwLengthOffset); // Bitmap if (lstrcmp(PathFindExtension(pstFileInfo->name), _T(".bmp")) == 0) { CImage clImage; clImage.Init(pclArc, &clmDst[0]); clImage.Write(dwDstSize); clImage.Close(); } else // Other { pclArc->OpenFile(); pclArc->WriteFile(&clmDst[0], dwDstSize); pclArc->CloseFile(); } return TRUE; }
/// <summary>Determines whether path has a given extension (case insensitive)</summary> /// <param name="ext">The extention preceeded by a dot</param> /// <returns></returns> /// <exception cref="Logic::ArgumentNullException">Path is null</exception> bool Path::HasExtension(const WCHAR* ext) const { REQUIRED(ext); // Optimization for usage with literals return StrCmpI(PathFindExtension(Buffer.get()), ext) == 0; }
void CUpdateServersDlg::OnTimer(UINT_PTR nIDEvent) { CSkinDialog::OnTimer( nIDEvent ); if ( m_pRequest.IsPending() ) { int n = m_wndProgress.GetPos(); if ( n < 5 ) n = 5; else if ( n < 100 ) n++; m_wndProgress.SetPos( n ); } else { KillTimer( 1 ); if ( m_pRequest.GetStatusSuccess() ) { const CString strExt = CString( PathFindExtension( m_sURL ) ).MakeLower(); if ( strExt == L".met" || m_sURL.Find( _T("//server"), 8 ) > 8 ) // || strExt == L".php" Settings.eDonkey.ServerListURL = m_sURL; else if ( strExt == L".bz2" || m_sURL.Find( _T("hublist"), 8 ) > 8 ) Settings.DC.HubListURL = m_sURL; // else if ( strExt == L".xml" ) // Settings.Gnutella.CacheURL = m_sURL; // else if ( strExt == L".dat" ) // Settings.KAD.NodesListURL = m_sURL; const CBuffer* pBuffer = m_pRequest.GetResponseBuffer(); CMemFile pFile; pFile.Write( pBuffer->m_pBuffer, pBuffer->m_nLength ); pFile.Seek( 0, CFile::begin ); if ( ( strExt == L".bz2" && HostCache.ImportHubList( &pFile ) ) || HostCache.ImportMET( &pFile ) ) // HostCache.ImportCache( &pFile ) || // ToDo: G2/Gnutella loading // HostCache.ImportNodes( &pFile ) ) // ToDo: KAD { HostCache.Save(); m_sURL.Empty(); EndDialog( IDOK ); return; } } CString strError; strError.Format( LoadString( IDS_DOWNLOAD_DROPPED ), m_sURL ); MsgBox( strError, MB_OK | MB_ICONEXCLAMATION ); m_sURL.Empty(); EndDialog( IDCANCEL ); } UpdateWindow(); }
int wmain(int argc, WCHAR* argv[]) { if ((argc == 1) || ((argc == 2) && (lstrcmpi(argv[1], L"/?") == 0))) { ShowUsage(); return E_INVALIDARG; } int i = argc - 1; //File name is always the last option LPCWSTR szFilePath = argv[i]; //Find whether the file is a .exe or a .dll LPCWSTR szExtension = PathFindExtension(szFilePath); bool bExe = false; bool bCurrentUser = false; bool bUnregister = false; if (lstrcmpi(szExtension, TEXT(".exe")) == 0) bExe = true; //else default to dll //Parse the command line to find the other options i--; while(i > 0) { if (lstrcmpi(argv[i], L"/u") == 0) bUnregister = true; else if (lstrcmpi(argv[i], L"/c") == 0) bCurrentUser = true; // else // { // //Ignore the option // } i--; } HRESULT hr; if (bExe) { hr = RegisterExe(szFilePath, bUnregister, bCurrentUser); } else { hr = RegisterDll(szFilePath, bUnregister, bCurrentUser); } if (FAILED(hr)) ShowErrorMessage(hr); return hr; }
void ListFileInDirection(const char * path, const char * extension, const std::function<void(const char *, const char *)> &f) { #ifdef WIN32 WIN32_FIND_DATA finder; char tmp[512] = { 0 }; SafeSprintf(tmp, sizeof(tmp), "%s/*.*", path); HANDLE handle = FindFirstFile(path, &finder); if (INVALID_HANDLE_VALUE == handle) return; while (FindNextFile(handle, &finder)) { if (strcmp(finder.cFileName, ".") == 0 || strcmp(finder.cFileName, "..") == 0) continue; SafeSprintf(tmp, sizeof(tmp), "%s/%s", path, finder.cFileName); if (finder.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ListFileInDirection(tmp, extension, f); else { if (0 == strcmp(extension, PathFindExtension(finder.cFileName))) { PathRemoveExtension(finder.cFileName); f(finder.cFileName, tmp); } } } #else DIR * dp = opendir(path); if (dp == nullptr) return; struct dirent * dirp; while ((dirp = readdir(dp)) != nullptr) { if (dirp->d_name[0] == '.') continue; char tmp[256] = { 0 }; SafeSprintf(tmp, sizeof(tmp), "%s/%s", path, dirp->d_name); struct stat st; if (stat(tmp, &st) == -1) continue; if (S_ISDIR(st.st_mode)) ListFileInDirection(tmp, extension, f); else { if (0 == strcmp(extension, GetFileExt(dirp->d_name))) { char name[256]; SafeSprintf(name, sizeof(name), "%s", dirp->d_name); char * dot = strrchr(name, '.'); if (dot != nullptr) *dot = 0; f(name, tmp); } } } #endif }
LRESULT CFileTreeView::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (ID_POPMENU_OPEN == wParam) { std::wstring path = m_Org.GetSelectedPath(); ShellExecute(NULL, _T("open"), path.c_str(), 0, 0, SW_SHOWNORMAL); } else if (ID_POPMENU_OPENIN == wParam) { std::wstring path = m_Org.GetSelectedPath(); if (0 == wcscmp(L".boo", PathFindExtension(path.c_str()))) { ::SendMessage(GetParent(), WM_USER_MAINFRM_OPENFILE, (WPARAM)path.c_str(), 0); } } else if (ID_POPMENU_USEASROOT == wParam) { std::wstring path = m_Org.GetSelectedPath(); CString strDir = path.c_str(); strDir.TrimLeft(); strDir.TrimRight(); strDir.Replace(L'/', L'\\'); if (strDir.IsEmpty()) { m_Org.SetRootFolder(NULL); m_editDir.m_strDir = strDir; } else { //CString tmp = strDir.Right(1); if (L"\\" != strDir.Right(1)) { strDir += L"\\"; } DWORD hFillAtt = GetFileAttributes((LPCWSTR)strDir); if (INVALID_FILE_ATTRIBUTES == hFillAtt) { MessageBox( _T("Invalidat directory."), _T("Warning"), MB_OK|MB_ICONEXCLAMATION); } else { m_editDir.m_strDir = strDir; //::PostMessage(GetParent(), WM_USER_CHANG_DIR, 0, 0); //m_strDir = szDir; } } m_editDir.SetWindowText((LPCWSTR)(m_editDir.m_strDir)); m_editDir.SetSel(m_editDir.m_strDir.GetLength(), m_editDir.m_strDir.GetLength()); //m_editDir.SetFocus(); TreeView_SelectItem(m_Org.m_hWnd, NULL); m_Org.SetRootFolder((LPCWSTR)m_editDir.m_strDir); RecordMemberVariable(); } return 0; }
BOOL CSecureRule::Match(const CEnvyFile* pFile) const { if ( m_nType == srAddress || m_nType == srContentRegExp || m_nType == srExternal || ! ( pFile && m_pContent ) ) return FALSE; if ( m_nType == srSizeType ) { if ( pFile->m_nSize == 0 || pFile->m_nSize == SIZE_UNKNOWN ) return FALSE; LPCTSTR pszExt = PathFindExtension( (LPCTSTR)pFile->m_sName ); if ( *pszExt != L'.' ) return FALSE; pszExt++; CString strFilter = (LPCTSTR)m_pContent; strFilter = strFilter.Mid( 5 ); // "size:" if ( ! StartsWith( strFilter, pszExt ) ) return FALSE; strFilter = strFilter.Mid( strFilter.Find( L':' ) + 1 ); if ( strFilter.Find( L':' ) > 0 ) { QWORD nLower, nUpper, nSize = pFile->m_nSize; _stscanf( (LPCTSTR)strFilter, L"%I64i:%I64i", &nLower, &nUpper ); return nSize >= nLower && nSize <= nUpper; } if ( strFilter.Find( L'-' ) > 0 ) { QWORD nLower, nUpper, nSize = pFile->m_nSize; _stscanf( (LPCTSTR)strFilter, L"%I64i-%I64i", &nLower, &nUpper ); return nSize >= nLower && nSize <= nUpper; } CString strCompare; strCompare.Format( L"size:%s:%I64i", pszExt, pFile->m_nSize ); return strCompare == (CString)m_pContent; } if ( m_nType == srContentHash ) { LPCTSTR pszHash = m_pContent; if ( m_nContentLength < 30 || _tcsnicmp( pszHash, L"urn:", 4 ) != 0 ) return FALSE; return ( pFile->m_oSHA1 && pFile->m_oSHA1.toUrn() == pszHash ) || // Not Match( pFile->m_oSHA1.toUrn() ) ( pFile->m_oTiger && pFile->m_oTiger.toUrn() == pszHash ) || ( pFile->m_oED2K && pFile->m_oED2K.toUrn() == pszHash ) || ( pFile->m_oBTH && pFile->m_oBTH.toUrn() == pszHash ) || ( pFile->m_oMD5 && pFile->m_oMD5.toUrn() == pszHash ); } return Match( pFile->m_sName ); }
// Set full path file name in buffer object, // and determinate its language by its extension. // If the ext is not in the list, the defaultLang passed as argument will be set. void Buffer::setFileName(const TCHAR *fn, LangType defaultLang) { NppParameters *pNppParamInst = NppParameters::getInstance(); if (_fullPathName == fn) { updateTimeStamp(); doNotify(BufferChangeTimestamp); return; } _fullPathName = fn; _fileName = PathFindFileName(_fullPathName.c_str()); // for _lang LangType newLang = defaultLang; TCHAR *ext = PathFindExtension(_fullPathName.c_str()); if (*ext == '.') // extension found { ext += 1; // Define User Lang firstly const TCHAR* langName = pNppParamInst->getUserDefinedLangNameFromExt(ext, _fileName); if (langName) { newLang = L_USER; _userLangExt = langName; } else // if it's not user lang, then check if it's supported lang { _userLangExt.clear(); newLang = pNppParamInst->getLangFromExt(ext); } } if (newLang == defaultLang || newLang == L_TEXT) //language can probably be refined { if ((!generic_stricmp(_fileName, TEXT("makefile"))) || (!generic_stricmp(_fileName, TEXT("GNUmakefile")))) newLang = L_MAKEFILE; else if (!generic_stricmp(_fileName, TEXT("CmakeLists.txt"))) newLang = L_CMAKE; else if ((!generic_stricmp(_fileName, TEXT("SConstruct"))) || (!generic_stricmp(_fileName, TEXT("SConscript"))) || (!generic_stricmp(_fileName, TEXT("wscript")))) newLang = L_PYTHON; else if (!generic_stricmp(_fileName, TEXT("Rakefile"))) newLang = L_RUBY; } updateTimeStamp(); if (newLang != _lang || _lang == L_USER) { _lang = newLang; doNotify(BufferChangeFilename | BufferChangeLanguage | BufferChangeTimestamp); return; } doNotify(BufferChangeFilename | BufferChangeTimestamp); }
BOOL cm_TargetPerceivedAsDirectory(const fschar_t *target) { char * ext; ext = PathFindExtension(target); if (!ext[0]) return TRUE; return FALSE; }
BOOL CChordEaseDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; if (gEngine.ReadSong(lpszPathName)) // read song AutoRecord(TRUE); // start auto-recording if applicable CString ext(PathFindExtension(lpszPathName)); if (!ext.CompareNoCase(LEAD_SHEET_EXT)) // if lead sheet extension UpdateSongText(); // update song text from song's binary data // intentionally override read return code, so user can correct errors return TRUE; }
inline void RemovePrivateExts(const winx::CString& strDir) { winx::CFindFile finder; for (BOOL f = finder.FindFile(strDir + _T("\\*_private.*")); f; f = finder.FindNextFile()) { if (!finder.IsDirectory()) { LPCTSTR szExt = PathFindExtension(finder.m_fd.cFileName); if (_tcsicmp(szExt, _T(".h")) == 0 || _tcsicmp(szExt, _T(".rc")) == 0) { DeleteFile(finder.GetFilePath()); } } } }
BOOL CParticleMenuGridProperty::OnDblClk(CPoint point) { CString texPath=ModelViewerConfig::GetInstance()->GetDataFileDir()+"\\"+(CString)GetValue(); CString strExt=PathFindExtension(texPath); if(_access(texPath,0)!=-1&&strExt!="") { CString texName=texPath.Right(texPath.GetLength()-texPath.ReverseFind('\\')-1); CTextureInfoDlg dlg(texPath,texName); dlg.DoModal(); } return TRUE; }
void CMixereView::OnDropFiles(CChannel *Chan, HDROP hDropInfo) { char Path[MAX_PATH]; UINT Files = DragQueryFile(hDropInfo, -1, 0, 0); DragQueryFile(hDropInfo, 0, Path, MAX_PATH); CString MixerExt; GetExtension(MixerExt); CStringArray ChanExt; CChannel::GetExtensionList(ChanExt); int Pos = Chan != NULL ? Chan->GetIndex() : GetItemCount(); // assume any non-mixer files are audio files CStringArray LoadErr; CStringArray FormatErr; for (UINT i = 0; i < Files; i++) { DragQueryFile(hDropInfo, i, Path, MAX_PATH); if (stricmp(PathFindExtension(Path), MixerExt)) { for (int j = 0; j < ChanExt.GetSize(); j++) { if (!stricmp(PathFindExtension(Path), ChanExt[j])) break; } if (j < ChanExt.GetSize()) { if (!LoadAudio(Pos++, Path)) AddStringUnique(LoadErr, Path); } else AddStringUnique(FormatErr, Path); } } // if audio files couldn't be loaded, display error message if (LoadErr.GetSize()) MsgBoxStrList(LDS(CANT_LOAD_AUDIO), LoadErr); // if audio files had invalid formats, display error message if (FormatErr.GetSize()) MsgBoxStrList(LDS(BAD_FILE_FORMAT), FormatErr); // now open mixer files if any for (i = 0; i < Files; i++) { DragQueryFile(hDropInfo, i, Path, MAX_PATH); if (!stricmp(PathFindExtension(Path), MixerExt)) AfxGetApp()->OpenDocumentFile(Path); } }
CAtlStringW CFilePath::GetExtension() const { LPCTSTR psPath = msPath; LPCTSTR psExt = PathFindExtension(psPath); if (psExt == NULL) return CString(); if (*psExt == '.') ++psExt; return msPath.Mid(psExt - psPath); }
CString CGZIPFile::GetUncompressedFilePath() const { // return path of input file without ".gz" extension CString strUncompressedFilePath; LPCTSTR pszExt = PathFindExtension(m_strGzFilePath); if (pszExt != NULL && _tcsicmp(pszExt, _T(".gz")) == 0) { strUncompressedFilePath = m_strGzFilePath; PathRemoveExtension(strUncompressedFilePath.GetBuffer(strUncompressedFilePath.GetLength())); strUncompressedFilePath.ReleaseBuffer(); } return strUncompressedFilePath; }
CAtlStringW CFilePath::GetTitle() const { LPCTSTR psPath = msPath; LPCTSTR psFileName = PathFindFileName(psPath); LPCTSTR psExt = PathFindExtension(psPath); if (psFileName == NULL) return CString(); if (psExt == NULL) return msPath.Mid(psFileName - psPath); return msPath.Mid(psFileName - psPath, psExt - psFileName); }
int _tmain(DWORD argc, LPCTSTR argv[]) { if(argc == 2) { LPTSTR lpNoEXT = HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, _tcslen(argv[1]) * sizeof(TCHAR)); HMODULE hImage = NULL; BOOL (__cdecl *MainRoutine)(); if(_tcsstr(PathFindExtension(argv[1]), _T(".exe"))) { _tcsncpy(lpNoEXT, argv[1], _tcslen(argv[1])); PathRemoveExtension(lpNoEXT); hImage = LoadLibrary(lpNoEXT); if(hImage) { _ftprintf(stdout, _T("\n Loading image: %s\n\n"), argv[1]); MainRoutine = (BOOL(__cdecl *)())GetProcAddress(hImage, "_tmain"); if(MainRoutine()) { _ftprintf(stdout, _T("\n _tmain entry address retrieved!\n Executing...!\n\n")); } else { _ftprintf(stdout, _T("\n Failed to retrieve a valid entry address [_tmain]\n")); } } else { _ftprintf(stdout, _T("\n Failed to load image: %s\n Last error recieved: %i\n\n"), argv[1], GetLastError()); } HeapFree(lpNoEXT, HEAP_NO_SERIALIZE, GetProcessHeap()); FreeLibrary(hImage); } else { _ftprintf(stdout, _T("\n The extension given is not valid [EXE ONLY].\n") \ _T(" NOTE: PE header checking is not done, the image must be valid\n\n")); } } return 0; }
HRESULT GetPDBName(LPWSTR wzFileName, LPWSTR wzPDBName, DWORD *pdwSize) { LPWSTR wzExt = NULL; ASSERT(wzFileName && wzPDBName && pdwSize); lstrcpyW(wzPDBName, wzFileName); wzExt = PathFindExtension(wzPDBName); lstrcpyW(wzExt, L".PDB"); return S_OK; }
int CKillerDlg::ScanFile(char *FileDir,char *FileType) { // 扫描文件 CString MyExt; char buffer[2*MAX_PATH]={'\0'}; sprintf(buffer,"%s\\%s",FileDir,FileType); HANDLE hFind; WIN32_FIND_DATA dat; hFind = ::FindFirstFile(buffer,&dat); if( hFind == INVALID_HANDLE_VALUE ) { GetDlgItem(IDC_EDIT_SCAN)->SetWindowText(" 扫描过程中出错!"); return -1; } else { char NewBuf[2*MAX_PATH]; do { if(dat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)// 判断是否为文件夹 { if(dat.cFileName[0] == '.') continue; else { sprintf(NewBuf,"%s\\%s",FileDir,dat.cFileName); // 递归 ScanFile(NewBuf,"*.*"); } } else// 是文件 { sprintf(buffer,"%s\\%s",FileDir,dat.cFileName); MyExt = PathFindExtension(dat.cFileName); if( MyExt == ".exe" || MyExt == ".com" || MyExt == ".pif" || MyExt == ".scr" || MyExt == ".html" || MyExt == ".asp" || MyExt == ".php" || MyExt == ".jsp" || MyExt==".dll" || MyExt==".txt" ) { m_FileList.push_back((CString)buffer); GetDlgItem(IDC_EDIT_SCAN)->SetWindowText(((CString)buffer)+"加入扫描队列"); } } }while(::FindNextFile(hFind,&dat)); CString str; str.Format("%d",m_FileList.size()); GetDlgItem(IDC_STATIC_TOTAL)->SetWindowText("总文件数:"+str); } return 1; }
void OnOpen() { REQUIRE_FILE_THREAD(); if(file_) return; #if defined(OS_WIN) TCHAR szFolderPath[MAX_PATH]; // Save the file in the user's "My Documents" folder. if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, szFolderPath))) { std::wstring fileNameStr = filename_; LPWSTR name = PathFindFileName(fileNameStr.c_str()); LPWSTR ext = PathFindExtension(fileNameStr.c_str()); int ct = 0; std::wstringstream ss; if(ext) { name[ext-name] = 0; ext++; } // Make sure the file name is unique. do { if(ct > 0) ss.str(L""); ss << szFolderPath << L"\\" << name; if(ct > 0) ss << L" (" << ct << L")"; if(ext) ss << L"." << ext; ct++; } while(PathFileExists(ss.str().c_str())); { AutoLock lock_scope(this); filename_ = ss.str(); } file_ = _wfopen(ss.str().c_str(), L"wb"); ASSERT(file_ != NULL); } #else // TODO(port): Implement this. ASSERT(false); // Not implemented #endif }