Ejemplo n.º 1
0
int _tmain(int argc, _TCHAR* argv[])
{
	_chdir(ExePath().c_str());

	Spellchecker::checkSpelling();
	return 0;
}
Ejemplo n.º 2
0
int _tmain(int argc, char* argv[])
{
	//TCHAR cCurrentPath[FILENAME_MAX + 1];

	// use default config file path of _getcwd() + "/config.xml"
	std::string currentPath = ExePath();
	currentPath.append("\\config.xml");

	std::cout << "Attempting to load Configuration from " << currentPath << std::endl;
 

	g_EngineService = new SGX::EngineService();
	g_EngineService->StartUp(currentPath.c_str());

	const SGX::CfgSection  * currentSection = g_EngineService->GetConfig()->GetConfig();

	while(currentSection != NULL)
	{
		SGX::CfgNode * currentNode = currentSection->First;
		
		while(currentNode != NULL)
		{
			std::cout << currentSection->sectionName << "." << currentNode->configName  << " = " << currentNode->StringValue << std::endl;
			currentNode = currentNode->Next;
		}

		currentSection = currentSection->Next;
	}


	g_EngineService->Shutdown();
	delete g_EngineService;

	return 0;
}
Ejemplo n.º 3
0
INT _tmain(INT argc, _TCHAR* argv[])
{
	ULONG o;
	auto PID = GetFFXIVProcId();
	if (PID == 0)
	{
		std::cout << "*** NO FFXIV FOUND\n";
		Sleep(4000);
		return 0;
	}
	if (IsDLLLoaded(PID))
	{
		std::cout << "*** ALREADY LOADED\n";
		Sleep(4000);
		return 0;
	}
	auto DLLPath = ExePath().append("\\FCBondage.dll");
	auto hProc = OpenProcess(PROCESS_ALL_ACCESS,FALSE,PID);
	auto arg1 = VirtualAllocEx(hProc,NULL,MAX_PATH,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
	WriteProcessMemory(hProc,arg1,DLLPath.c_str(),DLLPath.size(),&o);
	auto hThread = CreateRemoteThread(hProc,NULL,NULL,LOADLIBRARY_ROUTINE,arg1,NULL,&o);
	WaitForSingleObject(hThread,INFINITE);
	CloseHandle(hThread);
	VirtualFreeEx(hProc,arg1,MAX_PATH,MEM_RELEASE);
	CloseHandle(hProc);
	std::cout << "Hook Complete, goodbye!\n";
	Sleep(4000);
	return 0;
}
Ejemplo n.º 4
0
//need to add button for uploading
void initWindowUploader(int width, int height){
	windowUploader = SDL_CreateWindow("Image To Upload", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height + (ButtonHeight + 26), 0);

	rendererUploader = SDL_CreateRenderer(windowUploader, -1, 0);

	string filepath = ExePath() + '\\' + "screenshot.bmp";
	image = SDL_LoadBMP(filepath.c_str());
	imageTexture = SDL_CreateTextureFromSurface(rendererUploader, image);

	//uploadButton = SDL_LoadBMP("uploadbutton.bmp");
	//buttonTexture = SDL_CreateTextureFromSurface(rendererUploader, uploadButton);



	SDL_SetRenderDrawColor(rendererUploader, 255, 255, 255, 0);
	SDL_RenderClear(rendererUploader);


	SDL_Rect imageRect = { 0 , 0, width, height };
	SDL_RenderCopy(rendererUploader, imageTexture, NULL, &imageRect);

	//SDL_Rect buttonRect = { width - (ButtonWidth + 13), height + 13, ButtonWidth, ButtonHeight };
	//SDL_RenderCopy(rendererUploader, buttonTexture, NULL, &buttonRect);

	//add buttons
	uploadButton = Button(width - (ButtonWidth + 13), height + 13, ButtonWidth, ButtonHeight, "UploadButtonSprite.bmp");
	uploadButton.show(rendererUploader);


	SDL_RenderPresent(rendererUploader);
	uploaderRunning = true;
	initKeyBindings();
}
Ejemplo n.º 5
0
	Bitmap::Bitmap(int width, int height)
	{

		_Path = ExePath() + "\\" + default_path;
		_height = height;
		_width = width;
		//ctor
	}
Ejemplo n.º 6
0
// Ejects a module (fully qualified path) via process id
void Injector::EjectLib(DWORD ProcID, const std::wstring& Path)
{
	// Grab a new snapshot of the process
	EnsureCloseHandle Snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcID));
	if (Snapshot == INVALID_HANDLE_VALUE)
		throw std::runtime_error("Could not get module snapshot for remote process.");;

	// Get the HMODULE of the desired library
	MODULEENTRY32W ModEntry = { sizeof(ModEntry) };
	bool Found = false;
	BOOL bMoreMods = Module32FirstW(Snapshot, &ModEntry);
	for (; bMoreMods; bMoreMods = Module32NextW(Snapshot, &ModEntry)) 
	{
		std::wstring ModuleName(ModEntry.szModule);
		std::wstring ExePath(ModEntry.szExePath);
		Found = (ModuleName == Path || ExePath == Path);
		if (Found) break;
	}
	if (!Found)
		throw std::runtime_error("Could not find module in remote process.");;

	// Get a handle for the target process.
	EnsureCloseHandle Process(OpenProcess(
		PROCESS_QUERY_INFORMATION |   
		PROCESS_CREATE_THREAD     | 
		PROCESS_VM_OPERATION,  // For CreateRemoteThread
		FALSE, ProcID));
	if (!Process) 
		throw std::runtime_error("Could not get handle to process.");

	// Get the real address of LoadLibraryW in Kernel32.dll
	HMODULE hKernel32 = GetModuleHandle(TEXT("Kernel32"));
	if (hKernel32 == NULL) 
		throw std::runtime_error("Could not get handle to Kernel32.");
	PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)
		GetProcAddress(hKernel32, "FreeLibrary");
	if (pfnThreadRtn == NULL) 
		throw std::runtime_error("Could not get pointer to FreeLibrary.");

	// Create a remote thread that calls FreeLibrary()
	EnsureCloseHandle Thread(CreateRemoteThread(Process, NULL, 0, 
		pfnThreadRtn, ModEntry.modBaseAddr, 0, NULL));
	if (!Thread) 
		throw std::runtime_error("Could not create thread in remote process.");

	// Wait for the remote thread to terminate
	WaitForSingleObject(Thread, INFINITE);

	// Get thread exit code
	DWORD ExitCode;
	if (!GetExitCodeThread(Thread,&ExitCode))
		throw std::runtime_error("Could not get thread exit code.");

	// Check LoadLibrary succeeded and returned a module base
	if(!ExitCode)
		throw std::runtime_error("Call to FreeLibrary in remote process failed.");
}
Ejemplo n.º 7
0
int _tmain(int argc, _TCHAR* argv[])
{
	_chdir(ExePath().c_str());

	while (true)
	{
		Generator::generateWords();
	}

	return 0;
}
Ejemplo n.º 8
0
	ofstream CreateMuSeeLogFile()//create an empty log file (this also opens the file); return full pass
	{
		string logfullPath = ExePath();
		logfullPath +=  "\\Plug-Ins\\muSee\\Data\\";
		logfullPath += "museeLog.txt";
		FILE * tempFile;
		tempFile = fopen (logfullPath.c_str(),"w");
		fclose (tempFile);

		ofstream logfile;
		logfile.open(logfullPath);
		return logfile;
	}
Ejemplo n.º 9
0
std::string downloadImage(std::string urlImg)
{
	CreateDirectoryA("download", NULL);

	InternetManager inetMan;
	std::string path = ExePath(); // absolute path of exe

	BackgroundImg back = BackFromUrl(urlImg);
	std::string imgPath = path + std::string("download\\background") + back.extension;
	// if the download fail return nothing
	if (inetMan.DownloadFile(urlImg, imgPath) != S_OK)
		return "";
	_RPT1(0, "File downloaded in %s\n", imgPath.c_str());

	return imgPath;
}
Ejemplo n.º 10
0
	// 指定フォルダにある指定拡張子のプラグインから設定情報を読み込む
	void LoadPluginOptionDesc( tTVPCommandOptionList* coreopt, const std::wstring& path, const std::wstring& ext ) {
		std::wstring exename = ExePath();
		exename = IncludeTrailingBackslash(ExtractFileDir(exename));
		std::wstring filepath = exename + path;
		std::wstring mask = filepath + L"*." + ext;

		WIN32_FIND_DATA fd;
		HANDLE hSearch = ::FindFirstFile( mask.c_str(), &fd );
		if( hSearch != INVALID_HANDLE_VALUE ) {
			do {
				tTVPCommandOptionList* options = TVPGetPluginCommandDesc( (filepath + std::wstring(fd.cFileName) ).c_str() );
				if( options ) {
					TVPMargeCommandDesc( *coreopt, *options );
					delete options;
				}
			} while( FindNextFile( hSearch, &fd ) );
			::FindClose( hSearch );
		}
	}
Ejemplo n.º 11
0
void ListaCarti::sterge_carte(int index)
{
    Carte carte = indexuri[index];
    sqlite3 *db;
    char *err_msg = 0;

    int rc = sqlite3_open((ExePath() + "\\biblioteca.sqlite").c_str(), &db);
    if (rc)
    {
        cout << string("Eroare la deschiderea bazei de date: ") + sqlite3_errmsg(db);
        return;
    }
    string sql = string("DELETE FROM carti WHERE id=") + to_string(carte.id);
    rc = sqlite3_exec(db, sql.c_str(), 0, 0, &err_msg);

    if (rc)
    {
        cout << "Stergerea a esuat: " << err_msg;
    }

    sqlite3_close(db);
    afiseaza();
}
Ejemplo n.º 12
0
void ListaCarti::imprumuta_carte(int index)
{
    Carte carte = indexuri[index];
    sqlite3 *db;
    char *err_msg = 0;

    int rc = sqlite3_open((ExePath() + "\\biblioteca.sqlite").c_str(), &db);
    if (rc)
    {
        cout << string("Eroare la deschiderea bazei de date: ") + sqlite3_errmsg(db);
        return;
    }
    string sql = string("UPDATE carti SET imprumutat=") + to_string(EcranLogin::current_user.id) +  " WHERE id=" + to_string(carte.id);
    rc = sqlite3_exec(db, sql.c_str(), 0, 0, &err_msg);

    if (rc)
    {
        cout << "Modificarea a esuat: " << err_msg;
    }

    sqlite3_close(db);
    afiseaza();
}
Ejemplo n.º 13
0
	// 設定された内容を保存する
	void SaveSetting() {
		tTJSVariant val;
		std::wstring path;
		if( TVPGetCommandLine( L"-datapath", &val) ) {
			ttstr str(val);
			path.assign( str.c_str(), str.length() );
		}
		std::wstring exename = ExePath();
		std::wstring filename = ChangeFileExt( ExtractFileName( exename ), L".cfu" );
		filename = ApplicationSpecialPath::GetDataPathDirectory( path, exename ) + filename;
		const char * warnings =
"; ============================================================================\r\n"
"; *DO NOT EDIT* this file unless you are understanding what you are doing.\r\n"
"; FYI:\r\n"
";  Each line consists of NAME=\"VALUE\" pair, VALUE is a series of\r\n"
";  \\xNN, where NN is hexadecimal representation of UNICODE codepoint.\r\n"
";  For example, opt=\"\\x61\\x62\\x63\\x3042\\x3044\\x3046\" means that the\r\n"
";  value of options \"opt\" is alphabets a, b, and c followed by Japanese\r\n"
";  Hiraganas A, I, and U.\r\n"
";  DO NOT PUT non-escaped value like opt=\"abc\". This doesn't work and should\r\n"
";  be like opt=\"\\x61\\x62\\x63\".\r\n"
"; ============================================================================\r\n"
"";
		tTJSBinaryStream *stream = TVPCreateBinaryStreamForWrite( ttstr(filename), L"" );
		if( stream ) {
			try {
				stream->Write( warnings, strlen(warnings) );
				std::string option = ToStringOption();
				stream->Write( option.c_str(), option.length() );
			} catch(...) {
				delete stream;
				throw;
			}
			delete stream;
		}

	}
