예제 #1
0
//------------------------------------------------------------------------
//! Converts an integer-array setting value into a delimited string
//!
//! @param values Integer-array
//! @param strDelimiter The delimiter for combining the values of an array to a string
//! @return The string-array combined into a single string
//------------------------------------------------------------------------
CString CViewConfigSection::ConvertArraySetting(const CSimpleArray<int>& values, const CString& strDelimiter) const
{
	CString strValue;
	CString strArray;
	for (int i = 0; i < values.GetSize(); ++i)
	{
		if (!strArray.IsEmpty())
			strArray += strDelimiter;
		strValue.Format(_T("%d"), values[i]);
		strArray += strValue;
	}
	return strArray;
}
예제 #2
0
//------------------------------------------------------------------------
//! Splits a delimited string into a string-array
//!
//! @param strArray The delimited string 
//! @param values The string array
//! @param strDelimiter The delimiter
//------------------------------------------------------------------------
void CViewConfigSection::SplitArraySetting(const CString& strArray, CSimpleArray<CString>& values, const CString& strDelimiter) const
{
	// Perform tokenize using strDelimiter
	int cur_pos = 0;
	int prev_pos = 0;
	int length = strArray.GetLength();
	while (cur_pos < length)
	{
		cur_pos = strArray.Find(strDelimiter, prev_pos);
		if (cur_pos == -1)
		{
			CString value = strArray.Mid(prev_pos, length - prev_pos);
			values.Add(value);
			break;
		}
		else
		{
			CString value = strArray.Mid(prev_pos, cur_pos - prev_pos);
			values.Add(value);
			prev_pos = cur_pos + strDelimiter.GetLength();
		}
	}
}
예제 #3
0
int CLDEditTxtFile::WriteItemsToFile(CString strFile, CSimpleArray<CString> arrItems)
{
	int nRet = -1;
	USES_CONVERSION;

	CBkProcPrivilege privilege;

	if (!privilege.EnableShutdown())
		return -1;

	char pszFilePath[MAX_PATH] = {0};
	CString strDesFile = strFile;
	StringCbPrintfA(pszFilePath, sizeof(pszFilePath), "%s_tmp", W2A(strFile));
	
	DWORD dwFileAttr = ::GetFileAttributes(strFile);
//	dwFileAttr &= ~FILE_ATTRIBUTE_READONLY;
	::SetFileAttributes(strFile, FILE_ATTRIBUTE_NORMAL);
	FILE* pFile = NULL;
	//open file
	fopen_s(&pFile, const_cast<char*>(pszFilePath), "w+b");
	if (NULL == pFile)
	{
		::SetFileAttributes(strFile, dwFileAttr);
		return nRet;
	}
	//write file
	int nCount = arrItems.GetSize();
	for (int i = 0; i < nCount; i++)
	{
		if (NULL != m_pStop && TRUE == *m_pStop)
			break;

		CString strValue = arrItems[i];
		if (TRUE == strValue.IsEmpty())
			continue;
		fputs(CW2A(strValue.GetBuffer(-1)), pFile);
		if (strValue.Right(1) != "\n")
			fputs("\r\n", pFile);
		strValue.ReleaseBuffer(-1);
	}
	if (NULL != pFile)
		fclose(pFile);
	pFile = NULL;

	MoveFileEx(CString(pszFilePath), strDesFile, MOVEFILE_REPLACE_EXISTING);
	::SetFileAttributes(strDesFile, dwFileAttr);
	nRet = 0;

	return nRet;
}
예제 #4
0
BOOL CEnumerateSerial::UsingGetDefaultCommConfig(CSimpleArray<UINT>& ports)
#endif
{
  //Make sure we clear out any elements which may already be in the array
  ports.RemoveAll();

  //Up to 255 COM ports are supported so we iterate through all of them seeing
  //if we can get the default configuration
  for (UINT i=1; i<256; i++)
  {
    //Form the Raw device name
    CString sPort;
    sPort.Format(_T("COM%d"), i);

    COMMCONFIG cc;
    DWORD dwSize = sizeof(COMMCONFIG);
    if (GetDefaultCommConfig(sPort, &cc, &dwSize))
      ports.Add(i);
  }

  //Return the success indicator
  return TRUE;
}
예제 #5
0
void LoadIgnoredID(CSimpleArray<int>& arrayIgnoredID)
{
	arrayIgnoredID.RemoveAll();
	CString strIgnoredIniPath;
	CAppPath::Instance().GetLeidianAppPath(strIgnoredIniPath);
	strIgnoredIniPath.Append(IGNORED_FILEPATH);
	CIniFile ini_IgnoredList(strIgnoredIniPath);
	CString strGetValue;
	ini_IgnoredList.GetStrValue(SEC_IGNOREDLIST_MAIN,KEY_IGNOREDLIST_COMMENT,strGetValue.GetBuffer(65536),65536);
	strGetValue.ReleaseBuffer(65536);

	WCHAR *szValue;
	WCHAR szTemp[10];
	szValue = strGetValue.GetBuffer();
	strGetValue.ReleaseBuffer();
	WCHAR* p = wcstok(szValue,L"|");
	while(p)
	{
		wcscpy_s(szTemp,p);
		arrayIgnoredID.Add(_wtoi(szTemp));
		p = wcstok(NULL,L"|");
	}
}
예제 #6
0
BOOL HasIgnored(int nID,CSimpleArray<int>& arrayIgnoredID)
{
	BOOL bFind = FALSE;
	for (int i = 0; i < arrayIgnoredID.GetSize();i++)
	{	
		if (nID == arrayIgnoredID[i])
		{
			bFind = TRUE;
			goto Exit0;
		}
	}
Exit0:
	return bFind;
}
예제 #7
0
int RepairCOMVul(const CSimpleArray<LPTVulSoft>& arr)
{
	int count = 0;
	for(int i=0; i<arr.GetSize(); ++i)
	{
		LPTVulSoft pItem = arr[i];
		int state = GetSoftItemState(pItem->state, pItem->nDisableCom);
		if(state==VUL_DISABLE_COM)
		{
			++count;
			theEngine->m_pSoftVulScan->EnableVulCOM( pItem->nID, FALSE );
		}
	}
	return count;
}
예제 #8
0
int FillDownloadsItem(const CSimpleArray<T> &arr, const IntArray&arrayId, CSimpleArray<T_RepairItem>&arrDownloadItem)
{
	int count = 0;
	for(int i=0; i<arrayId.GetSize(); ++i)
	{
		int nID = arrayId[i];
		T pItem = FindArrayItem(arr, nID);
		if(pItem)
		{
			arrDownloadItem.Add( T_RepairItem(pItem) );
			++ count;
		}
	}
	return count;
}
예제 #9
0
void CVulEngine::IgnoreVuls( CSimpleArray<int> &arr, bool bIgnore )
{
	if(m_pVulScan==NULL)
	{
		m_pVulScan = CreateVulFix();
	}
	if(m_pVulScan)
	{
		for(int i=0; i<arr.GetSize(); ++i)
		{
			m_pVulScan->Ignore(arr[i], bIgnore);
		}
		m_pVulScan->PersistIgnored();
	}
}
예제 #10
0
void CUserPatcher::_FillRegInfo( INT nKBID, LPCTSTR szPatchName, LPCTSTR szProductKey, LPCTSTR szPatchKey, LPCTSTR szPatchValue, LPCTSTR szLogfile )
{
	LPCTSTR _key_patch = _T("Patches");
	
	CString strProduct;
	strProduct.Format(_T("Installer\\Products\\%s\\Patches"), szProductKey);
	WriteRegString(HKEY_CLASSES_ROOT, strProduct, szPatchKey, szPatchValue);

	CSimpleArray<CString> ms;
	ReadRegMString(HKEY_CLASSES_ROOT, strProduct, _key_patch, ms);
	if( ms.Find(szPatchKey)==-1 )
	{
		ms.Add( szPatchKey );
		WriteRegMString(HKEY_CLASSES_ROOT, strProduct, _key_patch, ms);
	}

	// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\4080110900063D11C8EF10054038389C\Patches\CEA540E1AE6DD1D41A6E01E6EF2B271C
	CString strPatchInfo;
	strPatchInfo.Format(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\%s\\Patches\\%s"), szProductKey, szPatchKey);

	CString strMoreInfoURL;
	FormatKBWebUrl( strMoreInfoURL, nKBID );
	
	CString strDate;
	_GetDateString(strDate);

	WriteRegString(HKEY_LOCAL_MACHINE, strPatchInfo, _T("DisplayName"), szPatchName);
	WriteRegString(HKEY_LOCAL_MACHINE, strPatchInfo, _T("Installed"), strDate);
	WriteRegString(HKEY_LOCAL_MACHINE, strPatchInfo, _T("MoreInfoURL"), strMoreInfoURL);

	WriteRegDWord(HKEY_LOCAL_MACHINE, strPatchInfo, _T("LUAEnabled"),	0);
	WriteRegDWord(HKEY_LOCAL_MACHINE, strPatchInfo, _T("MSI3"),			1);
	WriteRegDWord(HKEY_LOCAL_MACHINE, strPatchInfo, _T("PatchType"),	0);
	WriteRegDWord(HKEY_LOCAL_MACHINE, strPatchInfo, _T("State"),		1);
	WriteRegDWord(HKEY_LOCAL_MACHINE, strPatchInfo, _T("Uninstallable"),0);
}
N2FCORE_API bool ControllerWebServices::InitializeController(TWSCutsomEPList& list)
{
	LOGMSG("Initializing");

	bool result = false;

	CSimpleArray<WebServiceBase*> arrayServices;

	arrayServices.Add(new WebServiceN2FMemberService);
	arrayServices.Add(new WebServiceN2FMemberService_v2);
	arrayServices.Add(new WebServiceN2FPhotoOrganise);
	arrayServices.Add(new WebServiceN2FPhotoOrganise_v2);
	arrayServices.Add(new WebServiceN2FMemberService_v3);
	arrayServices.Add(new WebServiceN2FSnapUpService);
	// add all supported web-services here

	for ( int i = 0; i < arrayServices.GetSize(); ++i )
	{
		iSupportedServices.Add(arrayServices[i]->GetType(), arrayServices[i]);
	}

	// custom end-points initialization
	for ( int i = 0; i < list.GetSize(); ++i )
	{
		int idxFound = iSupportedServices.FindKey(list[i].wsType);
		if ( -1 != idxFound )
		{
			iSupportedServices.GetValueAt(idxFound)->Initialize(list[i].wsEndPoint);
		}
	}

	CString csEmpty;
	for ( int i = 0; i < iSupportedServices.GetSize(); ++i )
	{
		WebServiceBase *wsb = iSupportedServices.GetValueAt(i);
		if ( false == wsb->IsInitialized() )
			wsb->Initialize(csEmpty);
	}


	result = true;
	return result;

	LOGMSG("Initialized");
}
예제 #12
0
BOOL CKSogoClean::ScanSogoCookies()
{
	if (!_CheckSogouExist())
	{
		g_vsNoinstallapp.Add(SOGO_COOKIES);
		return TRUE;
	}
	BOOL bRet = FALSE;
	WCHAR szCookiesPath[MAX_PATH] = {0};
	WCHAR szSogoAppPath[MAX_PATH] = {0};
	std::wstring strFilePath;
	CSimpleArray<CString> vec_file;
	SHGetSpecialFolderPath(NULL, szCookiesPath, CSIDL_COOKIES, FALSE);
	SHGetSpecialFolderPath(NULL, szSogoAppPath, CSIDL_APPDATA, FALSE);
	PathAppend(szSogoAppPath, L"SogouExplorer\\Webkit\\Cookies");
	strFilePath = szSogoAppPath;
	g_fnScanFile(g_pMain, BEGINPROC(SOGO_COOKIES), 0, 0, 0);
	std::wstring str;
	std::vector<std::wstring>::iterator it;
	for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
	{
		str = *it;
		transform(str.begin(), str.end(), str.begin(), towlower);
		if (str == L"sogouexplorer.exe")
		{
			str = L"正在运行,跳过";
			goto clean0;
		}
	}
	str = L"";
	if (m_bScan)
	{
		m_appHistory.CommfunFile(SOGO_COOKIES, szCookiesPath, vec_file);
		ScanDbTable(strFilePath, L"cookies", SOGO_COOKIES);
	}
clean0:

	g_fnScanFile(g_pMain, ENDPROC(SOGO_COOKIES), str.c_str(), 0, 0);
	return bRet;
}
예제 #13
0
static EnvDTE::ProjectItemPtr EnumItem(EnvDTE::ProjectPtr & pProject, CSimpleArray<CString> & ar, EnvDTE::ProjectItemPtr pPrevElem)
{
	EnvDTE::ProjectItemsPtr pItems = NULL;
	if (pPrevElem == NULL)
	{
		pProject->get_ProjectItems(&pItems);
	}
	else
	{
		pPrevElem->get_ProjectItems(&pItems);
	}
	if (pItems == NULL)
		return EnvDTE::ProjectItemPtr(NULL);
	long Count;
	pItems->get_Count(&Count);
	if (Count == 0)
		return EnvDTE::ProjectItemPtr(NULL);
	for (short i = 1; i <= Count; i++)
	{
		EnvDTE::ProjectItemPtr pItem;
		pItems->Item(_variant_t(i), &pItem);
		_bstr_t IName;
		//pItem->get_Name(IName.GetAddress());
		pItem->get_FileNames(i,IName.GetAddress());
		/*
		if (!_wcsicmp(IName, ItemName))
		{
			return pItem;
		}
		*/
		CString Name = (LPCTSTR)IName;
		ar.Add(Name);
		EnvDTE::ProjectItemPtr pItem2 = EnumItem(pProject, ar,pItem);
		if (pItem2 != NULL)
			return pItem2;
	}
	return EnvDTE::ProjectItemPtr(NULL);
}
예제 #14
0
BOOL CKSogoClean::ScanSogoPass()
{
	if (!_CheckSogouExist())
	{
		g_vsNoinstallapp.Add(SOGO_PASS);
		return TRUE;
	}

	BOOL bRet = FALSE;
	static BOOL bFlag = FALSE;
	std::wstring str;

	g_fnScanFile(g_pMain,BEGINPROC(SOGO_PASS),0,0,0);
	std::vector<std::wstring>::iterator it;
	for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
	{
		str = *it;
		transform(str.begin(), str.end(), str.begin(), towlower);
		if (str == L"sogouexplorer.exe")
		{
			str = L"正在运行,跳过";
			goto clean0;
		}
	}
	str = L"";

	if (!bFlag)
	{
		str = L"可以清理";
		bFlag = TRUE;
	}
clean0:
	g_fnScanFile(g_pMain,ENDPROC(SOGO_PASS),str.c_str(),0,0);

	return bRet;
}
예제 #15
0
BOOL CEnumerateSerial::UsingSetupAPI2(CSimpleArray<UINT>& ports, CSimpleArray<CString>& sFriendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
  ports.RemoveAll();
  sFriendlyNames.RemoveAll();

  //Get the function pointers to "SetupDiGetClassDevs", "SetupDiGetClassDevs", "SetupDiEnumDeviceInfo", "SetupDiOpenDevRegKey" 
  //and "SetupDiDestroyDeviceInfoList" in setupapi.dll
  HINSTANCE hSetupAPI = LoadLibrary(_T("SETUPAPI.DLL"));
  if (hSetupAPI == NULL)
    return FALSE;

  SETUPDIOPENDEVREGKEY* lpfnLPSETUPDIOPENDEVREGKEY = reinterpret_cast<SETUPDIOPENDEVREGKEY*>(GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey"));
#ifdef _UNICODE
  SETUPDICLASSGUIDSFROMNAME* lpfnSETUPDICLASSGUIDSFROMNAME = reinterpret_cast<SETUPDICLASSGUIDSFROMNAME*>(GetProcAddress(hSetupAPI, "SetupDiClassGuidsFromNameW"));
  SETUPDIGETCLASSDEVS* lpfnSETUPDIGETCLASSDEVS = reinterpret_cast<SETUPDIGETCLASSDEVS*>(GetProcAddress(hSetupAPI, "SetupDiGetClassDevsW"));
  SETUPDIGETDEVICEREGISTRYPROPERTY* lpfnSETUPDIGETDEVICEREGISTRYPROPERTY = reinterpret_cast<SETUPDIGETDEVICEREGISTRYPROPERTY*>(GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyW"));
#else
  SETUPDICLASSGUIDSFROMNAME* lpfnSETUPDICLASSGUIDSFROMNAME = reinterpret_cast<SETUPDICLASSGUIDSFROMNAME*>(GetProcAddress(hSetupAPI, "SetupDiClassGuidsFromNameA"));
  SETUPDIGETCLASSDEVS* lpfnSETUPDIGETCLASSDEVS = reinterpret_cast<SETUPDIGETCLASSDEVS*>(GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA"));
  SETUPDIGETDEVICEREGISTRYPROPERTY* lpfnSETUPDIGETDEVICEREGISTRYPROPERTY = reinterpret_cast<SETUPDIGETDEVICEREGISTRYPROPERTY*>(GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA"));
#endif
  SETUPDIDESTROYDEVICEINFOLIST* lpfnSETUPDIDESTROYDEVICEINFOLIST = reinterpret_cast<SETUPDIDESTROYDEVICEINFOLIST*>(GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList"));
  SETUPDIENUMDEVICEINFO* lpfnSETUPDIENUMDEVICEINFO = reinterpret_cast<SETUPDIENUMDEVICEINFO*>(GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo"));

  if ((lpfnLPSETUPDIOPENDEVREGKEY == NULL) || (lpfnSETUPDICLASSGUIDSFROMNAME == NULL) || (lpfnSETUPDIDESTROYDEVICEINFOLIST == NULL) ||
      (lpfnSETUPDIENUMDEVICEINFO == NULL) || (lpfnSETUPDIGETCLASSDEVS == NULL) || (lpfnSETUPDIGETDEVICEREGISTRYPROPERTY == NULL))
  {
    //Unload the setup dll
    FreeLibrary(hSetupAPI);

    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);

    return FALSE;
  }
  
  //First need to convert the name "Ports" to a GUID using SetupDiClassGuidsFromName
  DWORD dwGuids = 0;
  lpfnSETUPDICLASSGUIDSFROMNAME(_T("Ports"), NULL, 0, &dwGuids);
  if (dwGuids == 0)
  {
		DWORD dwLastError = GetLastError();
  
    //Unload the setup dll
    FreeLibrary(hSetupAPI);
    
    SetLastError(dwLastError);

    return FALSE;
  }

  //Allocate the needed memory
  ATL::CHeapPtr<GUID> pGuids;
  if (!pGuids.Allocate(dwGuids))
  {
    //Unload the setup dll
    FreeLibrary(hSetupAPI);
    
    SetLastError(ERROR_OUTOFMEMORY);

    return FALSE;
  }

  //Call the function again
  if (!lpfnSETUPDICLASSGUIDSFROMNAME(_T("Ports"), pGuids, dwGuids, &dwGuids))
  {
		DWORD dwLastError = GetLastError();
  
    //Unload the setup dll
    FreeLibrary(hSetupAPI);
    
    SetLastError(dwLastError);

    return FALSE;
  }

  //Now create a "device information set" which is required to enumerate all the ports
  HDEVINFO hDevInfoSet = lpfnSETUPDIGETCLASSDEVS(pGuids, NULL, NULL, DIGCF_PRESENT);
  if (hDevInfoSet == INVALID_HANDLE_VALUE)
  {
		DWORD dwLastError = GetLastError();
  
    //Unload the setup dll
    FreeLibrary(hSetupAPI);
    
    SetLastError(dwLastError);

    return FALSE;
  }

  //Finally do the enumeration
  BOOL bMoreItems = TRUE;
  int nIndex = 0;
  SP_DEVINFO_DATA devInfo;
  while (bMoreItems)
  {
    //Enumerate the current device
    devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
    bMoreItems = lpfnSETUPDIENUMDEVICEINFO(hDevInfoSet, nIndex, &devInfo);
    if (bMoreItems)
    {
      //Did we find a serial port for this device
      BOOL bAdded = FALSE;

      //Get the registry key which stores the ports settings
      HKEY hDeviceKey = lpfnLPSETUPDIOPENDEVREGKEY(hDevInfoSet, &devInfo, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
      if (hDeviceKey)
      {
        //Read in the name of the port
        TCHAR pszPortName[256];
        DWORD dwSize = sizeof(pszPortName);
        DWORD dwType = 0;
  	    if ((RegQueryValueEx(hDeviceKey, _T("PortName"), NULL, &dwType, reinterpret_cast<LPBYTE>(pszPortName), &dwSize) == ERROR_SUCCESS) && (dwType == REG_SZ))
        {
          //If it looks like "COMX" then
          //add it to the array which will be returned
          size_t nLen = _tcslen(pszPortName);
          if (nLen > 3)
          {
            if ((_tcsnicmp(pszPortName, _T("COM"), 3) == 0) && IsNumeric(&pszPortName[3], FALSE))
            {
              //Work out the port number
              int nPort = _ttoi(&pszPortName[3]);
              ports.Add(nPort);

              bAdded = TRUE;
            }
          }
        }

        //Close the key now that we are finished with it
        RegCloseKey(hDeviceKey);
      }

      //If the port was a serial port, then also try to get its friendly name
      if (bAdded)
      {
        TCHAR pszFriendlyName[256];
        DWORD dwSize = sizeof(pszFriendlyName);
        DWORD dwType = 0;
        if (lpfnSETUPDIGETDEVICEREGISTRYPROPERTY(hDevInfoSet, &devInfo, SPDRP_DEVICEDESC, &dwType, reinterpret_cast<PBYTE>(pszFriendlyName), dwSize, &dwSize) && (dwType == REG_SZ))
          sFriendlyNames.Add(pszFriendlyName);
        else
          sFriendlyNames.Add(_T(""));
      }
    }

    ++nIndex;
  }

  //Free up the "device information set" now that we are finished with it
  lpfnSETUPDIDESTROYDEVICEINFOLIST(hDevInfoSet);

  //Unload the setup dll
  FreeLibrary(hSetupAPI);

  //Return the success indicator
  return TRUE;
}
예제 #16
0
BOOL CEnumerateSerial::UsingQueryDosDevice(CSimpleArray<UINT>& ports)
#endif
{
  //What will be the return value from this function (assume the worst)
  BOOL bSuccess = FALSE;

  //Make sure we clear out any elements which may already be in the array
  ports.RemoveAll();

  //Determine what OS we are running on
  OSVERSIONINFO osvi;
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  BOOL bGetVer = GetVersionEx(&osvi);

  //On NT use the QueryDosDevice API
  if (bGetVer && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT))
  {
    //Use QueryDosDevice to look for all devices of the form COMx. Since QueryDosDevice does
    //not consitently report the required size of buffer, lets start with a reasonable buffer size
    //of 4096 characters and go from there
    int nChars = 4096;
    BOOL bWantStop = FALSE;
    while (nChars && !bWantStop)
    {
      ATL::CHeapPtr<TCHAR> szDevices;
      if (szDevices.Allocate(nChars))
      {
        DWORD dwChars = QueryDosDevice(NULL, szDevices, nChars);
        if (dwChars == 0)
        {
          DWORD dwError = GetLastError();
          if (dwError == ERROR_INSUFFICIENT_BUFFER)
          {
            //Expand the buffer and  loop around again
            nChars *= 2;
          }
          else
            bWantStop = TRUE;
        }
        else
        {
          bSuccess = TRUE;
          bWantStop = TRUE;
          size_t i=0;
          while (szDevices[i] != _T('\0'))
          {
            //Get the current device name
            TCHAR* pszCurrentDevice = &szDevices[i];

            //If it looks like "COMX" then
            //add it to the array which will be returned
            size_t nLen = _tcslen(pszCurrentDevice);
            if (nLen > 3)
            {
              if ((_tcsnicmp(pszCurrentDevice, _T("COM"), 3) == 0) && IsNumeric(&pszCurrentDevice[3], FALSE))
              {
                //Work out the port number
                int nPort = _ttoi(&pszCurrentDevice[3]);
                ports.Add(nPort);
              }
            }

            //Go to next device name
            i += (nLen + 1);
          }
        }
      }
      else
      {
        bWantStop = TRUE;
        SetLastError(ERROR_OUTOFMEMORY);        
      }
    }
  }
  else
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);

  return bSuccess;
}
예제 #17
0
void CFileOpt::DoFileEnumerationEx(LPCTSTR lpPath,CSimpleArray<FILEEXTS_IN>& vec_wildCard ,BOOL bRecursion, BOOL bEnumFiles, EnumerateFuncEx pFunc, void* pUserData)
{	
	
	LARGE_INTEGER large;
	large.HighPart =0;
	large.LowPart =0;
	
	//用于扫描路径显示
#define PATHMAX__ 2048
	TCHAR szBuf[PATHMAX__];
	wmemset(szBuf,0,PATHMAX__);
	if (NULL==GetShortPathName(lpPath,szBuf,PATHMAX__))
	{
		pFunc(SCANING(FILEGARBAGE_EXTS),lpPath,pUserData,large);
	}
	else
	{
		pFunc(SCANING(FILEGARBAGE_EXTS),szBuf,pUserData,large);
	}

	try
	{	CString strTmp;

		if(s_bUserBreak) return;
		int len = (int)wcslen(lpPath);
		if(lpPath==NULL || len<=0) return;
		

		//NotifySys(NRS_DO_EVENTS, 0,0);
		//-------------------------------------------------------------------------
		//枚举通配符文件

		for (int i=0;i<vec_wildCard.GetSize();i++)
		{

			CString strFilePath;
			strFilePath = lpPath;
			if (strFilePath.GetAt(len-1) != '\\')
			{
				strFilePath.Append(_T("\\"));
			}
			strFilePath.Append(vec_wildCard[i].strFileExts);
			
			
			WIN32_FIND_DATA fd;
			HANDLE hFindFile = FindFirstFile(strFilePath, &fd);
			if(hFindFile == INVALID_HANDLE_VALUE)
			{	
				::FindClose(hFindFile); 
		
				continue;
			}
			
			CString strFile = fd.cFileName;
			
			int iLen = strFile.GetLength();

			int iExtLen = vec_wildCard[i].strFileExts.GetLength();
		
			if ((vec_wildCard[i].strFileExts.GetAt(iExtLen-1) != 
				strFile.GetAt(iLen-1))
				)
			{	
				::FindClose(hFindFile);
				continue;
			}
			

			CString tempPath; BOOL bUserReture=TRUE; BOOL bIsDirectory;

			BOOL bFinish = FALSE;
			while(!bFinish)
			{
				bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
				//如果是文件
				if(pFunc && FALSE==bIsDirectory)
				{	

					LARGE_INTEGER large;
					large.LowPart = fd.nFileSizeLow;
					large.HighPart = fd.nFileSizeHigh;

					CString strFileFullPath;
					strFileFullPath.Append(lpPath);
					
					int iLen = strFileFullPath.GetLength();
					if(strFileFullPath.GetAt(iLen-1)!='\\')
					{
						strFileFullPath.Append(_T("\\"));
					}

					strFileFullPath.Append(fd.cFileName);
					
					//CString str;
					//str.Format(_T("扫描:%s\n"),strFilePath);
					//OutputDebugString(str); 
					
					//返回正在扫描的路径



					bUserReture = pFunc(vec_wildCard[i].iType,strFileFullPath, pUserData,large);
					if(bUserReture==FALSE)
					{
						s_bUserBreak = TRUE; 
						::FindClose(hFindFile); 
						return;
					}
				}

				bFinish = (FindNextFile(hFindFile, &fd) == FALSE);

			}

			::FindClose(hFindFile);

		}


		//-------------------------------------------------------------------------
		try
		{

			if(s_bUserBreak) return;

			int len = (int)wcslen(lpPath);
			if(lpPath==NULL || len<=0) return;

			//NotifySys(NRS_DO_EVENTS, 0,0);

			CString strFilePath;
			strFilePath = lpPath;
			if (strFilePath.GetAt(len-1) != '\\')
			{
				strFilePath.Append(_T("\\"));
			}
			strFilePath.Append(_T("*"));


			WIN32_FIND_DATA fd;
			HANDLE hFindFile = FindFirstFile(strFilePath, &fd);
			if(hFindFile == INVALID_HANDLE_VALUE)
			{
				::FindClose(hFindFile);
				return;
			}


			CString strTempFilePath;; BOOL bUserReture=TRUE; BOOL bIsDirectory;
			
			BOOL bFinish = FALSE;
			while(!bFinish)
			{	

				strTempFilePath = lpPath;
				if (strTempFilePath.GetAt(len-1) != '\\')
				{
					strTempFilePath.Append(_T("\\"));
				}
				strTempFilePath.Append(fd.cFileName);

				bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);

				//如果是.或..
				if( bIsDirectory
					&& (wcscmp(fd.cFileName, _T("."))==0 || wcscmp(fd.cFileName, _T(".."))==0)) 
				{                
					bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
					continue;
				}

				//if(pFunc && bEnumFiles!=bIsDirectory)
				//{	
				//	LARGE_INTEGER large;
				//	large.LowPart = fd.nFileSizeLow;
				//	large.HighPart = fd.nFileSizeHigh;

				//	bUserReture = pFunc(tempPath, pUserData,large);
				//	if(bUserReture==FALSE)
				//	{
				//		s_bUserBreak = TRUE; ::FindClose(hFindFile); return;
				//	}
				//}

				//NotifySys(NRS_DO_EVENTS, 0,0);

				if(bIsDirectory && bRecursion) //是子目录
				{
					DoFileEnumerationEx(strTempFilePath,vec_wildCard ,bRecursion, bEnumFiles, pFunc, pUserData);
				}



				bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
			}

			::FindClose(hFindFile);

			//-------------------------------------------------------------------------
		}
		catch(...)
		{	 

			/*ASSERT(0); */return; 
		}



	}
	catch(...)
	{
		return ;
	}

}
예제 #18
0
void CFileOpt::DoFileEnumeration(LPCTSTR lpPath,CSimpleArray<CString>& vec_wildCard ,BOOL bRecursion, BOOL bEnumFiles, EnumerateFunc pFunc, void* pUserData)
{	

	try
	{
		if(s_bUserBreak) return;
		int len = (int)wcslen(lpPath);
		if(lpPath==NULL || len<=0) return;
		
	
		//NotifySys(NRS_DO_EVENTS, 0,0);
		//-------------------------------------------------------------------------
		//枚举通配符文件
		for (int i=0; i<vec_wildCard.GetSize();i++)
		{

			CString strFilePath;
			strFilePath = lpPath;
			if (strFilePath.GetAt(len-1) != '\\')
			{
				strFilePath.Append(_T("\\"));
			}
			strFilePath.Append(vec_wildCard[i].GetBuffer());

			WIN32_FIND_DATA fd;
			HANDLE hFindFile = FindFirstFile(strFilePath.GetBuffer(), &fd);
			if(hFindFile == INVALID_HANDLE_VALUE)
			{
				::FindClose(hFindFile); continue;
			}

			CString tempPath; BOOL bUserReture=TRUE; BOOL bIsDirectory;

			BOOL bFinish = FALSE;
			while(!bFinish)
			{
				bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
				//如果是文件
				if(pFunc && (FALSE==bIsDirectory))
				{	
					LARGE_INTEGER large;
					large.LowPart = fd.nFileSizeLow;
					large.HighPart = fd.nFileSizeHigh;
					
					CString strFileFullPath;
					strFileFullPath.Append(lpPath);

					int iLen = strFileFullPath.GetLength();
					if (strFileFullPath.GetAt(len -1)!= '\\')
					{
						strFileFullPath.Append(_T("\\"));
					}
	
					strFileFullPath.Append(fd.cFileName);

					bUserReture = pFunc(strFileFullPath.GetBuffer(), pUserData,large);
					if(bUserReture==FALSE)
					{
						s_bUserBreak = TRUE; ::FindClose(hFindFile); return;
					}
				}

				bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
				
			}
			FindClose(hFindFile);

		}

		//-------------------------------------------------------------------------
		try
		{
			//-------------------------------------------------------------------------
			if(s_bUserBreak) return;

			int len = (int)wcslen(lpPath);
			if(lpPath==NULL || len<=0) return;

			//NotifySys(NRS_DO_EVENTS, 0,0);
			
			CString strFilePath;
			strFilePath = lpPath;
			if (strFilePath.GetAt(len-1)!= '\\')
			{
				strFilePath.Append(_T("\\"));
			}
			strFilePath.Append(_T("*"));
			


			WIN32_FIND_DATA fd;
			HANDLE hFindFile = FindFirstFile(strFilePath.GetBuffer(), &fd);
			if(hFindFile == INVALID_HANDLE_VALUE)
			{
				::FindClose(hFindFile); return;
			}

			CString strTempFilePath;; BOOL bUserReture=TRUE; BOOL bIsDirectory;

			BOOL bFinish = FALSE;
			while(!bFinish)
			{	

				strTempFilePath = lpPath;
				if (strTempFilePath.GetAt(len-1) != '\\')
				{
					strTempFilePath.Append(_T("\\"));
				}
				strTempFilePath.Append(fd.cFileName);
	
				bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);

				//如果是.或..
				if( bIsDirectory
					&& (wcscmp(fd.cFileName, _T("."))==0 || wcscmp(fd.cFileName, _T(".."))==0)) 
				{                
					bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
					continue;
				}

				//if(pFunc && bEnumFiles!=bIsDirectory)
				//{	
				//	LARGE_INTEGER large;
				//	large.LowPart = fd.nFileSizeLow;
				//	large.HighPart = fd.nFileSizeHigh;

				//	bUserReture = pFunc(tempPath, pUserData,large);
				//	if(bUserReture==FALSE)
				//	{
				//		s_bUserBreak = TRUE; ::FindClose(hFindFile); return;
				//	}
				//}

				//NotifySys(NRS_DO_EVENTS, 0,0);

				if(bIsDirectory && bRecursion) //是子目录
				{
					DoFileEnumeration(strTempFilePath.GetBuffer(),vec_wildCard ,bRecursion, bEnumFiles, pFunc, pUserData);
				}

				bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
			}

			::FindClose(hFindFile);

			//-------------------------------------------------------------------------
		}
		catch(...)
		{
			/*ASSERT(0); */return; 
		}
		


	}
	catch(...)
	{
		return ;
	}
}
예제 #19
0
BOOL CChromClean::ScanChromePass()
{	
	if (!_CheckChromeExist())
	{
		g_vsNoinstallapp.Add(CHROME_PASSWORD);
		return TRUE;
	}
	CSimpleArray<CString> vec_file;
	CString strPath; 

	g_fnScanFile(g_pMain,BEGINPROC(CHROME_PASSWORD),0,0,0);

	std::wstring str;
	std::vector<std::wstring>::iterator it;
	for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
	{
		str = *it;
		transform(str.begin(), str.end(), str.begin(), towlower);
		if (str == L"chrome.exe")
		{
			str = L"正在运行,跳过";
			goto _exit_;
		}
	}
	str = L"";
	if (m_bScan ==TRUE)
	{
        TCHAR szBuffer[MAX_PATH] = {0};

        ::SHGetSpecialFolderPath( NULL, szBuffer, CSIDL_LOCAL_APPDATA, FALSE);

        strPath = szBuffer;
        strPath += _T("\\Google\\Chrome\\User Data\\Default");
        sqlite3* pDB = NULL;
        sqlite3_stmt* sspStart = NULL;

        CString strDbPath = L"";
        strPath += L"\\";
        FindFileInDirectory(strPath.GetBuffer(),strDbPath,_T("Web Data"));
		strPath.ReleaseBuffer();

        if (strDbPath.GetLength()>=0)
        {
            KW2UTF8  szDataPath(strDbPath.GetBuffer());
            int nResult = sqlite3_open(szDataPath, &pDB);
            if (nResult != SQLITE_OK)
            {
                goto _exit_1;
            }
            nResult = sqlite3_prepare(pDB, "select * from logins", -1, &sspStart, 0);
            if (nResult != SQLITE_OK)
            {
                goto _exit_1;
            }

            nResult = sqlite3_step(sspStart);

            if(nResult == SQLITE_ROW)
            {
                CString strOutPut = strDbPath;
                strOutPut += L"|logins";
                g_fnScanFile(g_pMain, CHROME_PASSWORD, strOutPut, 0, 0);

            }
_exit_1:
            
            if (sspStart)
            {
                sqlite3_finalize(sspStart);
                sspStart = NULL;
            }

            if (pDB)
            {
                sqlite3_close(pDB);
                pDB = NULL;
            }

        }   

		strDbPath = L"";
		FindFileInDirectory(strPath.GetBuffer(),strDbPath,_T("Login Data"));
		strPath.ReleaseBuffer();

		if (strDbPath.GetLength()>=0)
		{
			KW2UTF8  szDataPath(strDbPath.GetBuffer());
			strDbPath.ReleaseBuffer();
			int nResult = sqlite3_open(szDataPath, &pDB);
			if (nResult != SQLITE_OK)
			{
				goto _exit_2;
			}
			nResult = sqlite3_prepare(pDB, "select * from logins", -1, &sspStart, 0);
			if (nResult != SQLITE_OK)
			{
				goto _exit_2;
			}

			nResult = sqlite3_step(sspStart);

			if(nResult == SQLITE_ROW)
			{
				CString strOutPut = strDbPath;
				strOutPut += L"|logins";
				g_fnScanFile(g_pMain, CHROME_PASSWORD, strOutPut, 0, 0);

			}
_exit_2:

			if (sspStart)
			{
				sqlite3_finalize(sspStart);
				sspStart = NULL;
			}

			if (pDB)
			{
				sqlite3_close(pDB);
				pDB = NULL;
			}

		}   
	}
_exit_:
	g_fnScanFile(g_pMain,ENDPROC(CHROME_PASSWORD),str.c_str(),0,0);

	return TRUE;		
}
예제 #20
0
BOOL CEnumerateSerial::UsingRegistry(CSimpleArray<CString>& ports)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
  ports.RemoveAll();

  //What will be the return value
  BOOL bSuccess = FALSE;

  HKEY hSERIALCOMM;
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE, &hSERIALCOMM) == ERROR_SUCCESS)
  {
		//Get the max value name and max value lengths
		DWORD dwMaxValueNameLen;
		DWORD dwMaxValueLen;
		DWORD dwQueryInfo = RegQueryInfoKey(hSERIALCOMM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwMaxValueNameLen, &dwMaxValueLen, NULL, NULL);
		if (dwQueryInfo == ERROR_SUCCESS)
		{
			DWORD dwMaxValueNameSizeInChars = dwMaxValueNameLen + 1; //Include space for the NULL terminator
			DWORD dwMaxValueNameSizeInBytes = dwMaxValueNameSizeInChars * sizeof(TCHAR);
			DWORD dwMaxValueDataSizeInChars = dwMaxValueLen/sizeof(TCHAR) + 1; //Include space for the NULL terminator
			DWORD dwMaxValueDataSizeInBytes = dwMaxValueDataSizeInChars * sizeof(TCHAR);
		
			//Allocate some space for the value name and value data			
      ATL::CHeapPtr<TCHAR> szValueName;
      ATL::CHeapPtr<BYTE> byValue;
      if (szValueName.Allocate(dwMaxValueNameSizeInChars) && byValue.Allocate(dwMaxValueDataSizeInBytes))
      {
				bSuccess = TRUE;

				//Enumerate all the values underneath HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
				DWORD dwIndex = 0;
				DWORD dwType;
				DWORD dwValueNameSize = dwMaxValueNameSizeInChars;
				DWORD dwDataSize = dwMaxValueDataSizeInBytes;
				memset(szValueName.m_pData, 0, dwMaxValueNameSizeInBytes);
				memset(byValue.m_pData, 0, dwMaxValueDataSizeInBytes);
				LONG nEnum = RegEnumValue(hSERIALCOMM, dwIndex, szValueName, &dwValueNameSize, NULL, &dwType, byValue, &dwDataSize);
				while (nEnum == ERROR_SUCCESS)
				{
					//If the value is of the correct type, then add it to the array
					if (dwType == REG_SZ)
					{
						TCHAR* szPort = reinterpret_cast<TCHAR*>(byValue.m_pData);
						ports.Add(szPort);	
					}

					//Prepare for the next time around
					dwValueNameSize = dwMaxValueNameSizeInChars;
					dwDataSize = dwMaxValueDataSizeInBytes;
					memset(szValueName.m_pData, 0, dwMaxValueNameSizeInBytes);
					memset(byValue.m_pData, 0, dwMaxValueDataSizeInBytes);
					++dwIndex;
					nEnum = RegEnumValue(hSERIALCOMM, dwIndex, szValueName, &dwValueNameSize, NULL, &dwType, byValue, &dwDataSize);
				}
      }
      else
		    SetLastError(ERROR_OUTOFMEMORY);
		}
		
		//Close the registry key now that we are finished with it    
    RegCloseKey(hSERIALCOMM);
    
    if (dwQueryInfo != ERROR_SUCCESS)
			SetLastError(dwQueryInfo);
  }
	
	return bSuccess;
}
예제 #21
0
파일: enumser.cpp 프로젝트: yoszka/WinAPI
BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
  ports.clear();
  friendlyNames.clear();
