Wireshark-dev: [Wireshark-dev] QT Plugin produces function not defined error on run time

From: Jeswin Mathai <jeswinrokz@xxxxxxxxx>
Date: Tue, 13 Mar 2018 06:56:01 +0000
Hi!

I just started developing a plugin with QT, I tried the example given at https://github.com/wireshark/wireshark/tree/master/plugins/epan/pluginifdemo. Modified Makefile.am and CMakeFiles.txt according to wireshark-2.4.5, but it didn't work. The QT files were not being compiled. So I took the QT files added it to ui/qt directory with some modification in includes. The QT files were now in ui/qt folder and the rest of the plugin was in plugins/pluginifdemo folder. The program successfully compiled. But upon running wireshark it produces error "undefined symbol: pluginifdemo_ui_about". What am I missing here?

In plugins/pluginifdemo directory
==================================
plugindemo.c
----------------------------------------------------------------------------------
/* pluginifdemo.c
 * Routines for plugin_if demo capability
 * Author: Roland Knall <rknall@xxxxxxxxx>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@xxxxxxxxxxxxx>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <stdio.h>

#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/tap.h>
#include <epan/plugin_if.h>
#include "pluginifdemo.h"

#include <ui/qt/uihandler.h>

void proto_register_pluginifdemo(void);
void proto_reg_handoff_pluginifdemo(void);

static int proto_pluginifdemo = -1;

void toolbar_cb(gpointer object, gpointer item_data, gpointer user_data);

void
void
menu_cb(ext_menubar_gui_type gui_type, gpointer gui_data, gpointer user_data _U_)
{
    pluginifdemo_ui_main(gui_type, gui_data);
}

void
about_cb(ext_menubar_gui_type gui_type _U_, gpointer gui_data _U_, gpointer user_data _U_)
{
    pluginifdemo_ui_about(gui_type, gui_data);
}

void
proto_register_pluginifdemo(void)
{
    static hf_register_info hf[] = {
    };

    static gint *ett[] = {
    };

#if 0
    module_t *pluginif_module = NULL;
#endif
    ext_menu_t * ext_menu = NULL;

    proto_pluginifdemo = proto_register_protocol("Plugin IF Demo Protocol", "Pluginifdemo", "pluginifdemo");

    proto_register_field_array(proto_pluginifdemo, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    ext_menu = ext_menubar_register_menu ( proto_pluginifdemo, "Plugin IF Demonstration", TRUE );
    ext_menubar_set_parentmenu (ext_menu, "Tools");

    ext_menubar_add_entry(ext_menu, "Toolbar Action Demonstrator", "Action demonstrator for the plugin toolbar", menu_cb, NULL);
    ext_menubar_add_separator(ext_menu);
    ext_menubar_add_website(ext_menu, "Wireshark Development", "See Wireshark Development", "https://www.wireshark.org/develop.html");
    ext_menubar_add_separator(ext_menu);
    ext_menubar_add_entry(ext_menu, "&About Plugin IF Demonstration", "Further information", menu_cb, NULL);
#if 0
    pluginif_module = prefs_register_protocol(proto_pluginifdemo, NULL);
#endif

    ext_toolbar_t * tb = ext_toolbar_register_toolbar("Plugin Interface Demo Toolbar");

    ext_toolbar_add_entry(tb, EXT_TOOLBAR_BUTTON, "Button 1", 0, "Button 1 to press", FALSE, 0, FALSE, 0, toolbar_cb, 0);
    ext_toolbar_add_entry(tb, EXT_TOOLBAR_BUTTON, "Button 2", 0, "Button 2 to press", TRUE, 0, FALSE, 0, toolbar_cb, 0);
    ext_toolbar_add_entry(tb, EXT_TOOLBAR_BOOLEAN, "Checkbox", 0, "Checkbox to Select", FALSE, 0, FALSE, 0, toolbar_cb, 0);
    ext_toolbar_add_entry(tb, EXT_TOOLBAR_STRING, "String 1", "Default String", "String without validation", FALSE, 0, TRUE, 0, toolbar_cb, 0);
    ext_toolbar_add_entry(tb, EXT_TOOLBAR_STRING, "String 2", "ABC", "String with validation", FALSE, 0, FALSE, "^[A-Z]+", toolbar_cb, 0);
    GList * entries = 0;
    entries = ext_toolbar_add_val( entries, "1", "ABCD", FALSE );
    entries = ext_toolbar_add_val(entries, "2", "EFG", FALSE );
    entries = ext_toolbar_add_val(entries, "3", "HIJ", TRUE );
    entries = ext_toolbar_add_val(entries, "4", "KLM", FALSE );
    entries = ext_toolbar_add_val(entries, "5", "NOP", FALSE );
    entries = ext_toolbar_add_val(entries, "6", "QRS", FALSE );
    entries = ext_toolbar_add_val(entries, "7", "TUVW", FALSE );
    entries = ext_toolbar_add_val(entries, "8", "XYZ", FALSE );
    ext_toolbar_add_entry(tb, EXT_TOOLBAR_SELECTOR, "Selector", 0, "Selector to choose from", FALSE, entries, FALSE, 0, toolbar_cb, 0);

    pluginifdemo_toolbar_register(tb);



}

void toolbar_cb(gpointer toolbar_item, gpointer item_data, gpointer user_data _U_)
{
    if ( ! toolbar_item )
        return;

    gchar * message = 0;
    ext_toolbar_t * entry = (ext_toolbar_t *)toolbar_item;

    if ( entry->item_type == EXT_TOOLBAR_BUTTON )
        pluginifdemo_toolbar_log ( "Button pressed at toolbar" );
    else if ( entry->item_type == EXT_TOOLBAR_BOOLEAN )
    {
        gboolean data = "" *)item_data);
        message = g_strdup_printf( "Checkbox selected value: %d", (int) (data) );
        pluginifdemo_toolbar_log(message);
    }
    else if ( entry->item_type == EXT_TOOLBAR_STRING )
    {
        gchar * data = "" *)item_data;
        message = g_strdup_printf( "String entered in toolbar: %s", data );
        pluginifdemo_toolbar_log(message);
    }
    else if ( entry->item_type == EXT_TOOLBAR_SELECTOR )
    {
        ext_toolbar_value_t * data = "" *)item_data;
        message = g_strdup_printf( "Value from toolbar: %s", data->value );
        pluginifdemo_toolbar_log(message);
    }

    g_free(message);
}

void
proto_reg_handoff_pluginifdemo(void)
{

}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

In ui/qt directory
==================================
uihandler.h
----------------------------------------------------------------------------------
/* uihandler.h
 * Author: Roland Knall <rknall@xxxxxxxxx>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@xxxxxxxxxxxxx>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef PLUGINIFDEMO_UI_UIHANDLER_H_
#define PLUGINIFDEMO_UI_UIHANDLER_H_

#ifdef __cplusplus

#include <QObject>
#include <QDialog>
#include <QMutex>

#include <epan/plugin_if.h>

#include "ws_symbol_export.h"

class WS_DLL_PUBLIC_DEF GuiHandler : public QObject
{
    Q_OBJECT

public:

    static GuiHandler * getInstance();

    void showAboutDialog(ext_menubar_gui_type gui_type, gpointer gui_data);
    void showMainDialog(ext_menubar_gui_type gui_type, gpointer gui_data);

    void doReset();

    void addLogMessage(QString message);

    void setToolbar(ext_toolbar_t * toolbar);
    ext_toolbar_t * toolBar();

signals:
    void reset();
    void logChanged(QString newEntry);

protected:

    GuiHandler();

    // Stop the compiler generating methods of "copy the object"
    GuiHandler(GuiHandler const& copy); // Not implemented
    GuiHandler& operator=(GuiHandler const& copy); // Not implemented

private:

    static QMutex * singletonMutex;

    ext_toolbar_t * _toolbar;

    void executeDialog(QDialog * object);
};

extern "C" {
#endif

extern void pluginifdemo_ui_about(ext_menubar_gui_type gui_type, gpointer gui_data);
extern void pluginifdemo_ui_main(ext_menubar_gui_type gui_type, gpointer gui_data);
extern void pluginifdemo_toolbar_log(const gchar * message);

extern void pluginifdemo_toolbar_register(ext_toolbar_t * toolbar);

#ifdef __cplusplus
}
#endif

#endif /* BURANALYZER_UI_UIHANDLER_H_ */

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */