bool idaapi find_var(void *ud)
{
	vdui_t &vu = *(vdui_t *)ud;

	// Determine the ctree item to highlight
	vu.get_current_item(USE_KEYBOARD);
	citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL;

	// highlight == NULL might happen if one chooses variable at local variables declaration statement
	if (highlight != NULL)
	{
		// the chosen item must be an expression and of 'variable' type
		if (highlight->is_expr() && (highlight->op == cot_obj))
		{
			cexpr_t *highl_expr = (cexpr_t *)highlight;

			char expr_name[MAXSTR];
			highlight->print1(expr_name, MAXSTR, NULL);
			tag_remove(expr_name, expr_name, sizeof(expr_name));

			// initialize type rebuilder
			obj_fint_t obj_find;
			obj_find.vtbl_name = expr_name;


			// traverse the ctree structure
			obj_find.apply_to(&vu.cfunc->body, NULL);

			if (obj_find.bFound) {
				logmsg(DEBUG, obj_find.var_name.c_str());
				// Using this horrible code to remove warnings on GCC 4.9.2. Fix this later.
				qstring temp_var2 = qstring(obj_find.var_name.c_str());
				qstring &temp_var = temp_var2;
				reset_pointer_type(vu.cfunc, temp_var);


				vu.refresh_ctext();
			}
			else {
				warning("Failed to find variable...");
				logmsg(DEBUG, "Failed to find variable...");
			}
		}
	}
	else
	{
		logmsg(DEBUG, "Invalid item is choosen");
	}

	return true;
}
bool idaapi find_var(void *ud)
{
	vdui_t &vu = *(vdui_t *)ud;

	// Determine the ctree item to highlight
	vu.get_current_item(USE_KEYBOARD);
	citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL;

	// highlight == NULL might happen if one chooses variable at local variables declaration statement
	if (!highlight)
	{
		logmsg(DEBUG, "Invalid item is choosen");
		return false;
	}

	// the chosen item must be an expression and of 'variable' type
	if (highlight->is_expr() && (highlight->op == cot_obj))
	{
		cexpr_t *highl_expr = (cexpr_t *)highlight;

		qstring s;
		print1wrapper(highlight, &s, NULL);
		tag_remove(&s);

		// initialize type rebuilder
		obj_fint_t obj_find;
		obj_find.vtbl_name = s;

		// traverse the ctree structure
		obj_find.apply_to(&vu.cfunc->body, NULL);

		if (obj_find.bFound) {
			logmsg(DEBUG, (obj_find.var_name + "\n").c_str());
			reset_pointer_type(vu.cfunc, obj_find.var_name);

			vu.refresh_ctext();
		} else {
			warning("Failed to find variable...\n");
			logmsg(DEBUG, "Failed to find variable...\n");
		}
	}

	return true;
}
bool idaapi find_var(cfuncptr_t cfunc, const qstring& vtbl_name, qstring &var_name)
{
	var_name.clear();

	obj_fint_t obj_find;
	obj_find.vtbl_name = vtbl_name;

	if (obj_find.vtbl_name.find("const ") == 0)
		obj_find.vtbl_name.remove(0, 6);

	// traverse the ctree structure
	obj_find.apply_to(&cfunc->body, NULL);

	if (!obj_find.bFound) {
		logmsg(DEBUG, "Failed to find variable...\n");
		return false;
	}

	var_name = obj_find.var_name;
	reset_pointer_type(cfunc, var_name);
	return true;
}
bool idaapi find_var(cfuncptr_t cfunc, qstring vtbl_name, qstring &var_name)
{
	obj_fint_t obj_find;
	int offs = 0;
	if (!strncmp(vtbl_name.c_str(), "const ", 6))
		offs = 6;
	obj_find.vtbl_name = vtbl_name.c_str() + offs;
	bool bResult = false;
			
		
	// traverse the ctree structure
	obj_find.apply_to(&cfunc->body, NULL);

	if (obj_find.bFound) {
		var_name = obj_find.var_name.c_str();
		reset_pointer_type(cfunc, var_name);
		bResult = true;
	} else {
		logmsg(DEBUG, "Failed to find variable...");
	}

	return bResult;
}