From c2d9948e1e67b48d1a6c8a711024d8dd3f6ac507 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Wed, 18 Feb 2009 00:47:48 +0000
Subject: Begun to rewrite the way rendering lines are managed.

git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@49 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
---
 ChangeLog                |  30 ++++++
 configure.ac             |   1 +
 src/Makefile.am          |   3 +-
 src/analysis/Makefile.am |  16 ++++
 src/analysis/line.c      | 231 +++++++++++++++++++++++++++++++++++++++++++++++
 src/analysis/line.h      |  68 ++++++++++++++
 src/binary.c             |  86 +++++++++++++++++-
 src/common/Makefile.am   |   1 +
 src/common/dllist.c      | 154 +++++++++++++++++++++++++++++++
 src/common/dllist.h      | 130 ++++++++++++++++++++++++++
 src/editor.c             |   5 +-
 src/gtksnippet.c         |  41 +++++++++
 src/gtksnippet.h         |   6 ++
 13 files changed, 769 insertions(+), 3 deletions(-)
 create mode 100755 src/analysis/Makefile.am
 create mode 100644 src/analysis/line.c
 create mode 100644 src/analysis/line.h
 create mode 100644 src/common/dllist.c
 create mode 100644 src/common/dllist.h

diff --git a/ChangeLog b/ChangeLog
index 490b0de..698079e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2009-02-18  Cyrille Bagard <nocbos@gmail.com>
+
+	* configure.ac:
+	Add the new Makefile from 'src/analysis' directories to AC_CONFIG_FILES.
+
+	* src/analysis/line.c:
+	* src/analysis/line.h:
+	* src/analysis/Makefile.am:
+	Write some code to manage the lines for prologues.
+
+	* src/binary.c:
+	Build a prologue for each binary: license, file and checksum.
+
+	* src/common/dllist.c:
+	* src/common/dllist.h:
+	Import double linked lists from Firebox.
+
+	* src/common/Makefile.am:
+	Add dllist.[ch] to libcommon_a_SOURCES.
+
+	* src/editor.c:
+	Register the main widget in order to be able to create Pango layouts.
+
+	* src/gtksnippet.c:
+	* src/gtksnippet.h:
+	Update the way the content is printed (need to be updated).
+
+	* src/Makefile.am:
+	Add analysis to SUBDIRS and analysis/libanalysis.a to openida_LDADD.
+
 2009-02-16  Cyrille Bagard <nocbos@gmail.com>
 
 	* configure.ac:
