コード例 #1
0
ファイル: dllmain.cpp プロジェクト: jellyfunk/aoia-hack
/// Loads a list of message IDs that should be passed on to the AOIA application
void LoadMessageFilter(HKEY hKeyParent, LPCTSTR lpszKeyName)
{
    g_messageFilter.empty();

    ATL::CRegKey reg;
    if (reg.Open(hKeyParent, lpszKeyName, KEY_READ) == ERROR_SUCCESS)
    {
        TCHAR subkey[256];
        DWORD skLength = 256;
        DWORD dw;
        int index = 0;

        while (true)
        {
            if (reg.EnumKey(index, subkey, &skLength) == ERROR_SUCCESS)
            {
                index++;
                if (reg.QueryDWORDValue(subkey, dw) == ERROR_SUCCESS)
                {
                    g_messageFilter.insert(dw);
                }
            }
            else
            {
                break;
            }
        }
    }
    else
    {
        LOG("Unable to open key: " << lpszKeyName)
    }
}
コード例 #2
0
ファイル: AddinHelper.cpp プロジェクト: fanliaokeji/lvdun
BOOL AddinHelper::TodayNotDo(const wchar_t* szValueName)
{
	DWORD dwLastUTC = 0;
	BOOL bCando = FALSE;
	ATL::CRegKey key;
	if (key.Open(HKEY_CURRENT_USER, REGEDITPATH) == ERROR_SUCCESS) {
		bCando = TRUE;
		if(key.QueryDWORDValue(szValueName, dwLastUTC) == ERROR_SUCCESS) {
			__time64_t tTime = (__time64_t)dwLastUTC;
			tm* pTm = _localtime64(&tTime);
			LONG nLastDay = pTm->tm_mday;
			LONG nLastMonth = pTm->tm_mon;
			LONG nLastYear = pTm->tm_year;

			__time64_t lCurTime;
			_time64( &lCurTime); 
			tm* pTmc = _localtime64(&lCurTime);

			LONG nCurDay = pTmc->tm_mday;
			LONG nCurMonth = pTmc->tm_mon;
			LONG nCurYear = pTmc->tm_year;
			TSDEBUG4CXX("TodayHasDo check time pTmc = "<<nCurYear<<nCurMonth<<nCurDay<<", pTm = "<<nLastYear<<nLastMonth<<nLastDay);
			if (nCurDay == nLastDay && nCurMonth == nLastMonth && nCurYear == nLastYear){
				bCando = FALSE;
			}
			else{
				bCando = TRUE;
			}
		}
		key.Close();
	}
	return bCando;
}
コード例 #3
0
ファイル: AddinHelper.cpp プロジェクト: fanliaokeji/lvdun
RegData AddinHelper::QueryRegVal(HKEY hkey, LPCTSTR lpszKeyName, LPCTSTR lpszValuename, REGSAM flag)
{
	ATL::CRegKey key;
	HRESULT hr;
	RegData rd;
	if ((hr = key.Open(hkey, lpszKeyName, flag)) == ERROR_SUCCESS) {
		TCHAR tszValue[MAX_PATH] = {0};
		ULONG lLen = MAX_PATH;
		DWORD dwInfo;
		if (key.QueryStringValue(lpszValuename, tszValue, &lLen) == ERROR_SUCCESS){
			std::wstring wstrInfo =  tszValue;
			rd.strData = wstrInfo;
		}
		else if((key.QueryDWORDValue(lpszValuename, dwInfo) == ERROR_SUCCESS)){
			rd.dwData = dwInfo;
		}
		
		key.Close();
	}
	return rd;
}
コード例 #4
0
DWORD AddinHelper::GetIntervalTime() const
{
	TSAUTO();
	DWORD dwResult = 3600;
	std::wstring subKey = L"Software\\";
	subKey += this->m_productName;
	subKey += L"Host";
	if (this->m_isService) {
		DWORD dwSessionId = ::WTSGetActiveConsoleSessionId();
		HANDLE hUserToken = NULL;
		if(!::WTSQueryUserToken(dwSessionId, &hUserToken)) {
			TSERROR4CXX("WTSQueryUserToken fail. Error: " << ::GetLastError());
			return dwResult;
		}
		
		ScopeResourceHandle<HANDLE, BOOL (WINAPI*)(HANDLE)> autoCloseUserToken(hUserToken, ::CloseHandle);

		TOKEN_ELEVATION_TYPE tokenElevationType;
		DWORD dwSize = sizeof(TOKEN_ELEVATION_TYPE);
		if(!::GetTokenInformation(hUserToken, TokenElevationType, &tokenElevationType, dwSize, &dwSize)) {
			TSERROR4CXX("GetTokenInformation TokenElevationType fail." << ::GetLastError());
			return dwResult;
		}
		HANDLE hDuplicateToken = NULL;
		if(tokenElevationType == TokenElevationTypeLimited) {
			TOKEN_LINKED_TOKEN linkedToken; 
			dwSize = sizeof(TOKEN_LINKED_TOKEN);
			if (!::GetTokenInformation(hUserToken, TokenLinkedToken, &linkedToken, dwSize, &dwSize)) {
				TSERROR4CXX("GetTokenInformation TokenLinkedToken fail. Error: " << ::GetLastError());
				return dwResult;
			}

			ScopeResourceHandle<HANDLE, BOOL (WINAPI*)(HANDLE)> autoCloseLinkedToken(linkedToken.LinkedToken, ::CloseHandle);

			if(!::DuplicateTokenEx(linkedToken.LinkedToken, MAXIMUM_ALLOWED, NULL,  SecurityImpersonation, TokenPrimary, &hDuplicateToken)) {
				TSERROR4CXX("DuplicateTokenEx fail. Error: " << ::GetLastError());
				return dwResult;
			}
		}
		else {
			if(!::DuplicateTokenEx(hUserToken, MAXIMUM_ALLOWED, NULL,  SecurityImpersonation, TokenPrimary, &hDuplicateToken)) {
				TSERROR4CXX("DuplicateTokenEx fail. Error: " << ::GetLastError());
				return dwResult;
			}
		}

		ScopeResourceHandle<HANDLE, BOOL (WINAPI*)(HANDLE)> autoCloseDuplicateToken(hDuplicateToken, ::CloseHandle);
		TCHAR szUsername[MAX_PATH];
		DWORD dwUsernameLen = MAX_PATH;
		PROFILEINFO pi;
		std::memset(&pi, 0, sizeof(PROFILEINFO));
		pi.dwSize = sizeof(PROFILEINFO);
		if(!ImpersonateLoggedOnUser(hDuplicateToken)) {
			TSERROR4CXX("ImpersonateLoggedOnUser failed.");
			return dwResult;
		}
		DWORD dwUserNameLength = MAX_PATH;
		if(!::GetUserName(szUsername, &dwUserNameLength)) {
			TSERROR4CXX("GetUserName failed.");
			::RevertToSelf();
			return dwResult;
		}
		::RevertToSelf();
		pi.lpUserName = szUsername;
		pi.dwFlags = 1;
		if(!::LoadUserProfile(hDuplicateToken, &pi)) {
			TSERROR4CXX("LoadUserProfile failed.");
			return dwResult;
		}
		do {
			ATL::CRegKey key;
			if (key.Open((HKEY)pi.hProfile, subKey.c_str()) != ERROR_SUCCESS) {
				break;
			}
			DWORD dwInterval = 0;
			if(key.QueryDWORDValue(L"interval", dwInterval)!= ERROR_SUCCESS) {
				break;
			}
			dwResult = dwInterval;
		} while(false);
		::UnloadUserProfile(hDuplicateToken, pi.hProfile);
	}
	else {
		ATL::CRegKey key;
		TSERROR4CXX("GetIntervalTime subKey: " << subKey.c_str());
		if(key.Open(HKEY_CURRENT_USER, subKey.c_str()) != ERROR_SUCCESS) {
			return dwResult;
		}
		DWORD dwInterval = 0;
		if(key.QueryDWORDValue(L"interval", dwInterval)!= ERROR_SUCCESS) {
			return dwResult;
		}
		dwResult = dwInterval;
		TSERROR4CXX("GetIntervalTime dwInterval: " << dwInterval);
	}
	if (dwResult < 600) {
		dwResult = 600;
	}
	return dwResult;
}
コード例 #5
0
ファイル: AddinHelper.cpp プロジェクト: fanliaokeji/lvdun
void AddinHelper::LaunchExe()
{
	TSDEBUG4CXX("LaunchExe , enter Now = "<<::GetTickCount());
	BOOL bFirst = TodayNotDo();
	if (bFirst){
		SendState::Send("explorerplugin_startup", "explorerplugin");
	}
	else{
		SendState::Send("explorerplugin_timer", "explorerplugin");
	}
	//判断地域标志
	DWORD dwLastUTC = 0;
	DWORD dwZoneAllow = 0;
	BOOL bCando = FALSE;
	ATL::CRegKey key;
	if (!bFirst && key.Open(HKEY_CURRENT_USER, REGEDITPATH) == ERROR_SUCCESS) {
		bCando = TRUE;
		if (key.QueryDWORDValue(ZONESWITCH, dwZoneAllow) != ERROR_SUCCESS || dwZoneAllow != 1){
			bCando = FALSE;
		}
		else if(key.QueryDWORDValue(LASTLAUNCHUTC, dwLastUTC) == ERROR_SUCCESS) {
			__time64_t tTime = (__time64_t)dwLastUTC;
			tm* pTm = _localtime64(&tTime);
			LONG nLastDay = pTm->tm_mday;
			LONG nLastMonth = pTm->tm_mon;
			LONG nLastYear = pTm->tm_year;

			__time64_t lCurTime;
			_time64( &lCurTime); 
			tm* pTmc = _localtime64(&lCurTime);

			LONG nCurDay = pTmc->tm_mday;
			LONG nCurMonth = pTmc->tm_mon;
			LONG nCurYear = pTmc->tm_year;
			TSDEBUG4CXX("check time pTmc = "<<nCurYear<<nCurMonth<<nCurDay<<", pTm = "<<nLastYear<<nLastMonth<<nLastDay);
			if (nCurDay == nLastDay && nCurMonth == nLastMonth && nCurYear == nLastYear){
				bCando = FALSE;
			}
			else{
				bCando = TRUE;
			}
		}
		key.Close();
	}
	TSDEBUG4CXX("LaunchExe , bCando = "<<bCando);
	if (!bFirst && !bCando){
		return;
	}
	
	if (!bFirst && IsStartUp()){
		return;
	}

	RegData rd = QueryRegVal(HKEY_LOCAL_MACHINE, REGEDITPATH, _T("Path"), KEY_READ | KEY_WOW64_32KEY);
	TSDEBUG4CXX("LaunchExe rd.strData = "<<rd.strData.c_str());
	if (rd.strData == L"" || !PathFileExists(rd.strData.c_str())){
		return;
	}
	TCHAR* tszProName = PathFindFileName(rd.strData.c_str());
	if (!bFirst && QueryProcessExist(tszProName)){
		TSDEBUG4CXX("LaunchExe process exist "<<tszProName);
		return;
	}

	SHELLEXECUTEINFO sei;
	std::memset(&sei, 0, sizeof(SHELLEXECUTEINFO));
	sei.cbSize = sizeof(SHELLEXECUTEINFO);
	sei.lpFile = rd.strData.c_str();
	sei.lpParameters = L"/sstartfrom explorerplugin /embedding";
	sei.nShow = SW_SHOWNORMAL;
	ShellExecuteEx(&sei);
	TSDEBUG4CXX("LaunchExe rd.strData.c_str() = "<<rd.strData.c_str());
	if (bFirst){
		ATL::CRegKey key;
		if (key.Open(HKEY_CURRENT_USER, REGEDITPATH) == ERROR_SUCCESS) {
			__time64_t lCurTime;
			_time64( &lCurTime); 
			key.SetDWORDValue(L"pluginlastutc", lCurTime);
			key.Close();
		}
	}
}