From abd96dbbe27246e9303173e5e2f47b2e4cedbcb7 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Wed, 11 Feb 2015 08:43:35 +0000
Subject: Marked buffer lines as containing an entry point when needed.

git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@470 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
---
 ChangeLog                    |  21 ++++++++++++++
 pixmaps/Makefile.am          |   5 ++--
 pixmaps/entrypoint.png       | Bin 0 -> 657 bytes
 src/analysis/disass/output.c |   6 ++++
 src/format/elf/symbols.c     |   2 +-
 src/format/symbol.c          |   4 +++
 src/glibext/gbufferline.c    |  64 +++++++++++++++++++++++++++++++++++++++++--
 src/glibext/gbufferline.h    |  15 ++++++++++
 8 files changed, 111 insertions(+), 6 deletions(-)
 create mode 100644 pixmaps/entrypoint.png

diff --git a/ChangeLog b/ChangeLog
index c1e6d79..a4396ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+15-02-11  Cyrille Bagard <nocbos@gmail.com>
+
+	* pixmaps/entrypoint.png:
+	New entry: create entry points in buffer views.
+
+	* pixmaps/Makefile.am:
+	Add entrypoint.png to EXTRA_DIST.
+
+	* src/analysis/disass/output.c:
+	Mark buffer lines as containing an entry point when needed.
+
+	* src/format/elf/symbols.c:
+	Define some symbols as entry points.
+
+	* src/format/symbol.c:
+	Update code.
+
+	* src/glibext/gbufferline.c:
+	* src/glibext/gbufferline.h:
+	Add some flags for rendering buffer lines.
+
 15-02-10  Cyrille Bagard <nocbos@gmail.com>
 
 	* src/analysis/db/cdb.c:
diff --git a/pixmaps/Makefile.am b/pixmaps/Makefile.am
index f8f94fb..dbee07d 100644
--- a/pixmaps/Makefile.am
+++ b/pixmaps/Makefile.am
@@ -32,8 +32,9 @@ MISC =									\
 	welcome.png
 
 EXTRA_DIST =							\
-	bookmark.png					\
-	nil.png						\
+	bookmark.png						\
+	entrypoint.png						\
+	nil.png								\
 	breakpoint_disabled.png				\
 	breakpoint_normal.png				\
 	openida.xcf							\
diff --git a/pixmaps/entrypoint.png b/pixmaps/entrypoint.png
new file mode 100644
index 0000000..fc48aa8
Binary files /dev/null and b/pixmaps/entrypoint.png differ
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c
index 2ecb5f4..355d458 100644
--- a/src/analysis/disass/output.c
+++ b/src/analysis/disass/output.c
@@ -232,6 +232,12 @@ void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *form
 
             if (cmp_vmpa_by_virt(iaddr, saddr) == 0)
             {
+
+                /* Point d'entrée ? */
+
+                if (g_binary_symbol_get_target_type(symbols[sym_index]) == STP_ENTRY_POINT)
+                    g_buffer_line_add_flag(line, BLF_ENTRYPOINT);
+
                 /* Commentaire ? */
 
                 comment = g_binary_symbol_get_comment(symbols[sym_index]);
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 31fbabd..c09c429 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -244,7 +244,7 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le
 
 	g_binary_routine_set_range(routine, &range);
 
-	symbol = g_binary_symbol_new(STP_ROUTINE, "XXX", ~0);
+	symbol = g_binary_symbol_new(STP_ENTRY_POINT, "XXX", ~0);
 	g_binary_symbol_attach_routine(symbol, routine);
 	g_binary_format_add_symbol(base, symbol);
 
diff --git a/src/format/symbol.c b/src/format/symbol.c
index 1e6063f..ce5c837 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -225,6 +225,7 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol)
     switch (symbol->type)
     {
         case STP_ROUTINE:
+        case STP_ENTRY_POINT:
             result = g_binary_routine_get_name(symbol->extra.routine);
             break;
 
@@ -275,6 +276,7 @@ const char *g_binary_symbol_get_label(const GBinSymbol *symbol)
     switch (symbol->type)
     {
         case STP_ROUTINE:
+        case STP_ENTRY_POINT:
             result = g_binary_routine_get_name(symbol->extra.routine);
             break;
 
@@ -325,6 +327,7 @@ void g_binary_symbol_fix_range(GBinSymbol *symbol, const vmpa2t *full)
             break;
 
         case STP_ROUTINE:
+        case STP_ENTRY_POINT:
 
             routine = g_binary_symbol_get_routine(symbol);
 
@@ -371,6 +374,7 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol)
             break;
 
         case STP_ROUTINE:
+        case STP_ENTRY_POINT:
             result = g_binary_routine_get_range(symbol->extra.routine);
             break;
 
diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c
index 54f5fb6..824578d 100644
--- a/src/glibext/gbufferline.c
+++ b/src/glibext/gbufferline.c
@@ -95,6 +95,8 @@ struct _GBufferLine
     BufferLineColumn merge_start;           /* Début de la zone globale    */
     BufferLineColumn last_used;             /* Dernière colonne utilisée   */
 
+    BufferLineFlags flags;                  /* Drapeaux particuliers       */
+
 };
 
 /* Représentation de fragments de texte en ligne (classe) */
