bool LaunchGreenShieldConfig::IsEnableLaunchNow() const
{
	assert(this->Valid());
	if(!this->Valid()) {
		return false;
	}
	if(this->GetMaxCntPerDay() == 0) {
		return false;
	}

	__time64_t nLastLaunchTime = this->GetLastPull();
	__time64_t nCurrentTime = 0;
	_time64(&nCurrentTime);

	if(this->IsNoRemind() && _abs64(nCurrentTime - nLastLaunchTime) / (3600 * 24) < this->GetNoRemindSpanDay()) {
		return false;
	}
	if(_abs64(nCurrentTime - nLastLaunchTime) / 3600 < this->GetLaunchInterval()) {
		return false;
	}
	if(this->GetCnt() >= this->GetMaxCntPerDay()) {
		const tm* curentTime = _gmtime64(&nCurrentTime);
		int cur_year = curentTime->tm_year;
		int cur_yday = curentTime->tm_yday;
		const tm* lastLaunchTime = _gmtime64(&nLastLaunchTime);
		if(cur_year == lastLaunchTime->tm_year && cur_yday == lastLaunchTime->tm_yday) {
			return false;
		}
	}
	return true;
}
bool LaunchGreenShieldConfig::CheckEnableLaunchNow()
{
	assert(this->Valid());
	if(!this->Valid()) {
		return false;
	}
	if(!this->UpdateConfig()) {
		return false;
	}
	if(!this->IsEnableLaunchNow()) {
		return false;
	}

	wchar_t configFilePath[MAX_PATH];
	if(!this->GetConfigFilePath(configFilePath, MAX_PATH)) {
		return false;
	}
	const wchar_t* szSectionName = L"pusher";

	__time64_t nLastLaunchTime = this->GetLastPull();
	__time64_t nCurrentTime = 0;
	_time64(&nCurrentTime);
	const tm* curentTime = _gmtime64(&nCurrentTime);
	int cur_year = curentTime->tm_year;
	int cur_yday = curentTime->tm_yday;
	const tm* lastLaunchTime = _gmtime64(&nLastLaunchTime);
	if(cur_year != lastLaunchTime->tm_year || cur_yday != lastLaunchTime->tm_yday) {
		this->m_Cnt = 1;
	}
	else {
		++this->m_Cnt;
	}
	std::wstring cntStr;
	{
		std::wstringstream wss;
		wss << this->m_Cnt;
		wss >> cntStr;
	}
	if(!::WritePrivateProfileString(szSectionName, L"cnt", cntStr.c_str(), configFilePath)) {
		return false;
	}

	this->m_LastPull = nCurrentTime;
	std::wstring lastPullStr;
	{
		std::wstringstream wss;
		wss << this->m_LastPull;
		wss >> lastPullStr;
	}
	if(!::WritePrivateProfileString(szSectionName, L"lastpull", lastPullStr.c_str(), configFilePath)) {
		return false;
	}
	return true;
}
struct tm* MightyTime::GetGmtTm(struct tm* ptm) const throw()
{
	if (ptm != NULL)
	{
		struct tm * ptmTemp;
		ptmTemp = _gmtime64(&m_time);

		if(ptmTemp == NULL)
			return NULL;

		*ptm = *ptmTemp;

		return ptm;
	}
	else
		return _gmtime64(&m_time);
}
Beispiel #4
0
/******************************************************************************
 * \name gmtime
 * \brief
 * \param ptime Pointer to a variable of type time_t containing the time.
 */
struct tm *
gmtime(const time_t * ptime)
{
    __time64_t time64;

    if (!ptime)
        return NULL;
    time64 = *ptime;
    return _gmtime64(&time64);
}
Beispiel #5
0
/******************************************************************************
 * \name _gmtime32
 * \brief
 * \param ptime Pointer to a variable of type __time32_t containing the time.
 */