Ejemplo n.º 14
0
void ListaCarti::afiseaza()
{
    int columns = get_console_size().columns;
    int rows = get_console_size().rows;
    string c_titlu_text = "Titlu";
    string c_autor_text = "Autor";
    string c_editura_text = "Editura";
    string c_an_text = "An";
    string c_imprumutat_text = "Imprum.";

    int title_column_w = columns - 40;  // 40 = 20 pentru Editura, 10 pentru An, 10 pentru Imprumutat
    system("cls");
    SetConsoleTextAttribute(console, FOREGROUND_GREEN);

    CONSOLE_CURSOR_INFO cursorInfo;
    GetConsoleCursorInfo(console, &cursorInfo);
    cursorInfo.bVisible = FALSE;  // set the cursor visibility, http://stackoverflow.com/questions/18028808/blinking-underscore-with-console
    SetConsoleCursorInfo(console, &cursorInfo);

    // Deseneaza partea de sus a chenarului
    cout << (char)201;
    // Titlu
    for (int i=0; i<title_column_w/2-2; i++)    // -2 deoarece aici avem si coltul din stanga-sus
    {
        cout << (char)205;
    }
    cout << (char)209;  // Separator de coloana - https://www.google.ro/search?q=ascii+tabel&tbm=isch&imgil=IvVP_xaycIIKOM%253A%253BJMtOixefP_tDJM%253Bhttp%25253A%25252F%25252Fwww.asciitable.com%25252F&source=iu&pf=m&fir=IvVP_xaycIIKOM%253A%252CJMtOixefP_tDJM%252C_&biw=1536&bih=701&ved=0ahUKEwi-46TwwrjKAhUDWiwKHTzCCSwQyjcIMg&ei=Jo-fVr64DoO0sQG8hKfgAg#imgrc=IvVP_xaycIIKOM%3A
    // Autor
    for (int i=0; i<title_column_w/2-1; i++)
    {
        cout << (char)205;
    }
    cout << (char)209;  // Separator de coloana
    // Editura
    for (int i=0; i<EDITURA_W-1; i++)
    {
        cout << (char)205;
    }
    cout << (char)209;  // Separator de coloana
    // An
    for (int i=0; i<AN_W-1; i++)
    {
        cout << (char)205;
    }
    cout << (char)209;  // Separator de coloana
    // Imprumutat
    for (int i=0; i<IMPRUMUTAT_W-1; i++)
    {
        cout << (char)205;
    }
    cout << (char)187;

    // Randul cu titlurile coloanelor
    // Titlu
    cout << (char)186;
    int titlu_x_start = title_column_w/4 - c_titlu_text.length()/2;
    for (int i=1; i<titlu_x_start; i++)
    {
        cout << " ";
    }
    cout << c_titlu_text;
    for (int i=titlu_x_start+c_titlu_text.length(); i<title_column_w/2-1; i++)
    {
        cout << " ";
    }
    cout << (char)179;

    // Autor
    int autor_x_start = title_column_w/4 - c_autor_text.length()/2;
    for (int i=1; i<autor_x_start; i++)
    {
        cout << " ";
    }
    cout << c_autor_text;
    for (int i=autor_x_start+c_autor_text.length(); i<title_column_w/2; i++)
    {
        cout << " ";
    }
    cout << (char)179;

    // Editura
    int editura_x_start = EDITURA_W/2 - c_editura_text.length()/2;
    for (int i=1; i<editura_x_start; i++)
    {
        cout << " ";
    }
    cout << c_editura_text;
    for (int i=editura_x_start+c_editura_text.length(); i<EDITURA_W; i++)
    {
        cout << " ";
    }
    cout << (char)179;

    // An
    int an_x_start = AN_W/2 - c_an_text.length()/2;
    for (int i=1; i<an_x_start; i++)
    {
        cout << " ";
    }
    cout << c_an_text;
    for (int i=an_x_start+c_an_text.length(); i<AN_W; i++)
    {
        cout << " ";
    }
    cout << (char)179;

    // Imprumutat
    int imprumutat_x_start = IMPRUMUTAT_W/2 - c_imprumutat_text.length()/2;
    for (int i=1; i<imprumutat_x_start; i++)
    {
        cout << " ";
    }
    cout << c_imprumutat_text;
    for (int i=imprumutat_x_start+c_imprumutat_text.length(); i<IMPRUMUTAT_W; i++)
    {
        cout << " ";
    }
    cout << (char)186;

    // Separator
    cout << (char)199;
    for (int i=1; i<title_column_w/2-1; i++)
    {
        cout << (char)196;
    }
    cout << (char)197;
    for (int i=title_column_w/2+1; i<title_column_w; i++)
    {
        cout << (char)196;
    }
    cout << (char)197;
    for (int i=1; i<EDITURA_W; i++)
    {
        cout << (char)196;
    }
    cout << (char)197;
    for (int i=1; i<AN_W; i++)
    {
        cout << (char)196;
    }
    cout << (char)197;
    for (int i=1; i<IMPRUMUTAT_W; i++)
    {
        cout << (char)196;
    }
    cout << (char)182;

    // Interogare SQL
    sqlite3 *db;
    sqlite3_stmt *stmt;
    indexuri.clear();

    int rc = sqlite3_open((ExePath() + "\\biblioteca.sqlite").c_str(), &db);
    if (rc)
    {
        cout << string("Eroare la deschiderea bazei de date: ") + sqlite3_errmsg(db);
        return;
    }
    string sql = "SELECT id, titlu, autor, editura, an, imprumutat, pagini, isbn FROM carti ";
    if (filtru.length()) // filtru= 'black' din 'black beauty'
    {
        sql += string(" WHERE (titlu LIKE '%") + filtru + "%')";
        sql += string(" OR (autor LIKE '%") + filtru + "%')";
        sql += string(" OR (editura LIKE '%") + filtru + "%')";
    }
    if (filtrare != toate) // In cazul in care vrem sa vedem cartile disponibile sau cele imprumutate
    {
        if (filtru.length())
        {
            sql += " AND";
        }
        else
        {
            sql += " WHERE";
        }
        switch (filtrare)
        {
        case disponibile:
            sql += " imprumutat='0'";
            break;
        case imprumutate:
            sql += " imprumutat='" + to_string(EcranLogin::current_user.id) + "'";
            break;
        }
    }
    rc = sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, NULL);
    if (rc == SQLITE_OK)
    {
        int idx = 0;
        while (TRUE)
        {
            rc = sqlite3_step(stmt);
            if (rc != SQLITE_ROW && rc != SQLITE_DONE)
            {
                string errmsg(sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                sqlite3_close(db);
                break;
            }

            if (rc == SQLITE_ROW)
            {
                Carte carte;
                carte.id = sqlite3_column_int(stmt, 0);
                carte.titlu = (char*)sqlite3_column_text(stmt, 1);
                carte.autor = (char*)sqlite3_column_text(stmt, 2);
                carte.editura = (char*)sqlite3_column_text(stmt, 3);
                carte.an = (char*)sqlite3_column_text(stmt, 4);
                carte.imprumutat = sqlite3_column_int(stmt, 5);
                carte.nr_pag = (char*)sqlite3_column_text(stmt, 6);
                carte.isbn = (char*)sqlite3_column_text(stmt, 7);

                indexuri[idx] = carte;

                // Titlul cartii
                cout << (char)186;
                int titlu_carte_x_start = title_column_w/4 - carte.titlu.length()/2;
                for (int i=1; i<titlu_carte_x_start; i++)
                {
                    cout << " ";
                }
                cout << carte.titlu;
                for (int i=titlu_carte_x_start+carte.titlu.length(); i<title_column_w/2-1; i++)
                {
                    cout << " ";
                }
                cout << (char)179;

                // Autorul cartii
                int autor_carte_x_start = title_column_w/4 - carte.autor.length()/2;
                for (int i=1; i<autor_carte_x_start; i++)
                {
                    cout << " ";
                }
                cout << carte.autor;
                for (int i=autor_carte_x_start+carte.autor.length(); i<title_column_w/2; i++)
                {
                    cout << " ";
                }
                cout << (char)179;

                // Editura cartii
                int editura_carte_x_start = EDITURA_W/2 - carte.editura.length()/2;
                for (int i=1; i<editura_carte_x_start; i++)
                {
                    cout << " ";
                }
                cout << carte.editura;
                for (int i=editura_carte_x_start+carte.editura.length(); i<EDITURA_W; i++)
                {
                    cout << " ";
                }
                cout << (char)179;

                // Anul cartii
                int an_carte_x_start = AN_W/2 - carte.an.length()/2;
                for (int i=1; i<an_carte_x_start; i++)
                {
                    cout << " ";
                }
                cout << carte.an;
                for (int i=an_carte_x_start+carte.an.length(); i<AN_W; i++)
                {
                    cout << " ";
                }
                cout << (char)179;

                // Imprumutat
                string imprumutat_carte = (carte.imprumutat == 0) ? "NU" : "DA";
                int imprumutat_carte_x_start = IMPRUMUTAT_W/2 - imprumutat_carte.length()/2;
                for (int i=1; i<imprumutat_carte_x_start; i++)
                {
                    cout << " ";
                }
                cout << imprumutat_carte;
                for (int i=imprumutat_carte_x_start+imprumutat_carte.length(); i<IMPRUMUTAT_W; i++)
                {
                    cout << " ";
                }
                cout << (char)186;

                idx++;
            }
            else
            {
                sqlite3_finalize(stmt);
                sqlite3_close(db);
                break;
            }
        }
    }
    sqlite3_finalize(stmt);
    sqlite3_close(db);

    // Deseneaza randurile goale, daca e nevoie
    for (int i=indexuri.size(); i<rows-6; i++)
    {
        cout << (char)186;
        for (int j=1; j<title_column_w/2-1; j++)
        {
            cout << " ";
        }
        cout << (char)179;
        for (int j=1; j<title_column_w/2; j++)
        {
            cout << " ";
        }
        cout << (char)179;
        for (int j=1; j<EDITURA_W; j++)
        {
            cout << " ";
        }
        cout << (char)179;
        for (int j=1; j<AN_W; j++)
        {
            cout << " ";
        }
        cout << (char)179;
        for (int j=1; j<IMPRUMUTAT_W; j++)
        {
            cout << " ";
        }
        cout << (char)186;
    }

    // Deseneaza latura de jos a chenarului
    cout << (char)200;
    for (int j=1; j<title_column_w/2-1; j++)
    {
        cout << char(205);
    }
    cout << (char)207;
    for (int j=1; j<title_column_w/2; j++)
    {
        cout << char(205);
    }
    cout << (char)207;
    for (int j=1; j<EDITURA_W; j++)
    {
        cout << char(205);
    }
    cout << (char)207;
    for (int j=1; j<AN_W; j++)
    {
        cout << char(205);
    }
    cout << (char)207;
    for (int j=1; j<IMPRUMUTAT_W; j++)
    {
        cout << char(205);
    }
    cout << (char)188;

    // Afiseaza tastele pentru modificarea listei
    if (editare != NULL)
    {
        string taste = "F2: Modifica | F8: Sterge";
        cout << taste;
        for (int i=taste.length(); i<columns; i++)
        {
            cout << " ";
        }
    }
    else
    {
        string taste;
        if (filtrare == disponibile)
        {
            taste = "F2: Imprumuta";
        }
        else if (filtrare == imprumutate)
        {
            taste = "F2: Returneaza";
        }
        cout << taste;
        for (int i=taste.length(); i<columns; i++)
        {
            cout << " ";
        }
    }

    current_index = 0;
    highlight_index(current_index);
    if (filtru.length())
    {
        afiseaza_cautare();
    }

    while (TRUE)
    {
        int key = getch();
        if (key == 13)
        {
            if (indexuri.size() == 0) continue;
            if (filtru.length())
            {
                afiseaza();
                break;
            }
            Carte carte = indexuri[current_index];
            selection(carte);
            break;
        }
        else if (key == 224)      // vezi http://stackoverflow.com/questions/10463201/getch-and-arrow-codes
        {
            // empty the buffer, we don't want arrow keys to appear as letters
            int ch = getch();
            if (indexuri.size() == 0) continue;
            if (ch == 80)
            {
                clear_selection(current_index);
                current_index += 1;
                if (current_index > indexuri.size()-1) current_index = 0;
                highlight_index(current_index);
            }
            else if (ch == 72)
            {
                clear_selection(current_index);
                current_index -= 1;
                if (current_index < 0) current_index = indexuri.size() - 1;
                highlight_index(current_index);
            }
        }
        else if (key >= 32 && key <= 126)
        {
            if (filtru.length() == 0) afiseaza_cautare();
            if (filtru.length() > MAX_FILTRU_LENGTH) continue;
            filtru += (char)key;
            cout << (char)key;
        }
        else if (key == 8)      // backspace
        {
            filtru = filtru.substr(0, filtru.size()-1);
            cout << (char)key;
            cout << " ";
            cout << (char)key;
            if (filtru.length() == 0)
            {
                ascunde_cautare();
                afiseaza();
                continue;
            }
        }
        else if (key == 255)
        {
            afiseaza();
            break;
        }
        else if (key == 27)
        {
            if (filtru.length())
            {
                filtru = "";
                afiseaza();
                ascunde_cautare();
                continue;
            }
            cancel();
            break;
        }
        else if (key == 0)      // S-a apasat una din tastele F1, F2, F3, etc...
        {
            int f = getch();
            if (indexuri.size() == 0) continue;
            if (editare != NULL)    // Utilizatorul este admin
            {
                if (f == 60)    // F2
                {
                    editeaza_carte(current_index);
                }
                else if (f == 66)      // F8
                {
                    sterge_carte(current_index);
                }
            }
            else      // Utilizatorul este student
            {
                if (filtrare == disponibile)
                {
                    imprumuta_carte(current_index);
                }
                else if (filtrare == imprumutate)
                {
                    returneaza_carte(current_index);
                }
            }
        }
    }
}
Ejemplo n.º 15
0
int main()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_EVERY_16_DF);
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
	_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
	_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
	_CrtMemState s1, s2, s3;
	_CrtMemCheckpoint(&s1);

	ExePath();

	//////////// most common way to use licensing module ////
	{
		time_t LicenseRemainingTime;
		time_t GracePeriodRemainingTime;
		int GraceStatusCode;
		int LicenseCheckRes = GetRemainingTime(&LicenseRemainingTime, &GracePeriodRemainingTime, &GraceStatusCode);
		if (LicenseCheckRes != 0 || (LicenseRemainingTime == 0 && GracePeriodRemainingTime == 0))
		{
			printf("LicenseCheckRes %d", LicenseCheckRes);
			printf("LicenseRemainingTime %d", (int)LicenseRemainingTime);
			printf("GracePeriodRemainingTime %d", (int)GracePeriodRemainingTime);
		}

		char ActivationKeyBuffer[200];
		int GetKeyRes = GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));
		if (GetKeyRes == 0)
			printf("For project ALMA and Feature KPI we obtained activation key '%s'\n", ActivationKeyBuffer);
		else
			printf("License did not contain a valid activation key\n");
	}
	//////////// most common way to use licensing module ////

	///////////////////////////////////////// get the key using class ////////////////////////////////////
	//create a license
	License *TestLicense = new License;
