summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-04-04 21:57:54 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-04-04 21:57:54 (GMT)
commit286ba13e0a5e908f9ebe67286bb6006adb4102fc (patch)
tree06d1ef353ae623c579a8fff5a74d22ecc0b9b862 /src
parentc1cac2ce69f01deb99c5c91a803dfa04af90ef14 (diff)
Simplified the plugin interface.
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Makefile.am3
-rw-r--r--src/plugins/plugin-def.h61
-rw-r--r--src/plugins/plugin-int.h12
-rw-r--r--src/plugins/plugin.c23
-rw-r--r--src/plugins/plugin.h7
-rw-r--r--src/plugins/self.h128
6 files changed, 159 insertions, 75 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 4059e0b..be459e3 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -8,7 +8,8 @@ libplugins_la_SOURCES = \
pglist.h pglist.c \
plugin-def.h \
plugin-int.h \
- plugin.h plugin.c
+ plugin.h plugin.c \
+ self.h
libplugins_la_CFLAGS = $(AM_CFLAGS)
diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h
index bb5641b..7895eeb 100644
--- a/src/plugins/plugin-def.h
+++ b/src/plugins/plugin-def.h
@@ -45,9 +45,7 @@ typedef uint32_t plugin_abi_version_t;
#define GET_ABI_MIN_VERSION(vs) ((vs >> 16) & 0xff)
#define GET_ABI_REV_VERSION(vs) (vs & 0xffff)
-#define CURRENT_ABI_VERSION DEFINE_PLUGIN_ABI_VERSION(0, 2, 0)
-
-//#define HARD_CODE_CURRENT_ABI_VERSION const plugin_abi_version_t abi_version = CURRENT_ABI_VERSION
+#define CURRENT_ABI_VERSION DEFINE_PLUGIN_ABI_VERSION(0, 3, 0)
@@ -235,6 +233,7 @@ typedef struct _plugin_interface
char *name; /* Désignation humaine courte */
char *desc; /* Description plus loquace */
char *version; /* Version du greffon */
+ char *url; /* Site Web associé */
bool container; /* Mise en place de greffons ? */
@@ -247,61 +246,5 @@ typedef struct _plugin_interface
} plugin_interface;
-/* Facilitations de déclarations */
-
-#define EMPTY_PG_LIST(name) \
- name = NULL, \
- name ## _count = 0 \
-
-#define BUILD_PG_LIST(name, lst) \
- name = lst, \
- name ## _count = sizeof(lst) / sizeof(lst[0]) \
-
-#define AL(...) BUILD_PG_LIST(.actions, ((plugin_action_t []){ __VA_ARGS__ }))
-
-#define RL(...) BUILD_PG_LIST(.required, ((char *[]){ __VA_ARGS__ }))
-
-#define NO_REQ EMPTY_PG_LIST(.required)
-
-
-#define DEFINE_CHRYSALIDE_PLUGIN(t, n, d, v, r, a) \
-G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = { \
- \
- .magic = CHRYSALIDE_PLUGIN_MAGIC, \
- .abi_version = CURRENT_ABI_VERSION, \
- \
- .gtp_name = t, \
- .name = n, \
- .desc = d, \
- .version = v, \
- \
- .container = false, \
- \
- r, \
- \
- a, \
- \
-}
-
-#define DEFINE_CHRYSALIDE_CONTAINER_PLUGIN(t, n, d, v, r, a) \
-G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = { \
- \
- .magic = CHRYSALIDE_PLUGIN_MAGIC, \
- .abi_version = CURRENT_ABI_VERSION, \
- \
- .gtp_name = t, \
- .name = n, \
- .desc = d, \
- .version = v, \
- \
- .container = true, \
- \
- r, \
- \
- a, \
- \
-}
-
-
#endif /* _PLUGINS_PLUGIN_DEF_H */
diff --git a/src/plugins/plugin-int.h b/src/plugins/plugin-int.h
index 62517d0..4f245b1 100644
--- a/src/plugins/plugin-int.h
+++ b/src/plugins/plugin-int.h
@@ -30,14 +30,15 @@
#include "plugin.h"
-#include "plugin-def.h"
#include "../analysis/content.h"
#include "../analysis/loaded.h"
#include "../common/bits.h"
-#include "../core/logs.h"
+/* Transfert de la conscience de soi. */
+typedef void (* pg_set_self_fc) (GPluginModule *);
+
/* Prend acte du [dé]chargement du greffon. */
typedef bool (* pg_management_fc) (GPluginModule *);
@@ -112,12 +113,5 @@ struct _GPluginModuleClass
};
-/* Présente dans le journal un message simple. */
-void g_plugin_module_log_simple_message(const GPluginModule *, LogMessageType, const char *);
-
-/* Présente dans le journal un message complexe. */
-void g_plugin_module_log_variadic_message(const GPluginModule *, LogMessageType, const char *, ...);
-
-
#endif /* _PLUGINS_PLUGIN_INT_H */
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index a6dadb9..674b1a8 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -207,6 +207,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
{
GPluginModule *result; /* Structure à retourner */
GModule *module; /* Abstration de manipulation */
+ pg_set_self_fc set_self; /* Copie du greffon */
const plugin_interface *interface; /* Déclaration d'interfaçage */
plugin_abi_version_t current; /* Version de l'ABI actuelle */
bool valid; /* Statut de validité */
@@ -243,6 +244,9 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
/* Récupération de la version d'ABI */
+ if (!load_plugin_symbol(module, "chrysalide_plugin_set_self", &set_self))
+ goto no_self_setter;
+
if (!load_plugin_symbol(module, "_chrysalide_plugin", &interface))
goto no_interface;
@@ -398,11 +402,11 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
case PGA_FORMAT_ANALYSIS_ENDED:
case PGA_FORMAT_POST_ANALYSIS_STARTED:
case PGA_FORMAT_POST_ANALYSIS_ENDED:
- valid = check_plugin_symbol(module, "handle_binary_format_analysis");
+ valid = check_plugin_symbol(module, "chrysalide_plugin_handle_binary_format_analysis");
break;
case PGA_FORMAT_PRELOAD:
- valid = check_plugin_symbol(module, "preload_binary_format");
+ valid = check_plugin_symbol(module, "chrysalide_plugin_preload_binary_format");
break;
case PGA_FORMAT_ATTACH_DEBUG:
@@ -420,7 +424,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
break;
case DPS_DISASSEMBLY:
- valid = check_plugin_symbol(module, "process_binary_disassembly");
+ valid = check_plugin_symbol(module, "chrysalide_plugin_process_binary_disassembly");
break;
case DPS_DETECTION:
@@ -461,8 +465,15 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
result->interface = interface;
+ set_self(result);
+
return result;
+ no_self_setter:
+
+ log_variadic_message(LMT_ERROR, _("Self pointer setter is missing for plugin '%s'"), filename);
+ goto bad_plugin;
+
no_interface:
log_variadic_message(LMT_ERROR, _("Main interface is missing for plugin '%s'"), filename);
@@ -652,12 +663,12 @@ static void g_plugin_module_init_gclass(GPluginModuleClass *class, GModule *modu
case PGA_FORMAT_ANALYSIS_ENDED:
case PGA_FORMAT_POST_ANALYSIS_STARTED:
case PGA_FORMAT_POST_ANALYSIS_ENDED:
- load_plugin_symbol(module, "handle_binary_format_analysis",
+ load_plugin_symbol(module, "chrysalide_plugin_handle_binary_format_analysis",
&class->handle_fmt_analysis);
break;
case PGA_FORMAT_PRELOAD:
- load_plugin_symbol(module, "preload_binary_format", &class->preload_format);
+ load_plugin_symbol(module, "chrysalide_plugin_preload_binary_format", &class->preload_format);
break;
case PGA_FORMAT_ATTACH_DEBUG:
@@ -673,7 +684,7 @@ static void g_plugin_module_init_gclass(GPluginModuleClass *class, GModule *modu
break;
case DPS_DISASSEMBLY:
- load_plugin_symbol(module, "process_binary_disassembly", &class->process_disass);
+ load_plugin_symbol(module, "chrysalide_plugin_process_binary_disassembly", &class->process_disass);
break;
case DPS_DETECTION:
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index c7ecff2..3a55041 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -31,6 +31,7 @@
#include "plugin-def.h"
#include "../analysis/binary.h"
+#include "../core/logs.h"
#include "../format/format.h"
#include "../format/known.h"
#include "../format/preload.h"
@@ -92,6 +93,12 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *, GPluginModule **, siz
/* Termine le chargement du greffon préparé. */
bool g_plugin_module_load(GPluginModule *, GPluginModule **, size_t);
+/* Présente dans le journal un message simple. */
+void g_plugin_module_log_simple_message(const GPluginModule *, LogMessageType, const char *);
+
+/* Présente dans le journal un message complexe. */
+void g_plugin_module_log_variadic_message(const GPluginModule *, LogMessageType, const char *, ...);
+
/* Accompagne la fin du chargement des modules natifs. */
void g_plugin_module_notify_native_loaded(GPluginModule *, PluginAction, void *);
diff --git a/src/plugins/self.h b/src/plugins/self.h
new file mode 100644
index 0000000..6a2e12d
--- /dev/null
+++ b/src/plugins/self.h
@@ -0,0 +1,128 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * self.h - définitions pour inclusion dans les différents greffons
+ *
+ * Copyright (C) 2020 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _PLUGINS_SELF_H
+#define _PLUGINS_SELF_H
+
+
+#include <config.h>
+
+
+#ifndef _PLUGINS_PLUGIN_H
+# include "plugin.h"
+#endif
+
+
+
+/* Facilitations de déclarations */
+
+#define CHRYSALIDE_WEBSITE(p) "https://www.chrysalide.re/" p
+
+#define EMPTY_PG_LIST(name) \
+ name = NULL, \
+ name ## _count = 0 \
+
+#define BUILD_PG_LIST(name, lst) \
+ name = lst, \
+ name ## _count = sizeof(lst) / sizeof(lst[0]) \
+
+#define AL(...) BUILD_PG_LIST(.actions, ((plugin_action_t []){ __VA_ARGS__ }))
+
+#define RL(...) BUILD_PG_LIST(.required, ((char *[]){ __VA_ARGS__ }))
+
+#define NO_REQ EMPTY_PG_LIST(.required)
+
+
+/* Composants d'interface */
+
+#define __private __attribute__((visibility("hidden")))
+
+#define PLUGIN_CORE_SELF \
+static GPluginModule *_this_plugin = NULL; \
+G_MODULE_EXPORT void chrysalide_plugin_set_self(GPluginModule *p); \
+G_MODULE_EXPORT void chrysalide_plugin_set_self(GPluginModule *p) { _this_plugin = p; }; \
+__private GPluginModule *_chrysalide_plugin_get_self(void); \
+__private GPluginModule *_chrysalide_plugin_get_self(void) { return _this_plugin; };
+
+#define PLUGIN_CORE_PROPS(n, d, v, u, c) \
+ \
+ .magic = CHRYSALIDE_PLUGIN_MAGIC, \
+ .abi_version = CURRENT_ABI_VERSION, \
+ \
+ .gtp_name = "G" n "Plugin", \
+ .name = n, \
+ .desc = d, \
+ .version = v, \
+ .url = u, \
+ \
+ .container = c
+
+#define DEFINE_CHRYSALIDE_PLUGIN(n, d, v, u, r, a) \
+PLUGIN_CORE_SELF \
+G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = { \
+ PLUGIN_CORE_PROPS(n, d, v, u, false), \
+ r, \
+ a, \
+}
+
+#define DEFINE_CHRYSALIDE_CONTAINER_PLUGIN(n, d, v, u, r, a) \
+PLUGIN_CORE_SELF \
+G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = { \
+ PLUGIN_CORE_PROPS(n, d, v, u, true), \
+ r, \
+ a, \
+}
+
+
+/* Manipulations accélérées */
+
+__private GPluginModule *_chrysalide_plugin_get_self(void);
+
+#define log_plugin_simple_message(type, msg) \
+ do \
+ { \
+ GPluginModule *__this; \
+ __this = _chrysalide_plugin_get_self(); \
+ if (__this != NULL) \
+ g_plugin_module_log_simple_message(__this, type, msg); \
+ else \
+ log_simple_message(type, msg); \
+ } \
+ while (0)
+
+#define log_plugin_variadic_message(type, msg, ...) \
+ do \
+ { \
+ GPluginModule *__this; \
+ __this = _chrysalide_plugin_get_self(); \
+ if (__this != NULL) \
+ g_plugin_module_log_variadic_message(__this, type, msg, __VA_ARGS__); \
+ else \
+ log_variadic_message(type, msg, __VA_ARGS__); \
+ } \
+ while (0)
+
+
+
+#endif /* _PLUGINS_SELF_H */