diff --git a/configure.ac b/configure.ac
index 21362e4..4bda689 100644
--- a/configure.ac
+++ b/configure.ac
@@ -182,6 +182,7 @@ AC_CONFIG_FILES([stamp-h po/Makefile.in], [echo timestamp > stamp-h])
 AC_CONFIG_FILES([Makefile
                  pixmaps/Makefile
                  src/Makefile
+                 src/analysis/Makefile
                  src/arch/Makefile
                  src/arch/x86/Makefile
                  src/common/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 68345bf..e2519a9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,6 +27,7 @@ openida_LDFLAGS = $(LIBGTK_LIBS) -L/usr/X11R6/lib -ldl -lm $(LIBXML_LIBS) `pkg-c
 
 
 openida_LDADD = $(LIBINTL) 				\
+	analysis/libanalysis.a				\
 	arch/libarch.a						\
 	arch/x86/libarchx86.a				\
 	format/libformat.a					\
@@ -38,4 +39,4 @@ openida_LDADD = $(LIBINTL) 				\
 	common/libcommon.a
 
 
-SUBDIRS = arch common format gtkext
+SUBDIRS = analysis arch common format gtkext
diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am
new file mode 100755
index 0000000..c3b2e64
--- /dev/null
+++ b/src/analysis/Makefile.am
@@ -0,0 +1,16 @@
+
+lib_LIBRARIES = libanalysis.a
+
+libanalysis_a_SOURCES =					\
+	line.h line.c
+
+libanalysis_a_CFLAGS = $(AM_CFLAGS)
+
+
+INCLUDES = $(LIBGTK_CFLAGS)
+
+AM_CPPFLAGS = 
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS)
+
+SUBDIRS = 
diff --git a/src/analysis/line.c b/src/analysis/line.c
new file mode 100644
index 0000000..7431e94
--- /dev/null
+++ b/src/analysis/line.c
@@ -0,0 +1,231 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * line.c - représentation des lignes de rendu
+ *
+ * Copyright (C) 2008 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 "line.h"
+
+
+#include <malloc.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#include "../common/dllist.h"
+
+
+
+/* FIXME */
+extern GtkWidget *mywid;
+
+
+
+/* Ligne de représentation générique */
+struct _rendering_line
+{
+    DL_LIST_ITEM;
+
+    RenderingLineType type;                 /* Type de représentation      */
+
+    PangoLayout *layout;                    /* Moteur de rendu du code/txt */
+
+};
+
+
+#define RENDERING_LINE(l) ((rendering_line *)l)
+
+
+/* Procède à l'initialisation des bases d'une représentation. */
+void init_rendering_line(rendering_line *);
+
+
+
+
+/* ------------------------- LIGNE EN TETE DE DESASSEMBLAGE ------------------------- */
+
+
+/* Ligne de représentation de prologue */
+typedef struct _prologue_line
+{
+    rendering_line basic;                   /* A laisser en premier        */
+
+    char *comment;                          /* Texte à afficher            */
+
+} prologue_line;
+
+
+/* Met à jour la ligne de représentation de prologue. */
+void refresh_prologue_markup(prologue_line *);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : line = adresse de la structure commune.                      *
+*                                                                             *
+*  Description : Procède à l'initialisation des bases d'une représentation.   *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void init_rendering_line(rendering_line *line)
+{
+    DL_LIST_ITEM_INIT(DLL_CAST(line));
+
+    line->layout = gtk_widget_create_pango_layout(mywid, NULL);
+
+
+
+
+}
+
+
+
+
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : lines = liste de lignes à compléter, ou NULL.                *
+*                line  = nouvelle ligne à intégrer à l'ensemble.              *
+*                                                                             *
+*  Description : Ajoute une ligne à un ensemble existant.                     *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void add_line_to_rendering_lines(rendering_line **lines, rendering_line *line)
+{
+    dl_list_add_tail(DLL_CAST(line), (dl_list_item **)lines);
+
+}
+
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : line     = adresse de la structure à représenter.            *
+*                drawable = support de rendu pour le dessin.                  *
+*                gc       = contexte graphique à utiliser.                    *
+*                x        = abscisse de la zone de rendu.                     *
+*                y        = ordonnée de la zone de rendu.                     *
+*                                                                             *
+*  Description : Procède à l'initialisation des bases d'une représentation.   *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void draw_rendering_line(rendering_line *line, GdkDrawable *drawable, GdkGC *gc, gint x, gint y)
+{
+    gdk_draw_layout(drawable, gc, x, y, line->layout);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/*                           LIGNE EN TETE DE DESASSEMBLAGE                           */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : comment = texte à afficher au final.                         *
+*                                                                             *
+*  Description : Choisit d'afficher le code brut ou non.                      *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+rendering_line *create_prologue_line(const char *comment)
+{
+    prologue_line *result;                  /* Structure à retourner       */
+
+    result = (prologue_line *)calloc(1, sizeof(prologue_line));
+
+    init_rendering_line(RENDERING_LINE(result));
+
+    RENDERING_LINE(result)->type = RLT_PROLOGUE;
+
+    result->comment = strdup(comment);
+
+    refresh_prologue_markup(result);
+
+    return RENDERING_LINE(result);
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : line = ligne de représentation à actualiser.                 *
+*                                                                             *
+*  Description : Met à jour la ligne de représentation de prologue.           *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void refresh_prologue_markup(prologue_line *line)
+{
+    size_t len;                             /* Taille du contenu           */
+    char *content;                          /* Contenu réellement imprimé  */
+
+    len = strlen("<b><span foreground='#003300'>");
+    len += strlen("; ") + strlen(line->comment);
+    len += strlen("</span></b>");
+
+    content = (char *)calloc(len + 1, sizeof(char));
+
+    snprintf(content, len + 1, "<b><span foreground='#003300'>; %s</span></b>", line->comment);
+
+    pango_layout_set_markup(RENDERING_LINE(line)->layout, content, len);
+
+    free(content);
+
+}
+
+
diff --git a/src/analysis/line.h b/src/analysis/line.h
new file mode 100644
index 0000000..dd0915c
--- /dev/null
+++ b/src/analysis/line.h
@@ -0,0 +1,68 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * line.h - prototypes pour la représentation des lignes de rendu
+ *
+ * Copyright (C) 2008 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 _ANALYSIS_LINE_H
+#define _ANALYSIS_LINE_H
+
+
+#include <gtk/gtk.h>
+
+
+/* Définitions des types de ligne */
+typedef enum _RenderingLineType
+{
+    RLT_PROLOGUE                            /* Description de l'analyse    */
+
+
+
+} RenderingLineType;
+
+
+
+
+/* Ligne de représentation générique */
+typedef struct _rendering_line rendering_line;
+
+
+
+/* Ajoute une ligne à un ensemble existant. */
+void add_line_to_rendering_lines(rendering_line **, rendering_line *);
+
+
+
+/* Procède à l'initialisation des bases d'une représentation. */
+void draw_rendering_line(rendering_line *, GdkDrawable *, GdkGC *, gint, gint);
+
+
+
+/* ------------------------- LIGNE EN TETE DE DESASSEMBLAGE ------------------------- */
+
+
+/* Choisit d'afficher le code brut ou non. */
+rendering_line *create_prologue_line(const char *);
+
+
+
+
+
+#endif  /* _ANALYSIS_LINE_H */
diff --git a/src/binary.c b/src/binary.c
index 45dc0e0..16be5ef 100644
--- a/src/binary.c
+++ b/src/binary.c
@@ -25,6 +25,8 @@
 
 
 #include <fcntl.h>
+#include <malloc.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -66,6 +68,8 @@ openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr);
 /* Charge en mémoire le contenu d'un fichier. */
 uint8_t *map_binary_file(const char *, size_t *);
 
+/* Construit la description d'introduction du désassemblage. */
+rendering_line *build_binary_prologue(const char *, const uint8_t *, off_t);
 
 
 
@@ -342,7 +346,80 @@ uint8_t *map_binary_file(const char *filename, size_t *length)
 }
 
 
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : filename = nom du fichier chargé.                            *
+*                data     = données en mémoire pour l'empreinte.              *
+*                length   = quantité de données à prendre en compte.          *
+*                                                                             *
+*  Description : Construit la description d'introduction du désassemblage.    *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+rendering_line *build_binary_prologue(const char *filename, const uint8_t *data, off_t length)
+{
+    rendering_line *result;                 /* Contenu à renvoyer          */
+    size_t len;                             /* Taille du texte             */
+    char *content;                          /* Contenu textuel d'une ligne */
+    rendering_line *line;                   /* Représentation à ajouter    */
+    GChecksum *checksum;                    /* Calcul de l'empreinte       */
+    const gchar *hex;                       /* Valeur hexadécimale du SHA  */
+
+    result = NULL;/* FIXME DL_LIST_HEAD_INIT(  **/
+
+    line = create_prologue_line("Disassembly generated by OpenIDA");
+    add_line_to_rendering_lines(&result, line);
+
+    line = create_prologue_line("OpenIDA is free software - © 2008-2009 Cyrille Bagard");
+    add_line_to_rendering_lines(&result, line);
+
+    line = create_prologue_line("");
+    add_line_to_rendering_lines(&result, line);
+
+    /* Fichier */
+
+    len = strlen(_("File: ")) + strlen(filename);
+    content = (char *)calloc(len + 1, sizeof(char));
+
+    snprintf(content, len + 1, "%s%s", _("File: "), filename);
+
+    line = create_prologue_line(content);
+    add_line_to_rendering_lines(&result, line);
+
+    free(content);
 
+    /* Checksum SHA256 */
+
+    checksum = g_checksum_new(G_CHECKSUM_SHA256);
+
+    g_checksum_update(checksum, data, length);
+    hex = g_checksum_get_string(checksum);
+
+    len = strlen(_("Sha256: ")) + strlen(hex);
+    content = (char *)calloc(len + 1, sizeof(char));
+
+    snprintf(content, len + 1, "%s%s", _("Sha256: "), hex);
+
+    g_checksum_free(checksum);
+
+    line = create_prologue_line(content);
+    add_line_to_rendering_lines(&result, line);
+
+    free(content);
+
+    line = create_prologue_line("");
+    add_line_to_rendering_lines(&result, line);
+
+    line = create_prologue_line("");
+    add_line_to_rendering_lines(&result, line);
+
+    return result;
+
+}
 
 
 
@@ -367,7 +444,7 @@ void fill_snippet(GtkSnippet *snippet, GtkWidget *panel, GtkWidget *panel2)
     size_t comments_count;
     code_line_info **comments_list;
 
-
+    rendering_line *line;
 
     code_line_info **list;
     size_t list_len;
@@ -412,6 +489,13 @@ void fill_snippet(GtkSnippet *snippet, GtkWidget *panel, GtkWidget *panel2)
 
     //exit(0);
 
+
+    line = build_binary_prologue("/tmp/hello", bin_data, length);
+
+
+    gtk_snippet_set_rendering_lines(snippet, line);
+
+
     return;
 
 
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 323ba17..a27a192 100755
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -2,6 +2,7 @@
 lib_LIBRARIES = libcommon.a
 
 libcommon_a_SOURCES =					\
+	dllist.h dllist.c					\
 	endianness.h endianness.c
 
 libcommon_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/common/dllist.c b/src/common/dllist.c
new file mode 100644
index 0000000..10f73e1
--- /dev/null
+++ b/src/common/dllist.c
@@ -0,0 +1,154 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dllist.c - implantation simple des listes doublement chaînées
+ *
+ * Copyright (C) 2008 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 "dllist.h"
+
+
+#include <stdbool.h>
+
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : new  = nouvel élément à ajouter.                             *
+*                head = adresse d'enregistrement de la tête de la liste.      *
+*                prev = élément précédent dans la liste.                      *
+*                next = élément suivant dans la liste.                        *
+*                                                                             *
+*  Description : Ajoute un élément dans une liste doublement chaînée.         *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void __dl_list_add(dl_list_item *new, dl_list_head *head, dl_list_item *prev, dl_list_item *next)
+{
+    if (prev != NULL) prev->next = new;
+    new->prev = prev;
+
+    new->next = next;
+    if (next != NULL) next->prev = new;
+
+    if (*head == NULL)
+        *head = new;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : prev = élément précédent dans la liste.                      *
+*                next = élément suivant dans la liste.                        *
+*                                                                             *
+*  Description : Supprime un élément d'une liste doublement chaînée.          *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void __dl_list_del(dl_list_item *prev, dl_list_item *next)
+{
+    next->prev = prev;
+    prev->next = next;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : head = début de la liste, à mettre éventuellement à jour.    *
+*                a    = premier élément à traiter.                            *
+*                b    = second élément à traiter.                             *
+*                                                                             *
+*  Description : Intervertit deux éléments dans une liste doublement chaînée. *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void swap_dl_list_items(dl_list_head *head, dl_list_item *a, dl_list_item *b)
+{
+    bool a_is_head;                         /* Indique si a est le début   */
+    bool b_is_head;                         /* Indique si b est le début   */
+    dl_list_item tmp;                       /* Stockage temporaire         */
+
+    a_is_head = (*head == a);
+    b_is_head = (*head == b);
+
+    /* Liens vers l'extérieur et l'intérieur */
+
+    if (a->prev != b) a->prev->next = b;
+    if (a->next != b) a->next->prev = b;
+
+    if (b->prev != a) b->prev->next = a;
+    if (b->next != a) b->next->prev = a;
+
+    /* Liens propres aux éléments */
+
+    tmp = *a;
+
+    a->prev = (b->prev == a ? b : b->prev);
+    a->next = (b->next == a ? b : b->next);
+
+    b->prev = (tmp.prev == b ? a : tmp.prev);
+    b->next = (tmp.next == b ? a : tmp.next);
+
+    /* Mise à jour éventuelle de la tête */
+
+    if (a_is_head) *head = b;
+    else if (b_is_head) *head = a;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : list = liste à parcourir.                                    *
+*                                                                             *
+*  Description : Compte le nombre d'éléments présents dans une liste.         *
+*                                                                             *
+*  Retour      : Nombre d'éléments comptabilisés.                             *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+unsigned int count_dl_list_items(dl_list_head list)
+{
+    unsigned int result;                    /* Résultat à renvoyer         */
+    dl_list_item *iter;                     /* Boucle de parcours          */
+
+    result = 0;
+
+    dl_list_for_each(iter, list, dl_list_item *)
+        result++;
+
+    return result;
+
+}
diff --git a/src/common/dllist.h b/src/common/dllist.h
new file mode 100644
index 0000000..970edf9
--- /dev/null
+++ b/src/common/dllist.h
@@ -0,0 +1,130 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dllist.h - prototypes de l'implantation simple des listes doublement chaînées
+ *
+ * Copyright (C) 2008 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 _DLLIST_H
+#define _DLLIST_H
+
+
+#define NULL ((void *)0)
+
+
+
+/* Structure à inclure en tête de structure */
+typedef struct _dl_list_item
+{
+    struct _dl_list_item *prev;             /* Elément précédent           */
+    struct _dl_list_item *next;             /* Elément suivant             */
+
+} dl_list_item;
+
+
+typedef dl_list_item *dl_list_head;
+
+
+#define DL_LIST_ITEM dl_list_item dummy
+
+#define DLL_CAST(item) ((dl_list_item *)item)
+
+#define DL_LIST_HEAD_INIT(head)                                         \
+    *(head) = NULL
+
+#define DL_LIST_ITEM_INIT(item)                                         \
+    do                                                                  \
+    {                                                                   \
+        DLL_CAST(item)->prev = NULL;                                    \
+        DLL_CAST(item)->next = NULL;                                    \
+                                                                        \
+    } while(0)
+
+#define DL_LIST_NEXT(item, type) (type)DLL_CAST(item)->next
+#define DL_LIST_PREV(item, type) (type)DLL_CAST(item)->prev
+
+#define DL_LIST_IS_ALONE(head) (DLL_CAST(head)->next == DLL_CAST(head))
+
+ 
+/* Ajoute un élément dans une liste doublement chaînée. */
+void __dl_list_add(dl_list_item *, dl_list_head *, dl_list_item *, dl_list_item *);
+
+/* Supprime un élément d'une liste doublement chaînée. */
+void __dl_list_del(dl_list_item *, dl_list_item *);
+
+/* Intervertit deux éléments dans une liste doublement chaînée. */
+void swap_dl_list_items(dl_list_head *, dl_list_item *, dl_list_item *);
+
+/* Compte le nombre d'éléments présents dans une liste. */
+unsigned int count_dl_list_items(dl_list_head);
+
+
+#define dl_list_empty(head)                                             \
+    ((head) == NULL)
+
+#define dl_list_last(head, type)                                        \
+    (dl_list_empty(head) ? NULL : (type)((head)->prev == NULL ? (head) : (head)->prev))
+
+#define dl_list_add(new, head)                                          \
+    __dl_list_add(DLL_CAST(new), (head), (dl_list_empty(*(head)) ? DLL_CAST(new) : dl_list_last(*head, dl_list_item *)), (dl_list_empty(*(head)) ? DLL_CAST(new) : *(head)))
+
+#define dl_list_add_tail(new, head)                                     \
+    __dl_list_add(DLL_CAST(new), (head), (dl_list_empty(*(head)) ? DLL_CAST(new) : (*(head))->prev), (dl_list_empty(*(head)) ? DLL_CAST(new) : *(head)))
+
+#define dl_list_del(item, head)                                         \
+    do                                                                  \
+    {                                                                   \
+        __dl_list_del(DLL_CAST(item)->prev, DLL_CAST(item)->next);      \
+        if (*head == DLL_CAST(item)) *head = DLL_CAST(item)->next;      \
+        if (*head == DLL_CAST(item)) *head = NULL;                      \
+        DLL_CAST(item)->next = NULL;                                    \
+        DLL_CAST(item)->prev = NULL;                                    \
+                                                                        \
+    } while(0)
+
+#define dl_list_move_tail(item, head)                                   \
+    do                                                                  \
+    {                                                                   \
+        dl_list_del(item, head);                                        \
+        dl_list_add_tail(item, head);                                   \
+                                                                        \
+    } while(0)
+
+#define dl_list_for_each(pos, head, type)                               \
+	for (pos = (type)(head);                                            \
+         pos != NULL;                                                   \
+         pos = (type)(DLL_CAST(pos)->next == (head) ? NULL : DLL_CAST(pos)->next))
+
+#define dl_list_for_each_safe(pos, head, tmp, type)                     \
+	for (pos = (type)*(head),                                           \
+             tmp = (type)(pos != NULL && DLL_CAST(pos)->next != *(head) ?\
+                 DLL_CAST(pos)->next : NULL);                           \
+         pos != NULL;                                                   \
+         pos = tmp,                                                     \
+             tmp = (type)(pos != NULL && DLL_CAST(pos)->next != *(head) ?\
+                 DLL_CAST(pos)->next : NULL))
+
+#define dl_list_for_each_prev(pos, head, type)                          \
+	for (pos = dl_list_last(head, type);                                \
+         pos != NULL;                                                   \
+         pos = (type)(DLL_CAST(pos) == (head) ? NULL : DLL_CAST(pos)->prev))
+
+
+
+#endif  /* _DLLIST_H */
diff --git a/src/editor.c b/src/editor.c
index 7236735..e59a9a5 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -385,7 +385,7 @@ on_button2_clicked                     (GtkButton       *button,
 
 
 
-
+GtkWidget *mywid;
 
 
 
@@ -484,6 +484,9 @@ GtkWidget *create_editor(void)
 
 
 
+    mywid = result;
+
+
   vbox1 = gtk_vbox_new (FALSE, 0);
   gtk_widget_show (vbox1);
   gtk_container_add (GTK_CONTAINER (result), vbox1);
diff --git a/src/gtksnippet.c b/src/gtksnippet.c
index 3fc8ccc..791338e 100644
--- a/src/gtksnippet.c
+++ b/src/gtksnippet.c
@@ -28,6 +28,10 @@
 #include <string.h>
 
 
+#include "common/dllist.h"
+
+
+
 #define CONTENT_BUFFER_LEN 64
 
 #define MARGIN_SPACE 4
@@ -357,6 +361,9 @@ gtk_snippet_paint(GtkSnippet *snippet)
     int y0;                                 /* Ordonnée du haut d'une ligne*/
     int y1;                                 /* Ordonnée du bas d'une ligne */
 
+    rendering_line *liter;
+
+
     widget = GTK_WIDGET(snippet);
     gdk_gc_get_values(snippet->gc, &values);
 
@@ -399,6 +406,20 @@ gtk_snippet_paint(GtkSnippet *snippet)
                     2 * MARGIN_SPACE + snippet->line_height, 0,
                     snippet->layout);
 
+
+    y0 = 0;
+
+    dl_list_for_each(/**/liter, snippet->lines, rendering_line *)
+    {
+        draw_rendering_line(liter, GDK_DRAWABLE(widget->window), snippet->gc,
+                            2 * MARGIN_SPACE + snippet->line_height, y0);
+
+        y0 += snippet->line_height;
+
+    }
+
+
+
 }
 
 
@@ -536,6 +557,26 @@ void gtk_snippet_set_processor(GtkSnippet *snippet, const asm_processor *proc)
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : snippet = composant GTK à mettre à jour.                     *
+*                lines   = informations à intégrer.                           *
+*                                                                             *
+*  Description : Définit les lignes du bloc de représentation.                *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void gtk_snippet_set_rendering_lines(GtkSnippet *snippet, rendering_line *lines)
+{
+    snippet->lines = lines;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : snippet = composant GTK à mettre à jour.                     *
 *                line    = informations à intégrer.                           *
 *                                                                             *
 *  Description : Ajoute une ligne dans le bloc de représentation.             *
diff --git a/src/gtksnippet.h b/src/gtksnippet.h
index a4e2eb5..f3b541d 100644
--- a/src/gtksnippet.h
+++ b/src/gtksnippet.h
@@ -30,6 +30,7 @@
 #include <cairo.h>
 
 
+#include "analysis/line.h"
 #include "arch/instruction.h"
 #include "arch/processor.h"
 #include "format/exe_format.h"
@@ -104,6 +105,8 @@ struct _GtkSnippet {
     code_line_info *info;                   /* Contenu à représenter       */
     unsigned int info_count;                /* Quantité d'informations     */
 
+    rendering_line *lines;                  /* Contenu à représenter       */
+
 
   gint sel;
 };
@@ -142,6 +145,9 @@ void gtk_snippet_set_processor(GtkSnippet *, const asm_processor *);
 /* Ajoute une ligne dans le bloc de représentation. */
 void gtk_snippet_add_line(GtkSnippet *, const code_line_info *);
 
+/* Définit les lignes du bloc de représentation. */
+void gtk_snippet_set_rendering_lines(GtkSnippet *, rendering_line *);
+
 /* Définit le contenu visuel à partir des infos enregistrées. */
 void gtk_snippet_build_content(GtkSnippet *);
 
-- 
cgit v0.11.2-87-g4458