Example #1
0
	bool iat_manager::hook(const char* api_name, uintptr_t* old_function_ptr, uintptr_t new_function)
	{
		if (!old_function_ptr)
			return false;

		uintptr_t address = iat_ptr_->get_proc_address(api_name);
		if (!address)
			return false;

		uintptr_t old_function = detail::replace_pointer(address, new_function);
		*old_function_ptr = old_function;
		hook_info_.push_front(hook_info(old_function, new_function, address));
		return true;
	}
Example #2
0
void
plugin_api_init ()
{
    /* WeeChat core modifiers */
    hook_modifier (NULL, "color_decode_ansi",
                   &plugin_api_modifier_color_decode_ansi, NULL);

    /* WeeChat core info hooks */
    hook_info (NULL, "version", N_("WeeChat version"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "version_number", N_("WeeChat version (as number)"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "version_git", N_("WeeChat git version (output of "
                                       "command \"git describe\" for a "
                                       "development version only, empty for a "
                                       "stable release)"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "date", N_("WeeChat compilation date"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "dir_separator", N_("directory separator"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_dir", N_("WeeChat directory"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_libdir", N_("WeeChat \"lib\" directory"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_sharedir", N_("WeeChat \"share\" directory"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_localedir", N_("WeeChat \"locale\" directory"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_site", N_("WeeChat site"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_site_download", N_("WeeChat site, download page"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "weechat_upgrading", N_("1 if WeeChat is upgrading (command `/upgrade`)"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "charset_terminal", N_("terminal charset"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "charset_internal", N_("WeeChat internal charset"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "locale", N_("locale used for translating messages"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "inactivity", N_("keyboard inactivity (seconds)"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "filters_enabled", N_("1 if filters are enabled"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "cursor_mode", N_("1 if cursor mode is enabled"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "term_width", N_("width of terminal"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "term_height", N_("height of terminal"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "color_ansi_regex", N_("POSIX extended regular expression to search ANSI escape codes"), NULL,
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "color_term2rgb", N_("terminal color (0-255) converted to RGB color"),
               N_("color (terminal color: 0-255)"),
               &plugin_api_info_get_internal, NULL);
    hook_info (NULL, "color_rgb2term", N_("RGB color converted to terminal color (0-255)"),
               N_("rgb,limit (limit is optional and is set to 256 by default)"),
               &plugin_api_info_get_internal, NULL);

    /* WeeChat core infolist hooks */
    hook_infolist (NULL, "bar", N_("list of bars"),
                   N_("bar pointer (optional)"),
                   N_("bar name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "bar_item", N_("list of bar items"),
                   N_("bar item pointer (optional)"),
                   N_("bar item name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "bar_window", N_("list of bar windows"),
                   N_("bar window pointer (optional)"),
                   NULL,
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "buffer", N_("list of buffers"),
                   N_("buffer pointer (optional)"),
                   N_("buffer name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "buffer_lines", N_("lines of a buffer"),
                   N_("buffer pointer"),
                   NULL,
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "filter", N_("list of filters"),
                   NULL,
                   N_("filter name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "history", N_("history of commands"),
                   N_("buffer pointer (if not set, return global history) (optional)"),
                   NULL,
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "hook", N_("list of hooks"),
                   N_("hook pointer (optional)"),
                   N_("type,arguments (type is command/timer/.., arguments to "
                      "get only some hooks (can start or end with \"*\" as "
                      "wildcard), both are optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "hotlist", N_("list of buffers in hotlist"),
                   NULL,
                   NULL,
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "key", N_("list of key bindings"),
                   NULL,
                   N_("context (\"default\", \"search\", \"cursor\" or "
                      "\"mouse\") (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "layout", N_("list of layouts"),
                   NULL,
                   NULL,
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "nicklist", N_("nicks in nicklist for a buffer"),
                   N_("buffer pointer"),
                   N_("nick_xxx or group_xxx to get only nick/group xxx "
                      "(optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "option", N_("list of options"),
                   NULL,
                   N_("option name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "plugin", N_("list of plugins"),
                   N_("plugin pointer (optional)"),
                   N_("plugin name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "proxy", N_("list of proxies"),
                   N_("proxy pointer (optional)"),
                   N_("proxy name (can start or end with \"*\" as wildcard) (optional)"),
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "url_options", N_("options for URL"),
                   NULL,
                   NULL,
                   &plugin_api_infolist_get_internal, NULL);
    hook_infolist (NULL, "window", N_("list of windows"),
                   N_("window pointer (optional)"),
                   N_("\"current\" for current window or a window number (optional)"),
                   &plugin_api_infolist_get_internal, NULL);

    /* WeeChat core hdata */
    hook_hdata (NULL, "bar", N_("bar"),
                &gui_bar_hdata_bar_cb, NULL);
    hook_hdata (NULL, "bar_item", N_("bar item"),
                &gui_bar_item_hdata_bar_item_cb, NULL);
    hook_hdata (NULL, "bar_window", N_("bar window"),
                &gui_bar_window_hdata_bar_window_cb, NULL);
    hook_hdata (NULL, "buffer", N_("buffer"),
                &gui_buffer_hdata_buffer_cb, NULL);
    hook_hdata (NULL, "buffer_visited", N_("visited buffer"),
                &gui_buffer_hdata_buffer_visited_cb, NULL);
    hook_hdata (NULL, "completion", N_("structure with completion"),
                &gui_completion_hdata_completion_cb, NULL);
    hook_hdata (NULL, "completion_partial", N_("structure with partial completion"),
                &gui_completion_hdata_completion_partial_cb, NULL);
    hook_hdata (NULL, "config_file", N_("config file"),
                &config_file_hdata_config_file_cb, NULL);
    hook_hdata (NULL, "config_section", N_("config section"),
                &config_file_hdata_config_section_cb, NULL);
    hook_hdata (NULL, "config_option", N_("config option"),
                &config_file_hdata_config_option_cb, NULL);
    hook_hdata (NULL, "filter", N_("filter"),
                &gui_filter_hdata_filter_cb, NULL);
    hook_hdata (NULL, "history", N_("history of commands in buffer"),
                &gui_history_hdata_history_cb, NULL);
    hook_hdata (NULL, "hotlist", N_("hotlist"),
                &gui_hotlist_hdata_hotlist_cb, NULL);
    hook_hdata (NULL, "input_undo", N_("structure with undo for input line"),
                &gui_buffer_hdata_input_undo_cb, NULL);
    hook_hdata (NULL, "key", N_("a key (keyboard shortcut)"),
                &gui_key_hdata_key_cb, NULL);
    hook_hdata (NULL, "layout", N_("layout"),
                &gui_layout_hdata_layout_cb, NULL);
    hook_hdata (NULL, "layout_buffer", N_("buffer layout"),
                &gui_layout_hdata_layout_buffer_cb, NULL);
    hook_hdata (NULL, "layout_window", N_("window layout"),
                &gui_layout_hdata_layout_window_cb, NULL);
    hook_hdata (NULL, "lines", N_("structure with lines"),
                &gui_line_hdata_lines_cb, NULL);
    hook_hdata (NULL, "line", N_("structure with one line"),
                &gui_line_hdata_line_cb, NULL);
    hook_hdata (NULL, "line_data", N_("structure with one line data"),
                &gui_line_hdata_line_data_cb, NULL);
    hook_hdata (NULL, "nick_group", N_("group in nicklist"),
                &gui_nicklist_hdata_nick_group_cb, NULL);
    hook_hdata (NULL, "nick", N_("nick in nicklist"),
                &gui_nicklist_hdata_nick_cb, NULL);
    hook_hdata (NULL, "plugin", N_("plugin"),
                &plugin_hdata_plugin_cb, NULL);
    hook_hdata (NULL, "proxy", N_("proxy"),
                &proxy_hdata_proxy_cb, NULL);
    hook_hdata (NULL, "window", N_("window"),
                &gui_window_hdata_window_cb, NULL);
    hook_hdata (NULL, "window_scroll", N_("scroll info in window"),
                &gui_window_hdata_window_scroll_cb, NULL);
    hook_hdata (NULL, "window_tree", N_("tree of windows"),
                &gui_window_hdata_window_tree_cb, NULL);
}