Ejemplo n.º 1
1
CString NameFromVKey(UINT nVK)
{
	CString str;
	if (0x00 == nVK)
	{
		str = _T("None");
	}
	else if (VK_SNAPSHOT == nVK)
	{
		str = _T("Prt Scr");
	}
	else
	{
		UINT nScanCode = MapVirtualKeyEx(nVK, 0, GetKeyboardLayout(0));
		switch(nVK) {
			// Keys which are "extended" (except for Return which is Numeric Enter as extended)
			case VK_INSERT:
			case VK_DELETE:
			case VK_HOME:
			case VK_END:
			case VK_NEXT:  // Page down
			case VK_PRIOR: // Page up
			case VK_LEFT:
			case VK_RIGHT:
			case VK_UP:
			case VK_DOWN:
				nScanCode |= 0x100; // Add extended bit
		}	

		// GetKeyNameText() expects the scan code to be on the same format as WM_KEYDOWN
		// Hence the left shift
		LPTSTR prb = str.GetBuffer(80);
		BOOL bResult = GetKeyNameText(nScanCode << 16, prb, 79);

		// these key names are capitalized and look a bit daft
		int len = lstrlen(prb);
		if(len > 1) {
			LPTSTR p2 = CharNext(prb);
			CharLowerBuff(p2, len - (p2 - prb) );
		}

		str.ReleaseBuffer();
		ATLASSERT(str.GetLength());
	}
	return str; // internationalization ready, sweet!
}
Ejemplo n.º 2
0
int install_util::GetProcessCount(const TCHAR* szExeName)
{
  TCHAR sztarget[MAX_PATH] = {0};
  lstrcpy(sztarget, szExeName);
  CharLowerBuff(sztarget, MAX_PATH);

  int count = 0;
  PROCESSENTRY32 my = {0};
  HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if (((int)l) != -1)
  {
    my.dwSize = sizeof(my);
    if (Process32First(l, &my))
    {
      do
      {
        CharLowerBuff(my.szExeFile, MAX_PATH);
        if (lstrcmp(sztarget, my.szExeFile) == 0)
        {
          count++;
        }
      }while (Process32Next(l, &my));
    }
    CloseHandle(l);
  }

  return count;
}
Ejemplo n.º 3
0
bool ProcessExists(const TCHAR* szExeName) {
  bool bResult = false;
  bool bRetCode = false;
  TCHAR sztarget[MAX_PATH] = {0};
  BOOL bFind   = FALSE;
  PROCESSENTRY32 my = {0};
  HANDLE l = NULL;

  lstrcpy(sztarget, szExeName);
  CharLowerBuff(sztarget, MAX_PATH);

  l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  YG_PROCESS_ERROR(l != INVALID_HANDLE_VALUE);

  my.dwSize = sizeof(my);
  bRetCode = !!Process32First(l, &my);
  YG_PROCESS_ERROR(bRetCode);
  
  do
  {
    CharLowerBuff(my.szExeFile, MAX_PATH);
    if (lstrcmp(sztarget, my.szExeFile) == 0) {
      bResult = true;
      break;
    }
  }while (Process32Next(l, &my));

Exit0:
  if (l) {
    CloseHandle(l);
    l = NULL;
  }
  return bResult;
}
Ejemplo n.º 4
0
int install_util::KillProcess(const TCHAR* szExeName)
{
  TCHAR sztarget[MAX_PATH] = {0};
  lstrcpy(sztarget, szExeName);
  CharLowerBuff(sztarget, MAX_PATH);

  BOOL bFind   = FALSE;
  BOOL bResult = TRUE;
  PROCESSENTRY32 my = {0};
  HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if (((int)l) != -1)
  {
    my.dwSize = sizeof(my);
    if (Process32First(l, &my))
    {
      do
      {
        CharLowerBuff(my.szExeFile, MAX_PATH);
        if (lstrcmp(sztarget, my.szExeFile) == 0)
        {
          bFind = TRUE;
          HANDLE handLe =  OpenProcess(PROCESS_TERMINATE , FALSE, my.th32ProcessID);
          bResult &= ::TerminateProcess(handLe, 0);
        }
      }while (Process32Next(l, &my));
    }
    CloseHandle(l);
  }

  return bFind && bResult;//找到并关闭成功才返回TRUE
}
Ejemplo n.º 5
0
PinSound *PinDirectSound::LoadWaveFile(TCHAR* strFileName)
{
    PinSound * const pps = new PinSound();

    // Create the sound buffer object from the wave file data
    if (FAILED(CreateStaticBuffer(strFileName, pps)))
    {
        ShowError("Could not create static sound buffer.");
        delete pps;
        return NULL;
        //SetFileUI( hDlg, TEXT("Couldn't create sound buffer.") ); 
    }
    else // The sound buffer was successfully created
    {
        // Fill the buffer with wav data
        FillBuffer(pps);

        // Update the UI controls to show the sound as the file is loaded
        //SetFileUI( hDlg, strFileName );
        //OnEnablePlayUI( hDlg, TRUE );
    }

    lstrcpy(pps->m_szPath, strFileName);

    TitleFromFilename(strFileName, pps->m_szName);

    lstrcpy(pps->m_szInternalName, pps->m_szName);

    CharLowerBuff(pps->m_szInternalName, lstrlen(pps->m_szInternalName));

    return pps;
}
Ejemplo n.º 6
0
pvoid  STDCALL os_filefullname( pubyte filename, pvoid buf )
{
   pubyte  ptr;

#ifdef LINUX

   char  cur[512];
   if ( filename[0] != '/' )
   {
      getcwd( cur, 512 );
      chdir( filename );
      basename( filename );
      getcwd( str_ptr( ( pstr )buf ), 512 );
      str_setlen( ( pstr )buf, strlen( str_ptr( ( pstr )buf ) ) );
      str_appendb( buf, '/' );
       str_appendp( buf, filename );
      chdir( cur );
   }
   else
   { //Ìîæåò ðàáîòàòü íåêîððåêòíî åñëè â àáñîëþòíîì ïóòè âñòðå÷àþòñÿ '.' '..'
       str_appendp( buf, filename );
   }
#else
   DWORD  temp;
   temp = GetFullPathName( filename, 512, str_ptr( ( pstr )buf ), &ptr );
   // äëÿ Windows
   CharLowerBuff( str_ptr( ( pstr )buf ), temp );
   str_setlen( ( pstr )buf, temp );
#endif
   return buf;
}
Ejemplo n.º 7
0
void PinBinary::ReadFromFile(char *szfilename)
	{
	HANDLE hFile = CreateFile(szfilename,
		GENERIC_READ, FILE_SHARE_READ,
		NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
		{
		ShowError("The file could not be opened.");
		return;
		}

	if (m_pdata)
		{
		delete [] m_pdata;
		}

	m_cdata = GetFileSize(hFile, NULL);

	m_pdata = new char[m_cdata];

	DWORD read;

	/*int fFoo =*/ ReadFile(hFile, m_pdata, m_cdata, &read, NULL);

	/*fFoo =*/ CloseHandle(hFile);

	lstrcpy(m_szPath, szfilename);

	TitleFromFilename(szfilename, m_szName);

	lstrcpy(m_szInternalName, m_szName);

	CharLowerBuff(m_szInternalName, lstrlen(m_szInternalName));
	}
Ejemplo n.º 8
0
// static
bool CConEmuUpdate::IsUpdatePackage(LPCWSTR asFilePath)
{
	bool bIsUpdatePackage = false;

	if (asFilePath && *asFilePath && lstrlen(asFilePath) <= MAX_PATH)
	{
		wchar_t szName[MAX_PATH+1];
		LPCWSTR pszName = PointToName(asFilePath);
		if (pszName && *pszName)
		{
			lstrcpyn(szName, pszName, countof(szName));
			CharLowerBuff(szName, lstrlen(szName));
			LPCWSTR pszExt = PointToExt(szName);
			if (pszExt)
			{
				if ((wcsncmp(szName, L"conemupack.", 11) == 0)
					&& (wcscmp(pszExt, L".7z") == 0))
				{
					bIsUpdatePackage = true;
				}
				else if ((wcsncmp(szName, L"conemusetup.", 12) == 0)
					&& (wcscmp(pszExt, L".exe") == 0))
				{
					bIsUpdatePackage = true;
				}
			}
		}
	}

	return bIsUpdatePackage;
}
Ejemplo n.º 9
0
	//将字符串翻译为加速键
    DWORD CAccelerator::TranslateAccelKey( LPCTSTR pszAccelKey )
    {
        TCHAR szBuf[101]={0};//保证字符串结束有两个结束符
        WORD wModifier=0;
        WORD wKey=0;
        int nKeyLen=(int)_tcslen(pszAccelKey);
        if(_tcslen(pszAccelKey)>=100) return 0;
        _tcscpy(szBuf,pszAccelKey);
        CharLowerBuff(szBuf,nKeyLen);

        LPTSTR pszBuf=szBuf;
        LPTSTR pszKey=_tcstok(pszBuf,_T("+"));
        while(pszKey)
        {
            if(_tcsicmp(pszKey,_T("ctrl"))==0)
            {
                wModifier|=MOD_CONTROL;
            }else if(_tcsicmp(pszKey,_T("alt"))==0)
            {
                wModifier |=MOD_ALT;
            }else if(_tcsicmp(pszKey,_T("shift"))==0)
            {
                wModifier |= MOD_SHIFT;
			}else
            {
				wKey = VkFromString(pszKey);
                break;
            }
            pszBuf+=_tcslen(pszKey)+1;
            pszKey=_tcstok(pszBuf,_T("+"));
        }
        return MAKELONG(wKey,wModifier);
    }
Ejemplo n.º 10
0
// Funções Internas
//===========================================================================
void TapePegaTitulo(char *NomeImagem) {
	BOOL found = 0;
	int  loop  = 0;

	char  imagetitle[128];
	char* startpos = NomeImagem;
	if (strrchr(startpos,'\\'))
		startpos = strrchr(startpos,'\\')+1;
	strncpy(imagetitle, startpos, 127);
	imagetitle[127] = 0;
	while (imagetitle[loop] && !found)
		if (IsCharLower(imagetitle[loop]))
			found = 1;
		else
			loop++;
	if ((!found) && (loop > 2))
		CharLowerBuff(imagetitle+1, strlen(imagetitle+1));
	strncpy(NomeTitulo, imagetitle, 127);
	NomeTitulo[127] = 0;
	if (imagetitle[0]) {
		char *dot = imagetitle;
		if (strrchr(dot,'.'))
			dot = strrchr(dot,'.');
		if (dot > imagetitle)
			*dot = 0;
	}
	strncpy(NomeTitulo, imagetitle, 30);
	NomeTitulo[30] = 0;
}
Ejemplo n.º 11
0
BOOL IsUrlContains(TCHAR * Str)
{
	const int CountUrl=11;
	const TCHAR  URL[CountUrl][5]=
	{
		L"http",
		L"www",
		L".ru",
		L".com",
		L".de",
		L".cz",
		L".org",
		L".net",
		L".su",
		L".ua",
		L".tv"
	};

	if(Str && _tcslen(Str)>0) {
		TCHAR *StrLower = NEWTSTR_MALLOC(Str);
		CharLowerBuff(StrLower, lstrlen(StrLower));
		for (int i=0; i<CountUrl; i++)
			if(_tcsstr (StrLower, URL[i]))
			{
				mir_free(StrLower);
				return 1;
			}
		mir_free(StrLower);
	}
	return 0;
}
Ejemplo n.º 12
0
	void SetLPSLowerCaseW(const CMStringW &str)
	{
		DWORD dwSize = str.GetLength() * sizeof(WCHAR);
		SetUL(dwSize);
		WCHAR *buf = (WCHAR*)Allocate(dwSize);
		memcpy(buf, str, dwSize);
		CharLowerBuff(buf, str.GetLength());
	}
Ejemplo n.º 13
0
void install_util::NotifyProcessExit(const TCHAR* szExeName) {
  TCHAR sztarget[MAX_PATH] = {0};
  lstrcpy(sztarget, szExeName);
  CharLowerBuff(sztarget, MAX_PATH);

  BOOL bResult = TRUE;
  PROCESSENTRY32 my = {0};
  HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if (((int)l) != -1) 
  {
    my.dwSize = sizeof(my);
    if (Process32First(l, &my))
    {
      do
      {
        CharLowerBuff(my.szExeFile, MAX_PATH);
        if (lstrcmp(sztarget, my.szExeFile) == 0)
        {
          HANDLE pProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, my.th32ProcessID);
          TCHAR lpszModule[MAX_PATH + 1] = {0};
          GetModuleFileNameEx(pProcess, NULL, lpszModule, MAX_PATH + 1);
          if (lpszModule[0]) 
          {
            std::wstring wstrRunYYECmdLine(L"quit");
            SHELLEXECUTEINFO ShExecInfo = {0};
            ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
            ShExecInfo.fMask = 0;
            ShExecInfo.hwnd = NULL;
            ShExecInfo.lpVerb = NULL;

            ShExecInfo.lpFile = lpszModule;
            // 数据统计需要知道启动的来源
            ShExecInfo.lpParameters = wstrRunYYECmdLine.c_str();
            ShExecInfo.lpDirectory = NULL;
            ShExecInfo.nShow = SW_SHOW;
            ShExecInfo.hInstApp = NULL;
            ShellExecuteEx(&ShExecInfo);
            break;
          }
        }
      }while (Process32Next(l, &my));
    }
    CloseHandle(l);
  }
}
Ejemplo n.º 14
0
// add a new update item into the current list
void WICondListAdd(char *str, WICONDLIST *List)
{
	WICONDITEM *newItem = (WICONDITEM*)mir_alloc(sizeof(WICONDITEM));
	wSetData(&newItem->Item, str);
	CharLowerBuff(newItem->Item, (DWORD)mir_tstrlen(newItem->Item));
	newItem->Next = NULL;
	if (List->Tail == NULL)	List->Head = newItem;
	else List->Tail->Next = newItem;
	List->Tail = newItem;
}
Ejemplo n.º 15
0
BYTE MBToLower( LPTSTR pszChar )
// Converts a single byte character in a buffer to lower case
/***********************************************************************/
{
    if( !pszChar )
        return 0;

    CharLowerBuff( pszChar, sizeof( TCHAR ));
    return *(( LPBYTE )pszChar );
}
Ejemplo n.º 16
0
WORD MBToLowerW( LPTSTR pszChar )
// Converts a double byte character in a buffer to lower case
/***********************************************************************/
{
    if( !pszChar )
        return 0;

    CharLowerBuff( pszChar, sizeof( WORD ));
    return *(( LPWORD )pszChar );
}
Ejemplo n.º 17
0
// ******************************************************************
// Local Functions 
// ******************************************************************
static LONG findDrvPath (char *clsidstr,char *dllpath,int dllpathsize)
{
	HKEY			hkEnum,hksub,hkpath;
	char			databuf[512];
	LONG 			cr,rc = -1;
	DWORD			datatype,datasize;
	DWORD			index;
	OFSTRUCT		ofs;
	HFILE			hfile;
	BOOL			found = FALSE;

	CharLowerBuff(clsidstr,(DWORD)strlen(clsidstr));
	if ((cr = RegOpenKey(HKEY_CLASSES_ROOT,COM_CLSID,&hkEnum)) == ERROR_SUCCESS) {

		index = 0;
		while (cr == ERROR_SUCCESS && !found) {
			cr = RegEnumKey(hkEnum,index++,(LPTSTR)databuf,512);
			if (cr == ERROR_SUCCESS) {
				CharLowerBuff(databuf,(DWORD)strlen(databuf));
				if (!(strcmp(databuf,clsidstr))) {
					if ((cr = RegOpenKeyEx(hkEnum,(LPCTSTR)databuf,0,KEY_READ,&hksub)) == ERROR_SUCCESS) {
						if ((cr = RegOpenKeyEx(hksub,(LPCTSTR)INPROC_SERVER,0,KEY_READ,&hkpath)) == ERROR_SUCCESS) {
							datatype = REG_SZ; datasize = (DWORD)dllpathsize;
							cr = RegQueryValueEx(hkpath,0,0,&datatype,(LPBYTE)dllpath,&datasize);
							if (cr == ERROR_SUCCESS) {
								memset(&ofs,0,sizeof(OFSTRUCT));
								ofs.cBytes = sizeof(OFSTRUCT); 
								hfile = OpenFile(dllpath,&ofs,OF_EXIST);
								if (hfile) rc = 0; 
							}
							RegCloseKey(hkpath);
						}
						RegCloseKey(hksub);
					}
					found = TRUE;	// break out 
				}
			}
		}				
		RegCloseKey(hkEnum);
	}
	return rc;
}
Ejemplo n.º 18
0
LPTSTR ChangeTextCase(LPCTSTR ptszInText)
{
	LPTSTR ptszOutText = (LPTSTR)mir_alloc(MaxTextSize*sizeof(TCHAR));
	_tcscpy(ptszOutText, ptszInText);

	for (DWORD i = 0; i < _tcslen(ptszInText); i++) {
		CharUpperBuff(&ptszOutText[i], 1);
		if (ptszOutText[i] == ptszInText[i])
			CharLowerBuff(&ptszOutText[i], 1);
	}
	return ptszOutText;
}
Ejemplo n.º 19
0
BOOL ChangeFilterParamValue(PFILTER_TRANSMIT pFilter, PFILTER_PARAM	pNewParam)
{
	if (pNewParam->m_ParamSize + sizeof(FILTER_TRANSMIT) > FILTER_BUFFER_SIZE)
		return FALSE;

	char bFound = FALSE;
	char pBuff[FILTER_BUFFER_SIZE];
	PFILTER_TRANSMIT pFilterSave;

	pFilterSave = (PFILTER_TRANSMIT) pBuff;

	memcpy(pFilterSave, pFilter, FILTER_BUFFER_SIZE);

	int ParamCount = 0;

	PFILTER_PARAM	pSingleParam;
	PFILTER_PARAM	pSingleParamSave;
	pSingleParam = (PFILTER_PARAM) pFilter->m_Params;
	pSingleParamSave = (PFILTER_PARAM) pFilterSave->m_Params;

	for (DWORD cou = 0; cou < pFilter->m_ParamsCount; cou++)
	{
		if (pSingleParamSave->m_ParamID != pNewParam->m_ParamID)
		{
			pSingleParam->m_ParamFlags = pSingleParamSave->m_ParamFlags;
			pSingleParam->m_ParamFlt = pSingleParamSave->m_ParamFlt;
			pSingleParam->m_ParamID = pSingleParamSave->m_ParamID;
			pSingleParam->m_ParamSize = pSingleParamSave->m_ParamSize;
			memcpy(pSingleParam->m_ParamValue, pSingleParamSave->m_ParamValue, pSingleParam->m_ParamSize);

			pSingleParam = (PFILTER_PARAM)((BYTE*)pSingleParam + sizeof(FILTER_PARAM) + pSingleParam->m_ParamSize);
			ParamCount++;
		}
		pSingleParamSave = (PFILTER_PARAM)((BYTE*)pSingleParamSave + sizeof(FILTER_PARAM) + pSingleParamSave->m_ParamSize);
	}

	// add new param
	pSingleParam->m_ParamFlags = pNewParam->m_ParamFlags;
	pSingleParam->m_ParamFlt = pNewParam->m_ParamFlt;
	pSingleParam->m_ParamID = pNewParam->m_ParamID;
	pSingleParam->m_ParamSize = pNewParam->m_ParamSize;
	memcpy(pSingleParam->m_ParamValue, pNewParam->m_ParamValue, pSingleParam->m_ParamSize);
	if(pSingleParam->m_ParamID == _PARAM_OBJECT_URL)
		CharLowerBuff((char*) pSingleParam->m_ParamValue, pSingleParam->m_ParamSize);

	ParamCount++;

	pFilter->m_ParamsCount = ParamCount;

	return TRUE;
}
Ejemplo n.º 20
0
int strcasecmp(LPCSTR s1,LPCSTR s2)
{
	CHAR *tmp1,*tmp2;	
	int ret;
	DWORD nLen1=(DWORD)istrlen(s1);
	DWORD nLen2=(DWORD)istrlen(s2);
	
	tmp1=new CHAR[nLen1+2];
	if (tmp1==NULL)
		SetHFCError(HFC_CANNOTALLOC);
	CopyMemory(tmp1,s1,nLen1+1);
	
	tmp2=new CHAR[nLen2+2];
	if (tmp2==NULL)
		SetHFCError(HFC_CANNOTALLOC);
	CopyMemory(tmp2,s2,nLen2+1);
	
	CharLowerBuff(tmp1,nLen1);
	CharLowerBuff(tmp2,nLen2);
	ret=strcmp(tmp1,tmp2);
	delete[] tmp1;
	delete[] tmp2;
	return ret;
}
Ejemplo n.º 21
0
// this function convert the string to the format with 1 upper case followed by lower case char
void CaseConv(TCHAR *str) 
{
	TCHAR *pstr;
	BOOL nextUp = TRUE;

	CharLowerBuff(str, (DWORD)_tcslen(str));
	for(pstr = str; *pstr; pstr++) {
		if (*pstr == ' ' || *pstr == '-')
			nextUp = TRUE;
		else {
			TCHAR ch = *(TCHAR*)pstr;
			if (nextUp)
				*pstr = ( TCHAR )CharUpper((LPTSTR)ch);
			nextUp = FALSE;
}	}	}
Ejemplo n.º 22
0
void cairo_container::transform_text( litehtml::tstring& text, litehtml::text_transform tt )
{
	if(text.empty()) return;

#ifndef LITEHTML_UTF8
	switch(tt)
	{
	case litehtml::text_transform_capitalize:
		if(!text.empty())
		{
			text[0] = (WCHAR) CharUpper((LPWSTR) text[0]);
		}
		break;
	case litehtml::text_transform_uppercase:
		for(size_t i = 0; i < text.length(); i++)
		{
			text[i] = (WCHAR) CharUpper((LPWSTR) text[i]);
		}
		break;
	case litehtml::text_transform_lowercase:
		for(size_t i = 0; i < text.length(); i++)
		{
			text[i] = (WCHAR) CharLower((LPWSTR) text[i]);
		}
		break;
	}
#else
	LPWSTR txt = cairo_font::utf8_to_wchar(text.c_str());
	switch(tt)
	{
	case litehtml::text_transform_capitalize:
		CharUpperBuff(txt, 1);
		break;
	case litehtml::text_transform_uppercase:
		CharUpperBuff(txt, lstrlen(txt));
		break;
	case litehtml::text_transform_lowercase:
		CharLowerBuff(txt, lstrlen(txt));
		break;
	}
	LPSTR txtA = cairo_font::wchar_to_utf8(txt);
	text = txtA;
	delete txtA;
	delete txt;
#endif
}
Ejemplo n.º 23
0
bool CMatch::IsValidFile(LPCWSTR asFrom, int anLen, LPCWSTR pszInvalidChars, LPCWSTR pszSpacing, int& rnLen)
{
	while (anLen > 0)
	{
		wchar_t wc = asFrom[anLen-1];
		if (wcschr(pszSpacing, wc) || wcschr(pszInvalidChars, wc))
			anLen--;
		else
			break;
	}

	LPCWSTR pszFile, pszBadChar;

	if ((anLen <= 0) || !(pszFile = ms_FileCheck.Set(asFrom, anLen)) || ms_FileCheck.IsEmpty())
		return false;

	pszBadChar = wcspbrk(pszFile, pszInvalidChars);
	if (pszBadChar != NULL)
		return false;

	pszBadChar = wcspbrk(pszFile, pszSpacing);
	if (pszBadChar != NULL)
		return false;

	// where are you, regexps...
	if ((anLen <= 1) || !::IsFilePath(pszFile))
		return false;
	if (pszFile[0] == L'.' && (pszFile[1] == 0 || (pszFile[1] == L'.' && (pszFile[2] == 0 || (pszFile[2] == L'.' && (pszFile[3] == 0))))))
		return false;
	CharLowerBuff(ms_FileCheck.ms_Val, anLen);
	if ((wcschr(pszFile, L'.') == NULL)
		//&& (wcsncmp(pszFile, L"make", 4) != 0)
		&& (wcspbrk(pszFile, L"abcdefghijklmnopqrstuvwxyz") == NULL))
		return false;

	CEStr szFullPath;
	if (mp_RCon)
	{
		if (!mp_RCon->GetFileFromConsole(pszFile, szFullPath))
			return false;
	}

	rnLen = anLen;
	return true;
}
Ejemplo n.º 24
0
static void GetImageTitle(LPCTSTR imagefilename, Disk_t* fptr)
{
	TCHAR   imagetitle[ MAX_DISK_FULL_NAME+1 ];
	LPCTSTR startpos = imagefilename;

	// imagetitle = <FILENAME.EXT>
	if (_tcsrchr(startpos,TEXT('\\')))
		startpos = _tcsrchr(startpos,TEXT('\\'))+1;

	_tcsncpy(imagetitle,startpos,MAX_DISK_FULL_NAME);
	imagetitle[MAX_DISK_FULL_NAME] = 0;

	// if imagetitle contains a lowercase char, then found=1 (why?)
	BOOL found = 0;
	int  loop  = 0;
	while (imagetitle[loop] && !found)
	{
		if (IsCharLower(imagetitle[loop]))
			found = 1;
		else
			loop++;
	}

	if ((!found) && (loop > 2))
		CharLowerBuff(imagetitle+1,_tcslen(imagetitle+1));

	// fptr->fullname = <FILENAME.EXT>
	_tcsncpy( fptr->fullname, imagetitle, MAX_DISK_FULL_NAME );
	fptr->fullname[ MAX_DISK_FULL_NAME ] = 0;

	if (imagetitle[0])
	{
		LPTSTR dot = imagetitle;
		if (_tcsrchr(dot,TEXT('.')))
			dot = _tcsrchr(dot,TEXT('.'));
		if (dot > imagetitle)
			*dot = 0;
	}

	// fptr->imagename = <FILENAME> (ie. no extension)
	_tcsncpy( fptr->imagename, imagetitle, MAX_DISK_IMAGE_NAME );
	fptr->imagename[ MAX_DISK_IMAGE_NAME ] = 0;
}
Ejemplo n.º 25
0
static void GetImageTitle (LPCTSTR imagefilename, PHDD pHardDrive)
{
	TCHAR   imagetitle[128];
	LPCTSTR startpos = imagefilename;
	
	// imagetitle = <FILENAME.EXT>
	if (_tcsrchr(startpos,TEXT('\\')))
		startpos = _tcsrchr(startpos,TEXT('\\'))+1;
	_tcsncpy(imagetitle,startpos,127);
	imagetitle[127] = 0;
	
	// if imagetitle contains a lowercase char, then found=1 (why?)
	BOOL found = 0;
	int  loop  = 0;
	while (imagetitle[loop] && !found)
	{
		if (IsCharLower(imagetitle[loop]))
			found = 1;
		else
			loop++;
	}
		
	if ((!found) && (loop > 2))
		CharLowerBuff(imagetitle+1,_tcslen(imagetitle+1));
	
	// fptr->fullname = <FILENAME.EXT>
	_tcsncpy(pHardDrive->hd_fullname,imagetitle,127);
	pHardDrive->hd_fullname[127] = 0;
	
	if (imagetitle[0])
	{
		LPTSTR dot = imagetitle;
		if (_tcsrchr(dot,TEXT('.')))
			dot = _tcsrchr(dot,TEXT('.'));
		if (dot > imagetitle)
			*dot = 0;
	}
	
	// fptr->imagename = <FILENAME> (ie. no extension)
	_tcsncpy(pHardDrive->hd_imagename,imagetitle,15);
	pHardDrive->hd_imagename[15] = 0;
}
Ejemplo n.º 26
0
void AppSettings::SetNames(LPCWSTR asAppNames)
{
	size_t iLen = wcslen(asAppNames);

	if (!AppNames || !AppNamesLwr || (iLen >= cchNameMax))
	{
		SafeFree(AppNames);
		SafeFree(AppNamesLwr);

		cchNameMax = iLen+32;
		AppNames = (wchar_t*)malloc(cchNameMax*sizeof(wchar_t));
		AppNamesLwr = (wchar_t*)malloc(cchNameMax*sizeof(wchar_t));
		if (!AppNames || !AppNamesLwr)
		{
			_ASSERTE(AppNames!=NULL && AppNamesLwr!=NULL);
			return;
		}
	}

	_wcscpy_c(AppNames, iLen+1, asAppNames);
	_wcscpy_c(AppNamesLwr, iLen+1, asAppNames);
	CharLowerBuff(AppNamesLwr, iLen);
}
Ejemplo n.º 27
0
/*! \brief Builds an absolute pathname.
 *  \par Function Description
 *  This function derives an absolute pathname for the pathname
 *  pointed to by \a name with '.' and '..' resolved. It does not
 *  resolve symbolic links.
 *
 *  It returns NULL and sets the \a error (if not NULL) if it failed
 *  to build the pathname or the pathname does not exists.
 *
 *  \note
 *  The code for this function is derived from the realpath() of
 *  the GNU C Library (Copyright (C) 1996-2002, 2004, 2005, 2006 Free
 *  Software Foundation, Inc. / LGPL 2.1 or later).
 *
 *  The part for the resolution of symbolic links has been discarded
 *  and it has been adapted for glib and for use on Windows.
 *
 *  \param [in]     name  A character string containing the pathname
 *                        to resolve.
 *  \param [in,out] error Return location for a GError, or NULL.
 *  \return A newly-allocated string with the resolved absolute
 *  pathname on success, NULL otherwise.
 */