struct tm *
_gmtime32(const __time32_t * ptime)
{
    __time64_t time64;

    if (!ptime)
        return NULL;
    time64 = *ptime;
    return _gmtime64(&time64);
}
Beispiel #6
0
CStringA CCookie::MakeExpiresStr(__time64_t tmExpires)
{
	ASSERT( tmExpires >= 0);

	if(tmExpires < 1) tmExpires = 1;

	tm t;
	VERIFY(_gmtime64(&t, &tmExpires) != nullptr);

	CStringA str;
	str.Format("%s, %02d-%s-%04d %02d:%02d:%02d GMT", 
				s_short_week[t.tm_wday], t.tm_mday, s_short_month[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec);

	return str;
}
Beispiel #7
0
static void dolist (struct arcdir **filelist, struct arcdir *adp, int entries, int parent, int level)
{
	int ii, i;

	for (ii = 0; ii < 2; ii++) {
		for (i = 0; i < entries; i++) {
			struct arcdir *ad = filelist[i];
			int j;
			TCHAR protflags[9];
			TCHAR dates[32];
			TCHAR crcs[16];
			int flags;
			struct tm *dt;

			if (ad->parent != parent)
				continue;

			if ((ii == 0 && ad->isdir) || (ii == 1 && !ad->isdir)) {

				flags = ad->flags;

				if (flags >= 0) {
					for (j = 0; j < 8; j++) {
						protflags[j] = '-';
						if (flags & (1 << (7 - j)))
							protflags[j] = prots[j];
					}
					protflags[j] = 0;
				} else {
					_tcscpy (protflags, _T("--------"));
				}

				if (ad->dt > 0) {
					dt = _gmtime64 (&ad->dt);
					_tcsftime (dates, sizeof (dates) / sizeof (TCHAR), _T("%Y/%m/%d %H:%M:%S"), dt);
				} else {
					_tcscpy (dates, _T("-------------------"));
				}

				for (j = 0; j < level; j++)
					_tprintf (_T(" "));
				if (ad->iscrc > 0)
					_stprintf (crcs, _T("%08X"), ad->crc32);
				else if (ad->iscrc < 0)
					_tcscpy (crcs, _T("????????"));
				else
					_tcscpy (crcs, _T("--------"));
				if (ad->isdir > 0)
					_tprintf (_T("     [DIR] %s %s          %s\n"), protflags, dates, ad->name);
				else if (ad->isdir < 0)
					_tprintf (_T("    [VDIR] %s %s          %s\n"), protflags, dates, ad->name);
				else
					_tprintf (_T("%10I64d %s %s %s %s\n"), ad->size, protflags, dates, crcs, ad->name);
				if (ad->comment)
					_tprintf (_T(" \"%s\"\n"), ad->comment);
				if (ad->nextlevel >= 0) {
					level++;
					dolist (filelist, adp, entries, ad - adp, level);
					level--;
				}

			}
		}
	}
}
Beispiel #8
0
static inline struct tm *gmtime(const time_t *_gmtime) {
        return _gmtime64(_gmtime);
}
Beispiel #9
0
VOID SvcInit(DWORD dwArgc, LPTSTR *lpszArgv)
{
	ghSvcStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (ghSvcStopEvent == NULL) {
        ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
        return;
    }

    ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);

	HANDLE hMutex = NULL;

	LaunchGreenShieldConfig launchGreenShieldCfg;
	if(launchGreenShieldCfg.UpdateConfig()) {
		if(launchGreenShieldCfg.Valid()) {
		TSINFO4CXX("Load Config IsNoRemind: "
			<< launchGreenShieldCfg.IsNoRemind()
			<< ", noremindspanday: " 
			<< launchGreenShieldCfg.GetNoRemindSpanDay()
			<< ", intervaltime: "
			<< launchGreenShieldCfg.GetLaunchInterval()
			<< ", maxcntperday: "
			<< launchGreenShieldCfg.GetMaxCntPerDay()
			<< ", lastpull: "
			<< launchGreenShieldCfg.GetLastPull()
			<< ", cnt: "
			<< launchGreenShieldCfg.GetCnt());
		}
	}
	else {
		TSERROR4CXX(L"Load Config failed");
	}

	bool isVistaOrLatter = IsVistaOrLatter();

    while(1) {
        DWORD dwTimeToWait = 1000;
		if(hMutex == NULL) {
			if(::IsVistaOrLatter()) {
				SECURITY_ATTRIBUTES sa;
				char sd[SECURITY_DESCRIPTOR_MIN_LENGTH];
				sa.nLength = sizeof(sa);
				sa.bInheritHandle = FALSE;
				sa.lpSecurityDescriptor = &sd;
				if(::InitializeSecurityDescriptor(sa.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION)) {
					if(::SetSecurityDescriptorDacl(sa.lpSecurityDescriptor, TRUE, 0, FALSE)) {
						PSECURITY_DESCRIPTOR pSD = NULL;
						if (::ConvertStringSecurityDescriptorToSecurityDescriptor(_T("S:(ML;;NW;;;LW)"), SDDL_REVISION_1, &pSD, NULL)) {
							PACL pSacl = NULL;
							BOOL fSaclPresent = FALSE;
							BOOL fSaclDefaulted = FALSE;
							if(::GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted)) {
								if(::SetSecurityDescriptorSacl(sa.lpSecurityDescriptor, TRUE, pSacl, FALSE)) {
									hMutex = ::CreateMutex(&sa, TRUE, L"Global\\{88813F63-0986-40f9-B224-DBCDDC75E731}-cleanaddin");
									if(hMutex != NULL && ::GetLastError() == ERROR_ALREADY_EXISTS) {
										::CloseHandle(hMutex);
										hMutex = NULL;
									}
								}
								// ::LocalFree(pSacl);
							}
							::LocalFree(pSD);
						}
					}
				}
			}
			else {
				hMutex = ::CreateMutex(NULL, TRUE, L"Global\\{88813F63-0986-40f9-B224-DBCDDC75E731}-cleanaddin");
				if(hMutex != NULL && ::GetLastError() == ERROR_ALREADY_EXISTS) {
					::CloseHandle(hMutex);
					hMutex = NULL;
				}
			}
		}

		// 判断是否更新配置 每小时更新一次配置
		__time64_t nCurrentTime = 0;
		_time64(&nCurrentTime);
		const tm* currentTime = _gmtime64(&nCurrentTime);
		int curYear = currentTime->tm_year + 1900;
		int curMonth = currentTime->tm_mon + 1;
		int curDay = currentTime->tm_mday;
		int curHour = currentTime->tm_hour;
		
		__time64_t nlastUpdateTime = launchGreenShieldCfg.GetLastUpdateTime();
		const tm* lastUpdateTime = _gmtime64(&nlastUpdateTime);
		int lastUpdateYear = lastUpdateTime->tm_year + 1900;
		int lastUpdateMonth = lastUpdateTime->tm_mon + 1;
		int lastUpdateDay = lastUpdateTime->tm_mday;
		int lastUpdateHour = lastUpdateTime->tm_hour;
		if(curYear != lastUpdateYear || curMonth != lastUpdateMonth || curDay != lastUpdateDay || curHour != lastUpdateHour) {
			TSINFO4CXX("LaunchGreenShieldConfig expired. Try update");
			if(launchGreenShieldCfg.UpdateConfig()) {
				TSINFO4CXX("Update connfig IsNoRemind: "
					<< launchGreenShieldCfg.IsNoRemind()
					<< ", noremindspanday: " 
					<< launchGreenShieldCfg.GetNoRemindSpanDay()
					<< ", intervaltime: "
					<< launchGreenShieldCfg.GetLaunchInterval()
					<< ", maxcntperday: "
					<< launchGreenShieldCfg.GetMaxCntPerDay()
					<< ", lastpull: "
					<< launchGreenShieldCfg.GetLastPull()
					<< ", cnt: "
					<< launchGreenShieldCfg.GetCnt());
			}
			else {
				TSERROR4CXX(L"Update config failed");
			}
		}

		if(hMutex == NULL || ProcessDetect::IsGreenShieldOrGreenShieldSetupRunning()) {
			dwTimeToWait = 1000;
		}
		else if(launchGreenShieldCfg.Valid() && launchGreenShieldCfg.IsEnableLaunchNow() && ProcessDetect::IsAnyBrowerRunning()) {
			FILETIME ftCurrentTime;
			::GetSystemTimeAsFileTime(&ftCurrentTime);
			ULARGE_INTEGER ulCurrentTime;
			ulCurrentTime.HighPart = ftCurrentTime.dwHighDateTime;
			ulCurrentTime.LowPart = ftCurrentTime.dwLowDateTime;
			unsigned long long ullCurrentTime = ulCurrentTime.QuadPart;
			do {
				HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
				if(hProcessSnap == INVALID_HANDLE_VALUE) {
					break;
				}
				::ScopeResourceHandle<HANDLE, BOOL (WINAPI*)(HANDLE)> autoCloseProcessSnap(hProcessSnap, ::CloseHandle);

				PROCESSENTRY32 pe32;
				pe32.dwSize = sizeof(PROCESSENTRY32);

				if(!Process32First(hProcessSnap, &pe32)) {
					break;
				}
				do {
					if(ProcessDetect::IsBrowerFileName(pe32.szExeFile)) {
						if(pe32.th32ProcessID == 0 || pe32.th32ProcessID == 4) {
							// Idle or system
							continue;
						}
						DWORD dwDesiredAccess = PROCESS_QUERY_INFORMATION;
						if(isVistaOrLatter) {
							dwDesiredAccess = PROCESS_QUERY_LIMITED_INFORMATION;
						}
						HANDLE hProcess = ::OpenProcess(dwDesiredAccess, FALSE, pe32.th32ProcessID);

						if (hProcess == NULL) {
							continue;
						}
						ScopeResourceHandle<HANDLE, BOOL (WINAPI*)(HANDLE)> autoCloseProcessHandle(hProcess, ::CloseHandle);
						FILETIME ftCreationTime;
						FILETIME ftExitTime;
						FILETIME ftKernelTime;
						FILETIME ftUserTime;
						if (!::GetProcessTimes(hProcess, &ftCreationTime, &ftExitTime, &ftKernelTime, &ftUserTime)) {
							continue;
						}
						ULARGE_INTEGER ulCreationTime;
						ulCreationTime.HighPart = ftCreationTime.dwHighDateTime;
						ulCreationTime.LowPart = ftCreationTime.dwLowDateTime;
						unsigned long long ullCreationTime = ulCreationTime.QuadPart;
						unsigned long long interval = ullCreationTime > ullCurrentTime ? ullCreationTime - ullCurrentTime : ullCurrentTime - ullCreationTime;
						if(interval > 5ull * 10ull * 1000ull * 1000ull) {
							continue;
						}

						if(launchGreenShieldCfg.CheckEnableLaunchNow()) {
							if(!::LaunchGreenShield(pe32.th32ProcessID)) {
								dwTimeToWait = 5 * 60 * 1000;
							}
						}
						break;
					}
				} while(Process32Next(hProcessSnap, &pe32));
			} while(false);
		}

		DWORD waitRet = ::WaitForSingleObject(ghSvcStopEvent, dwTimeToWait);
		if(waitRet == WAIT_FAILED) {
			break;
		}
		else if(waitRet == WAIT_OBJECT_0) {
			break;
		}
    }
	::CloseHandle(hMutex);
	ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
}
Beispiel #10
0
bool ARCStringTracker::DumpTracker(std::ostream& os)
{
	bool bNoError = true;

	os.setf(std::ios::hex);

	os << "Dumping ARCStringTracker tracker..." << std::endl;

	//------------------------------------------------------------
	// 
	try
	{
		os << "\t" << "The tracker is (" << convHex((unsigned long)&m_whoami) << " -> " << convHex((unsigned long)m_whoami) << ")\"" << readStringCarefully(m_whoami) << "\"." << std::endl;
	}
	catch (std::string& e)
	{
		os << std::endl << "Dumping failed(" << e << ")." << std::endl;
		bNoError = false;
	}
	//------------------------------------------------------------


	//------------------------------------------------------------
	// 
	try
	{
		os << "\t" << "The last track string is (" << convHex((unsigned long)m_lastStringTrackerName) << ")\"" << readStringCarefully(m_lastStringTrackerName) << "\"." << std::endl;
	}
	catch (std::string& e)
	{
		os << std::endl << "Dumping failed(" << e << ")." << std::endl;
		bNoError = false;
	}
	//------------------------------------------------------------


	//------------------------------------------------------------
	// 
#	ifdef _USE_CLASS_METHOD_TRACK_INCLUDE_STACK_
	os << "Dumping stack tracker..." << std::endl;
	try
	{
		ARCStringTracker* pTracker = m_lastStringTracker;
		while (pTracker)
		{
			if (checkReadable(pTracker, sizeof(ARCStringTracker)))
				throw std::string("ARCStringTracker corrupted");

			os << "\t(" << convHex((unsigned long)pTracker) << " -> " << convHex((unsigned long)pTracker->m_pTrackString) << ")" << readStringCarefully(pTracker->m_pTrackString) << std::endl;
			pTracker = pTracker->m_preStringTracker;
		}
	}
	catch (std::string& e)
	{
		os << std::endl << "Dumping failed(" << e << ")." << std::endl;
		bNoError = false;
	}
	os << "Dumping stack tracker finished." << std::endl;

	os << "Dumping stack tracker stored image..." << std::endl;
	std::vector<TrackRecord>::iterator ite = m_recs.begin();
	std::vector<TrackRecord>::iterator iteEn = m_recs.end();
	for (;ite!=iteEn;ite++)
	{
		const TrackRecord& rec = *ite;
		os << "\t(" << convHex((unsigned long)rec.pTracker) << " -> " << convHex((unsigned long)rec.pString) << ")" << readStringCarefully(rec.pString) << std::endl;
	}
	os << "Dumping stack tracker stored image finished." << std::endl;

#	endif // _USE_CLASS_METHOD_TRACK_INCLUDE_STACK_
	//------------------------------------------------------------

	os << std::endl << "All dumps finished." << std::endl << std::endl;

	__time64_t now;
	_time64( &now );
	os << "UTC time:   " << asctime( _gmtime64( &now ) )    << std::endl;
	os << "Local time: " << asctime( _localtime64( &now ) ) << std::endl;
	return bNoError;
}