#else
  ports.RemoveAll();
  friendlyNames.RemoveAll();
#endif  

  //What will be the return value
  BOOL bSuccess = FALSE;

  //Create the WBEM locator
  ATL::CComPtr<IWbemLocator> locator;
  HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&locator));
  if (SUCCEEDED(hr))
  {
    ATL::CComPtr<IWbemServices> services;
    hr = locator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &services);
    if (SUCCEEDED(hr))
    {
      //Execute the query
      ATL::CComPtr<IEnumWbemClassObject> classObject;
      hr = services->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &classObject);
      if (SUCCEEDED(hr))
      {
        bSuccess = TRUE;

        //Now enumerate all the ports
        hr = WBEM_S_NO_ERROR;

        //Final Next will return WBEM_S_FALSE
        while (hr == WBEM_S_NO_ERROR)
        {
          ULONG uReturned = 0;
          ATL::CComPtr<IWbemClassObject> apObj[10];
          hr = classObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned);
          if (SUCCEEDED(hr))
          {
            for (ULONG n=0; n<uReturned; n++)
            {
              ATL::CComVariant varProperty1;
              HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL);
              if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3))
              {
                //If it looks like "COMX" then add it to the array which will be returned
                if ((_wcsnicmp(varProperty1.bstrVal, L"COM", 3) == 0) && IsNumeric(&(varProperty1.bstrVal[3]), TRUE))
                {
                  //Work out the port number
                  int nPort = _wtoi(&(varProperty1.bstrVal[3]));
                #if defined CENUMERATESERIAL_USE_STL
                  ports.push_back(nPort);
                #else
                  ports.Add(nPort);
                #endif

                  //Also get the friendly name of the port
                  ATL::CComVariant varProperty2;
                  if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR))
                  {  
                #if defined CENUMERATESERIAL_USE_STL
                  #if defined _UNICODE  
                    std::wstring szName(varProperty2.bstrVal);
                  #else
                    std::string szName(ATL::CW2A(varProperty2.bstrVal));
                  #endif
                    friendlyNames.push_back(szName);
                  #else
                    friendlyNames.Add(CString(varProperty2.bstrVal));    
                  #endif
                  }
                  else
                  {
                  #if defined CENUMERATESERIAL_USE_STL
                    friendlyNames.push_back(_T(""));
                  #else
                    friendlyNames.Add(_T(""));
                  #endif  
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  return bSuccess;
}
예제 #22
0
파일: enumser.cpp 프로젝트: yoszka/WinAPI
BOOL CEnumerateSerial::UsingSetupAPI2(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
  ports.clear();
  friendlyNames.clear();
#else
  ports.RemoveAll();
  friendlyNames.RemoveAll();
#endif  

  //Get the function pointers to "SetupDiGetClassDevs", "SetupDiGetClassDevs", "SetupDiEnumDeviceInfo", "SetupDiOpenDevRegKey" 
  //and "SetupDiDestroyDeviceInfoList" in setupapi.dll
  CAutoHModule setupAPI(LoadLibraryFromSystem32(_T("SETUPAPI.DLL")));
  if (setupAPI == NULL)
    return FALSE;

  SETUPDIOPENDEVREGKEY* lpfnLPSETUPDIOPENDEVREGKEY = reinterpret_cast<SETUPDIOPENDEVREGKEY*>(GetProcAddress(setupAPI, "SetupDiOpenDevRegKey"));
#if defined _UNICODE
  SETUPDICLASSGUIDSFROMNAME* lpfnSETUPDICLASSGUIDSFROMNAME = reinterpret_cast<SETUPDICLASSGUIDSFROMNAME*>(GetProcAddress(setupAPI, "SetupDiClassGuidsFromNameW"));
  SETUPDIGETCLASSDEVS* lpfnSETUPDIGETCLASSDEVS = reinterpret_cast<SETUPDIGETCLASSDEVS*>(GetProcAddress(setupAPI, "SetupDiGetClassDevsW"));
  SETUPDIGETDEVICEREGISTRYPROPERTY* lpfnSETUPDIGETDEVICEREGISTRYPROPERTY = reinterpret_cast<SETUPDIGETDEVICEREGISTRYPROPERTY*>(GetProcAddress(setupAPI, "SetupDiGetDeviceRegistryPropertyW"));
#else
  SETUPDICLASSGUIDSFROMNAME* lpfnSETUPDICLASSGUIDSFROMNAME = reinterpret_cast<SETUPDICLASSGUIDSFROMNAME*>(GetProcAddress(setupAPI, "SetupDiClassGuidsFromNameA"));
  SETUPDIGETCLASSDEVS* lpfnSETUPDIGETCLASSDEVS = reinterpret_cast<SETUPDIGETCLASSDEVS*>(GetProcAddress(setupAPI, "SetupDiGetClassDevsA"));
  SETUPDIGETDEVICEREGISTRYPROPERTY* lpfnSETUPDIGETDEVICEREGISTRYPROPERTY = reinterpret_cast<SETUPDIGETDEVICEREGISTRYPROPERTY*>(GetProcAddress(setupAPI, "SetupDiGetDeviceRegistryPropertyA"));
#endif
  SETUPDIDESTROYDEVICEINFOLIST* lpfnSETUPDIDESTROYDEVICEINFOLIST = reinterpret_cast<SETUPDIDESTROYDEVICEINFOLIST*>(GetProcAddress(setupAPI, "SetupDiDestroyDeviceInfoList"));
  SETUPDIENUMDEVICEINFO* lpfnSETUPDIENUMDEVICEINFO = reinterpret_cast<SETUPDIENUMDEVICEINFO*>(GetProcAddress(setupAPI, "SetupDiEnumDeviceInfo"));

  if ((lpfnLPSETUPDIOPENDEVREGKEY == NULL) || (lpfnSETUPDICLASSGUIDSFROMNAME == NULL) || (lpfnSETUPDIDESTROYDEVICEINFOLIST == NULL) ||
      (lpfnSETUPDIENUMDEVICEINFO == NULL) || (lpfnSETUPDIGETCLASSDEVS == NULL) || (lpfnSETUPDIGETDEVICEREGISTRYPROPERTY == NULL))
  {
    //Set the error to report
    setupAPI.m_dwError = ERROR_CALL_NOT_IMPLEMENTED;

    return FALSE;
  }
  
  //First need to convert the name "Ports" to a GUID using SetupDiClassGuidsFromName
  DWORD dwGuids = 0;
  lpfnSETUPDICLASSGUIDSFROMNAME(_T("Ports"), NULL, 0, &dwGuids);
  if (dwGuids == 0)
  {
    //Set the error to report
    setupAPI.m_dwError = GetLastError();

    return FALSE;
  }

  //Allocate the needed memory
  ATL::CHeapPtr<GUID> pGuids;
  if (!pGuids.Allocate(dwGuids))
  {
    //Set the error to report
    setupAPI.m_dwError = ERROR_OUTOFMEMORY;

    return FALSE;
  }

  //Call the function again
  if (!lpfnSETUPDICLASSGUIDSFROMNAME(_T("Ports"), pGuids, dwGuids, &dwGuids))
  {
    //Set the error to report
    setupAPI.m_dwError = GetLastError();

    return FALSE;
  }

  //Now create a "device information set" which is required to enumerate all the ports
  HDEVINFO hDevInfoSet = lpfnSETUPDIGETCLASSDEVS(pGuids, NULL, NULL, DIGCF_PRESENT);
  if (hDevInfoSet == INVALID_HANDLE_VALUE)
  {
    //Set the error to report
    setupAPI.m_dwError = GetLastError();

    return FALSE;
  }

  //Finally do the enumeration
  BOOL bMoreItems = TRUE;
  int nIndex = 0;
  SP_DEVINFO_DATA devInfo;
  while (bMoreItems)
  {
    //Enumerate the current device
    devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
    bMoreItems = lpfnSETUPDIENUMDEVICEINFO(hDevInfoSet, nIndex, &devInfo);
    if (bMoreItems)
    {
      //Did we find a serial port for this device
      BOOL bAdded = FALSE;

      //Get the registry key which stores the ports settings
      HKEY hDeviceKey = lpfnLPSETUPDIOPENDEVREGKEY(hDevInfoSet, &devInfo, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
      if (hDeviceKey)
      {
        int nPort = 0;
        if (QueryRegistryPortName(hDeviceKey, nPort))
        {
        #if defined CENUMERATESERIAL_USE_STL
          ports.push_back(nPort);
        #else
          ports.Add(nPort);
        #endif  
          bAdded = TRUE;
        }

        //Close the key now that we are finished with it
        RegCloseKey(hDeviceKey);
      }

      //If the port was a serial port, then also try to get its friendly name
      if (bAdded)
      {
        TCHAR szFriendlyName[1024];
        szFriendlyName[0] = _T('\0');
        DWORD dwSize = sizeof(szFriendlyName);
        DWORD dwType = 0;
        if (lpfnSETUPDIGETDEVICEREGISTRYPROPERTY(hDevInfoSet, &devInfo, SPDRP_DEVICEDESC, &dwType, reinterpret_cast<PBYTE>(szFriendlyName), dwSize, &dwSize) && (dwType == REG_SZ))
        {
        #if defined CENUMERATESERIAL_USE_STL
          friendlyNames.push_back(szFriendlyName);
        #else
          friendlyNames.Add(szFriendlyName);
        #endif  
        }
        else
        {
        #if defined CENUMERATESERIAL_USE_STL
          friendlyNames.push_back(_T(""));
        #else
          friendlyNames.Add(_T(""));
        #endif  
        }
      }
    }

    ++nIndex;
  }

  //Free up the "device information set" now that we are finished with it
  lpfnSETUPDIDESTROYDEVICEINFOLIST(hDevInfoSet);

  //Return the success indicator
  return TRUE;
}
예제 #23
0
//------------------------------------------------------------------------
//! Converts a font setting value into a delimited string
//!
//! @param font The setting value
//! @return The delimited string
//------------------------------------------------------------------------
CString CViewConfigSection::ConvertLogFontSetting(const LOGFONT& font) const
{
	CSimpleArray<CString> strArray;

	CString strValue(font.lfFaceName, sizeof(font.lfFaceName) / sizeof(TCHAR));
	strArray.Add(strValue);
	strValue.Format(_T("%d"), font.lfHeight);
	strArray.Add(strValue);
	strValue.Format(_T("%d"), font.lfWidth);
	strArray.Add(strValue);
	strValue.Format(_T("%d"), font.lfEscapement);
	strArray.Add(strValue);
	strValue.Format(_T("%d"), font.lfOrientation);
	strArray.Add(strValue);
	strValue.Format(_T("%d"), font.lfWeight);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfItalic);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfUnderline);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfStrikeOut);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfCharSet);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfOutPrecision);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfQuality);
	strArray.Add(strValue);
	strValue.Format(_T("%u"), font.lfPitchAndFamily);
	strArray.Add(strValue);

	return ConvertArraySetting(strArray);
}
예제 #24
0
HRESULT CImplVulfix::Scan(DWORD dwFlags)
{
	TIME_CHECK( _T("CImplVulfix::Scan ") );
	m_Canceled = FALSE;
	T_ComInit __init__com__;
	HRESULT hr ; 	
	do
	{
		Reset();
		GetLangID();
		
		CSysEnv& sysEnv = singleton<CSysEnv>::Instance();
		sysEnv.Init();
		if( FAILED( hr=sysEnv.IsSupported(FALSE) ) )
			break;
		
		Init();
		m_objIgnore.LoadIgnoreDB();

		CString filenameSystem, filenameOffice, filenameSoft;
		GetXmlDBFileName(VTYPE_WINDOWS, filenameSystem, IsWin64());
		GetXmlDBFileName(VTYPE_OFFICE, filenameOffice, FALSE);
		GetXmlDBFileName(VTYPE_SOFTLEAK, filenameSoft, FALSE);
		if( !PathFileExists(filenameSystem) && !PathFileExists(filenameOffice) && !PathFileExists(filenameSoft) )
		{
			hr = KERR_LOAD_FILE;
			break;
		}
		
		m_pFilterOS = CreateOSFilter(sysEnv.m_WinVer, dwFlags);
		InitOSFilter( m_pFilterOS, sysEnv.m_WinVer, dwFlags);
		if( m_pFilterOS->WaitComplete() )
		{
			m_dbOS.SetObserver( m_Observer );
			m_dbOffice.SetObserver( m_Observer );
			m_dbSoft.SetObserver( m_Observer );
			m_pFilterOS->SetIIgnore( &m_objIgnore );
			
			CString filename;
			try
			{
				FixLocale();

				//BOOL bWin64 = IsWin64();
				//PVOID OldValue = NULL;
				//if(bWin64)
				//	Wow64DisableWow64FsRedirection(&OldValue);
				
				!m_Canceled && m_dbOffice.Load( filenameOffice, m_pFilterOS, dwFlags );
				!m_Canceled && sysEnv.IsLangSupported() && sysEnv.IsOsSupported() && m_dbOS.Load( filenameSystem, m_pFilterOS, dwFlags );
				!m_Canceled && m_dbSoft.Load( filenameSoft, NULL, dwFlags);

				//if(bWin64)
				//	Wow64RevertWow64FsRedirection(OldValue);
			}
			catch (...)
			{
				hr = KERR_LOAD_FILE;
			}
			
			CSimpleArray<LPTUpdateItem> arrLeaks;
			CSimpleArray<TReplacedUpdate*> arrReplaced;			
			m_dbOS.GetUnfixedLeakList( arrLeaks, m_arrFixedVuls, m_arrInvalid, arrReplaced );
			m_dbOffice.GetUnfixedLeakList( arrLeaks, m_arrFixedVuls, m_arrInvalid, arrReplaced );

			const CSimpleArray<int> &arrExpired = m_dbOS.GetExpiredIds();
			CSimpleArray<int> arrReplacedId;
			for(int i=0; i<arrReplaced.GetSize(); ++i)
			{
				arrReplacedId.Add( arrReplaced[i]->nKBID );
			}
			
			// select soft ignored vuls 
			CSimpleArray<LPTVulSoft> arrSoftLeaks;
			m_dbSoft.GetUnfixedLeakList( arrSoftLeaks );
			for(int i=0; i<arrSoftLeaks.GetSize(); ++i)
			{
				LPTVulSoft ps = arrSoftLeaks[i];
				ps->isIgnored = m_objIgnore.IsIgnored( ps->nID );
				if( ps->isIgnored )
				{
					LPTUpdateItem pu = new TUpdateItem;
					pu->m_nType = VTYPE_SOFTLEAK;
					pu->nID = ps->nID;
					pu->strName = ps->matchedItem.strName;
					pu->strDescription = ps->strDescription;
					pu->strWebpage = ps->matchedItem.strWebpage;
					pu->nWarnLevel = ps->nLevel;
					pu->strPubdate = ps->strPubdate;

					m_arrIgnoredVuls.Add( pu );
					m_arrIgnoredVulsFromSoft.Add( pu );
				}
				else
					m_arrSoftLeaks.Add( ps );
			}
			
			// select installable, ignored , expired 
			for(int i=0; i<arrLeaks.GetSize(); ++i )
			{
				LPTUpdateItem &pi = arrLeaks[i];
				pi->isExpired = arrExpired.Find( pi->nID )!=-1;

				if(pi->isExpired)
					m_arrInvalid.Add( pi );
				else if(pi->isIgnored)
					m_arrIgnoredVuls.Add( pi );
				else
				{
					bool bReplaced = arrReplacedId.Find( pi->nID )!=-1;
					if(!bReplaced)
						m_arrLeaks.Add( pi );
				}
			}
			
			// find correct replace relationship 
			for(int i=0; i<arrReplaced.GetSize(); ++i)
			{
				TReplacedUpdate* pu = arrReplaced[i];
				BOOL bInstalled = FindArrayIndex( m_arrFixedVuls, pu->nKBID )!=-1;
				if( !bInstalled )
				{
					if( FindArrayIndex(m_arrFixedVuls, pu->nKBID2)!=-1 
						|| FindArrayIndex(m_arrLeaks, pu->nKBID2)!=-1
						|| FindArrayIndex(m_arrIgnoredVuls, pu->nKBID2)!=-1 )
						m_arrReplacedUpdates.Add( pu );
				}
			}

			// - 保存最后无漏洞时间, 使得下次不再提示有风险 
			// -- 非快速扫描的结果才有效果 
			if( RequireUsingInterface() && !(dwFlags & VULSCAN_EXPRESS_SCAN) )
			{
				BOOL hasMustLeak = FALSE;
				const CSimpleArray<LPTUpdateItem> &arrLeaks = GetResults();
				for(int i=0; i<arrLeaks.GetSize(); ++i)
				{
					if(arrLeaks[i]->nWarnLevel>0)
					{
						hasMustLeak = TRUE;
						break;
					}
				}
				CString strVal;
				if(!hasMustLeak)
				{
					T_Date date;
					GetLatestPackgeDate(date.nYear, date.nMonth, date.nDay);
					strVal.Format(_T("%04d-%02d-%02d"), date.nYear, date.nMonth, date.nDay);
				}
				WriteVulConfig(_T("VulScan"), _T("LastSafePkgDate"), strVal);
			}			
		}
		
		hr = KERR_NONE;
	} while (FALSE);
	return hr;
}
예제 #25
0
BOOL CChromClean::ScanChormCookies()
{
	BOOL bRet = FALSE;
	WCHAR szPath[MAX_PATH] = {0};
	CString strPath;
	sqlite3* pDb = NULL;
	sqlite3_stmt* sspStart = NULL;
	string strFullPath;
	char* szError = NULL;
	char szSql[MAX_PATH] = {0};
	int nResult = -1;
	if (!_CheckChromeExist())
	{
		g_vsNoinstallapp.Add(CHROME_COOKIES);
		return TRUE;
	}
	g_fnScanFile(g_pMain, BEGINPROC(CHROME_COOKIES), 0, 0, 0);

	std::wstring str;
	std::vector<std::wstring>::iterator it;
	for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
	{
		str = *it;
		transform(str.begin(), str.end(), str.begin(), towlower);
		if (str == L"chrome.exe")
		{
			str = L"正在运行,跳过";
			goto clean0;
		}
	}
	str = L"";
	if(m_bScan)
	{

		SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE);
		strPath = szPath;
		if (strPath.ReverseFind(L'\\') != strPath.GetLength() - 1)
		{
			strPath += L"\\";
		}
		strPath += L"Google\\Chrome\\User Data\\Default\\Cookies";
		strFullPath = UnicodeToUtf8(strPath.GetBuffer());
		nResult = sqlite3_open(strFullPath.c_str(), &pDb);
		if (nResult != SQLITE_OK)
		{
			bRet = FALSE;
			goto clean0;
		}
		nResult = sqlite3_prepare(pDb, "select * from cookies", -1, &sspStart, 0);
		if (nResult != SQLITE_OK)
		{
			bRet = FALSE;
			goto clean0;
		}

		nResult = sqlite3_step(sspStart);
		if (nResult == SQLITE_ROW)
		{
			CString strOutput;
			strOutput = Utf8ToUnicode(strFullPath).c_str();
			strOutput += L"|";
			strOutput += L"cookies";
			g_fnScanFile(g_pMain, CHROME_COOKIES, strOutput, 0, 0);
		}

	}