gchar *f_normalize_filename (const gchar *name, GError **error)
{
#if defined (_WIN32)
    char buf[MAX_PATH];
#else
    GString *rpath;
    const char *start, *end;
#endif

  if (name == NULL) {
    g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
                 "%s", g_strerror (EINVAL));
    return NULL;
  }

  if (*name == '\0') {
    g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT,
                 "%s", g_strerror (ENOENT));
    return NULL;
  }

#if defined (_WIN32)
  /* Windows method (modified) from libiberty's lrealpath.c, GPL V2+
   *
   * We assume we don't have symlinks and just canonicalize to a
   * Windows absolute path.  GetFullPathName converts ../ and ./ in
   * relative paths to absolute paths, filling in current drive if
   * one is not given or using the current directory of a specified
   * drive (eg, "E:foo"). It also converts all forward slashes to
   * back slashes.
   */
  DWORD len = GetFullPathName (name, MAX_PATH, buf, NULL);
  if (len == 0 || len > MAX_PATH - 1) {
    return g_strdup (name);
  } else {
    /* The file system is case-preserving but case-insensitive,
     * canonicalize to lowercase, using the codepage associated
     * with the process locale.  */
    CharLowerBuff (buf, len);
    return g_strdup (buf);
  }
#else
#define ROOT_MARKER_LEN 1

  rpath = g_string_sized_new (strlen (name));

  /* if relative path, prepend current dir */
  if (!g_path_is_absolute (name)) {
    gchar *cwd = g_get_current_dir ();
    g_string_append (rpath, cwd);
    g_free (cwd);
    if (!G_IS_DIR_SEPARATOR (rpath->str[rpath->len - 1])) {
      g_string_append_c (rpath, G_DIR_SEPARATOR);
    }
  } else {
    g_string_append_len (rpath, name, ROOT_MARKER_LEN);
    /* move to first path separator */
    name += ROOT_MARKER_LEN - 1;
  }

  for (start = end = name; *start != '\0'; start = end) {
    /* skip sequence of multiple path-separators */
    while (G_IS_DIR_SEPARATOR (*start)) {
      ++start;
    }

    /* find end of path component */
    for (end = start; *end != '\0' && !G_IS_DIR_SEPARATOR (*end); ++end);

    if (end - start == 0) {
      break;
    } else if (end - start == 1 && start[0] == '.') {
      /* nothing */;
    } else if (end - start == 2 && start[0] == '.' && start[1] == '.') {
      /* back up to previous component, ignore if at root already.  */
      if (rpath->len > ROOT_MARKER_LEN) {
        while (!G_IS_DIR_SEPARATOR (rpath->str[(--rpath->len) - 1]));
        g_string_set_size (rpath, rpath->len);
      }
    } else {
      /* path component, copy to new path */
      if (!G_IS_DIR_SEPARATOR (rpath->str[rpath->len - 1])) {
        g_string_append_c (rpath, G_DIR_SEPARATOR);
      }

      g_string_append_len (rpath, start, end - start);

      if (!g_file_test (rpath->str, G_FILE_TEST_EXISTS)) {
        g_set_error (error,G_FILE_ERROR, G_FILE_ERROR_NOENT,
                     "%s", g_strerror (ENOENT));
        goto error;
      } else if (!g_file_test (rpath->str, G_FILE_TEST_IS_DIR) &&
                 *end != '\0') {
        g_set_error (error,G_FILE_ERROR, G_FILE_ERROR_NOTDIR,
                     "%s", g_strerror (ENOTDIR));
        goto error;
      }
    }
  }

  if (G_IS_DIR_SEPARATOR (rpath->str[rpath->len - 1]) &&
      rpath->len > ROOT_MARKER_LEN) {
    g_string_set_size (rpath, rpath->len - 1);
  }

  return g_string_free (rpath, FALSE);