//TestLicense->SaveToFile("t.t", "LicenseSeed.dat");

	if (TestLicense == NULL)
	{
		printf("Unexpected error: feature list object is NULL\n");
		return 1;
	}

	//for testing, load up the saved license and check if we can extract feature keys
	printf("Load license into temp buffer\n");
	int er = TestLicense->LoadFromFile("../License.dat");
	if (er != 0)
	{
		printf("Error %d while loading license. Please solve it to continue\n",er);
		delete TestLicense;
		_getch();
		return 1;
	}

	printf("Seach for activation key inside license\n");
	//find the key we need to activate a feature
	char ActivationKeyBuffer[200];
	int GetKeyRes = TestLicense->GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));

	//this is for debugging only, you should not need to check for return value inside siemens projects. Hacker might be able to intercept the event and track the variable used for the activation key
	if (GetKeyRes == 0)
		printf("For project ALMA and Feature KPI we obtained activation key '%s'\n", ActivationKeyBuffer);
	else
		printf("License did not contain a valid activation key\n");



	//cleanup
	delete TestLicense;
	///////////////////////////////////////// get the key using class ////////////////////////////////////





	///////////////////////////////////////// get the key in an async way ////////////////////////////////////
/*	GetActivationKeyAsync(ALMA, ALMA_KPI, &HandleAsyncKeyAssignCallback);
	while (ReceivedCallback==0)
		Sleep(10); 
	printf("For project ALMA and Feature KPI we obtained activation key '%s'\n", GlobalKeyStoreTestCallback);
	printf("\n\nAll done. Push a key to exit.");
	_getch();*/
	///////////////////////////////////////// get the key in an async way ////////////////////////////////////




	///////////////////////////////////////// simulate HW failure. Test Grace period ////////////////////////////////////
	// !! in previous tests we made a successfull query for an activation key. 
	// Grace period should be initialized at this point and even if fingerprint is no longer valid, it should trigger grace period and allow us to gte the key
	TestLicense = new License;
	er = TestLicense->LoadFromFile("../License.dat", "../License.dat"); // !! we are loading a bad file as fingerprint !!
	if (er == 0)
	{
//		int GracePeriodTriggered;
//		int erGraceCall = IsLicenseInGracePeriod(&GracePeriodTriggered);
		char ActivationKeyBuffer[200];
		int GetKeyRes = TestLicense->GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));
		//this is for debugging only, you should not need to check for return value inside siemens projects. Hacker might be able to intercept the event and track the variable used for the activation key
		if (GetKeyRes == 0)
			printf("Tested bad hardware configuration license check. Got key '%s'\n", ActivationKeyBuffer);
	}
	else
		printf("!!Load error\n");
	delete TestLicense;
	TestLicense = NULL;
	///////////////////////////////////////// simulate HW failure. Test Grace period ////////////////////////////////////



	///////////////////////////////////////// simulate license expire. Test Grace period ////////////////////////////////////
	TestLicense = new License;
	er = TestLicense->LoadFromFile("../License.dat");
	//set license expiration to a very short interval
	TestLicense->SetDuration(time(NULL), 1, 5 * 60);
	//wait for the license to expire
	Sleep(1000);
	//check if we can query an activation key. It should succeed as we are in grace period
	time_t GracePeriodTriggered;
	char IsGraceTriggered;
	GetKeyRes = TestLicense->IsGracePeriodTriggered(&GracePeriodTriggered, &IsGraceTriggered);
	GetKeyRes = TestLicense->GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));
	//this is for debugging only, you should not need to check for return value inside siemens projects. Hacker might be able to intercept the event and track the variable used for the activation key
 	if (GetKeyRes == 0)
		printf("Got key '%s'. Grace period is triggered %d\n", ActivationKeyBuffer, GracePeriodTriggered);

	//make the license be valid again
	TestLicense->SetDuration(time(NULL), 10000, 5 * 60);
	//query an activation key to force grace period to get disabled
	GetKeyRes = TestLicense->GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));
	//make license expire more than max grace period
	TestLicense->SetDuration(time(NULL) - MAX_GRACE_PERIOD_SECONDS, 1, 1);
	//wait for the license to expire
	Sleep(1000);
	//query an activation key. It should fail as grace period ended
	GetKeyRes = TestLicense->IsGracePeriodTriggered(&GracePeriodTriggered, &IsGraceTriggered);
	if (GetKeyRes != 0)
		printf("Error obtaining grace data %d\n", GetKeyRes);
	GetKeyRes = TestLicense->GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));
	//this is for debugging only, you should not need to check for return value inside siemens projects. Hacker might be able to intercept the event and track the variable used for the activation key
	if (GetKeyRes == WARNING_NO_LICENSE_FOUND)
		printf("Could not obtain license. Expected behavior as grace period expired. Status %d\n", GracePeriodTriggered);

	delete TestLicense;
	TestLicense = NULL;
	///////////////////////////////////////// simulate license expire. Test Grace period ////////////////////////////////////



	///////////////////////////////////////// simulate bad license file content and check error proofness ////////////////////////////////////
#ifdef _DEBUG
	EnableErrorTests();
	for (int i = 0; i < 201; i++)	// the 500 is a fictional number, should know the sizeo of the license file
	{
 		GetKeyRes = GetActivationKey(ALMA, ALMA_KPI, ActivationKeyBuffer, sizeof(ActivationKeyBuffer));
		printf("Corrupting byte %d from license file. Got result '%s'\n", i, ActivationKeyBuffer);
	}
#endif
	///////////////////////////////////////// simulate bad license file content and check error proofness ////////////////////////////////////


	printf("\n\nAll done. Push a key to continue.\n");
	_getch();

	_CrtMemCheckpoint(&s2);
	if (_CrtMemDifference(&s3, &s1, &s2) && (s3.lCounts[0]>0 || s3.lCounts[1] > 0 || s3.lCounts[3] > 0 || s3.lCounts[3] > 0)) //ignore CRT block allocs, can't do much about them. Some come from printf...
	{
		_CrtMemDumpStatistics(&s3);
		printf("!!Memory issues detected. Investigate !\n");
		_getch();
	}

	_CrtCheckMemory();
	_CrtDumpMemoryLeaks();

	return 0;
}