summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analysis/disass/disassembler.c52
-rw-r--r--src/arch/operand-int.h4
-rw-r--r--src/arch/operand.c48
-rw-r--r--src/arch/operand.h3
-rw-r--r--src/plugins/pglist.c30
-rw-r--r--src/plugins/pglist.h7
-rw-r--r--src/plugins/plugin-def.h26
-rw-r--r--src/plugins/plugin.c2
8 files changed, 127 insertions, 45 deletions
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 73d75cf..6d0bd61 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -60,13 +60,13 @@ typedef struct _GDelayedDisassembly
{
GDelayedWork parent; /* A laisser en premier */
- const GLoadedBinary *binary; /* Destinataire final */
- const GExeFormat *format; /* Format du binaire représenté*/
+ GLoadedBinary *binary; /* Destinataire final */
+ GExeFormat *format; /* Format du binaire représenté*/
GBinPart **parts; /* Parties binaires à traiter */
size_t count; /* Nombre de ces parties */
- GArchInstruction *instrs; /* Instructions résultantes */
+ GArchInstruction **instrs; /* Instructions résultantes */
GCodeBuffer *buffer; /* Tampon pour le rendu */
} GDelayedDisassembly;
@@ -89,7 +89,7 @@ static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *);
static void g_delayed_disassembly_init(GDelayedDisassembly *);
/* Crée une tâche de désassemblage différé. */
-static GDelayedDisassembly *g_delayed_disassembly_new(const GLoadedBinary *, GBinPart **, size_t, GCodeBuffer *);
+static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *, GBinPart **, size_t, GArchInstruction **, GCodeBuffer *);
/* Assure le désassemblage en différé. */
static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkExtStatusBar *);
@@ -155,6 +155,7 @@ static void g_delayed_disassembly_init(GDelayedDisassembly *disass)
* format = format du binaire représenté. *
* parts = parties binaires à désassembler. *
* count = nombre de parties à traiter. *
+* instrs = emplacement pour la liste d'instructions. *
* buffer = tampon de sortie pour les instructions. *
* *
* Description : Crée une tâche de désassemblage différé. *
@@ -165,7 +166,7 @@ static void g_delayed_disassembly_init(GDelayedDisassembly *disass)
* *
******************************************************************************/
-static GDelayedDisassembly *g_delayed_disassembly_new(const GLoadedBinary *binary, GBinPart **parts, size_t count, GCodeBuffer *buffer)
+static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *binary, GBinPart **parts, size_t count, GArchInstruction **instrs, GCodeBuffer *buffer)
{
GDelayedDisassembly *result; /* Tâche à retourner */
@@ -177,6 +178,7 @@ static GDelayedDisassembly *g_delayed_disassembly_new(const GLoadedBinary *binar
result->parts = parts;
result->count = count;
+ result->instrs = instrs;
result->buffer = buffer;
return result;
@@ -216,8 +218,8 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta
id = gtk_extended_status_bar_push(statusbar, _("Disassembling..."), true);
- disass->instrs = disassemble_binary_parts(disass->binary, disass->parts, disass->count,
- statusbar, id);
+ *disass->instrs = disassemble_binary_parts(disass->binary, disass->parts, disass->count,
+ statusbar, id);
gtk_extended_status_bar_remove(statusbar, id);
@@ -239,35 +241,43 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta
#endif
+ run_plugins_on_binary(disass->binary, PGA_BINARY_DISASSEMBLED);
+
/* Seconde étape */
id = gtk_extended_status_bar_push(statusbar, _("Establishing links..."), true);
- establish_links_between_lines(disass->instrs, routines, routines_count, statusbar, id);
+ establish_links_between_lines(*disass->instrs, routines, routines_count, statusbar, id);
gtk_extended_status_bar_remove(statusbar, id);
+ run_plugins_on_binary(disass->binary, PGA_BINARY_LINKED);
+
/* Troisième étape */
id = gtk_extended_status_bar_push(statusbar, _("Finding remaining limits..."), true);
qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_rcompare);
- limit_all_routines(disass->instrs, routines, routines_count, statusbar, id);
+ limit_all_routines(*disass->instrs, routines, routines_count, statusbar, id);
gtk_extended_status_bar_remove(statusbar, id);
+ run_plugins_on_binary(disass->binary, PGA_BINARY_BOUNDED);
+
/* Quatrième étape */
id = gtk_extended_status_bar_push(statusbar, _("Printing disassembled code..."), true);
qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_compare);
- print_disassembled_instructions(disass->buffer, disass->format, disass->instrs,
+ print_disassembled_instructions(disass->buffer, disass->format, *disass->instrs,
routines, routines_count);
gtk_extended_status_bar_remove(statusbar, id);
+ run_plugins_on_binary(disass->binary, PGA_BINARY_PRINTED);
+
}
@@ -387,39 +397,19 @@ void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_co
off_t length; /* Quantité de ces données */
GDelayedDisassembly *disass; /* Désassemblage à mener */
GWorkQueue *queue; /* Gestionnaire de différés */
- GPluginModule **pglist; /* Liste de greffons */
- size_t pgcount; /* Taille de cette liste */
- size_t i; /* Boucle de parcours */
-
- /* Déroulement de l'opération principale */
*buffer = g_code_buffer_new();
data = g_loaded_binary_get_data(binary, &length);
build_disass_prologue(*buffer, g_loaded_binary_get_filename(binary, true), data, length);
- disass = g_delayed_disassembly_new(binary, parts, parts_count, *buffer);
+ disass = g_delayed_disassembly_new(binary, parts, parts_count, instrs, *buffer);
queue = get_work_queue();
g_work_queue_schedule_work(queue, G_DELAYED_WORK(disass));
g_delayed_work_wait_for_completion(G_DELAYED_WORK(disass));
- *instrs = disass->instrs;
-
g_object_unref(G_OBJECT(disass));
- /* Actions post-désassemblage */
-
- pglist = get_all_plugins_for_action(PGA_DISASS_PROCESS, &pgcount);
-
- if (pgcount > 0)
- {
- for (i = 0; i < pgcount; i++)
- g_plugin_module_execute_action_on_binary(pglist[i], binary, PGA_DISASS_PROCESS);
-
- free(pglist);
-
- }
-
}
diff --git a/src/arch/operand-int.h b/src/arch/operand-int.h
index d9ebde0..b9712c4 100644
--- a/src/arch/operand-int.h
+++ b/src/arch/operand-int.h
@@ -44,6 +44,10 @@ struct _GArchOperand
operand_compare_fc compare; /* Comparaison d'opérandes */
operand_print_fc print; /* Texte humain équivalent */
+ char *alt_text; /* Eventuel texte alternatif */
+ size_t alt_len; /* Taille de ce texte */
+ RenderingTagType alt_tag; /* Type de rendu */
+
};
diff --git a/src/arch/operand.c b/src/arch/operand.c
index e98683e..667921a 100644
--- a/src/arch/operand.c
+++ b/src/arch/operand.c
@@ -24,6 +24,10 @@
#include "operand.h"
+#include <malloc.h>
+#include <string.h>
+
+
#include "operand-int.h"
@@ -107,6 +111,41 @@ bool g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b)
/******************************************************************************
* *
* Paramètres : operand = opérande à traiter. *
+* text = représentation lisible alternative. *
+* tag = style d'impression pour le remplacement. *
+* *
+* Description : Définit une autre représentation textuelle pour l'opérande. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_arch_operand_set_alt_text(GArchOperand *operand, const char *text, RenderingTagType tag)
+{
+ if (operand->alt_text != NULL)
+ free(operand->alt_text);
+
+ if (text != NULL)
+ {
+ operand->alt_text = strdup(text);
+ operand->alt_len = strlen(text);
+ operand->alt_tag = tag;
+ }
+ else
+ {
+ operand->alt_text = NULL;
+ operand->alt_len = 0;
+ operand->alt_tag = RTT_COUNT;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
* line = ligne tampon où imprimer l'opérande donné. *
* syntax = type de représentation demandée. *
* *
@@ -120,6 +159,13 @@ bool g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b)
void g_arch_operand_print(const GArchOperand *operand, GBufferLine *line, AsmSyntax syntax)
{
- return operand->print(operand, line, syntax);
+ if (operand->alt_text != NULL)
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY,
+ operand->alt_text,
+ operand->alt_len,
+ operand->alt_tag);
+
+ else
+ operand->print(operand, line, syntax);
}
diff --git a/src/arch/operand.h b/src/arch/operand.h
index c0cd767..b521f7c 100644
--- a/src/arch/operand.h
+++ b/src/arch/operand.h
@@ -51,6 +51,9 @@ GType g_arch_operand_get_type(void);
/* Compare un opérande avec un autre. */
bool g_arch_operand_compare(const GArchOperand *, const GArchOperand *);
+/* Définit une autre représentation textuelle pour l'opérande. */
+void g_arch_operand_set_alt_text(GArchOperand *, const char *, RenderingTagType);
+
/* Traduit un opérande en version humainement lisible. */
void g_arch_operand_print(const GArchOperand *, GBufferLine *, AsmSyntax);
diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c
index 3fd2cb0..14e6b48 100644
--- a/src/plugins/pglist.c
+++ b/src/plugins/pglist.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* pglist.c - gestion de l'ensemble des greffons
*
- * Copyright (C) 2009-2010 Cyrille Bagard
+ * Copyright (C) 2009-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -33,7 +33,7 @@
#include <config.h>
-#include "plugin.h"
+#include "plugin-int.h"
#include "../common/extstr.h"
@@ -207,7 +207,7 @@ GPluginModule *get_one_plugin_for_action(PluginAction action)
* Paramètres : action = fonctionnalité recherchée. *
* count = nombre de greffons trouvés. [OUT] *
* *
-* Description : Founit less greffons offrant le service demandé. *
+* Description : Founit les greffons offrant le service demandé. *
* *
* Retour : Liste de greffons correspondants à libérer de la mémoire. *
* *
@@ -257,3 +257,27 @@ void add_plugin_to_main_list(GPluginModule *plugin)
list->plugins[list->plugins_count - 1] = plugin;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = binaire chargé en mémoire à traiter. *
+* action = fonctionnalité recherchée. *
+* *
+* Description : Opère une action donnée sur un binaire défini. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void run_plugins_on_binary(GLoadedBinary *binary, PluginAction action)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < _list.plugins_count; i++)
+ if (g_plugin_module_get_action(_list.plugins[i]) & action)
+ g_plugin_module_execute_action_on_binary(_list.plugins[i], binary, action);
+
+}
diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h
index 36b998e..2804108 100644
--- a/src/plugins/pglist.h
+++ b/src/plugins/pglist.h
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* pglist.h - prototypes pour la gestion de l'ensemble des greffons
*
- * Copyright (C) 2009 Cyrille Bagard
+ * Copyright (C) 2009-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -42,7 +42,10 @@ bool init_all_plugins(GObject *);
GPluginModule *get_one_plugin_for_action(PluginAction);
/* Founit less greffons offrant le service demandé. */
-GPluginModule **get_all_plugins_for_action(PluginAction, size_t *);
+GPluginModule **get_all_plugins_for_action(PluginAction, size_t *) __attribute__ ((deprecated));
+
+/*Opère une action donnée sur un binaire défini. */
+void run_plugins_on_binary(GLoadedBinary *, PluginAction);
diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h
index c1579b2..602b296 100644
--- a/src/plugins/plugin-def.h
+++ b/src/plugins/plugin-def.h
@@ -43,22 +43,34 @@ typedef enum _PluginType
/* Action(s) menée(s) par le greffon */
typedef enum _PluginAction
{
- PGA_NONE = (0 << 0), /* Aucun intérêt */
+ PGA_NONE = (0 << 0), /* Aucun intérêt */
- PGA_FORMAT_MATCHER = (1 << 0), /* Détection et chargement */
+ PGA_FORMAT_MATCHER = (1 << 0), /* Détection et chargement */
- PGA_DISASSEMBLE = (1 << 1), /* Désassemblage (non trivial) */
+ PGA_DISASSEMBLE = (1 << 1), /* Désassemblage (non trivial) */
- PGA_DISASS_PROCESS = (1 << 2), /* Traitement niveau assembleur*/
- PGA_CODE_PROCESS = (1 << 3), /* Traitement du code existant */
+ PGA_BINARY_DISASSEMBLED = (1 << 2), /* Désassemblage fini */
+ PGA_BINARY_LINKED = (1 << 3), /* Liaison en place */
+ PGA_BINARY_BOUNDED = (1 << 4), /* Limites de routines définies*/
+ PGA_BINARY_PRINTED = (1 << 5), /* Instructions imprimées */
- PGA_DEBUGGER_ATTACH = (1 << 4), /* Activation d'un débogueur */
- PGA_DEBUGGER_DETACH = (1 << 5) /* Désactivation d'un débogueur*/
+ PGA_DISASS_PROCESS = (1 << 6), /* Traitement niveau assembleur*/
+ PGA_CODE_PROCESS = (1 << 7), /* Traitement du code existant */
+
+ PGA_DEBUGGER_ATTACH = (1 << 8), /* Activation d'un débogueur */
+ PGA_DEBUGGER_DETACH = (1 << 9) /* Désactivation d'un débogueur*/
} PluginAction;
+/* Actions éligibles pour run_plugins_on_binary() */
+#define PGA_BINARY_ACTIONS ( 0 \
+ | PGA_BINARY_DISASSEMBLED | PGA_BINARY_LINKED \
+ | PGA_BINARY_BOUNDED | PGA_BINARY_PRINTED \
+ )
+
+
/* Fournit une indication sur le(s) type(s) du greffon présent. */
typedef PluginType (* get_plugin_type_fc) (void);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 416c647..c6a49c6 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -153,7 +153,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
result->get_action = get_action;
- if (g_plugin_module_get_action(result) & (PGA_DISASSEMBLE | PGA_DISASS_PROCESS | PGA_CODE_PROCESS))
+ if (g_plugin_module_get_action(result) & (PGA_BINARY_ACTIONS | /* FIXME : supprimer le reste */ PGA_DISASSEMBLE | PGA_DISASS_PROCESS | PGA_CODE_PROCESS))
{
if (!g_module_symbol(result->module, "execute_action_on_binary", (gpointer *)&result->exec_on_bin))
{