LONG ServiceRegistry::GetStringRegKey(String hKey, String strValueName, String &strValue, String strDefaultValue)
{
	HKEY key;
	LONG l = GetKey(hKey, key);
	if (l == ERROR_SUCCESS)
		return GetStringRegKey(key, strValueName, strValue, strDefaultValue);
	return l;
}
Example #2
0
std::wstring FileContextMenuExt::GetApplicationPath() 
{
	HKEY hKey;
	LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\CoEIA\\CPC", 0, KEY_READ, &hKey);

	bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
	bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);

	std::wstring strValueOfBinDir;
	GetStringRegKey(hKey, L"APP_PATH", strValueOfBinDir, L"bad");

	std::wstring fullpath = strValueOfBinDir + L"\\CPC.exe";
	return fullpath;
}
void getCredentials(char* token){

	HKEY hKey;
	if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Tyler Menezes\\Rfid Login\\Keys", 0, KEY_READ, &hKey) != ERROR_SUCCESS){
		delete hKey;
		return; // Token not recognized.
	}

	std::wstring keySalt;
	GetStringRegKey(hKey, L"Salt", keySalt, L"bad");


	CSHA1 *sha1 = new CSHA1();
	sha1->Update((unsigned char*)token, strlen(token));
	sha1->Update((unsigned char*)s2cs(ws2s(keySalt)), wcslen(keySalt.c_str()));
	sha1->Final();
	std::wstring hash;
	sha1->ReportHashStl(hash, CSHA1::REPORT_HEX_SHORT);
	delete sha1;

	std::string key = std::string("SOFTWARE\\Tyler Menezes\\Rfid Login\\Keys\\");
	key += ws2s(hash);

	if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, s2ws(key).c_str(), 0, KEY_READ, &hKey) != ERROR_SUCCESS){
		delete hKey;
		return; // Token not recognized.
	}

	std::wstring salt;
	std::wstring username;
	std::wstring password;
	std::wstring domain;

	char* cUsername = s2cs(GetCharRegKey(hKey, L"Username"));
	char* cPassword = s2cs(GetCharRegKey(hKey, L"Password"));
	char* cDomain	= s2cs(GetCharRegKey(hKey, L"Domain"));
	
	GetStringRegKey(hKey, L"Salt", salt, L"");
	
	unsigned char* cSalt = (unsigned char*)s2cs(ws2s(salt));

	std::wstring decryptionKey;
	sha1 = new CSHA1();
	sha1->Update((unsigned char*)token, strlen(token));
	sha1->Update(cSalt, strlen((char*)cSalt));
	sha1->Final();
	sha1->ReportHashStl(decryptionKey, CSHA1::REPORT_HEX_SHORT);
	delete sha1;

	char* cDecryptionKey = s2cs(ws2s(decryptionKey));

	decrypt(cUsername, cDecryptionKey);
	decrypt(cPassword, cDecryptionKey);
	decrypt(cDomain, cDecryptionKey);

	username = s2ws(std::string(cUsername));
	password = s2ws(std::string(cPassword));
	domain = s2ws(std::string(cDomain));

	delete cSalt;
	delete cUsername;
	delete cPassword;
	delete cDomain;
	delete cDecryptionKey;

	prp->_dwNumCreds -= 1;

	wchar_t* wUsername = wcs2cs(username);
	wchar_t* wPassword = wcs2cs(password);
	wchar_t* wDomain = wcs2cs(domain);

	RfidCredential::lastLoginFailed = false;

	doAutoLogin = true;
	prp->_EnumerateOneCredential(prp->_dwNumCreds, wUsername, wPassword, wDomain);
	prp->Pcpe->CredentialsChanged(prp->UpAdviseContext);
}
Serial::Serial()
{
	//We're not yet connected
	this->connected = false;

	HKEY hKey;
	if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Tyler Menezes\\Rfid Login", 0, KEY_READ, &hKey) != ERROR_SUCCESS){
		delete hKey;
		return; // Token not recognized.
	}

	std::wstring port;
	GetStringRegKey(hKey, L"Port", port, L"COM3");

	//Try to connect to the given port throuh CreateFile
	this->hSerial = CreateFile(port.c_str(),
			GENERIC_READ | GENERIC_WRITE,
			0,
			NULL,
			OPEN_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			NULL);

	//Check if the connection was successfull
	if(this->hSerial==INVALID_HANDLE_VALUE)
	{
		//If not success full display an Error
		if(GetLastError()==ERROR_FILE_NOT_FOUND){

			//Print Error if neccessary
			printf("ERROR: Handle was not attached. Reason: %s not available.\n");

		}
		else
		{
			printf("ERROR!!!");
		}
	}
	else
	{
		//If connected we try to set the comm parameters
		DCB dcbSerialParams = {0};

		//Try to get the current
		if (!GetCommState(this->hSerial, &dcbSerialParams))
		{
			//If impossible, show an error
			printf("failed to get current serial parameters!");
		}
		else
		{
			//Define serial connection parameters for the arduino board
			dcbSerialParams.BaudRate=CBR_9600;
			dcbSerialParams.ByteSize=8;
			dcbSerialParams.StopBits=ONESTOPBIT;
			dcbSerialParams.Parity=NOPARITY;

			 //Set the parameters and check for their proper application
			 if(!SetCommState(hSerial, &dcbSerialParams))
			 {
				printf("ALERT: Could not set Serial Port parameters");
			 }
			 else
			 {
				 //If everything went fine we're connected
				 this->connected = true;
				 //We wait 2s as the arduino board will be reseting
				 Sleep(ARDUINO_WAIT_TIME);
			 }
		}
	}

}
Example #5
0
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
    // --CHANGED by Anton Likhtarov for resource support
    rs::hInst = hInstance;
    // --END

	WSADATA			wData;
	WORD			wVersion = MAKEWORD(1,1);
    if (dwReason == DLL_PROCESS_ATTACH)
    {
	    if( WSAStartup(wVersion, &wData) )
	    {
		    return FALSE;
	    }

		hMlang = LoadLibrary(L"mlang.dll");
		fConvertINetMultiByteToUnicode = (HRESULT (__stdcall *)(LPDWORD, DWORD, LPCSTR, LPINT, LPWSTR, LPINT))
			GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");

		HKEY hKeyDB, hKeyCP;
		wchar_t cp_subkey[256], cp_fullpath[256];

		if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"MIME\\DataBase\\Codepage", 0, KEY_READ, &hKeyDB) == ERROR_SUCCESS) {
			DWORD n_cps;
			RegQueryInfoKey(hKeyDB,NULL,NULL,NULL,&n_cps,NULL,NULL,NULL,NULL,NULL,NULL,NULL);      

			for (int i = 0; i < n_cps; i++) {
				DWORD dwSize = sizeof(cp_subkey);
				RegEnumKeyEx(hKeyDB,i,cp_subkey,&dwSize,NULL,NULL,NULL,NULL);

				UINT cp = _wtoi(cp_subkey);
				
				swprintf(cp_fullpath, L"MIME\\DataBase\\Codepage\\%ls", cp_subkey);
				if (RegOpenKeyEx(HKEY_CLASSES_ROOT, cp_fullpath, 0, KEY_READ, &hKeyCP) != ERROR_SUCCESS)
					continue;
				
				wstring cp_name;
				GetStringRegKey(hKeyCP, L"WebCharset", cp_name);
				if (cp_name.length() == 0)
					GetStringRegKey(hKeyCP, L"BodyCharset", cp_name);
				if (cp_name.length() > 0 && cp_name[0] != L'_') {
					transform(cp_name.begin(), cp_name.end(), cp_name.begin(), ::towlower);
					CPNames[cp] = cp_name;
					CPIDs[cp_name] = cp;
				}
			}

			RegCloseKey(hKeyDB);
		}

		MudCodePage = GetACP();

        InitializeCriticalSection(&secSubstSection);
        InitializeCriticalSection(&secHotkeys);
        InitializeCriticalSection(&secStatusSection);
