Ejemplo n.º 1
0
/* Convert *TP to UTC, storing the broken-down time into *TMP.
   Return TMP if successful, NULL otherwise.  This is like gmtime_r(TP, TMP),
   except typically faster if USE_LOCALTIME_RZ.  */
static struct tm *
my_gmtime_r(time_t *tp, struct tm *tmp)
{
	return USE_LOCALTIME_RZ ?
	    localtime_rz(gmtz, tp, tmp) : gmtime_r(tp, tmp);
}

#ifndef TYPECHECK
#define my_localtime_rz	localtime_rz
#else /* !defined TYPECHECK */
static struct tm *
my_localtime_rz(timezone_t tz, const time_t *tp, struct tm *tmp)
{
	tmp = localtime_rz(tz, tp, tmp);
	if (tmp) {
		struct tm	tm;
		time_t	t;

		tm = *tmp;
		t = mktime_z(tz, &tm);
		if (t != *tp) {
			(void) fflush(stdout);
			(void) fprintf(stderr, "\n%s: ", progname);
			(void) fprintf(stderr, tformat(), *tp);
			(void) fprintf(stderr, " ->");
			(void) fprintf(stderr, " year=%d", tmp->tm_year);
			(void) fprintf(stderr, " mon=%d", tmp->tm_mon);
			(void) fprintf(stderr, " mday=%d", tmp->tm_mday);
			(void) fprintf(stderr, " hour=%d", tmp->tm_hour);
			(void) fprintf(stderr, " min=%d", tmp->tm_min);
			(void) fprintf(stderr, " sec=%d", tmp->tm_sec);
			(void) fprintf(stderr, " isdst=%d", tmp->tm_isdst);
			(void) fprintf(stderr, " -> ");
			(void) fprintf(stderr, tformat(), t);
			(void) fprintf(stderr, "\n");
			errout = true;
		}
	}
	return tmp;
}
Ejemplo n.º 2
0
/* The minimum and maximum finite time values.  */
static time_t	absolute_min_time =
  ((time_t) -1 < 0
    ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
    : 0);
static time_t	absolute_max_time =
  ((time_t) -1 < 0
    ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
   : -1);
static size_t	longest;
static char *	progname;
static int	warned;

static const char *	abbr(struct tm * tmp);
static void	abbrok(const char * abbrp, const char * zone);
static intmax_t	delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE;
static void	dumptime(const struct tm * tmp);
static time_t	hunt(char * name, time_t lot, time_t	hit);
static void	show(char * zone, time_t t, int v);
static const char *	tformat(void);
static time_t	yeartot(long y) ATTRIBUTE_PURE;