@@ -102,6 +104,7 @@ struct _GBufferLineClass
 {
     GObjectClass parent;                    /* A laisser en premier        */
 
+    cairo_surface_t *entrypoint_img;        /* Image pour les entrées      */
     cairo_surface_t *bookmark_img;          /* Image pour les signets      */
 
 };
@@ -440,6 +443,13 @@ static void g_buffer_line_class_init(GBufferLineClass *class)
 {
     gchar *filename;                        /* Chemin d'accès à utiliser   */
 
+    filename = find_pixmap_file("entrypoint.png");
+    /* assert(filename != NULL); */
+
+    class->entrypoint_img = cairo_image_surface_create_from_png(filename);
+
+    g_free(filename);
+
     filename = find_pixmap_file("bookmark.png");
     /* assert(filename != NULL); */
 
@@ -1130,6 +1140,46 @@ void g_buffer_line_start_merge_at(GBufferLine *line, BufferLineColumn start)
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : line = ligne à venir compléter.                              *
+*                flag = propriété à intégrer.                                 *
+*                                                                             *
+*  Description : Ajoute une propriété particulière à une ligne donnée.        *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void g_buffer_line_add_flag(GBufferLine *line, BufferLineFlags flag)
+{
+    line->flags |= flag;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : line = ligne à venir compléter.                              *
+*                flag = propriété à supprimer.                                *
+*                                                                             *
+*  Description : Retire une propriété particulière à une ligne donnée.        *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+void g_buffer_line_remove_flag(GBufferLine *line, BufferLineFlags flag)
+{
+    line->flags &= ~flag;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : line       = ligne de texte à manipuler.                     *
 *                cairo      = contexte graphique à utiliser pour les pinceaux.*
 *                max_widths = largeurs de colonne à respecter.                *
@@ -1151,10 +1201,18 @@ void g_buffer_line_draw(GBufferLine *line, cairo_t *cairo, const gint max_widths
     gint x;                                 /* Point de départ d'impression*/
     BufferLineColumn i;                     /* Boucle de parcours          */
 
-    class = G_BUFFER_LINE_GET_CLASS(line);
+    if (line->flags != BLF_NONE)
+    {
+        class = G_BUFFER_LINE_GET_CLASS(line);
+
+        if (line->flags & BLF_ENTRYPOINT)
+            cairo_set_source_surface(cairo, class->entrypoint_img, 5, y);
+        else if (line->flags & BLF_BOOKMARK)
+            cairo_set_source_surface(cairo, class->bookmark_img, 5, y);
 
-    cairo_set_source_surface(cairo, class->bookmark_img, 5, y);
-    cairo_paint(cairo);
+        cairo_paint(cairo);
+
+    }
 
     x = x_init;
 
diff --git a/src/glibext/gbufferline.h b/src/glibext/gbufferline.h
index 9b35f0b..6984c37 100644
--- a/src/glibext/gbufferline.h
+++ b/src/glibext/gbufferline.h
@@ -83,6 +83,15 @@ typedef enum _BufferLineColumn
 #define COL_MARGIN 23
 
 
+/* Propriétés particulières supplémentaires */
+typedef enum _BufferLineFlags
+{
+    BLF_NONE        = 0 << 0,               /* Aucune                      */
+    BLF_ENTRYPOINT  = 1 << 0,               /* Représentation d'une entrée */
+    BLF_BOOKMARK    = 1 << 1                /* Signet associé              */
+
+} BufferLineFlags;
+
 
 /* Détermine le type de la représentation de fragments de texte en ligne. */
 GType g_buffer_line_get_type(void);
@@ -126,6 +135,12 @@ gint g_buffer_line_get_merge_width(GBufferLine *, BufferLineColumn *, const bool
 /* Définit la colonne à partir de laquelle la fusion opère. */
 void g_buffer_line_start_merge_at(GBufferLine *, BufferLineColumn);
 
+/* Ajoute une propriété particulière à une ligne donnée. */
+void g_buffer_line_add_flag(GBufferLine *, BufferLineFlags);
+
+/* Retire une propriété particulière à une ligne donnée. */
+void g_buffer_line_remove_flag(GBufferLine *, BufferLineFlags);
+
 /* Imprime la ligne de texte représentée. */
 void g_buffer_line_draw(GBufferLine *, cairo_t *, const gint [BLC_COUNT], gint, gint, const bool *);
 
-- 
cgit v0.11.2-87-g4458