error:
  g_string_free (rpath, TRUE);
  return NULL;
#undef ROOT_MARKER_LEN
#endif
}
Ejemplo n.º 28
0
Archivo: lrealpath.c Proyecto: bert/pcb
/*!
 * \brief A well-defined realpath () that is always compiled in.
 */
char *
lrealpath (const char *filename)
{
    /* Method 1: The system has a compile time upper bound on a filename
       path.  Use that and realpath() to canonicalize the name.  This is
       the most common case.  Note that, if there isn't a compile time
       upper bound, you want to avoid realpath() at all costs.  */
#if defined(REALPATH_LIMIT)
    {
        char buf[REALPATH_LIMIT];
        const char *rp = realpath (filename, buf);
        if (rp == NULL)
            rp = filename;
        return strdup (rp);
    }
    /* REALPATH_LIMIT */

    /* Method 2: The host system (i.e., GNU) has the function
       canonicalize_file_name() which malloc's a chunk of memory and
       returns that, use that.  */
#elif defined(HAVE_CANONICALIZE_FILE_NAME)
    {
        char *rp = canonicalize_file_name (filename);
        if (rp == NULL)
            return strdup (filename);
        else
            return rp;
    }
    /* HAVE_CANONICALIZE_FILE_NAME */

    /* Method 3: Now we're getting desperate!  The system doesn't have a
       compile time buffer size and no alternative function.  Query the
       OS, using pathconf(), for the buffer limit.  Care is needed
       though, some systems do not limit PATH_MAX (return -1 for
       pathconf()) making it impossible to pass a correctly sized buffer
       to realpath() (it could always overflow).  On those systems, we
       skip this.  */
#elif defined (HAVE_REALPATH) && defined (HAVE_UNISTD_H)
    {
        /* Find out the max path size.  */
        long path_max = pathconf ("/", _PC_PATH_MAX);
        if (path_max > 0)
        {
            /* PATH_MAX is bounded.  */
            char *buf, *rp, *ret;
            buf = (char *) malloc (path_max);
            if (buf == NULL)
                return NULL;
            rp = realpath (filename, buf);
            ret = strdup (rp ? rp : filename);
            free (buf);
            return ret;
        }
    }
    /* HAVE_REALPATH && HAVE_UNISTD_H */

    /* The MS Windows method.  If we don't have realpath, we assume we
       don't have symlinks and just canonicalize to a Windows absolute
       path.  GetFullPath converts ../ and ./ in relative paths to
       absolute paths, filling in current drive if one is not given
       or using the current directory of a specified drive (eg, "E:foo").
       It also converts all forward slashes to back slashes.  */
#elif defined (_WIN32)
    {
        char buf[MAX_PATH];
        char* basename;
        DWORD len = GetFullPathName (filename, MAX_PATH, buf, &basename);
        if (len == 0 || len > MAX_PATH - 1)
            return strdup (filename);
        else
        {
            /* The file system is case-preserving but case-insensitive,
               Canonicalize to lowercase, using the codepage associated
               with the process locale.  */
            CharLowerBuff (buf, len);
            return strdup (buf);
        }
    }
#else

    /* This system is a lost cause, just duplicate the filename.  */
    return strdup (filename);
#endif
}
Ejemplo n.º 29
0
// Проверка окна переднего плана. Если оно принадлежит к хукаемым процесса - вставить хук.
bool CDefaultTerminal::CheckForeground(HWND hFore, DWORD nForePID, bool bRunInThread /*= true*/)
{
	if (!isDefaultTerminalAllowed())
		return false;

	bool lbRc = false;
	bool lbLocked = false;
	bool lbConHostLocked;
	DWORD nResult = 0;
	wchar_t szClass[MAX_PATH]; szClass[0] = 0;
	PROCESSENTRY32 prc;
	bool bMonitored = false;
	const wchar_t* pszMonitored = NULL;
	HANDLE hProcess = NULL;
	//int nBits = 0;
	//wchar_t szCmdLine[MAX_PATH*3];
	//wchar_t szName[64];
	//PROCESS_INFORMATION pi = {};
	//STARTUPINFO si = {sizeof(si)};
	//BOOL bStarted = FALSE;
	DWORD nErrCode = 0;
	int iHookerRc = -1;

	// Если главное окно еще не создано
	if (!mb_ReadyToHook)
	{
		// Сразу выходим
		goto wrap;
	}

	//_ASSERTE(gpConEmu->isMainThread());
	if (!hFore || !nForePID)
	{
		_ASSERTE(hFore && nForePID);
		goto wrap;
	}

	if (hFore == mh_LastWnd || hFore == mh_LastIgnoredWnd)
	{
		// Это окно уже проверялось
		lbRc = (hFore == mh_LastWnd);
		goto wrap;
	}

	if (bRunInThread && (hFore == mh_LastCall))
	{
		// Просто выйти. Это проверка на частые фоновые вызовы.
		goto wrap;
	}
	mh_LastCall = hFore;

	if (bRunInThread)
	{
		if (gpConEmu->isMainThread())
		{
			// Clear finished threads
			ClearThreads(false);
		}

		HANDLE hPostThread = NULL; DWORD nThreadId = 0;
		ThreadArg* pArg = (ThreadArg*)malloc(sizeof(ThreadArg));
		if (!pArg)
		{
			_ASSERTE(pArg);
			goto wrap;
		}
		pArg->pTerm = this;
		pArg->hFore = hFore;
		pArg->nForePID = nForePID;

		hPostThread = CreateThread(NULL, 0, PostCheckThread, pArg, 0, &nThreadId);
		_ASSERTE(hPostThread!=NULL);
		if (hPostThread)
		{
			m_Threads.push_back(hPostThread);
		}

		lbRc = (hPostThread != NULL); // вернуть OK?
		goto wrap;
	}

	EnterCriticalSection(&mcs);
	lbLocked = true;

	// Clear dead processes and windows
	ClearProcessed(false);

	// Check window class
	if (GetClassName(hFore, szClass, countof(szClass)))
	{
		if ((lstrcmp(szClass, VirtualConsoleClass) == 0)
			//|| (lstrcmp(szClass, L"#32770") == 0) // Ignore dialogs // -- Process dialogs too (Application may be dialog-based)
			|| isConsoleClass(szClass))
		{
			mh_LastIgnoredWnd = hFore;
			goto wrap;
		}
	}

	// Go and check
	if (!GetProcessInfo(nForePID, &prc))
	{
		mh_LastIgnoredWnd = hFore;
		goto wrap;
	}

	CharLowerBuff(prc.szExeFile, lstrlen(prc.szExeFile));

	if (lstrcmp(prc.szExeFile, L"csrss.exe") == 0)
	{
		// This is "System" process and may not be hooked
		mh_LastIgnoredWnd = hFore;
		goto wrap;
	}

	// Is it in monitored applications?
	pszMonitored = gpSet->GetDefaultTerminalAppsMSZ();
	if (pszMonitored)
	{
		// All strings are lower case
		const wchar_t* psz = pszMonitored;
		while (*psz)
		{
			if (_tcscmp(psz, prc.szExeFile) == 0)
			{
				bMonitored = true;
				break;
			}
			psz += _tcslen(psz)+1;
		}
	}

	// And how it is?
	if (!bMonitored)
	{
		mh_LastIgnoredWnd = hFore;
		goto wrap;
	}

	// Need to process
	for (INT_PTR i = m_Processed.size(); i--;)
	{
		if (m_Processed[i].nPID == nForePID)
		{
			bMonitored = false;
			break; // already hooked
		}
	}

	// May be hooked already?
	if (!bMonitored)
	{
		mh_LastWnd = hFore;
		lbRc = true;
		goto wrap;
	}

	_ASSERTE(isDefaultTerminalAllowed());

	TODO("Show status in status line?");

	lbConHostLocked = gpConEmu->LockConhostStart();
	iHookerRc = StartDefTermHooker(nForePID, hProcess, nResult, gpConEmu->ms_ConEmuBaseDir, nErrCode);
	if (lbConHostLocked) gpConEmu->UnlockConhostStart();
	if (iHookerRc != 0)
	{
		mh_LastIgnoredWnd = hFore;
		if (iHookerRc == -3)
			DisplayLastError(L"Failed to start hooking application!\nDefault terminal feature will not be available!", nErrCode);
		goto wrap;
	}

	//hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|SYNCHRONIZE, FALSE, nForePID);
	//if (!hProcess)
	//{
	//	// Failed to hook
	//	mh_LastIgnoredWnd = hFore;
	//	goto wrap;
	//}

	//// Need to be hooked
	//nBits = GetProcessBits(nForePID, hProcess);
	//switch (nBits)
	//{
	//case 32:
	//	_wsprintf(szCmdLine, SKIPLEN(countof(szCmdLine)) L"\"%s\\%s\" /DEFTRM=%u",
	//		gpConEmu->ms_ConEmuBaseDir, L"ConEmuC.exe", nForePID);
	//	break;
	//case 64:
	//	_wsprintf(szCmdLine, SKIPLEN(countof(szCmdLine)) L"\"%s\\%s\" /DEFTRM=%u",
	//		gpConEmu->ms_ConEmuBaseDir, L"ConEmuC64.exe", nForePID);
	//	break;
	//}
	//if (!*szCmdLine)
	//{
	//	// Unsupported bitness?
	//	CloseHandle(hProcess);
	//	mh_LastIgnoredWnd = hFore;
	//	goto wrap;
	//}

	//// Prepare event
	//_wsprintf(szName, SKIPLEN(countof(szName)) CEDEFAULTTERMHOOK, nForePID);
	//SafeCloseHandle(mh_SignEvent);
	//mh_SignEvent = CreateEvent(LocalSecurity(), FALSE, FALSE, szName);
	//if (mh_SignEvent) SetEvent(mh_SignEvent); // May be excess, but if event already exists...

	//// Run hooker
	//si.dwFlags = STARTF_USESHOWWINDOW;
	//bStarted = CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
	//if (!bStarted)
	//{
	//	DisplayLastError(L"Failed to start hooking application!\nDefault terminal feature will not be available!");
	//	CloseHandle(hProcess);
	//	mh_LastIgnoredWnd = hFore;
	//	goto wrap;
	//}
	//CloseHandle(pi.hThread);
	//// Waiting for result
	//WaitForSingleObject(pi.hProcess, INFINITE);
	//GetExitCodeProcess(pi.hProcess, &nResult);
	//CloseHandle(pi.hProcess);

	// And what?
	if ((nResult == (UINT)CERR_HOOKS_WAS_SET) || (nResult == (UINT)CERR_HOOKS_WAS_ALREADY_SET))
	{
		mh_LastWnd = hFore;
		ProcessInfo inf = {};
		inf.hProcess = hProcess;
		hProcess = NULL; // его закрывать НЕ нужно, сохранен в массиве
		inf.nPID = nForePID;
		//inf.bHooksSucceeded = (nResult == (UINT)CERR_HOOKS_WAS_ALREADY_SET);
		inf.nHookTick = GetTickCount();
		m_Processed.push_back(inf);
		lbRc = true;
		goto wrap;
	}
	// Failed, remember this
	CloseHandle(hProcess);
	mh_LastIgnoredWnd = hFore;
	_ASSERTE(lbRc == false);
wrap:
	if (lbLocked)
	{
		LeaveCriticalSection(&mcs);
	}
	return lbRc;
}
Ejemplo n.º 30
0
//===========================================================================
int APIENTRY WinMain (HINSTANCE passinstance,
					  HINSTANCE previnstance,
					  LPSTR     lpCmdLine,
					  int       nCmdShow)
{
#ifdef CPUDEBUG
	char nomearq[MAX_PATH];
#endif

	char imagefilename[MAX_PATH];

	// DO ONE-TIME INITIALIZATION
	instance = passinstance;

	// Initialize COM
	CoInitialize( NULL );

	GdiSetBatchLimit(512);
	GetProgramDirectory();
	RegisterExtensions();
	FrameRegisterClass();
	Inicializar1();

	strcpy(imagefilename, progdir);
	strcat(imagefilename, NOMEARQTKDOS);

	if (lpCmdLine[0] != '\0')
	{
		CharLowerBuff(&lpCmdLine[strlen(lpCmdLine)-3],3);
		strcpy(imagefilename, lpCmdLine);
	}

#ifdef CPUDEBUG
	strcpy(nomearq, progdir);
	strcat(nomearq, "debugCPU.txt");
	DeleteFile(nomearq);
	arquivocpu = fopen(nomearq, "wb");
#endif


	do
	{
		// DO INITIALIZATION THAT MUST BE REPEATED FOR A RESTART
		restart = 0;
		mode    = MODE_LOGO;
		LoadConfiguration();
		DebugInitialize();
		JoyInitialize();
		MemInitialize();
		VideoInitialize();
		Timer_InitTimer();

		FrameCreateWindow();
		MemAtualizaSlotAux();

		if (imagefilename[0] != '\0')
		{
			DiskInsert(0, imagefilename, FALSE, FALSE);
			imagefilename[0] = '\0';
		}

		// ENTER THE MAIN MESSAGE LOOP
		EnterMessageLoop();
	}
	while (restart);

#ifdef CPUDEBUG
	//CloseHandle(arquivocpu);
	fclose(arquivocpu);
#endif

	// Release COM
	CoUninitialize();

	return 0;
}