#ifndef TYPECHECK
#define my_localtime	localtime
#else /* !defined TYPECHECK */
static struct tm *
my_localtime(time_t *tp)
{
	struct tm *tmp;

	tmp = localtime(tp);
	if (tp != NULL && tmp != NULL) {
		struct tm	tm;
		time_t	t;

		tm = *tmp;
		t = mktime(&tm);
		if (t != *tp) {
			(void) fflush(stdout);
			(void) fprintf(stderr, "\n%s: ", progname);
			(void) fprintf(stderr, tformat(), *tp);
			(void) fprintf(stderr, " ->");
			(void) fprintf(stderr, " year=%d", tmp->tm_year);
			(void) fprintf(stderr, " mon=%d", tmp->tm_mon);
			(void) fprintf(stderr, " mday=%d", tmp->tm_mday);
			(void) fprintf(stderr, " hour=%d", tmp->tm_hour);
			(void) fprintf(stderr, " min=%d", tmp->tm_min);
			(void) fprintf(stderr, " sec=%d", tmp->tm_sec);
			(void) fprintf(stderr, " isdst=%d", tmp->tm_isdst);
			(void) fprintf(stderr, " -> ");
			(void) fprintf(stderr, tformat(), t);
			(void) fprintf(stderr, "\n");
		}
	}
	return tmp;
}
Ejemplo n.º 3
0
std::string
Variant::typeToString(Type t)
{
	switch (t)
	{
	case Void:          return "void";
	case Int:           return "int";
	case Float:         return "float";
	case Bool:          return "bool";
	case Float4:        return "float4";
	case String:        return "string";
	case Float4x4:      return "float4x4";
	case Blob:          return "blob";
	case Guid:          return "guid";
	case Object:        return "object";
	case IntArray:      return "intarray";
	case FloatArray:    return "floatarray";
	case BoolArray:     return "boolarray";
	case Float4Array:   return "float4array";
	case Float4x4Array: return "float4x4Array";
	case StringArray:   return "stringarray";
	default:
		throw failure(tformat(__TEXT("Variant::typeToString(): invalid type enum '%d'!")) % t);
	}
}
Ejemplo n.º 4
0
Variant::Type
Variant::stringToType(const std::string& str)
{
	if ("void" == str)             return Void;
	else if ("int" == str)              return Int;
	else if ("float" == str)            return Float;
	else if ("bool" == str)             return Bool;
	else if ("float4" == str)           return Float4;
	else if ("color" == str)            return Float4; // NOT A BUG!
	else if ("string" == str)           return String;
	else if ("Float4x4" == str)        return Float4x4;
	else if ("blob" == str)             return Blob;
	else if ("guid" == str)             return Guid;
	else if ("object" == str)           return Object;
	else if ("intarray" == str)         return IntArray;
	else if ("floatarray" == str)       return FloatArray;
	else if ("boolarray" == str)        return BoolArray;
	else if ("float4array" == str)      return Float4Array;
	else if ("Float4x4array" == str)   return Float4x4Array;
	else if ("stringarray" == str)      return StringArray;
	else
	{
		throw failure(tformat(__TEXT("Variant::stringToType(): invalid type string!")));
	}
}
Ejemplo n.º 5
0
static void
show(char *zone, time_t t, int v)
{
	register struct tm *	tmp;

	(void) printf("%-*s  ", (int) longest, zone);
	if (v) {
		tmp = gmtime(&t);
		if (tmp == NULL) {
			(void) printf(tformat(), t);
		} else {
			dumptime(tmp);
			(void) printf(" UTC");
		}
		(void) printf(" = ");
	}
	tmp = my_localtime(&t);
	dumptime(tmp);
	if (tmp != NULL) {
		if (*abbr(tmp) != '\0')
			(void) printf(" %s", abbr(tmp));
		if (v) {
			(void) printf(" isdst=%d", tmp->tm_isdst);
#ifdef TM_GMTOFF
			(void) printf(" gmtoff=%ld", tmp->TM_GMTOFF);
#endif /* defined TM_GMTOFF */
		}
	}
	(void) printf("\n");
	if (tmp != NULL && *abbr(tmp) != '\0')
		abbrok(abbr(tmp), zone);
}
Ejemplo n.º 6
0
static void
show(timezone_t tz, char *zone, time_t t, bool v)
{
	struct tm *	tmp;
	struct tm *	gmtmp;
	struct tm tm, gmtm;

	(void) printf("%-*s  ", (int) longest, zone);
	if (v) {
		gmtmp = my_gmtime_r(&t, &gmtm);
		if (gmtmp == NULL) {
			printf(tformat(), t);
		} else {
			dumptime(gmtmp);
			(void) printf(" UT");
		}
		(void) printf(" = ");
	}
	tmp = my_localtime_rz(tz, &t, &tm);
	dumptime(tmp);
	if (tmp != NULL) {
		if (*abbr(tmp) != '\0')
			(void) printf(" %s", abbr(tmp));
		if (v) {
			long off = gmtoff(tmp, NULL,  gmtmp);
			(void) printf(" isdst=%d", tmp->tm_isdst);
			if (off != LONG_MIN)
				(void) printf(" gmtoff=%ld", off);
		}
	}
	(void) printf("\n");
	if (tmp != NULL && *abbr(tmp) != '\0')
		abbrok(abbr(tmp), zone);
}
Ejemplo n.º 7
0
void driver::load(const std::wstring &name, const std::wstring &file)
{
	{
		tstring strBuf = boost::str(tformat(_T("[driver] [load(2)]    preparing to load driver - name: [%1%], file: [%2%]"))
			% name.c_str() % file.c_str() );
		TRACEBUFI(strBuf);
	}

	load(name, file, L"\\\\.\\" + name);
}
Ejemplo n.º 8
0
void driver::load(const std::wstring &name)
{
	wchar_t path[MAX_PATH + 1], *pathend;

	{
		tstring strBuf = boost::str(tformat(_T("[driver] [load(1)]    preparing to load driver - name: [%1%]")) % name.c_str() );
		TRACEBUFI(strBuf);
	}

	DWORD ret = SearchPath(NULL, name.c_str(), L".sys", MAX_PATH, path, &pathend);
	if(!ret) throw win32_error("SearchPath");

	load(name, path);
}
Ejemplo n.º 9
0
void
StackWalker::printModule(const util::string& img, const util::string& mod, DWORD64 baseAddr, DWORD size, DWORD result, const util::string& symType, const util::string& pdbName, ULONGLONG fileVersion) noexcept
{
	if (_options & _Mybase::module_info)
	{
		if (_options & _Mybase::file_version)
		{
			DWORD v4 = (DWORD)(fileVersion)& 0xFFFF;
			DWORD v3 = (DWORD)(fileVersion >> 16) & 0xFFFF;
			DWORD v2 = (DWORD)(fileVersion >> 32) & 0xFFFF;
			DWORD v1 = (DWORD)(fileVersion >> 48) & 0xFFFF;
			this->print(tformat(__TEXT("%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s', fileVersion: %d.%d.%d.%d")) % img % mod % baseAddr % size % result % symType % pdbName % v1 % v2 % v3 % v4, _module);
		}
		else
		{
			this->print(tformat(__TEXT("%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s'")) % img % mod % baseAddr % size % result % symType % pdbName, _module);
Ejemplo n.º 10
0
void CLogGraph::CopyToClipboard()
{
	if (!m_bDragSel)return;

	if ( !OpenClipboard() )
	{
		AfxMessageBox( "Cannot open the Clipboard" );
		return;
	} 
	if( !EmptyClipboard() )
	{
		AfxMessageBox( "Cannot empty the Clipboard" );
		return;
	}
	int size = m_pDataEt - m_pDataSt;
	tdata* p = m_pDataSt;
	CString strsum = "";
	CString str;
	for (int i = 0; i<size; i++)
	{
		str.Format("%s, %d\r\n", tformat("%Y-%m-%d %H:%M:%S", p->time), p->temp/100);
		strsum += str;
		p++;
	}

	HGLOBAL hGlobal = GlobalAlloc( GHND | GMEM_SHARE, (strsum.GetLength() + 1) *sizeof(TCHAR) );
	PSTR pGlobal = (PSTR)GlobalLock( hGlobal );
	lstrcpy( pGlobal, TEXT( strsum ) );
	GlobalUnlock( hGlobal ); 



	if ( ::SetClipboardData( CF_TEXT, hGlobal  ) == NULL )
	{
		AfxMessageBox( "Unable to set Clipboard data" );
		CloseClipboard();
		return;
	}

	CloseClipboard(); 


}
Ejemplo n.º 11
0
void driver::close()
{
	TRACEI("[driver] [close]  > Entering routine.");

	tstring strBuf = boost::str(tformat(_T("[driver] [close]   closing driver - name: [%1%]")) % m_name.c_str() );
	TRACEBUFI(strBuf);

	if(!m_loaded)
	{
		TRACEW("[driver] [close]    Tried to close driver, but it wasn't loaded.");
		TRACEI("[driver] [close]  < Leaving routine (without doing anything).");
		return;
	}

	stop();

	if(this->removable)
	{
		TRACEV("[driver] [close]    driver is removable");
		SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if(!manager) throw win32_error("OpenSCManager");

		SC_HANDLE service = OpenService(manager, m_name.c_str(), SERVICE_ALL_ACCESS);
		if(!service) {
			DWORD err = GetLastError();

			CloseServiceHandle(manager);
			throw win32_error("OpenService", err);
		}

		DeleteService(service);

		CloseServiceHandle(service);
		CloseServiceHandle(manager);
	}

	TRACEI("[driver] [close]    unloaded driver");
	m_loaded = false;

	TRACEI("[driver] [close]  < Leaving routine.");

} // End of close()
Ejemplo n.º 12
0
/* Show a time transition.  */
static void
showtrans(char const *time_fmt, struct tm const *tm, time_t t, char const *ab,
	  char const *zone_name)
{
  if (!tm) {
    printf(tformat(), t);
    putchar('\n');
  } else {
    char stackbuf[1000];
    size_t size = sizeof stackbuf;
    char *buf = stackbuf;
    char *bufalloc = NULL;
    while (! istrftime(buf, size, time_fmt, tm, t, ab, zone_name)) {
      size = sumsize(size, size);
      free(bufalloc);
      buf = bufalloc = xmalloc(size);
    }
    puts(buf);
    free(bufalloc);
  }
}
Ejemplo n.º 13
0
static char *date_time_str (int32 timepast)
{
	long days, hours, mins, secs; 
	static char tmptime[50];
	char *fptr, *tmpptr;

	/* 14Aug2010, Maiko, Should really be using a format string here */
	sprintf (tmptime, "%s", tformat (secclock() - timepast));

	tmpptr = tmptime;

	// log (-1, "date_time_str (%d) [%s]", strlen (tmptime), tmptime);

	days = strtol (tmpptr, &tmpptr, 0);
	hours = strtol (tmpptr+1, &tmpptr, 0);
	mins = strtol (tmpptr+1, &tmpptr, 0);
	secs = strtol (tmpptr+1, &tmpptr, 0);

	fptr = tmptime;

	/* log (-1, "days %ld hours %ld mins %ld secs %ld",
		days, hours, mins, secs);
	 */

	*fptr = 0;	/* always start with a null string */

	if (days)
		fptr += sprintf (fptr, " %ld day", days);
	if (hours)
		fptr += sprintf (fptr, " %ld hour", hours);
	if (mins)
		fptr += sprintf (fptr, " %ld min", mins);
	if (secs)
		fptr += sprintf (fptr, " %ld sec", secs);

	return tmptime;
}
Ejemplo n.º 14
0
void driver::load(const std::wstring &name, const std::wstring &file, const std::wstring &devfile)
{
	TRACEV("[driver] [load(3)]  > Entering routine.");
	if(m_loaded) throw std::exception("driver already loaded", 0);

	{
		tstring strBuf = boost::str(tformat(_T("[driver] [load(3)]    loading driver - name: [%1%], file: [%2%], devfile: [%3%]"))
			% name.c_str() % file.c_str() % devfile.c_str() );
		TRACEBUFI(strBuf);
	}

	m_name = name;
	m_file = file;
	m_devfile = devfile;

	SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager) throw win32_error("OpenSCManager");

	SC_HANDLE service = CreateService(manager, m_name.c_str(), m_name.c_str(),
		SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
		m_file.c_str(), NULL, NULL, NULL, NULL, NULL);

	if(!service)
	{
		DWORD err = 0;

		TRACEERR("[driver] [load(3)]", L"driver not currently installed as service", err = GetLastError());

		err = 0;
		service = OpenService(manager, m_name.c_str(), SERVICE_ALL_ACCESS);
		if(!service)
		{
			TRACEERR("[driver] [load(3)]", L"opening service", err = GetLastError());
			CloseServiceHandle(manager);
			throw win32_error("OpenService", err);
		}

		// make sure it has the same path as m_file.

		DWORD bytes;
		BOOL ret = QueryServiceConfig(service, NULL, 0, &bytes);

		if(ret || (err = GetLastError()) != ERROR_INSUFFICIENT_BUFFER)
		{
			TRACEERR("[driver] [load(3)]", L"calling QueryServiceConfig", err);
			CloseServiceHandle(service);
			CloseServiceHandle(manager);
			throw win32_error("QueryServiceConfig", err);
		}
		err = 0; // reset error-code, so that nobody else accidentally trips over it.

		QUERY_SERVICE_CONFIG *qsc = (QUERY_SERVICE_CONFIG*)malloc(bytes);
		if(!qsc)
		{
			TRACEERR("[driver] [load(3)]", L"allocating memory for QueryServiceConfig", err = GetLastError());
			CloseServiceHandle(service);
			CloseServiceHandle(manager);
			throw std::bad_alloc();
		}

		ret = QueryServiceConfig(service, qsc, bytes, &bytes);
		if(!ret)
		{
			TRACEERR("[driver] [load(3)]", L"second call to QueryServiceConfig", err = GetLastError());
			CloseServiceHandle(service);
			CloseServiceHandle(manager);
			throw win32_error("QueryServiceConfig", err);
		}

		bool del = _wcsicmp(qsc->lpBinaryPathName, m_file.c_str()) != 0;
		if (del)
		{
			// check for e.g. \??\C:\WINDOWS\System32\DRIVERS\ipfltdrv.sys
			wchar_t * descr = _wgetenv(L"WINDIR");
			if (descr)
			{
				wstring strFullPath(L"\\??\\");
				strFullPath += descr;
				strFullPath += L"\\";
				strFullPath += m_file;

				tstring strBuf = boost::str(tformat(_T("[driver] [load(3)]    comparing against driver full-path:[%1%]")) % strFullPath );
				TRACEBUFI(strBuf);

				del = _wcsicmp(qsc->lpBinaryPathName, strFullPath.c_str()) != 0;
			}
			else
			{
				TRACEW("[driver] [load(3)]    WINDIR environment variable not found!");
			}
		}

		tstring strBuf = boost::str(tformat(_T("[driver] [load(3)]    service name: [%1%], file name: [%2%]"))
			% qsc->lpBinaryPathName % m_file.c_str() );
		TRACEBUFI(strBuf);

		free(qsc);

		// paths don't match, remove service and recreate.
		if(del)
		{
			TRACEW("[driver] [load(3)]    paths don't match, removing and recreating driver-service");
			TCHAR buf[128];

			// if it's not removable, bail out.
			if(!this->removable)
			{
				TRACEC("[driver] [load(3)]    ERROR trying to remove driver-service");
				CloseServiceHandle(service);
				CloseServiceHandle(manager);
				throw std::exception("unremovable service mismatch", 0);
			}

			// check if its running
			SERVICE_STATUS status;
			ret = QueryServiceStatus(service, &status);
			if(!ret)
			{
				TRACEERR("[driver] [load(3)]", L"ERROR calling QueryServiceStatus", err = GetLastError());
				CloseServiceHandle(service);
				CloseServiceHandle(manager);
				throw win32_error("QueryServiceStatus", err);
			}

			// and stop it if it is.
			switch(status.dwCurrentState)
			{
				case SERVICE_STOPPED:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_STOPPED]");
					break;

				case SERVICE_START_PENDING:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_START_PENDING]");
					break;

				case SERVICE_STOP_PENDING:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_STOP_PENDING]");
					break;

				case SERVICE_RUNNING:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_RUNNING]");
					break;

				case SERVICE_CONTINUE_PENDING:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_CONTINUE_PENDING]");
					break;

				case SERVICE_PAUSE_PENDING:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_PAUSE_PENDING]");
					break;

				case SERVICE_PAUSED:
					TRACEI("[driver] [load(3)]    service state: [SERVICE_PAUSED]");
					break;

				default:
					swprintf_s(buf, _countof(buf), L"[driver] [load(3)]  * ERROR: Unknown service state: [%u]", status.dwCurrentState);
					TRACEBUFE(buf);
					break;
			}
			if(status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
			{
				ret = ControlService(service, SERVICE_CONTROL_STOP, &status);
				if(!ret)
				{
					TRACEERR("[driver] [load(3)]", L"ERROR stopping driver-service", err = GetLastError());
					CloseServiceHandle(service);
					CloseServiceHandle(manager);
					throw win32_error("ControlService", err);
				}
			}

			// now delete the service.
			ret = DeleteService(service);
			err = GetLastError();
			CloseServiceHandle(service);

			if(!ret && err != ERROR_SERVICE_MARKED_FOR_DELETE)
			{
				TRACEERR("[driver] [load(3)]", L"ERROR deleting driver-service", err);
				CloseServiceHandle(manager);
				throw win32_error("DeleteService", err);
			}

			// finally recreate it.
			service = CreateService(manager, m_name.c_str(), m_name.c_str(),
				SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
				m_file.c_str(), NULL, NULL, NULL, NULL, NULL);

			if(!service && (err = GetLastError()) == ERROR_SERVICE_MARKED_FOR_DELETE)
			{
				TRACEW("[driver] [load(3)]    Service marked for delete; trying closing/reopening SCM");
				CloseServiceHandle(manager);
				Sleep(10000);
				manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

				if (!manager)
				{
					TRACEERR("[driver] [load(3)]", L"ERROR while re-opening SCM", err = GetLastError());
					throw win32_error("OpenSCManager 2", err);
				}

				service = CreateService(manager, m_name.c_str(), m_name.c_str(),
					SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
					m_file.c_str(), NULL, NULL, NULL, NULL, NULL);
			}

			if(!service)
			{
				TRACEERR("[driver] [load(3)]", L"ERROR re-creating driver-service", err = GetLastError());
				CloseServiceHandle(manager);
				throw win32_error("CreateService", err);
			}

			TRACEI("[driver] [load(3)]    finished re-creating driver-service");
		}
	}

	SERVICE_STATUS status;
	if(QueryServiceStatus(service, &status))
	{
		if (status.dwCurrentState == SERVICE_RUNNING)
		{
			TRACES("[driver] [load(3)]    Driver-service is running");
			m_started = true;
		}
		else if (status.dwCurrentState == SERVICE_START_PENDING)
		{
			TRACEI("[driver] [load(3)]    Driver-service is starting");
		}
		else
		{
			TRACEI("[driver] [load(3)]    driver-service not running");
			TCHAR buf[128];
			swprintf_s(buf, _countof(buf), L"[driver] [load(3)]    - service state: [%u]", status.dwCurrentState);
			TRACEBUFW(buf);
		}
	}

	CloseServiceHandle(service);
	CloseServiceHandle(manager);

	m_loaded = true;
	TRACEV("[driver] [load(3)]  < Leaving routine.");
}
Ejemplo n.º 15
0
void CLogGraph::drawHeader(CDC& dc)
{
	XTPPaintManager()->GradientFill(&dc, m_rectHeader,m_crHeaderBack, RGB(0,0,0), FALSE);

	CPen* pOldPen, pen;
	CFont* pOldFont;
	CString fmt, s;
	int i;

	if (m_nScaleIndex != -1)
		drawScale(dc, m_nScaleIndex, m_rectScale, DT_RIGHT);

	if (m_nScaleIndex2 != -1)
		drawScale(dc, m_nScaleIndex2, m_rectScale2, DT_LEFT);

	// draw Header (로그 시작점, 로그 끝점 표시)

	CString tmp;

	pOldFont = dc.SelectObject(&m_fontHeader);
	dc.SetTextColor(m_crHeader);

	if (!m_bLoad)return;
	//short* a = new short [lib->mque_reclen(m_hQue)]; //////////////
	tdata* tp = getTptr(m_nCurrentPos);
	// read date
//	lib->mque_getn(m_hQue, m_nCurrentPos+1, a);
	m_tStart = tp->time;
	s = tformat("%Y-%m-%d\r\n%H:%M:%S", m_tStart);
	tmp.Format("%s\r\n%d", s, m_nCurrentPos);
	dc.DrawText(tmp, &m_rectHeader, DT_LEFT);

//	lib->mque_getn(m_hQue, getWndQueLastPos()-1, a);
	tp = getTptr(getWndQueLastPos()-1);
//	m_tEnd = lib->mque_time(m_hQue);
//	s = tformat("%Y-%m-%d\r\n%H:%M:%S", (int)m_tEnd);
	tmp.Format("%s\r\n%d", s, getWndQueLastPos());
	dc.DrawText(tmp, &m_rectHeader, DT_RIGHT);
//	delete a;

	// draw Header (nav button, zoom)
	
	int nav[4][20] = {		// 20x20 짜리 nav button
		{ 1,1,  4,1,  4,8,  18,1,  18,19,  4,12,  4,19,  1,19,  1,1,  0,0 },		// home
		{ 1,10,  10,1,  10,8,  19,1,  19,19,  10,12,  10,19,  1,10,  0,0 },			// pgup
		{ 1,1,   10,8,  10,1,  19,10,  10,19,  10,12,   1,19,  1,1,  0,0 },			// pgdn
		{ 1,1,  16,8,  16,1,  19,1,  19,19,  16,19,  16,12,  1,19,  1,1,  0,0 }		// end
	};

	CRect r = m_rectHeader;
	int w = 20;				// button width & height
	int iw = w - 4;		// icon size

	CBrush brush;
	CRgn rgn;
	CPoint pt[20];

	brush.CreateSolidBrush(RGB(255, 100, 100));
	pen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
	pOldPen = dc.SelectObject(&pen);
	r.left = r.Width() / 2 - (w * 4) / 2;
	r.right = r.left + w * 4;
	r.bottom = r.top + w;
	int x = r.left;
	for (i = 0; i < 4; i++) {
		CRect rect = r;
		rect.left = x + 1;
		rect.right = x + w - 1;
		rect.top++;
		rect.bottom--;
		switch (i) {
			case 0 : m_rectHome = rect; break;
			case 1 : m_rectPgUp = rect; break;
			case 2 : m_rectPgDn = rect; break;
			case 3 : m_rectEnd = rect; break;
		}

		XTPPaintManager()->GradientFill(&dc, &rect, RGB(100,100,100), RGB(0,0,0), FALSE);
		int j;
		for (j = 0; nav[i][j] !=0; j+=2) {
			pt[j/2].x = int(double(nav[i][j]) * iw / 20.0) + x + 2;
			pt[j/2].y = int(double(nav[i][j+1]) * iw / 20.0) + r.top + 2;
		}
		VERIFY(rgn.CreatePolygonRgn(pt, j/2, WINDING));
		dc.FillRgn(&rgn, &brush);
		rgn.DeleteObject();
		x += w;
	}
	dc.SelectObject(pOldPen);

	r.top = r.top + w;
	r.DeflateRect(2, 2);
	r.bottom = m_rectHeader.bottom;
	m_rectZoom = r;

	XTPPaintManager()->GradientFill(&dc, &r, RGB(100,50,50), RGB(0,0,0), FALSE);
	s.Format("Zoom %.0f:1", m_fZoomFactor);
	dc.DrawText(s, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

	dc.SelectObject(pOldFont);
}
Ejemplo n.º 16
0
void
StackWalker::printModule(const util::string& img, const util::string& mod, DWORD64 baseAddr, DWORD size, DWORD result, const util::string& symType, const util::string& pdbName, ULONGLONG fileVersion) noexcept
{
	if (_options & _Mybase::module_info)
	{
		if (_options & _Mybase::file_version)
		{
			DWORD v4 = (DWORD)(fileVersion)& 0xFFFF;
			DWORD v3 = (DWORD)(fileVersion >> 16) & 0xFFFF;
			DWORD v2 = (DWORD)(fileVersion >> 32) & 0xFFFF;
			DWORD v1 = (DWORD)(fileVersion >> 48) & 0xFFFF;
			this->print(tformat(__TEXT("%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s', fileVersion: %d.%d.%d.%d")) % img % mod % baseAddr % size % result % symType % pdbName % v1 % v2 % v3 % v4, _module);
		}
		else
		{
			this->print(tformat(__TEXT("%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s'")) % img % mod % baseAddr % size % result % symType % pdbName, _module);
		}
	}
}

void
StackWalker::printSymbol(const util::string& searchPath, DWORD symOptions, const util::string& username) noexcept
{
	if (_options & _Mybase::symbol)
	{
		this->print(tformat(__TEXT("SymInit: Symbol-SearchPath: '%s', symOptions: %d, UserName: '******'")) % searchPath % symOptions % username, _module);

		OSVERSIONINFOEX ver = { 0 };
		ver.dwOSVersionInfoSize = sizeof(ver);

		DWORDLONG conditionMask = 0;
Ejemplo n.º 17
0
//================================================================================================
//
//  PerformPrevRelUpdates()
//
//    - Called by Main_OnInitDialog()
//
/// <summary>
///   Checks the version of the last time we ran, and if that number falls within certain ranges
///   we'll do some release-specific cleanup.
/// </summary>
//
void PerformPrevRelUpdates(HWND _hwnd)
{
	int prevRelease = g_config.LastVersionRun;

	if (prevRelease == PB_VER_BUILDNUM)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    no version change, so no updates to perform");
		return;
	}

	if (prevRelease > PB_VER_BUILDNUM)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    WARNING:  Downgrade detected!");
		return;
	}


	//--------------------------------------------------
	// Update PG hosted lists to iblocklist

	if (prevRelease < 134)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    Checking for old peerguardian-hosted lists, and updating any found to iblocklist.com-hosted ones");

		vector<DynamicList> tempList;

		// check each list in configured lists
		for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i)
		{
			// if it's a peerguardian list
			DynamicList *list = &(g_config.DynamicLists[i]);
			if (list->Url.find(_T("http://peerguardian.sourceforge.net/lists/")) != string::npos)
			{
				// swap it out
				tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates]    found old URL: [%1%]")) % list->Url );
				TRACEBUFW(strBuf);

				if (list->Url.find(_T("ads.php")) != string::npos)
				{
					// http://list.iblocklist.com/?list=bt_ads
					TRACEW("[mainproc] [PerformPrevRelUpdates]    - replacing ads.php list with bt_ads");
					//list->Url = _T("http://list.iblocklist.com/?list=bt_ads");
					DynamicList newList = *list;
					newList.Url = _T("http://list.iblocklist.com/lists/bluetack/ads-trackers-and-bad-pr0n");
					tempList.push_back(newList);
				}
				else if (list->Url.find(_T("edu.php")) != string::npos)
				{
					// http://list.iblocklist.com/?list=bt_edu
					TRACEW("[mainproc] [PerformPrevRelUpdates]    - replacing edu.php list with bt_edu");
					//list->Url = _T("http://list.iblocklist.com/?list=bt_edu");
					DynamicList newList = *list;
					newList.Url = _T("http://list.iblocklist.com/lists/bluetack/edu");
					tempList.push_back(newList);
				}
				else if (list->Url.find(_T("p2p.php")) != string::npos)
				{
					// http://list.iblocklist.com/?list=bt_level1
					TRACEW("[mainproc] [PerformPrevRelUpdates]    - replacing p2p.php list with bt_level1");
					//list->Url = _T("http://list.iblocklist.com/?list=bt_level1");
					DynamicList newList = *list;
					newList.Url = _T("http://list.iblocklist.com/lists/bluetack/level-1");
					tempList.push_back(newList);
				}
				else if (list->Url.find(_T("spy.php")) != string::npos)
				{
					// http://list.iblocklist.com/?list=bt_spyware
					TRACEW("[mainproc] [PerformPrevRelUpdates]    - replacing spy.php list with bt_spyware");
					//list->Url = _T("http://list.iblocklist.com/?list=bt_spyware");
					DynamicList newList = *list;
					newList.Url = _T("http://list.iblocklist.com/lists/bluetack/spyware");
					tempList.push_back(newList);
				}
				else if (list->Url.find(_T("gov.php")) != string::npos)
				{
					// remove list
					TRACEW("[mainproc] [PerformPrevRelUpdates]    - removing gov list");
				}
				else
				{
					TRACEE("[mainproc] [PerformPrevRelUpdates]    ERROR:  Unknown PG2 list!!");
				}
			}
			else
			{
				TRACED("[mainproc] [PerformPrevRelUpdates]    found non-PG2 URL");
				DynamicList newList = *list;
				tempList.push_back(newList);
			}
		}

		// Rebuild list if we need to remove Gov list.  Also, check for duplicates.
		g_config.DynamicLists.clear();
		for(vector<DynamicList>::size_type i = 0; i < tempList.size(); ++i)
		{
			if (std::find(g_config.DynamicLists.begin(), g_config.DynamicLists.end(), tempList[i]) == g_config.DynamicLists.end())
			{
				g_config.DynamicLists.push_back(tempList[i]);
			}
		}
	}


	//--------------------------------------------------
	// Update old list-names to new ones

	// Now that iblocklist.com has support for some "friendly" URLs for lists, we can migrate people
	// away from the slow, unreliable bluetack.co.uk servers and over to iblocklist.  We're checking
	// against any of the bluetack URLs from our old dropdown list, and changing 'em over.  Same
	// thing for any of the old naming-scheme iblocklist URLs.  We're also removing the bluetack
	// "trojan" list, since it resolves to an unusable file and there is no iblocklist equivalent.

	if (prevRelease < 268)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    Checking for old-URL lists, and migrating them to the new naming scheme (r268)");
		int result = MessageBox(_hwnd, IDS_PREVREL268TEXT, IDS_PREVREL, MB_ICONINFORMATION|MB_YESNO);
		if (result == IDNO)
		{
			TRACEI("[mainproc] [PerformPrevRelUpdates]    user clicked No");
		}
		else if (result == IDYES)
		{
			TRACEI("[mainproc] [PerformPrevRelUpdates]    user clicked Yes");

			vector<DynamicList> tempList;
			ListUrls listUrls;
			listUrls.Init();

			// check each list in configured lists
			for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i)
			{
				DynamicList *list = &(g_config.DynamicLists[i]);
				LISTNAME listId = listUrls.FindListNum(list->Url);
				if (listId != LISTNAME_COUNT)
				{
					DynamicList newList = *list;
					newList.Url = listUrls.GetBestUrl(listId);
					tempList.push_back(newList);
					if (newList.Url.compare(list->Url) == 0)
					{
						tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates]    - found no better list url than [%1%]"))
							% list->Url.c_str() );
						TRACEBUFW(strBuf);
					}
					else
					{
						tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates]    - migrated list from [%1%] to [%2%]"))
							% list->Url.c_str() % newList.Url.c_str() );
						TRACEBUFW(strBuf);
					}
				}
				else if (list->Url.compare(_T("http://www.bluetack.co.uk/config/trojan.zip")) == 0)
				{
					TRACEW("[mainproc] [PerformPrevRelUpdates]    - removing no-longer-existant bt trojan");
				}
				else
				{
					tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates]    - found unknown list url [%1%], copying over as-is"))
						% list->Url.c_str() );
					TRACEBUFW(strBuf);
					DynamicList newList = *list;
					tempList.push_back(newList);
				}
			}

			// Rebuild list, checking for duplicates.
			g_config.DynamicLists.clear();
			for(vector<DynamicList>::size_type i = 0; i < tempList.size(); ++i)
			{
				if (std::find(g_config.DynamicLists.begin(), g_config.DynamicLists.end(), tempList[i]) == g_config.DynamicLists.end())
				{
					g_config.DynamicLists.push_back(tempList[i]);
				}
			}
		}
	}


	//--------------------------------------------------
	// Update max history.db size from old default of 0 (unlimited) to 100 MB

	if (prevRelease < 341)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    Checking for old History defaults of 0, and migrating it to the new default of 100 MB (r341)");

		if (g_config.CleanupType == None && g_config.MaxHistorySize > 0)
		{
			TRACEW("[mainproc] [PerformPrevRelUpdates]    CleanupType = None, updating it to Delete every 7 Days");
			MessageBox(_hwnd, IDS_PREVREL341TEXT_DEL, IDS_PREVREL, MB_ICONINFORMATION|MB_OK);
			g_config.CleanupType = Delete;
			g_config.CleanupInterval = 7;
			g_config.Save();
		}
		else if (g_config.MaxHistorySize == 0 && g_config.CleanupType != None)
		{
			TRACEW("[mainproc] [PerformPrevRelUpdates]    Max history.db size 0 ('unlimited'), updating it to 100 MB");
			MessageBox(_hwnd, IDS_PREVREL341TEXT_MAX, IDS_PREVREL, MB_ICONINFORMATION|MB_OK);
			g_config.MaxHistorySize = 100 * 1000000;	// g_config.MaxHistory is in bytes...
			g_config.Save();
		}
		else if (g_config.MaxHistorySize == 0 && g_config.CleanupType == None)
		{
			TRACEW("[mainproc] [PerformPrevRelUpdates]    Changing history.db max size to 100 MB, and CleaupType to Delete every 7 days");
			MessageBox(_hwnd, IDS_PREVREL341TEXT_BOTH, IDS_PREVREL, MB_ICONINFORMATION|MB_OK);
			g_config.CleanupType = Delete;
			g_config.CleanupInterval = 7;
			g_config.MaxHistorySize = 100 * 1000000;	// g_config.MaxHistory is in bytes...
			g_config.Save();
		}
		else
		{
			TRACEW("[mainproc] [PerformPrevRelUpdates]    Not changing config");
			tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates]    Max history.db size (%1%) ")) % g_config.MaxHistorySize );
			g_tlog.LogMessage(strBuf, TRACELOG_LEVEL_WARNING);
		}
	}


	//--------------------------------------------------
	// Update Bluetack Webexploit/Forumspam merged list to new individual lists, and cw_bogon list
	// to the most frequently updated one, cidr_bogon

	if (prevRelease < 411)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    Checking for Bluetack Webexploit/Forumspam, cr_bogon, or default lists (r411)");

		vector<DynamicList> tempList;
		ListUrls listUrls;
		listUrls.Init();

		// check each list in configured lists
		for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i)
		{
			DynamicList *list = &(g_config.DynamicLists[i]);
			LISTNAME listId = listUrls.FindListNum(list->Url);
			if (listId == LISTNAME_BT_WEBEX_FSPAM)
			{
				TRACEW("[mainproc] [PerformPrevRelUpdates]    Updating Bluetack Webexploit/Forumspam merged list to new individual lists");
				MessageBox(_hwnd, IDS_PREVREL411TEXT_WEBEX, IDS_PREVREL, MB_ICONINFORMATION|MB_OK);

				DynamicList * newList = new DynamicList;
				newList->Url = listUrls.GetBestUrl(LISTNAME_BT_WEBEXPLOIT);
				newList->Enabled = list->Enabled;
				newList->Description = listUrls.GetListDesc(LISTNAME_BT_WEBEXPLOIT);
				tempList.push_back(*newList);

				DynamicList * newList2 = new DynamicList;
				newList2->Url = listUrls.GetBestUrl(LISTNAME_BT_FORUMSPAM);
				newList2->Enabled = list->Enabled;
				newList2->Description = listUrls.GetListDesc(LISTNAME_BT_FORUMSPAM);
				tempList.push_back(*newList2);
			}
			else if (listId == LISTNAME_CW_BOGON)
			{
				TRACEW("[mainproc] [PerformPrevRelUpdates]    Updating CW Bogon list to CIDR Bogon");
				MessageBox(_hwnd, IDS_PREVREL411TEXT_BOGON, IDS_PREVREL, MB_ICONINFORMATION|MB_OK);

				DynamicList * newList = new DynamicList;
				newList->Url = listUrls.GetBestUrl(LISTNAME_CIDR_BOGON);
				newList->Enabled = list->Enabled;
				newList->Description = listUrls.GetListDesc(LISTNAME_CIDR_BOGON);
				tempList.push_back(*newList);
			}
			else if ( listId == LISTNAME_BT_LEVEL1 || listId == LISTNAME_BT_ADS ||
					  listId == LISTNAME_BT_SPY || listId == LISTNAME_BT_EDU )
			{
				// Make sure Default Lists are set to Block, not Allow.  This will also take care
				// of any misconfigured PG2 lists, and is especially important since the PeerBlock
				// List Manager has no easy way to set lists to Block instead of Allow, nor will
				// it show you that it's an Allow list.

				if (list->Type == List::Allow)
				{
					tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates]    Updating list:[%1%] from type:[Allow] to type:[Block]")) % list->Description );
					TRACEBUFW(strBuf);

					DynamicList * newList = new DynamicList;
					newList->Url = list->Url;
					newList->Enabled = list->Enabled;
					newList->Description = list->Description;
					newList->Type = List::Block;
					tempList.push_back(*newList);
				}
				else
				{
					tempList.push_back(*list);
				}
			}
			else
			{
				// not LISTNAME_BT_WEBEX_FSPAM, LISTNAME_CIDR_BOGON, or a default list
				tempList.push_back(*list);
			}
		}

		// Rebuild list, checking for duplicates.
		g_config.DynamicLists.clear();
		for(vector<DynamicList>::size_type i = 0; i < tempList.size(); ++i)
		{
			if (std::find(g_config.DynamicLists.begin(), g_config.DynamicLists.end(), tempList[i]) == g_config.DynamicLists.end())
			{
				g_config.DynamicLists.push_back(tempList[i]);
			}
		}

	} // end of webex/forumspam update (r411)


	//--------------------------------------------------
	// Delete history.db if it's too large

	if (prevRelease < 454)
	{
		// check for filesize of history.db
		TRACEI("[mainproc] [PerformPrevRelUpdates]    checking size of history.db (r454)");

		struct _stat64 fileStat;
		path history_file = path::base_dir()/_T("history.db");
		int ret = _tstat64( history_file.c_str(), &fileStat );

		if (ret == 0)
		{
			// if it's too-large, delete it outright
			if (fileStat.st_size > g_config.MaxHistorySize*1.5) // 150 MB, by default
			{
				TRACEW("[mainproc] [PerformPrevRelUpdates]    Too-large history.db file detected!");
				path::remove(history_file);
				TRACEW("[mainproc] [PerformPrevRelUpdates]    Deleted history.db");
			}
		}

	} // end of delete too-large history.db (r454)


	//--------------------------------------------------
	// Remove I-Blocklist Subscription URL params if present, add them to peerblock.conf instead

	if (prevRelease < 653)
	{
		TRACEW("[mainproc] [PerformPrevRelUpdates]    Checking for I-Blocklist Subscription list URL params (r653)");

		ListUrls listUrls;
		listUrls.Init();
		tstring username;
		tstring pin;

		// check each list in configured lists
		for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i)
		{
			DynamicList *list = &(g_config.DynamicLists[i]);

			if (string::npos != list->Url.find(_T("http://list.iblocklist.com/?list=")))
			{
				// split url up into tokens
				size_t start = 0;
				size_t end = 0;
				map<tstring, tstring> params;

				start = list->Url.find(_T("?")) + 1;
				while (string::npos != end && string::npos != start)
				{
					end = list->Url.find(_T("&"), start);
					tstring paramSet = list->Url.substr(start,
						(end == string::npos) ? string::npos : end - start);
					start = (end > (string::npos - 1) ) ? string::npos : end + 1;

					size_t eqPos = 0;
					eqPos = paramSet.find(_T("="));
					if (string::npos != eqPos)
					{
						tstring key = paramSet.substr(0, eqPos);
						tstring val = paramSet.substr(eqPos + 1);
						params[key] = val;
					}
				}

				if (params.find(_T("username")) != params.end())
				{
					username = params.at(_T("username"));
				}

				if (params.find(_T("id")) != params.end())
				{
					username = params.at(_T("id"));
				}

				if (params.find(_T("pin")) != params.end())
				{
					pin = params.at(_T("pin"));
				}

				// sanity-check, make sure we didn't screw up and lost the list-param
				if (params.find(_T("list")) != params.end())
				{
					list->Url = tstring(_T("http://list.iblocklist.com/?list=")) + params.at(_T("list"));
				}
			}

			else if (string::npos != list->Url.find(_T("http://list.iblocklist.com/lists/")))
			{
				// split url up into tokens
				size_t urlRootEndPos = 0;
				size_t start = 0;
				size_t end = 0;
				map<tstring, tstring> params;

				urlRootEndPos = list->Url.find(_T("?"));
				if (string::npos != urlRootEndPos)
				{
					// we've got some params here
					start = urlRootEndPos + 1;
					while (string::npos != end && string::npos != start)
					{
						end = list->Url.find(_T("&"), start);
						tstring paramSet = list->Url.substr(start,
							(end == string::npos) ? string::npos : end - start);
						start = (end > (string::npos - 1) ) ? string::npos : end + 1;

						size_t eqPos = 0;
						eqPos = paramSet.find(_T("="));
						if (string::npos != eqPos)
						{
							tstring key = paramSet.substr(0, eqPos);
							tstring val = paramSet.substr(eqPos + 1);
							params[key] = val;
						}
					}

					if (params.find(_T("username")) != params.end())
					{
						username = params.at(_T("username"));
					}

					if (params.find(_T("id")) != params.end())
					{
						username = params.at(_T("id"));
					}

					if (params.find(_T("pin")) != params.end())
					{
						pin = params.at(_T("pin"));
					}

					// strip away all params from this URL, since none are applicable any longer
					list->Url = list->Url.substr(0, urlRootEndPos);
				}
			}
		}

		// if we have a username (id) and pin, save them to config, and remove them from here
		if (!username.empty() && !pin.empty())
		{
			g_config.IblUsername = username;
			g_config.IblPin = pin;
			g_config.Save();
		}

	} // end of i-blocklist subscription list-url param cleanup (r653)


	//--------------------------------------------------
	// Inform user about I-Blocklist's list-update limit

	if (prevRelease < 681)
	{
		TRACEI("[mainproc] [PerformPrevRelUpdates]    displaying info about I-Blocklist list-update limits (r681)");
        MessageBox(_hwnd, IDS_PREVREL681TEXT, IDS_PREVREL, MB_ICONINFORMATION|MB_OK);

	} // end of i-blocklist list-update limit info (r681)

}; // End of PerformPrevRelUpdates()
Ejemplo n.º 18
0
void CLogGraph::OnMouseMove(UINT nFlags, CPoint point)
{
	if (hitRect(point, m_rectGraph) && m_bNav) {
		CDC* pDC = GetDC();
		if (pDC) {
			int oldRop = pDC->GetROP2();
			pDC->SetROP2(R2_XORPEN);

			CPen pen(PS_DOT, 1, RGB(255, 255, 255));
			CPen* pOldPen = pDC->SelectObject(&pen);

			if (m_nLastCursorPos != -1) {
				pDC->MoveTo(m_rectGraph.left + m_nLastCursorPos, m_rectGraph.top);
				pDC->LineTo(m_rectGraph.left + m_nLastCursorPos, m_rectGraph.bottom);
			}

			m_nLastCursorPos = (point.x - m_rectGraph.left);
			pDC->MoveTo(m_rectGraph.left + m_nLastCursorPos, m_rectGraph.top);
			pDC->LineTo(m_rectGraph.left + m_nLastCursorPos, m_rectGraph.bottom);
			pDC->SelectObject(pOldPen);
			pDC->SetROP2(oldRop);

			if (m_bNav) {
				int pos = m_nCurrentPos + int(m_fZoomFactor * m_nLastCursorPos);
//				lib->mque_getn(m_hQue, pos, m_aTmp);
//				calcStat(m_aTmp, false);
				sendMsg(LG_NAV_MSG, pos);
				m_tLastNav = time(NULL);
			}
			ReleaseDC(pDC);
		}
	}

	if (m_bLdown)
	{
		m_bDragSel = true;
		m_ptEtMouse = point;
		redraw();
	}

	if (m_bLoad){
		tdata *tp = getTptr(m_nCurrentPos); //getPtrLeftPos();

		int x = point.x - m_rectGraph.left;	
		if (x < 0) goto NOMATCH;
		int last = getLength(); 
		int pos = m_nCurrentPos + point.x * (int)m_fZoomFactor - m_rectGraph.left;
		if (pos > last){
			goto NOMATCH;		
		}

		tp = tp+ x*((int)m_fZoomFactor);


		Channel* pCh = m_aChannels[0];
		int ey = m_rectGraph.top + m_rectGraph.Height();
		int ry = ey - int(pCh->C * (int(tp->temp) / pCh->scale - pCh->low));

	//	TRACE("%s %d\n", __FUNCTION__ , tp->temp);
	
		CString strTemp;
		CString stime = tformat("%Y-%m-%d %H:%M:%S", tp->time);
		strTemp.Format("%s\t  %d℃",stime, tp->temp/100 );
		//        strTemp.Format("%5ld",lUnitSize);
		m_ctrTooltip.Activate(TRUE);
		m_ctrTooltip.AddTool(this,strTemp, CRect(point.x-1,point.y-1,point.x+1,point.y+1), TRUE);    // skin[i].rc    각 버튼들의 Rect...
		m_ctrTooltip.Update();
	}
NOMATCH:	
//	TRACE("%s : cpos %d\n", __FUNCTION__, m_nCurrentPos);
	CWnd::OnMouseMove(nFlags, point);
}
Ejemplo n.º 19
0
void driver::start(bool _gethandle)
{
	TRACEV("[driver] [start]  > Entering routine.");
	if(m_started)
	{
		TRACEI("[driver] [start]    driver already started");
		return;
	}

	TRACEI("[driver] [start]    starting driver");

	DWORD err = 0;

	SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager)
	{
		TRACEERR("[driver] [start]", L"ERROR: OpenSCManager", err = GetLastError());
		throw win32_error("OpenSCManager");
	}

	SC_HANDLE service = OpenService(manager, m_name.c_str(), SERVICE_ALL_ACCESS);
	if(!service)
	{
		CloseServiceHandle(manager);
		TRACEERR("[driver] [start]", L"ERROR: OpenService", err = GetLastError());
		throw win32_error("OpenService", err);
	}

	if(!StartService(service, 0, NULL) && (err = GetLastError()) != ERROR_SERVICE_ALREADY_RUNNING)
	{
		bool startFailed = true;

		if (err == ERROR_SERVICE_DATABASE_LOCKED)
		{
			int numRetries = 0;

			do
			{
				TRACEW("[driver] [start]    experiencing ERROR_SERVICE_DATABASE_LOCKED condition; waiting 10 seconds and trying again");
				Sleep(10000); // 10 seconds
				err = 0;

				if (!StartService(service, 0, NULL) && (err = GetLastError()) != ERROR_SERVICE_ALREADY_RUNNING)
					// still having problems
					++numRetries;
				else
					// either success, or another error
					break;

			} while (err == ERROR_SERVICE_DATABASE_LOCKED && numRetries < 6);

			if (numRetries < 6 && (err == 0 || err == ERROR_SERVICE_ALREADY_RUNNING))
			{
				startFailed = false;
				TRACES("[driver] [start]    successfully recovered from ERROR_SERVICE_DATABASE_LOCKED condition");
			}
			else if (err == ERROR_SERVICE_DATABASE_LOCKED)
			{
				TRACEE("[driver] [start]    cannot recover from ERROR_SERVICE_DATABASE_LOCKED condition; giving up");
			}
			else
			{
				TRACEE("[driver] [start]    cannot recover from ERROR_SERVICE_DATABASE_LOCKED condition; another error surfaced; giving up");
			}
		}

		if (startFailed)
		{
			CloseServiceHandle(service);
			CloseServiceHandle(manager);

			TRACEERR("[driver] [start]", L"ERROR: StartService", err);
			throw win32_error("StartService", err);
		}
	}

	CloseServiceHandle(service);
	CloseServiceHandle(manager);

	if (_gethandle)
	{
		tstring strBuf = boost::str(tformat(_T("[driver] [start]    getting handle to driver - devfile: [%1%]")) % m_devfile.c_str() );
		TRACEBUFI(strBuf);

		m_dev = CreateFile(m_devfile.c_str(), GENERIC_READ | GENERIC_WRITE,
			0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);

		if(m_dev == INVALID_HANDLE_VALUE)
		{
			TRACEERR("[driver] [start]", L"ERROR: CreateFile", err = GetLastError());
			throw win32_error("CreateFile");
		}

		m_stoppable = true;
	}
	else
	{
		m_stoppable = false; // should only be false for MS IpFilterDriver
		TRACEI("[driver] [start]    flagging driver as not stoppable");
	}

	TRACEI("[driver] [start]    started driver");
	m_started = true;

	TRACEV("[driver] [start]  < Leaving routine.");

} // End of start()