Exemple #1
0
int main() {
    string str = "x > 0";
    Condition c {str};
    map<string, pair<char,string>> mm {"x", {'i', "3"}};
    bool b = c.evaluate(mm);
    cout << (b ? "true" : "false") << endl;
}
/* Updates an attribute that meets the condition
...With its new value						*/
void Database::update(string rname, vector<string> attributes, vector<_Data> newvalues, Condition& c)
{
	int indr = 0;
	for (indr = 0; indr < allRelations.size(); ++indr)
	{
		if (allRelations[indr].GetName() == rname)
			break;
	}

	_Relation r2 = *(c.evaluate(&allRelations[indr]));
	for (int i = 0; i < r2.Columns[0].Rows.size(); ++i) {
		for (int j = 0; j < allRelations[indr].Columns[0].Rows.size(); ++j) {
			bool upd = true;
			for (int k = 0; k < allRelations[indr].Columns.size(); ++i) {
				if (r2.Columns[k].Rows[i].Data != allRelations[indr].Columns[k].Rows[j].Data) {
					upd = false;
					break;
				}
			}
			if (upd == true) {
				for (int y = 0; y < attributes.size(); ++y) {
					for (int z = 0; z < allRelations[indr].Columns.size(); ++z) {
						if (attributes[y] == allRelations[indr].Columns[z].Name) {
							allRelations[indr].Columns[z].Rows[j] = newvalues[y];
						}
					}
				}
			}
		}
	}
}
/* Deletes elements from the relation named Name
...That meet the condition */
void Database::deleteFrom(string name, Condition& c) {
	int i;
	for (i = 0; i < allRelations.size(); ++i){
		if (allRelations[i].GetName() == name)
			break;
	}

	_Relation r2 = *(c.evaluate(&allRelations[i]));
	for (int j = 0; i < r2.Columns[0].Rows.size(); ++i) {
		for (int k = 0; k < allRelations[i].Columns[0].Rows.size(); ++k) {
			bool del = true;
			for (int z = 0; z < allRelations[i].Columns.size(); ++z) {
				if (r2.Columns[z].Rows[j].Data != allRelations[i].Columns[z].Rows[k].Data) {
					del = false;
					break;
				}
			}
			if (del == true) {
				allRelations[i].RemoveRow(k);
				break;
			}
		}
	}
}
Exemple #4
0
DWORD WINAPI inputThread(LPVOID param)
{
	title();
	help();
	ostringstream oss;
	oss << "Business thread: " << (void*)GetCurrentThreadId();
	log(oss.str());

	// debug
	ConditionContext context;
	Condition* cond = new Condition(Condition::Imm, (void*)20, 0, Condition::Imm, (void*)20, 0, Condition::Equal);
	oss.str("");
	oss << "20 == 20: " << cond->evaluate(context);
	log(oss.str());
	cond = new Condition(Condition::Imm, (void*)20, 0, Condition::Imm, (void*)19, 0, Condition::Equal);
	oss.str("");
	oss << "20 == 19: " << cond->evaluate(context);
	log(oss.str());

	// fix the console window
	SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
		ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT
		| ENABLE_EXTENDED_FLAGS | ENABLE_QUICK_EDIT_MODE | ENABLE_INSERT_MODE);
	HWND window = GetConsoleWindow();
	RemoveMenu(GetSystemMenu(window, 0), SC_CLOSE, MF_BYCOMMAND);
	char* title = new char[1024];
	if(GetConsoleTitle(title, 1024) < 1012)
	{
		strcat_s(title, 1024, " - apilog");
		SetConsoleTitleA(title);
	}
	delete[] title;
	COORD coord;
	coord.X = 80;
	coord.Y = 9999;
	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coord);
	SMALL_RECT rect;
	rect.Left = 0;
	rect.Top = 0;
	rect.Right = 79;
	rect.Bottom = 39;
	SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &rect);

	while(1)
	{
		string input = getInput();
		vector<string> words = strsplit(input, " ");
		if(words.size() >= 1)
		{
			if(words[0] == "hooks")
			{
				if(gHooks.size() == 0)
				{
					log("None");
				}
				else for(vector<Hook>::iterator iter = gHooks.begin(); iter != gHooks.end(); ++iter)
				{
					oss.str("");
					oss << "#" << iter->mId << ": " << (void*)(iter->mAddress) << " " << iter->mName;
					log(oss.str());
				}
				continue;
			}
			else if(words[0] == "hook" || words[0] == "log")
			{
				if(words.size() >= 4 && words[1] == "api")
				{
					string mod = words[2];
					string proc = words[3];
					LPVOID address = findApi(mod, proc);
					if(address)
					{
						string name = mod + " " + proc;
						if(hook(address, name))
						{
							oss.str("");
							oss << "Hook installed: " + name +  " (" << (void*)address << ") -> " << getHookFunction();
							log(oss.str());
						}
					}
					continue;
				}
				else if(words.size() >= 2)
				{
					istringstream iss(words[1]);
					DWORD address;
					iss >> hex >> address;
					if(address)
					{
						if(hook((LPVOID)address, words[1]))
						{
							oss.str("");
							oss << "Hook installed: " << (void*)address << " -> " << getHookFunction();
							log(oss.str());
						}
						continue;
					}
				}
			}
			else if(words.size() == 2 && words[0] == "unhook")
			{
				istringstream iss(words[1]);
				DWORD address;
				iss >> hex >> address;
				if(address)
				{
					if(unhook((LPVOID)address))
						log("Hook uninstalled");
					else
						log("Fail");
					continue;
				}
			}