diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/analysis/loading.c | 2 | ||||
-rw-r--r-- | src/format/Makefile.am | 2 | ||||
-rw-r--r-- | src/format/known-int.h | 65 | ||||
-rw-r--r-- | src/format/known.c | 260 | ||||
-rw-r--r-- | src/format/known.h | 72 | ||||
-rw-r--r-- | src/plugins/pglist.h | 3 | ||||
-rw-r--r-- | src/plugins/plugin.c | 27 | ||||
-rw-r--r-- | src/plugins/plugin.h | 4 |
8 files changed, 434 insertions, 1 deletions
diff --git a/src/analysis/loading.c b/src/analysis/loading.c index 664b8d6..5c105f5 100644 --- a/src/analysis/loading.c +++ b/src/analysis/loading.c @@ -843,7 +843,7 @@ void g_content_explorer_populate_group(GContentExplorer *explorer, wgroup_id_t w group->contents = realloc(group->contents, ++group->count * sizeof(GBinContent *)); group->contents[group->count - 1] = content; - g_object_ref(G_OBJECT(content)); + g_object_ref_sink(G_OBJECT(content)); /* Relancement des explorations */ diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 1ab4825..dab4260 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -10,6 +10,8 @@ libformat_la_SOURCES = \ flat.h flat.c \ format-int.h \ format.h format.c \ + known-int.h \ + known.h known.c \ preload-int.h \ preload.h preload.c \ strsym.h strsym.c \ diff --git a/src/format/known-int.h b/src/format/known-int.h new file mode 100644 index 0000000..e4d3bd6 --- /dev/null +++ b/src/format/known-int.h @@ -0,0 +1,65 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * known-int.h - prototypes utiles aux formats binaires reconnus + * + * Copyright (C) 2019 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _FORMAT_KNOWN_INT_H +#define _FORMAT_KNOWN_INT_H + + +#include "known.h" + + + +/* Indique la désignation interne du format. */ +typedef const char * (* known_get_name_fc) (const GKnownFormat *); + +/* Fournit une description humaine du format. */ +typedef const char * (* known_get_desc_fc) (const GKnownFormat *); + +/*Assure l'interprétation d'un format en différé. */ +typedef bool (* known_analyze_fc) (GKnownFormat *, wgroup_id_t, GtkStatusStack *); + + +/* Format binaire générique (instance) */ +struct _GKnownFormat +{ + GObject parent; /* A laisser en premier */ + + GBinContent *content; /* Contenu binaire à étudier */ + +}; + +/* Format binaire générique (classe) */ +struct _GKnownFormatClass +{ + GObjectClass parent; /* A laisser en premier */ + + known_get_name_fc get_name; /* Désignation interne */ + known_get_desc_fc get_desc; /* Désignation humaine */ + + known_analyze_fc analyze; /* Interprétation du format */ + +}; + + + +#endif /* _FORMAT_KNOWN_INT_H */ diff --git a/src/format/known.c b/src/format/known.c new file mode 100644 index 0000000..9a3eef6 --- /dev/null +++ b/src/format/known.c @@ -0,0 +1,260 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * format.c - support des différents formats binaires reconnus + * + * Copyright (C) 2019 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "known.h" + + +#include <assert.h> + + +#include "known-int.h" +#include "../plugins/pglist.h" + + + +/* Initialise la classe des formats binaires génériques. */ +static void g_known_format_class_init(GKnownFormatClass *); + +/* Initialise une instance de format binaire générique. */ +static void g_known_format_init(GKnownFormat *); + +/* Supprime toutes les références externes. */ +static void g_known_format_dispose(GKnownFormat *); + +/* Procède à la libération totale de la mémoire. */ +static void g_known_format_finalize(GKnownFormat *); + + + +/* Indique le type défini pour un format binaire générique. */ +G_DEFINE_TYPE(GKnownFormat, g_known_format, G_TYPE_OBJECT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des formats binaires génériques. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_known_format_class_init(GKnownFormatClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_known_format_dispose; + object->finalize = (GObjectFinalizeFunc)g_known_format_finalize; + +} + + +/****************************************************************************** +* * +* Paramètres : format = instance à initialiser. * +* * +* Description : Initialise une instance de format binaire générique. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_known_format_init(GKnownFormat *format) +{ + format->content = NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : format = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_known_format_dispose(GKnownFormat *format) +{ + g_clear_object(&format->content); + + G_OBJECT_CLASS(g_known_format_parent_class)->dispose(G_OBJECT(format)); + +} + + +/****************************************************************************** +* * +* Paramètres : format = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_known_format_finalize(GKnownFormat *format) +{ + G_OBJECT_CLASS(g_known_format_parent_class)->finalize(G_OBJECT(format)); + +} + + +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à consulter. * +* content = contenu binaire à parcourir. * +* * +* Description : Définit le contenu binaire à analyser. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_known_format_set_content(GKnownFormat *format, GBinContent *content) +{ + assert(format->content == NULL); + + g_object_ref_sink(G_OBJECT(content)); + + format->content = content; + +} + + +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à consulter. * +* * +* Description : Fournit une référence vers le contenu binaire analysé. * +* * +* Retour : Gestionnaire de contenu binaire en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GBinContent *g_known_format_get_content(const GKnownFormat *format) +{ + GBinContent *result; /* Instance à retourner */ + + result = format->content; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à consulter. * +* * +* Description : Indique la désignation interne du format. * +* * +* Retour : Description du format. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_known_format_get_name(const GKnownFormat *format) +{ + const char *result; /* Désignation à retourner */ + + result = G_KNOWN_FORMAT_GET_CLASS(format)->get_name(format); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à consulter. * +* * +* Description : Fournit une description humaine du format. * +* * +* Retour : Description du format. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_known_format_get_description(const GKnownFormat *format) +{ + const char *result; /* Désignation à retourner */ + + result = G_KNOWN_FORMAT_GET_CLASS(format)->get_desc(format); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = format chargé dont l'analyse est lancée. * +* gid = groupe de travail dédié. * +* status = barre de statut à tenir informée. * +* * +* Description : Assure l'interprétation d'un format en différé. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_known_format_analyze(GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status) +{ + bool result; /* Bilan à retourner */ + GKnownFormatClass *class; /* Classe de l'instance */ + + handle_known_format_analysis(PGA_FORMAT_ANALYSIS_STARTED, format, gid, status); + + class = G_KNOWN_FORMAT_GET_CLASS(format); + + result = class->analyze(format, gid, status); + + handle_known_format_analysis(PGA_FORMAT_ANALYSIS_ENDED, format, gid, status); + + return result; + +} diff --git a/src/format/known.h b/src/format/known.h new file mode 100644 index 0000000..c89ba4a --- /dev/null +++ b/src/format/known.h @@ -0,0 +1,72 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * format.h - prototypes pour le support des différents formats binaires reconnus + * + * Copyright (C) 2019 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _FORMAT_KNOWN_H +#define _FORMAT_KNOWN_H + + +#include <glib-object.h> +#include <stdbool.h> + + +#include "../analysis/content.h" +#include "../glibext/delayed.h" + + + +#define G_TYPE_KNOWN_FORMAT g_known_format_get_type() +#define G_KNOWN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_KNOWN_FORMAT, GKnownFormat)) +#define G_IS_KNOWN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_KNOWN_FORMAT)) +#define G_KNOWN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_KNOWN_FORMAT, GKnownFormatClass)) +#define G_IS_KNOWN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_KNOWN_FORMAT)) +#define G_KNOWN_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_KNOWN_FORMAT, GKnownFormatClass)) + + +/* Format binaire générique (instance) */ +typedef struct _GKnownFormat GKnownFormat; + +/* Format binaire générique (classe) */ +typedef struct _GKnownFormatClass GKnownFormatClass; + + +/* Indique le type défini pour un format binaire générique. */ +GType g_known_format_get_type(void); + +/* Définit le contenu binaire à analyser. */ +void g_known_format_set_content(GKnownFormat *, GBinContent *); + +/* Fournit une référence vers le contenu binaire analysé. */ +GBinContent *g_known_format_get_content(const GKnownFormat *); + +/* Indique la désignation interne du format. */ +const char *g_known_format_get_name(const GKnownFormat *); + +/* Fournit une description humaine du format. */ +const char *g_known_format_get_description(const GKnownFormat *); + +/* Assure l'interprétation d'un format en différé. */ +bool g_known_format_analyze(GKnownFormat *, wgroup_id_t, GtkStatusStack *); + + + +#endif /* _FORMAT_KNOWN_H */ diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h index 1306571..c55c6da 100644 --- a/src/plugins/pglist.h +++ b/src/plugins/pglist.h @@ -105,6 +105,9 @@ GPluginModule **get_all_plugins_for_action(PluginAction, size_t *); /* DPS_FORMAT */ +#define handle_known_format_analysis(a, f, g, s) \ + process_all_plugins_for(a, g_plugin_module_handle_known_format_analysis, f, g, s) + #define handle_binary_format_analysis(a, f, g, s) \ process_all_plugins_for(a, g_plugin_module_handle_binary_format_analysis, f, g, s) diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 27f1871..7423148 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -1139,6 +1139,33 @@ void g_plugin_module_handle_loaded_content(const GPluginModule *plugin, PluginAc * * ******************************************************************************/ +bool g_plugin_module_handle_known_format_analysis(const GPluginModule *plugin, PluginAction action, GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status) +{ + GPluginModuleClass *class; /* Classe de l'instance active */ + + class = G_PLUGIN_MODULE_GET_CLASS(plugin); + + return false;//class->handle_fmt_analysis(plugin, action, G_BIN_FORMAT(format), gid, status); + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* action = type d'action attendue. * +* format = format de binaire à manipuler pendant l'opération. * +* gid = groupe de travail dédié. * +* status = barre de statut à tenir informée. * +* * +* Description : Procède à une opération liée à l'analyse d'un format. * +* * +* Retour : Bilan de l'exécution du traitement. * +* * +* Remarques : - * +* * +******************************************************************************/ + bool g_plugin_module_handle_binary_format_analysis(const GPluginModule *plugin, PluginAction action, GBinFormat *format, wgroup_id_t gid, GtkStatusStack *status) { GPluginModuleClass *class; /* Classe de l'instance active */ diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h index cccd39b..9b8d294 100644 --- a/src/plugins/plugin.h +++ b/src/plugins/plugin.h @@ -32,6 +32,7 @@ #include "plugin-def.h" #include "../analysis/binary.h" #include "../format/format.h" +#include "../format/known.h" #include "../format/preload.h" #include "../gtkext/gtkstatusstack.h" @@ -104,6 +105,9 @@ void g_plugin_module_handle_binary_content(const GPluginModule *, PluginAction, void g_plugin_module_handle_loaded_content(const GPluginModule *, PluginAction, GLoadedContent *, wgroup_id_t, GtkStatusStack *); /* Procède à une opération liée à l'analyse d'un format. */ +bool g_plugin_module_handle_known_format_analysis(const GPluginModule *, PluginAction, GKnownFormat *, wgroup_id_t, GtkStatusStack *); + +/* Procède à une opération liée à l'analyse d'un format. */ bool g_plugin_module_handle_binary_format_analysis(const GPluginModule *, PluginAction, GBinFormat *, wgroup_id_t, GtkStatusStack *); /* Procède à un préchargement de format de fichier. */ |