clean0:

	g_fnScanFile(g_pMain, ENDPROC(CHROME_COOKIES), str.c_str(), 0, 0);
	if(sspStart != NULL)
	{
		sqlite3_finalize(sspStart);
		sspStart = NULL;
	}
	if(pDb != NULL)
	{
		sqlite3_close(pDb);
		pDb = NULL;
	}
	return bRet;
}
예제 #26
0
BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& sFriendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
  ports.RemoveAll();
  sFriendlyNames.RemoveAll();

  //What will be the return value
  BOOL bSuccess = FALSE;

  //Create the WBEM locator
  CComPtr<IWbemLocator> locator;
  HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&locator));
  if (SUCCEEDED(hr))
  {
    CComPtr<IWbemServices> services;
    hr = locator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &services);
    if (SUCCEEDED(hr))
    {
      // Execute the query
      CComPtr<IEnumWbemClassObject> classObject;
      hr = services->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &classObject);
      if (SUCCEEDED(hr))
      {
        bSuccess = TRUE;

        //Now enumerate all the ports
        hr = WBEM_S_NO_ERROR;

        //Final Next will return WBEM_S_FALSE
        while (hr == WBEM_S_NO_ERROR)
        {
          ULONG uReturned;
          CComPtr<IWbemClassObject> apObj[10];
          hr = classObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned);
          if (SUCCEEDED(hr))
          {
            for (ULONG n=0; n<uReturned; n++)
            {
              CComVariant varProperty1;
              HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL);
              if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3))
              {
                CW2T szPort(varProperty1.bstrVal);

                //If it looks like "COMX" then add it to the array which will be returned
                if ((_tcsnicmp(szPort, _T("COM"), 3) == 0) && IsNumeric(&szPort[3], TRUE))
                {
                  //Work out the port number
                  int nPort = _ttoi(&szPort[3]);
                  ports.Add(nPort);

                  //Also get the friendly name of the port
                  CString sFriendlyName;
                  CComVariant varProperty2;
                  if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR))
                    sFriendlyName = varProperty2.bstrVal;
                  sFriendlyNames.Add(sFriendlyName);    
                }
              }
            }
          }
        }
      }
    }
  }
  
  return bSuccess;
}
예제 #27
0
BOOL CEnumerateSerial::UsingComDB(CSimpleArray<UINT>& ports)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
  ports.RemoveAll();

  //What will be the return value
  BOOL bSuccess = FALSE;
  
  //Used to preserve the last error value
  DWORD dwLastError = ERROR_SUCCESS;

  //Get the function pointers to "ComDBOpen", "ComDBClose" & "ComDBGetCurrentPortUsage" in msports.dll
  HINSTANCE hMSPorts = LoadLibrary(_T("MSPORTS.DLL"));
  if (hMSPorts == NULL)
    return FALSE;

  COMDBOPEN* lpfnLPCOMDBOPEN = reinterpret_cast<COMDBOPEN*>(GetProcAddress(hMSPorts, "ComDBOpen"));
  COMDBCLOSE* lpfnLPCOMDBCLOSE = reinterpret_cast<COMDBCLOSE*>(GetProcAddress(hMSPorts, "ComDBClose"));
  COMDBGETCURRENTPORTUSAGE* lpfnCOMDBGETCURRENTPORTUSAGE = reinterpret_cast<COMDBGETCURRENTPORTUSAGE*>(GetProcAddress(hMSPorts, "ComDBGetCurrentPortUsage"));
  if ((lpfnLPCOMDBOPEN != NULL) && (lpfnLPCOMDBCLOSE != NULL) && (lpfnCOMDBGETCURRENTPORTUSAGE != NULL))
  {
    //First need to open up the DB
    HCOMDB hComDB;
    DWORD dwComOpen = lpfnLPCOMDBOPEN(&hComDB);
    if (dwComOpen == ERROR_SUCCESS)
    {
      //Work out the size of the buffer required
      DWORD dwMaxPortsReported = 0;
      DWORD dwPortUsage = lpfnCOMDBGETCURRENTPORTUSAGE(hComDB, NULL, 0, CDB_REPORT_BYTES, &dwMaxPortsReported);
      if (dwPortUsage == ERROR_SUCCESS)
      {
        //Allocate some heap space and recall the function
        ATL::CHeapPtr<BYTE> portBytes;
        if (portBytes.Allocate(dwMaxPortsReported))
        {
          bSuccess = TRUE;
          if (lpfnCOMDBGETCURRENTPORTUSAGE(hComDB, portBytes, dwMaxPortsReported, CDB_REPORT_BYTES, &dwMaxPortsReported) == ERROR_SUCCESS)
          {
            //Work thro the byte bit array for ports which are in use
            for (DWORD i=0; i<dwMaxPortsReported; i++)
            {
              if (portBytes[i])
                ports.Add(i + 1);
            }
          }
        }
        else
          SetLastError(ERROR_OUTOFMEMORY);        
      }
      else
				dwLastError = dwPortUsage;
    
      //Close the DB
      lpfnLPCOMDBCLOSE(hComDB);
    }
    else
			dwLastError = dwComOpen;
  }
  else
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);

  //Unload the msports dll
  FreeLibrary(hMSPorts);
  
  //Reinstate the last error
  if (dwLastError)
		SetLastError(dwLastError);
 
  return bSuccess;
}
예제 #28
0
void CFileOpt::DoFileFolder(LPCTSTR lpPath,CSimpleArray<CString>& vec_folder,BOOL bRecursion,BOOL bFullPath)
{
	try
	{	
		int len = (int)wcslen(lpPath);
		if(lpPath==NULL || len<=0) return;

		//NotifySys(NRS_DO_EVENTS, 0,0);

		CString strFilePath;
		strFilePath = lpPath;
		if (strFilePath.GetAt(len-1) != '\\')
		{
			strFilePath.Append(_T("\\"));
		}
		strFilePath.Append(_T("*"));

		WIN32_FIND_DATA fd;
		HANDLE hFindFile = FindFirstFile(strFilePath.GetBuffer(), &fd);
		if(hFindFile == INVALID_HANDLE_VALUE)
		{
			::FindClose(hFindFile); return;
		}
		
		CString strTempFilePath;
		BOOL bFinish = FALSE; BOOL bUserReture=TRUE; BOOL bIsDirectory;
		while(!bFinish)
		{
			strTempFilePath = lpPath;
			if (strTempFilePath.GetAt(len-1) != '\\')
			{
				strTempFilePath.Append(_T("\\"));
			}
			strTempFilePath.Append(fd.cFileName);

			bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);

			if( bIsDirectory
				&& (wcscmp(fd.cFileName, _T("."))==0 || wcscmp(fd.cFileName, _T(".."))==0)) 
			{                
				bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
				continue;
			}

			if(bIsDirectory) //是目录
			{	
				if (bFullPath == FALSE)	//是否需要全路径
				{
					vec_folder.Add(fd.cFileName);
				}
				else
				{
					vec_folder.Add(strTempFilePath);
				}
				
				
				if (bRecursion ==TRUE)
				{
					DoFileFolder(strTempFilePath,vec_folder, bRecursion,bFullPath);
				}
			}

			bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
		}

		::FindClose(hFindFile);


	}
	catch(...)
	{
		return ;
	}

	return ;
}
예제 #29
0
파일: enumser.cpp 프로젝트: yoszka/WinAPI
BOOL CEnumerateSerial::UsingComDB(CSimpleArray<UINT>& ports)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
  ports.clear();
#else
  ports.RemoveAll();
#endif  

  //What will be the return value from this function (assume the worst)
  BOOL bSuccess = FALSE;
  
  //Get the function pointers to "ComDBOpen", "ComDBClose" & "ComDBGetCurrentPortUsage" in msports.dll
  CAutoHModule msPorts(LoadLibraryFromSystem32(_T("MSPORTS.DLL")));
  if (msPorts == NULL)
    return FALSE;

  COMDBOPEN* lpfnLPCOMDBOPEN = reinterpret_cast<COMDBOPEN*>(GetProcAddress(msPorts, "ComDBOpen"));
  COMDBCLOSE* lpfnLPCOMDBCLOSE = reinterpret_cast<COMDBCLOSE*>(GetProcAddress(msPorts, "ComDBClose"));
  COMDBGETCURRENTPORTUSAGE* lpfnCOMDBGETCURRENTPORTUSAGE = reinterpret_cast<COMDBGETCURRENTPORTUSAGE*>(GetProcAddress(msPorts, "ComDBGetCurrentPortUsage"));
  if ((lpfnLPCOMDBOPEN != NULL) && (lpfnLPCOMDBCLOSE != NULL) && (lpfnCOMDBGETCURRENTPORTUSAGE != NULL))
  {
    //First need to open up the DB
    HCOMDB hComDB;
    DWORD dwComOpen = lpfnLPCOMDBOPEN(&hComDB);
    if (dwComOpen == ERROR_SUCCESS)
    {
      //Work out the size of the buffer required
      DWORD dwMaxPortsReported = 0;
      DWORD dwPortUsage = lpfnCOMDBGETCURRENTPORTUSAGE(hComDB, NULL, 0, CDB_REPORT_BYTES, &dwMaxPortsReported);
      if (dwPortUsage == ERROR_SUCCESS)
      {
        //Allocate some heap space and recall the function
        ATL::CHeapPtr<BYTE> portBytes;
        if (portBytes.Allocate(dwMaxPortsReported))
        {
          bSuccess = TRUE;
          if (lpfnCOMDBGETCURRENTPORTUSAGE(hComDB, portBytes, dwMaxPortsReported, CDB_REPORT_BYTES, &dwMaxPortsReported) == ERROR_SUCCESS)
          {
            //Work thro the byte bit array for ports which are in use
            for (DWORD i=0; i<dwMaxPortsReported; i++)
            {
              if (portBytes[i])
              {
              #if defined CENUMERATESERIAL_USE_STL
                ports.push_back(i + 1);
              #else
                ports.Add(i + 1);
              #endif
              }
            }
          }
        }
        else
          msPorts.m_dwError = ERROR_OUTOFMEMORY;
      }
      else
        msPorts.m_dwError = dwPortUsage;
    
      //Close the DB
      lpfnLPCOMDBCLOSE(hComDB);
    }
    else
			msPorts.m_dwError = dwComOpen;
  }
  else
    msPorts.m_dwError = ERROR_CALL_NOT_IMPLEMENTED;

  return bSuccess;
}
예제 #30
0
BOOL CChromClean::ScanChrome()
{	
	//文件部分
	if (!_CheckChromeExist())
	{
		g_vsNoinstallapp.Add(BROWSERSCLEAN_CHROME);
		return TRUE;
	}
	CSimpleArray<CString> vec_file;
	CString strPath; 
	std::wstring str;
	g_fnScanFile(g_pMain,BEGINPROC(BROWSERSCLEAN_CHROME),0,0,0);
	
	std::vector<std::wstring>::iterator it;
	for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
	{
		str = *it;
		transform(str.begin(), str.end(), str.begin(), towlower);
		if (str == L"chrome.exe")
		{
			str = L"正在运行,跳过";
			goto _exit_;
		}
	}
	str = L"";
	if (m_bScan ==TRUE)
	{
        TCHAR szBuffer[MAX_PATH] = {0};
		
        ::SHGetSpecialFolderPath( NULL, szBuffer, CSIDL_LOCAL_APPDATA, FALSE);

        strPath = szBuffer;
        strPath += _T("\\Google\\Chrome\\User Data\\Default\\Cache");
		m_appHistory.CommfunFile(BROWSERSCLEAN_CHROME,strPath,vec_file);
		
        strPath = szBuffer;
		strPath += _T("\\Google\\Chrome\\User Data\\Default\\Media Cache");
		m_appHistory.CommfunFile(BROWSERSCLEAN_CHROME,strPath,vec_file);

		//vec_file.Add(_T("Cookies"));
		//vec_file.Add(_T("Extension Cookies"));
		vec_file.Add(_T("Archived History"));
		//vec_file.Add(_T("History"));
		//vec_file.Add(_T("History-journal"));
		//vec_file.Add(_T("Thumbnails"));
		//vec_file.Add(_T("Thumbnails-journal"));
		vec_file.Add(_T("Current Tabs"));
		vec_file.Add(_T("Current Session"));
		vec_file.Add(_T("Last Tabs"));
		vec_file.Add(_T("Last Session"));
		vec_file.Add(_T("Safe Browsing Bloom"));
		vec_file.Add(_T("History Index*"));
		vec_file.Add(_T("Visited Links"));

		//vec_file.Add(_T("Extension Cookies"));
        strPath = szBuffer;
		strPath += _T("\\Google\\Chrome\\User Data\\Default");
		m_appHistory.CommfunFile(BROWSERSCLEAN_CHROME,strPath,vec_file);
		vec_file.RemoveAll();

        sqlite3* pDB = NULL;
        sqlite3_stmt* sspStart = NULL;

        CString strDbPath = L"";
        strPath += L"\\";
        FindFileInDirectory(strPath.GetBuffer(),strDbPath,_T("History"));
		strPath.ReleaseBuffer();

        if (strDbPath.GetLength()>=0)
        {
            KW2UTF8  szDataPath(strDbPath.GetBuffer());
			strDbPath.ReleaseBuffer();
            int nResult = sqlite3_open(szDataPath, &pDB);
            if (nResult != SQLITE_OK)
            {
                goto _exit_1;
            }
            nResult = sqlite3_prepare(pDB, "select * from segments", -1, &sspStart, 0);
            if (nResult != SQLITE_OK)
            {
                goto _exit_1;
            }

            nResult = sqlite3_step(sspStart);

            if(nResult == SQLITE_ROW)
            {
                CString strOutPut = strDbPath;
                strOutPut += L"|segments";
                g_fnScanFile(g_pMain, BROWSERSCLEAN_CHROME, strOutPut, 0, 0);
            }
        _exit_1:
			if (sspStart)
			{
				sqlite3_finalize(sspStart);
				sspStart = NULL;
			}

			if (pDB)
			{
				sqlite3_close(pDB);
				pDB = NULL;
			}

			nResult = sqlite3_open(szDataPath, &pDB);
			if (nResult != SQLITE_OK)
			{
				goto _exit_2;
			}

            nResult = sqlite3_prepare(pDB, "select * from visits", -1, &sspStart, 0);
            if (nResult != SQLITE_OK)
            {
                goto _exit_2;
            }

            nResult = sqlite3_step(sspStart);

            if(nResult == SQLITE_ROW)
            {
                CString strOutPut = strDbPath;
                strOutPut += L"|visits";
                g_fnScanFile(g_pMain, BROWSERSCLEAN_CHROME, strOutPut, 0, 0);

            }

        _exit_2:
            if (sspStart)
            {
                sqlite3_finalize(sspStart);
                sspStart = NULL;
            }
            if (pDB)
            {
                sqlite3_close(pDB);
                pDB = NULL;
            }

        }   

	}
	
_exit_:
	g_fnScanFile(g_pMain,ENDPROC(BROWSERSCLEAN_CHROME),str.c_str(),0,0);
	
	return TRUE;
}