//vls-begin// #system
        InitializeCriticalSection(&secSystemExec);
        InitializeCriticalSection(&secSystemList);
//vls-end//
//vls-begin// script files
        InitializeCriticalSection(&secScriptFiles);
        InitializeCriticalSection(&secReadingConfig);
        eventReadingConfig = CreateEvent(NULL, TRUE, FALSE, NULL);
        eventReadingHasUse = CreateEvent(NULL, TRUE, FALSE, NULL);
        eventReadingFirst = CreateEvent(NULL, TRUE, FALSE, NULL);
//vls-end//
        eventAllObjectEvent = CreateEvent(NULL, FALSE, FALSE, NULL );
        SetEvent(eventAllObjectEvent );

        eventMudEmuTextArrives = CreateEvent(NULL, TRUE, FALSE, NULL );

//vls-begin// base dir
        GetModuleFileName(NULL, szBASE_DIR, MAX_PATH);
        wchar_t *p = wcsrchr(szBASE_DIR, L'\\');
        if (p) *p = '\0';

        wcscpy(szSETTINGS_DIR, szBASE_DIR);
        wcscat(szSETTINGS_DIR, L"\\settings");
//vls-end//

        _Module.Init(ObjectMap, hInstance, &LIBID_TTCOREEXLib);
        DisableThreadLibraryCalls(hInstance);

		hPingThread = CreateThread(NULL, 0, &PingThread, NULL, 0, &dwPingThreadID);

		strLastCommand[0] = L'\0';

		last_line[0] = L'\0';
    }
    else if (dwReason == DLL_PROCESS_DETACH){
//vls-begin// multiple output
        StopLogging();
//vls-end//
//vls-begin// bugfix
        CloseHandle(eventMudEmuTextArrives);
//vls-end//
//vls-begin// script files
        CloseHandle(eventReadingFirst);
        CloseHandle(eventReadingHasUse);
        CloseHandle(eventReadingConfig);
        DeleteCriticalSection(&secReadingConfig);
        DeleteCriticalSection(&secScriptFiles);
//vls-end//
//vls-begin// #system
        systemkill_command(L"all");
        DeleteCriticalSection(&secSystemList);
        DeleteCriticalSection(&secSystemExec);
//vls-end//

        DeleteCriticalSection(&secSubstSection);
        DeleteCriticalSection(&secHotkeys);
        DeleteCriticalSection(&secStatusSection);
        CloseHandle(eventAllObjectEvent);

#ifdef _DEBUG_LOG
        if ( hExLog ) 
            CloseHandle(hExLog);
#endif
        _Module.Term();
    }
    return TRUE;    // ok
}