summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog50
-rw-r--r--configure.ac1
-rw-r--r--src/Makefile.am4
-rwxr-xr-xsrc/analysis/Makefile.am3
-rw-r--r--src/analysis/binary.c143
-rw-r--r--src/analysis/binary.h14
-rw-r--r--src/analysis/line.c18
-rw-r--r--src/common/extstr.c32
-rw-r--r--src/common/extstr.h3
-rw-r--r--src/editor.c49
-rw-r--r--src/plugins/Makefile.am15
-rw-r--r--src/plugins/overjump/Makefile.am17
-rw-r--r--src/plugins/overjump/overjump.c313
-rw-r--r--src/plugins/overjump/overjump.h50
-rw-r--r--src/plugins/pglist.c147
-rw-r--r--src/plugins/pglist.h7
-rw-r--r--src/plugins/plugin-def.h55
-rw-r--r--src/plugins/plugin.c77
-rw-r--r--src/plugins/plugin.h9
19 files changed, 936 insertions, 71 deletions
diff --git a/ChangeLog b/ChangeLog
index dbc7415..293fc9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,13 +1,55 @@
2009-04-29 Cyrille Bagard <nocbos@gmail.com>
- * src/arch/x86/op_and.c:
- * src/arch/x86/opcodes.h:
- * src/arch/x86/op_or.c:
- * src/arch/x86/processor.c:
+ * configure.ac:
+ Add the new Makefiles from the 'src/plugins/overjump' directory to
+ AC_CONFIG_FILES.
+
+ * src/analysis/binary.c:
+ * src/analysis/binary.h:
+ Update the code (provide more access and use the new functions).
+
+ * src/analysis/line.c:
+ Do not rely on the editor window to create Pango layouts.
+
+ * src/analysis/Makefile.am:
+ Update libanalysis_la_LDFLAGS (plugins).
+
+ * src/common/extstr.c:
+ * src/common/extstr.h:
+ Create the function strrcmp().
+
+ * src/editor.c:
+ Update the code.
+
+ * src/Makefile.am:
+ Update openida_LDFLAGS and openida_LDADD.
+
+ * src/plugins/Makefile.am:
+ Build a shared library. Add plugin-def.h to libplugins_la_SOURCES and
+ overjump to SUBDIRS. Update libpyoida_la_LDFLAGS and INCLUDES.
+
+ * src/plugins/overjump/Makefile.am:
+ * src/plugins/overjump/overjump.c:
+ * src/plugins/overjump/overjump.h:
+ Begin a plugin for overjumps with x86.
+
+ * src/plugins/pglist.c:
+ * src/plugins/pglist.h:
+ * src/plugins/plugin.c:
+ * src/plugins/plugin-def.h:
+ * src/plugins/plugin.h:
+ Manage plugins in an improved way.
+
+2009-04-29 Cyrille Bagard <nocbos@gmail.com>
+
* src/arch/x86/instruction.h:
* src/arch/x86/op_adc.c:
* src/arch/x86/op_add.c:
+ * src/arch/x86/op_and.c:
+ * src/arch/x86/op_or.c:
* src/arch/x86/op_sub.c:
+ * src/arch/x86/opcodes.h:
+ * src/arch/x86/processor.c:
Support more x86 opcodes.
2009-04-25 Cyrille Bagard <nocbos@gmail.com>
diff --git a/configure.ac b/configure.ac
index 4a4adf2..151ffa4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -232,6 +232,7 @@ AC_CONFIG_FILES([Makefile
src/gtkext/Makefile
src/panel/Makefile
src/plugins/Makefile
+ src/plugins/overjump/Makefile
src/plugins/pyoida/Makefile])
AC_OUTPUT
diff --git a/src/Makefile.am b/src/Makefile.am
index fa63b43..4f4aa1a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,13 +30,13 @@ openida_LDFLAGS = $(LIBGTK_LIBS) -L/usr/X11R6/lib -ldl -lm $(LIBXML_LIBS) `pkg-c
-Lformat/elf/.libs -lformatelf \
-Lformat/java/.libs -lformatjava \
-Lformat/mangling/.libs -lformatmangling \
- -Lformat/pe/.libs -lformatpe
+ -Lformat/pe/.libs -lformatpe \
+ -Lplugins/.libs -lplugins
openida_LDADD = $(LIBINTL) \
debug/libdebug.a \
debug/ptrace/libdebugptrace.a \
- plugins/libplugins.a \
plugins/pyoida/libpyoida.a \
common/libcommon.a
diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am
index 8d986a1..cc7675b 100755
--- a/src/analysis/Makefile.am
+++ b/src/analysis/Makefile.am
@@ -13,7 +13,8 @@ libanalysis_la_SOURCES = \
libanalysis_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) \
-L../common/.libs -lcommon \
- -L../format/.libs -lformat
+ -L../format/.libs -lformat \
+ -L../plugins/.libs -lplugins
INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 95b24b1..b606752 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -39,11 +39,11 @@
#include "line_comment.h"
#include "line_prologue.h"
#include "prototype.h"
-#include "../arch/processor.h"
+#include "../plugins/pglist.h"
#include "../format/dbg_format.h"
-#include "../format/exe_format.h"
+
@@ -230,6 +230,83 @@ const char *openida_binary_to_string(const openida_binary *binary)
}
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* length = taille en octets des données chargées. [OUT] *
+* *
+* Description : Fournit les détails du contenu binaire chargé en mémoire. *
+* *
+* Retour : Pointeur vers le début des données. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+uint8_t *get_openida_binary_data(const openida_binary *binary, off_t *length)
+{
+ *length = binary->bin_length;
+
+ return binary->bin_data;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* *
+* Description : Fournit le format de fichier reconnu dans le contenu binaire.*
+* *
+* Retour : Adresse du format reconnu. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+exe_format *get_openida_binary_format(const openida_binary *binary)
+{
+ return binary->format;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* *
+* Description : Fournit le processeur exécutant le contenu binaire. *
+* *
+* Retour : Adresse du processeur associé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+asm_processor *get_openida_binary_processor(const openida_binary *binary)
+{
+ return binary->proc;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* *
+* Description : Fournit les options d'affichage définies pour le binaire. *
+* *
+* Retour : Adresse des options d'affichage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+disass_options *get_openida_binary_options(const openida_binary *binary)
+{
+ return &binary->options;
+
+}
/******************************************************************************
@@ -525,6 +602,8 @@ void disassemble_openida_binary(openida_binary *binary)
+ GPluginModule *disass; /* Eventuel greffon de désass. */
+
binary->lines = build_binary_prologue(binary->filename, binary->bin_data, binary->bin_length);
@@ -532,60 +611,66 @@ void disassemble_openida_binary(openida_binary *binary)
routines = get_all_exe_routines(binary->format, &routines_count);
- parts = get_elf_default_code_parts(binary->format, &parts_count);
- qsort(parts, parts_count, sizeof(bin_part *), compare_bin_parts);
+ disass = get_one_plugin_for_action(PGA_DISASSEMBLE);
- for (i = 0; i < parts_count; i++)
- {
- get_bin_part_values(parts[i], &pos, &len, &base);
-
- /* Décodage des instructions */
+ if (disass != NULL)
+ binary->lines = g_plugin_module_disassemble_binary_parts(disass, binary);
- start = pos;
- pos = 0;
+ else
+ {
+ parts = get_elf_default_code_parts(binary->format, &parts_count);
+ qsort(parts, parts_count, sizeof(bin_part *), compare_bin_parts);
- while (pos < len)
+ for (i = 0; i < parts_count; i++)
{
- offset = base + pos;
+ get_bin_part_values(parts[i], &pos, &len, &base);
+ /* Décodage des instructions */
- instr = decode_instruction(binary->proc, &binary->bin_data[start], &pos, len, start, offset);
+ start = pos;
+ pos = 0;
+ while (pos < len)
+ {
+ offset = base + pos;
- line = g_code_line_new(offset, instr, &binary->options);
- g_rendering_line_add_to_lines(&binary->lines, line);
- }
+ instr = decode_instruction(binary->proc, &binary->bin_data[start], &pos, len, start, offset);
- /* Ajout des prototypes de fonctions */
- for (k = 0; k < routines_count; k++)
- {
- routine_offset = get_binary_routine_offset(routines[k]);
+ line = g_code_line_new(offset, instr, &binary->options);
+ g_rendering_line_add_to_lines(&binary->lines, line);
- if (!(base <= routine_offset && routine_offset < (base + len))) continue;
+ }
- routine_desc = routine_to_string(routines[k]);
+ /* Ajout des prototypes de fonctions */
- line = g_comment_line_new(routine_offset, routine_desc, &binary->options);
- g_rendering_line_insert_into_lines(&binary->lines, line, true);
+ for (k = 0; k < routines_count; k++)
+ {
+ routine_offset = get_binary_routine_offset(routines[k]);
- free(routine_desc);
+ if (!(base <= routine_offset && routine_offset < (base + len))) continue;
- }
+ routine_desc = routine_to_string(routines[k]);
- }
+ line = g_comment_line_new(routine_offset, routine_desc, &binary->options);
+ g_rendering_line_insert_into_lines(&binary->lines, line, true);
+
+ free(routine_desc);
+ }
+ }
+ }
line = g_rendering_line_find_by_offset(binary->lines, get_exe_entry_point(binary->format));
- g_rendering_line_add_flag(line, RLF_ENTRY_POINT);
+ if (line != NULL) g_rendering_line_add_flag(line, RLF_ENTRY_POINT);
diff --git a/src/analysis/binary.h b/src/analysis/binary.h
index 69da2a7..813e0ec 100644
--- a/src/analysis/binary.h
+++ b/src/analysis/binary.h
@@ -29,6 +29,8 @@
#include "line.h"
+#include "../arch/processor.h"
+#include "../format/exe_format.h"
#include "../xml.h"
@@ -49,6 +51,18 @@ const char *openida_binary_to_string(const openida_binary *);
/* Fournit le fichier correspondant à l'élément binaire. */
const char *openida_binary_get_filename(const openida_binary *);
+/* Fournit les détails du contenu binaire chargé en mémoire. */
+uint8_t *get_openida_binary_data(const openida_binary *, off_t *);
+
+/* Fournit le format de fichier reconnu dans le contenu binaire. */
+exe_format *get_openida_binary_format(const openida_binary *);
+
+/* Fournit le processeur exécutant le contenu binaire. */
+asm_processor *get_openida_binary_processor(const openida_binary *);
+
+/* Fournit les options d'affichage définies pour le binaire. */
+disass_options *get_openida_binary_options(const openida_binary *);
+
/* Fournit les lignes de rendu issues du désassemblage. */
GRenderingLine *get_openida_binary_lines(const openida_binary *);
diff --git a/src/analysis/line.c b/src/analysis/line.c
index bba601c..fb8295e 100644
--- a/src/analysis/line.c
+++ b/src/analysis/line.c
@@ -96,13 +96,21 @@ static void g_rendering_line_class_init(GRenderingLineClass *klass)
static void g_rendering_line_init(GRenderingLine *line)
{
- GdkScreen *screen;
- PangoContext *context;
+ GdkScreen *screen; /* Ecran d'application */
+ PangoFontDescription *desc; /* Description de la police */
+ static PangoContext *context = NULL; /* Contexte graphique Pango */
DL_LIST_ITEM_INIT(&line->link);
- screen = gdk_screen_get_default();
- context = gdk_pango_context_get_for_screen(screen);
+ if (context == NULL)
+ {
+ screen = gdk_screen_get_default();
+ desc = pango_font_description_from_string("mono 10");
+
+ context = gdk_pango_context_get_for_screen(screen);
+ pango_context_set_font_description(context, desc);
+
+ }
line->layout = pango_layout_new(context);
@@ -236,11 +244,11 @@ RenderingLineFlag g_rendering_line_get_flags(const GRenderingLine *line)
void g_rendering_line_draw(GRenderingLine *line, GdkDrawable *drawable, GdkGC *gc, gint x0, gint x1, gint y, gint h)
{
-#if 0
GdkPixbuf *pixbuf; /* Données utiles au dessin */
gdk_draw_layout(drawable, gc, x1, y, line->layout);
+#if 0
if (line->flags & RLF_BREAK_POINT)
pixbuf = gtk_widget_render_icon(mywid, "gtk-yes", GTK_ICON_SIZE_MENU, NULL);
diff --git a/src/common/extstr.c b/src/common/extstr.c
index deffbd4..5187567 100644
--- a/src/common/extstr.c
+++ b/src/common/extstr.c
@@ -88,6 +88,38 @@ char *strprep(char *str1, const char *str2)
/******************************************************************************
* *
+* Paramètres : str1 = chaîne de caractères à analyser. *
+* str2 = chaîne de caractères à retrouver. *
+* *
+* Description : Compare deux chaînes de caractères en partant de la fin. *
+* *
+* Retour : -1, 0, ou 1 selon la comparaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int strrcmp(const char *str1, const char *str2)
+{
+ int result; /* Bilan à renvoyer */
+ size_t len1; /* Longueur de la chaîne donnée*/
+ size_t len2; /* Longueur de la chaîne visée */
+
+ len1 = strlen(str1);
+ len2 = strlen(str2);
+
+ if (len1 <= len2)
+ result = strcmp(str1, str2);
+
+ else result = strcmp(&str1[len1 - len2], str2);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : input = chaîne de caractères à traiter. *
* *
* Description : S'assure qu'une chaîne de caractère tient sur une ligne. *
diff --git a/src/common/extstr.h b/src/common/extstr.h
index 8baa2e2..2ce0257 100644
--- a/src/common/extstr.h
+++ b/src/common/extstr.h
@@ -32,6 +32,9 @@ char *stradd(char *str1, const char *str2);
/* Fait précéder une chaîne de caractères par une autre. */
char *strprep(char *, const char *);
+/* Compare deux chaînes de caractères en partant de la fin. */
+int strrcmp(const char *, const char *);
+
/* S'assure qu'une chaîne de caractère tient sur une ligne. */
char *escape_crlf(char *);
diff --git a/src/editor.c b/src/editor.c
index 4e0b8c2..c975da6 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -137,6 +137,10 @@ void update_debug_menu_items(GObject *, gboolean);
+void open_last_file(GObject *ref);
+
+
+
/******************************************************************************
* *
* Paramètres : argc = nombre d'arguments dans la ligne de commande. *
@@ -188,6 +192,8 @@ int main(int argc, char **argv)
init_all_plugins(G_OBJECT(editor));
+ open_last_file(G_OBJECT(editor));
+
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
@@ -209,8 +215,6 @@ int main(int argc, char **argv)
-GtkWidget *mywid;
-
/******************************************************************************
@@ -269,8 +273,6 @@ GtkWidget *create_editor(void)
#endif
- openida_binary *binary;
-
result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(result, 800, 600);
@@ -282,8 +284,6 @@ GtkWidget *create_editor(void)
ref = G_OBJECT(result);
- mywid = result;
-
vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox1);
@@ -467,6 +467,7 @@ GtkWidget *create_editor(void)
snippet = gtk_snippet_new();
+ g_object_set_data(G_OBJECT(result), "snippet", snippet);
gtk_widget_show(binview);
/*
snippet = gtk_text_view_new ();
@@ -583,15 +584,6 @@ GtkWidget *create_editor(void)
- /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
-
- binary = load_binary_file("/tmp/hello");
- gtk_snippet_set_rendering_lines(snippet, get_openida_binary_lines(binary));
-
-
- g_object_set_data(G_OBJECT(result), "current_binary", binary);
-
-
return result;
}
@@ -1205,3 +1197,30 @@ void update_debug_menu_items(GObject *ref, gboolean stopped)
gtk_widget_set_sensitive(submenuitem, stopped);
}
+
+
+
+
+
+
+
+
+
+void open_last_file(GObject *ref)
+{
+
+ openida_binary *binary;
+
+
+
+ binary = load_binary_file("/tmp/hello");
+ gtk_snippet_set_rendering_lines(GTK_SNIPPET(g_object_get_data(ref, "snippet")), get_openida_binary_lines(binary));
+
+
+ g_object_set_data(ref, "current_binary", binary);
+
+
+
+
+
+}
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 2d480bb..f6ceef2 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -1,17 +1,22 @@
-lib_LIBRARIES = libplugins.a
+lib_LTLIBRARIES = libplugins.la
-libplugins_a_SOURCES = \
+libplugins_la_SOURCES = \
pglist.h pglist.c \
+ plugin-def.h \
plugin.h plugin.c
-libplugins_a_CFLAGS = $(AM_CFLAGS)
+libplugins_la_CFLAGS = $(AM_CFLAGS)
+libpyoida_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \
+ -L../common/.libs -lcommon \
+ -L../format/.libs -lformat
-INCLUDES = $(LIBGTK_CFLAGS)
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = pyoida
+SUBDIRS = overjump pyoida
diff --git a/src/plugins/overjump/Makefile.am b/src/plugins/overjump/Makefile.am
new file mode 100644
index 0000000..1101c34
--- /dev/null
+++ b/src/plugins/overjump/Makefile.am
@@ -0,0 +1,17 @@
+
+lib_LTLIBRARIES = libpluginoverjump.la
+
+libpluginoverjump_la_SOURCES = \
+ overjump.h overjump.c
+
+libpluginoverjump_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \
+ -L../../panel/.libs -lpanel
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS =
diff --git a/src/plugins/overjump/overjump.c b/src/plugins/overjump/overjump.c
new file mode 100644
index 0000000..f712979
--- /dev/null
+++ b/src/plugins/overjump/overjump.c
@@ -0,0 +1,313 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * overjump.c - greffon assurant un désassemblage pour les architectures Intel
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "overjump.h"
+
+
+#include <malloc.h>
+#include <stdlib.h>
+
+
+
+typedef uint64_t vmpa_t;
+
+
+
+
+/* Instance de désassemblage supportant les sauts */
+typedef struct _overjump_instance
+{
+ off_t bin_length; /* Taille des données brutes */
+ uint8_t *bin_data; /* Données binaires brutes */
+
+ exe_format *format; /* Format du binaire */
+ asm_processor *proc; /* Architecture du binaire */
+ disass_options *options; /* Options de désassemblage */
+
+ bin_part **parts; /* Parts binaires à ausculter */
+ size_t parts_count; /* Quantité de ces parts */
+
+} overjump_instance;
+
+
+/* Localise une adresse virtuelle donnée. */
+size_t get_bin_part_from_vmpa(overjump_instance *, vmpa_t, off_t *, off_t *, vmpa_t *);
+
+/* Désassemble une ou plusieures adresses virtuelles. */
+GRenderingLine *disassemble_address(overjump_instance *, vmpa_t, bool);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement global. *
+* *
+* Description : Initialise le greffon pour le désassemblage Intel. *
+* *
+* Retour : true. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+overjump_instance *create_overjump_instance(openida_binary *binary)
+{
+ overjump_instance *result; /* Instance crée à renvoyer */
+
+ result = (overjump_instance *)calloc(1, sizeof(overjump_instance));
+
+ result->bin_data = get_openida_binary_data(binary, &result->bin_length);
+
+ result->format = get_openida_binary_format(binary);
+ result->proc = get_openida_binary_processor(binary);
+ result->options = get_openida_binary_options(binary);
+
+ result->parts = get_elf_default_code_parts(result->format, &result->parts_count);
+ qsort(result->parts, result->parts_count, sizeof(bin_part *), compare_bin_parts);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instance = instance personnalisée du greffon à manipuler. *
+* addr = adresse en mémoire recherchée. *
+* pos = position de la section à donner. [OUT] *
+* size = taille de la section à donner. [OUT] *
+* base = adresse virtuelle de la section à donner. [OUT] *
+* *
+* Description : Localise une adresse virtuelle donnée. *
+* *
+* Retour : Indice de la partie concernée, ou parts_count si non trouvée.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t get_bin_part_from_vmpa(overjump_instance *instance, vmpa_t addr, off_t *pos, off_t *size, vmpa_t *base)
+{
+ size_t result; /* Indice à retourner */
+
+ for (result = 0; result < instance->parts_count; result++)
+ {
+ get_bin_part_values(instance->parts[result], pos, size, base);
+
+ if (*base <= addr && addr < (*base + *size))
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instance = instance personnalisée du greffon à manipuler. *
+* addr = adresse en mémoire recherchée. *
+* onlyone = fixe une limite pour le désassemblage. *
+* *
+* Description : Désassemble une ou plusieures adresses virtuelles. *
+* *
+* Retour : Liste de lignes de rendu transcrites. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRenderingLine *disassemble_address(overjump_instance *instance, vmpa_t addr, bool onlyone)
+{
+ GRenderingLine *result; /* Liste à retourner */
+ off_t pos; /* Début de partie concernée */
+ off_t size; /* Taille de cette partie */
+ vmpa_t base; /* Adresse de base de la partie*/
+ size_t index; /* Indice de la partie trouvée */
+
+
+
+ off_t start;
+
+ off_t npos;
+ uint64_t offset;
+
+
+
+
+ asm_instr *instr;
+ GRenderingLine *line;
+
+
+ result = NULL;
+
+ index = get_bin_part_from_vmpa(instance, addr, &pos, &size, &base);
+
+
+ start = pos + addr - base;
+ npos = 0;
+
+
+ offset = addr;
+
+
+ instr = decode_instruction(instance->proc, &instance->bin_data[start],
+ &npos, size, start, offset);
+
+
+ line = g_code_line_new(offset, instr, instance->options);
+ g_rendering_line_add_to_lines(&result, line);
+
+
+
+
+ return result;
+
+}
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement global. *
+* *
+* Description : Initialise le greffon pour le désassemblage Intel. *
+* *
+* Retour : true. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_plugin(GObject *ref)
+{
+
+ printf("Init overjump\n");
+
+
+
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit une indication sur le type d'opération(s) menée(s). *
+* *
+* Retour : Description d'une action. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+G_MODULE_EXPORT PluginAction get_plugin_action(void)
+{
+ return PGA_DISASSEMBLE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = binaire dont le contenu est à désassembler. *
+* *
+* Description : S'occupe du désassemblage (pur) de code binaire. *
+* *
+* Retour : Lignes de code pour la représentation à insérer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+G_MODULE_EXPORT GRenderingLine *disassemble_binary_parts(openida_binary *binary)
+{
+
+ GRenderingLine *result;
+ overjump_instance *instance;
+
+
+
+
+ off_t start;
+ off_t pos;
+ off_t len;
+
+ uint64_t base = 0;
+ uint64_t offset = 0;
+
+ GRenderingLine *line;
+
+ asm_instr *instr;
+
+ result = NULL;
+
+ instance = create_overjump_instance(binary);
+
+
+ result = disassemble_address(instance, get_exe_entry_point(instance->format), true);
+
+
+
+#if 0
+
+ get_bin_part_values(instance->parts[0], &pos, &len, &base);
+
+ /* Décodage des instructions */
+
+ start = pos;
+ pos = 0;
+
+
+ offset = base + pos;
+
+
+ instr = decode_instruction(instance->proc, &instance->bin_data[start], &pos, len, start, offset);
+
+
+ line = g_code_line_new(offset, instr, instance->options);
+ g_rendering_line_add_to_lines(&result, line);
+
+
+
+ disassemble_address(overjump_instance *instance, vmpa_t addr, bool onlyone);
+
+#endif
+
+
+ return result;
+
+}
+
+
diff --git a/src/plugins/overjump/overjump.h b/src/plugins/overjump/overjump.h
new file mode 100644
index 0000000..c7687d4
--- /dev/null
+++ b/src/plugins/overjump/overjump.h
@@ -0,0 +1,50 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * overjump.h - prototypes pour le greffon assurant un désassemblage pour les architectures Intel
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _PLUGINS_OVERJUMP_H
+#define _PLUGINS_OVERJUMP_H
+
+
+#include <glib-object.h>
+#include <gmodule.h>
+#include <stdbool.h>
+
+
+#include "../plugin-def.h"
+
+
+
+/* Initialise le greffon pour le désassemblage Intel. */
+bool init_plugin(GObject *);
+
+
+
+/* Fournit une indication sur le type d'opération(s) menée(s). */
+G_MODULE_EXPORT PluginAction get_plugin_action(void);
+
+/* S'occupe du désassemblage (pur) de code binaire. */
+G_MODULE_EXPORT GRenderingLine *disassemble_binary_parts(openida_binary *);
+
+
+
+#endif /* _PLUGINS_OVERJUMP_H */
diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c
index 8301eb3..85421e6 100644
--- a/src/plugins/pglist.c
+++ b/src/plugins/pglist.c
@@ -25,7 +25,16 @@
#include "pglist.h"
+#include <dirent.h>
+#include <malloc.h>
+#include <string.h>
+
+
+#include <config.h>
+
+
#include "plugin.h"
+#include "../common/extstr.h"
@@ -34,14 +43,21 @@ typedef struct _plugins_list
{
GObject *ref; /* Référencement global */
-
-
+ GPluginModule **plugins; /* Liste de greffons */
+ size_t plugins_count; /* Taille de cette liste */
} plugins_list;
/* Liste de l'ensemble des greffons */
-static plugins_list list;
+static plugins_list _list;
+
+
+/* Filtre les répertoire et les modules de greffons pootentels. */
+int filter_dirs_or_mods(const struct dirent *);
+
+/* Part à la recherche de greffons sous forme de modules. */
+void browse_directory_for_plugins(plugins_list *, const char *);
@@ -51,7 +67,7 @@ static plugins_list list;
* *
* Description : Procède au chargement des différents greffons trouvés. *
* *
-* Retour : Toujours true (même s'il y a des erreurs de chargemet). *
+* Retour : Toujours true (même s'il y a des erreurs de chargement). *
* *
* Remarques : - *
* *
@@ -59,15 +75,128 @@ static plugins_list list;
bool init_all_plugins(GObject *ref)
{
- GPluginModule *pg;
+ _list.ref = ref;
- list.ref = ref;
+ browse_directory_for_plugins(&_list, PACKAGE_SOURCE_DIR "/src/plugins");
+ return true;
- pg = g_plugin_module_new("/home/ocb/prog/openida.pg/src/plugins/pyoida/pyoidamodule.so", list.ref);
+}
- printf("plug ? %p\n", pg);
- return true;
+/******************************************************************************
+* *
+* Paramètres : entry = entrée de répertoire à analyser. *
+* *
+* Description : Filtre les répertoire et les modules de greffons pootentels. *
+* *
+* Retour : Valeur non nulle pour garder l'élément. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int filter_dirs_or_mods(const struct dirent *entry)
+{
+ int result; /* Conclusion à remonter */
+
+ if (entry->d_type == DT_DIR)
+ result = strcmp(entry->d_name, ".") * strcmp(entry->d_name, "..");
+
+ else
+ result = (strrcmp(entry->d_name, "." G_MODULE_SUFFIX) == 0 ? 1 : 0);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste de greffons à compléter si possible. *
+* dir = répertoire à parcourir en quête de greffons (sans /). *
+* *
+* Description : Part à la recherche de greffons sous forme de modules. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void browse_directory_for_plugins(plugins_list *list, const char *dir)
+{
+ struct dirent **namelist; /* Eléments trouvés */
+ int ret; /* Bilan du parcours */
+ char *filename; /* Elément à ausculter */
+ GPluginModule *plugin; /* Greffon à intégrer ou pas */
+
+ ret = scandir(dir, &namelist, filter_dirs_or_mods, alphasort);
+ if (ret < 0)
+ {
+ perror("scandir");
+ return;
+ }
+
+ while (ret--)
+ {
+ filename = (char *)calloc(strlen(dir) + 1 + strlen(namelist[ret]->d_name) + 1, sizeof(char));
+
+ strcpy(filename, dir);
+ strcat(filename, "/"); /* FIXME : Win */
+ strcat(filename, namelist[ret]->d_name);
+
+ if (namelist[ret]->d_type == DT_DIR)
+ browse_directory_for_plugins(list, filename);
+
+ else
+ {
+ plugin = g_plugin_module_new(filename, list->ref);
+
+ if (plugin != NULL)
+ {
+ list->plugins = (GPluginModule **)realloc(list->plugins, ++list->plugins_count * sizeof(GPluginModule *));
+ list->plugins[list->plugins_count - 1] = plugin;
+ }
+
+ }
+
+ free(filename);
+ free(namelist[ret]);
+
+ }
+
+ free(namelist);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : action = fonctionnalité recherchée. *
+* *
+* Description : Founit un greffon offrant le service demandé. *
+* *
+* Retour : Greffon satisfaisant ou NULL si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GPluginModule *get_one_plugin_for_action(PluginAction action)
+{
+ GPluginModule *result; /* Greffon à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = NULL;
+
+ for (i = 0; i < _list.plugins_count; i++)
+ if (g_plugin_module_get_action(_list.plugins[i]) & action)
+ {
+ result = _list.plugins[i];
+ break;
+ }
+
+ return result;
}
diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h
index 89abd51..4aa77cd 100644
--- a/src/plugins/pglist.h
+++ b/src/plugins/pglist.h
@@ -30,10 +30,17 @@
#include <gtk/gtk.h>
+#include "plugin-def.h"
+#include "plugin.h"
+
+
/* Procède au chargement des différents greffons trouvés. */
bool init_all_plugins(GObject *);
+/* Founit un greffon offrant le service demandé. */
+GPluginModule *get_one_plugin_for_action(PluginAction);
+
#endif /* _PLUGINS_PGLIST_H */
diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h
new file mode 100644
index 0000000..68167e2
--- /dev/null
+++ b/src/plugins/plugin-def.h
@@ -0,0 +1,55 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * plugin-def.h - prototypes pour les définitions de base utiles aux greffons
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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_PLUGIN_DEF_H
+#define _PLUGINS_PLUGIN_DEF_H
+
+
+#include "../analysis/binary.h"
+#include "../analysis/line.h"
+
+
+
+/* Action(s) menée(s) par le greffon */
+typedef enum _PluginAction
+{
+ PGA_DISASSEMBLE = (1 << 0) /* Désassemblage (non trivial) */
+
+} PluginAction;
+
+
+
+
+
+/* Fournit une indication sur le type d'opération(s) menée(s). */
+typedef PluginAction (* get_plugin_action_fc) (void);
+
+
+
+/* S'occupe du désassemblage (pur) de code binaire. */
+typedef GRenderingLine * (* disassemble_binary_parts_fc) (openida_binary *);
+
+
+
+#endif /* _PLUGINS_PLUGIN_DEF_H */
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index f21ac02..80daa74 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -30,6 +30,8 @@
+
+
/* Procède à l'initialisation du greffon */
typedef bool (* init_plugin_fc) (GObject *);
@@ -42,8 +44,12 @@ struct _GPluginModule
GModule *module; /* Abstration de manipulation */
+ PluginAction action; /* Opération(s) menée(s) */
+
init_plugin_fc init; /* Procédure d'initialisation */
+ disassemble_binary_parts_fc disassemble;/* Fonction de désassemblage */
+
};
@@ -104,7 +110,6 @@ static void g_plugin_module_init(GPluginModule *line)
}
-
/******************************************************************************
* *
* Paramètres : filename = nom du fichier à charger. *
@@ -121,6 +126,8 @@ static void g_plugin_module_init(GPluginModule *line)
GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
{
GPluginModule *result; /* Structure à retourner */
+ get_plugin_action_fc __get_action; /* Actions du greffon */
+
result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL);
@@ -128,6 +135,32 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
result->module = g_module_open(filename, G_MODULE_BIND_LAZY);
+
+ if (!g_module_symbol(result->module, "get_plugin_action", (gpointer *)&__get_action))
+ {
+ printf("Err plugin get_action sym\n");
+ //g_object_destroy(result);
+ return NULL;
+ }
+
+ result->action = __get_action();
+
+
+ /* ... */
+ if (result->action & PGA_DISASSEMBLE)
+ {
+ if (!g_module_symbol(result->module, "disassemble_binary_parts", (gpointer *)&result->disassemble))
+ {
+ printf("Err plugin disass sym\n");
+ //g_object_destroy(result);
+ return NULL;
+ }
+
+
+ }
+
+
+
if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init))
{
printf("Err plugin init sym\n");
@@ -136,9 +169,51 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
+
+
+
if (!result->init(ref))
printf("Err loading pg\n");
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à consulter. *
+* *
+* Description : Indique les opérations offertes par un greffon donné. *
+* *
+* Retour : Action(s) offerte(s) par le greffon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PluginAction g_plugin_module_get_action(const GPluginModule *plugin)
+{
+ return plugin->action;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à consulter. *
+* binary = binaire dont le contenu est à désassembler. *
+* *
+* Description : S'occupe du désassemblage (pur) de code binaire. *
+* *
+* Retour : Lignes de code pour la représentation à insérer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRenderingLine *g_plugin_module_disassemble_binary_parts(const GPluginModule *plugin, openida_binary *binary)
+{
+ return plugin->disassemble(binary);
+
+}
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index 6013e21..455f17c 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -29,6 +29,9 @@
#include <glib-object.h>
+#include "plugin-def.h"
+
+
/* Greffon pour OpenIDA (instance) */
typedef struct _GPluginModule GPluginModule;
@@ -51,6 +54,12 @@ GType g_plugin_module_get_type(void);
/* Crée un module pour un greffon donné. */
GPluginModule *g_plugin_module_new(const gchar *, GObject *);
+/* Indique les opérations offertes par un greffon donné. */
+PluginAction g_plugin_module_get_action(const GPluginModule *);
+
+/* S'occupe du désassemblage (pur) de code binaire. */
+GRenderingLine *g_plugin_module_disassemble_binary_parts(const GPluginModule *, openida_binary *);
+
#endif /* _PLUGINS_PLUGIN_H */