diff options
Diffstat (limited to 'src/graph')
| -rw-r--r-- | src/graph/dot.c | 9 | ||||
| -rw-r--r-- | src/graph/layout.c | 78 | ||||
| -rw-r--r-- | src/graph/layout.h | 6 | ||||
| -rw-r--r-- | src/graph/node.c | 20 | ||||
| -rw-r--r-- | src/graph/node.h | 7 | 
5 files changed, 64 insertions, 56 deletions
| diff --git a/src/graph/dot.c b/src/graph/dot.c index 27e60bc..5a80f59 100644 --- a/src/graph/dot.c +++ b/src/graph/dot.c @@ -2,7 +2,7 @@  /* OpenIDA - Outil d'analyse de fichiers binaires   * dot.c - interactions avec le système dot   * - * Copyright (C) 2009 Cyrille Bagard + * Copyright (C) 2009-2012 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -148,15 +148,12 @@ void place_nodes_of_graph_layout(const graph_layout *layout, GtkGraphView *view,  {      int height;                             /* Hauteur du graphique        */      node_t *iter;                           /* Boucle de parcours          */ -    GGraphNode *node;                       /* Intermédiaire concerné      */ +    const GGraphNode *node;                 /* Intermédiaire concerné      */      height = GD_bb(layout->graph).UR.y;      for (iter = agfstnode(layout->graph); iter != NULL; iter = agnxtnode(layout->graph, iter))      { - -        printf(" pos :: (%d ; %d)\n", iter->u.coord.x, height - iter->u.coord.y); -          node = find_graph_node_by_name(nodes, count, iter->name);          g_graph_node_place(node, view, iter->u.coord.x, height - iter->u.coord.y);      } @@ -227,7 +224,7 @@ GtkLinkRenderer **create_links_from_graph_layout(const graph_layout *layout, siz              }              result = (GtkLinkRenderer **)realloc(result, ++(*count) * sizeof(GtkLinkRenderer *)); -            result[*count - 1] = gtk_link_renderer_new(points, points_count); +            result[*count - 1] = GTK_LINK_RENDERER(gtk_link_renderer_new(points, points_count));          } diff --git a/src/graph/layout.c b/src/graph/layout.c index 667074b..21f7454 100644 --- a/src/graph/layout.c +++ b/src/graph/layout.c @@ -2,7 +2,7 @@  /* OpenIDA - Outil d'analyse de fichiers binaires   * layout.c - mise en place de graphique   * - * Copyright (C) 2009 Cyrille Bagard + * Copyright (C) 2009-2012 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -31,7 +31,9 @@  #include "dot.h"  #include "node.h" +#include "../analysis/binary.h"  #include "../common/extstr.h" +#include "../gtkext/gtkbufferview.h" @@ -40,7 +42,7 @@  /* Etablit tous les liens entre les différents morceaux de code. */ -static char *complete_graph_links(const GtkGraphView *, GtkBinView **, size_t, char *); +static char *complete_graph_links(const GtkGraphView *, GtkViewPanel **, size_t, char *); @@ -58,7 +60,7 @@ static char *complete_graph_links(const GtkGraphView *, GtkBinView **, size_t, c  *                                                                             *  ******************************************************************************/ -bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count) +bool build_graph_view(GtkGraphView *view, GtkViewPanel **views, size_t count)  {      GGraphNode **nodes;                     /* Intermédiaires en place     */      size_t i;                               /* Boucle de parcours          */ @@ -72,12 +74,11 @@ bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count)      nodes = (GGraphNode **)calloc(count, sizeof(GGraphNode *));      for (i = 0; i < count; i++) -        nodes[i] = g_graph_node_new(views[i]); +        nodes[i] = g_graph_node_new(GTK_WIDGET(views[i]));      /* Définition du graphique */      cmds = strdup("digraph G {\noverlap=false;\n  splines=true;\n"); -    //cmds = strdup("digraph G {\n");      for (i = 0; i < count; i++)          cmds = g_graph_node_register_for_dot(nodes[i], cmds); @@ -86,8 +87,6 @@ bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count)      cmds = stradd(cmds, "}"); -    printf("first step :: '%s'\n", cmds); -      layout = create_graph_layout(cmds);      /* Affichage du graphique */ @@ -113,7 +112,7 @@ bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count)  *  Paramètres  : view  = support contenant les différentes lignes.            *  *                views = morceaux de code à afficher de façon organisée.      *  *                count = quantité de ces morceaux de code.                    * -*                desc  = description du graphique à compléter.                * +*                desc  = description du graphique à compléter. [OUT]          *  *                                                                             *  *  Description : Etablit tous les liens entre les différents morceaux de code.*  *                                                                             * @@ -123,51 +122,65 @@ bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count)  *                                                                             *  ******************************************************************************/ -static char *complete_graph_links(const GtkGraphView *view, GtkBinView **views, size_t count, char *desc) +static char *complete_graph_links(const GtkGraphView *view, GtkViewPanel **views, size_t count, char *desc)  { +    GOpenidaBinary *binary;                 /* Binaire rattaché aux vues   */ +    GArchInstruction *instrs;               /* Instructions pour assembleur*/ +    GBufferView *buffer;                    /* Tampon d'une partie de code */ +    vmpa_t end;                             /* Adresse finale du tampon    */      size_t i;                               /* Boucle de parcours #1       */ -    GRenderingLine *last;                   /* Dernière ligne d'un bloc    */ -    GRenderingLine **dests;                 /* Ligne visée par une autre   */ +    GArchInstruction *last;                 /* Dernière instruc. d'un bloc */ +    vmpa_t addr;                            /* Addresse d'instruction      */ +    GArchInstruction **dests;               /* Instr. visée par une autre  */      InstructionLinkType *types;             /* Type de lien entre lignes   */      size_t dcount;                          /* Nombre de liens de dest.    */      size_t j;                               /* Boucle de parcours #2       */ -    vmpa_t addr;                            /* Addresse de destination     */      size_t k;                               /* Boucle de parcours #3       */ -    char buffer[LINKS_DESC_LEN];            /* Tampon pour l'ajout de liens*/ -    GRenderingLine *next;                   /* Ligne suivante dans le flux */ +    char cmd[LINKS_DESC_LEN];               /* Tampon pour l'ajout de liens*/ +    GArchInstruction *next;                 /* Instruction suivante        */ + +    if (count == 0) +        return desc; + +    binary = gtk_view_panel_get_binary(views[0]); +    instrs = g_openida_binary_get_instructions(binary);      for (i = 0; i < count; i++)      { -        last = gtk_bin_view_get_last_line(views[i]); +        buffer = gtk_buffer_view_get_buffer(GTK_BUFFER_VIEW(views[i])); +        g_buffer_view_get_restrictions(buffer, NULL, &end); -        if (g_rendering_line_has_destinations(last)) +        last = g_arch_instruction_find_by_address(instrs, end, true); +        g_arch_instruction_get_location(last, NULL, NULL, &addr); + +        if (g_arch_instruction_has_destinations(last))          { -            dcount = g_rendering_line_get_destinations(last, &dests, &types); +            dcount = g_arch_instruction_get_destinations(last, &dests, &types);              for (j = 0; j < dcount; j++)              { -                addr = get_rendering_line_address(dests[j]); +                g_arch_instruction_get_location(dests[j], NULL, NULL, &addr);                  for (k = 0; k < count; k++) -                    if (gtk_bin_view_contain_address(views[k], addr)) +                    if (gtk_view_panel_contain_address(views[k], addr))                          break;                  if (k < count)                      switch (types[j])                      {                          case ILT_JUMP: -                            snprintf(buffer, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); -                            desc = stradd(desc, buffer); +                            snprintf(cmd, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); +                            desc = stradd(desc, cmd);                              break;                          case ILT_JUMP_IF_TRUE: -                            snprintf(buffer, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); -                            desc = stradd(desc, buffer); +                            snprintf(cmd, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); +                            desc = stradd(desc, cmd);                              break;                          case ILT_JUMP_IF_FALSE: -                            snprintf(buffer, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); -                            desc = stradd(desc, buffer); +                            snprintf(cmd, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); +                            desc = stradd(desc, cmd);                              break;                          default: @@ -180,24 +193,21 @@ static char *complete_graph_links(const GtkGraphView *view, GtkBinView **views,          }          /* Si la ligne n'est pas la dernière, on suit le flux normal */ -        else if (last != gtk_bin_view_get_last_line(view)) +        else if (addr != end)          { -            next = g_rendering_line_get_next_iter(gtk_bin_view_get_lines(GTK_BIN_VIEW(view)), -                                                  last, -                                                  gtk_bin_view_get_last_line(GTK_BIN_VIEW(view))); - +            next = g_arch_instruction_get_next_iter(instrs, last, end);              if (next == NULL) continue; -            addr = get_rendering_line_address(next); +            g_arch_instruction_get_location(next, NULL, NULL, &addr);              for (k = 0; k < count; k++) -                if (gtk_bin_view_contain_address(views[k], addr)) +                if (gtk_view_panel_contain_address(views[k], addr))                      break;              if (k < count)              { -                snprintf(buffer, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); -                desc = stradd(desc, buffer); +                snprintf(cmd, LINKS_DESC_LEN, "_%p -> _%p;\n", views[i], views[k]); +                desc = stradd(desc, cmd);              }          } diff --git a/src/graph/layout.h b/src/graph/layout.h index 5212168..006fa9b 100644 --- a/src/graph/layout.h +++ b/src/graph/layout.h @@ -2,7 +2,7 @@  /* OpenIDA - Outil d'analyse de fichiers binaires   * layout.h - prototypes pour la mise en place de graphique   * - * Copyright (C) 2009 Cyrille Bagard + * Copyright (C) 2009-2012 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -28,13 +28,13 @@  #include <stdbool.h> -#include "../gtkext/gtkbinview.h"  #include "../gtkext/gtkgraphview.h" +#include "../gtkext/gtkviewpanel.h"  /* Dispose une série de morceaux d'affichage en graphique. */ -bool build_graph_view(GtkGraphView *, GtkBinView **, size_t); +bool build_graph_view(GtkGraphView *, GtkViewPanel **, size_t); diff --git a/src/graph/node.c b/src/graph/node.c index 09cfe30..3e6cc14 100644 --- a/src/graph/node.c +++ b/src/graph/node.c @@ -2,7 +2,7 @@  /* OpenIDA - Outil d'analyse de fichiers binaires   * node.c - éléments de graphiques chez dot   * - * Copyright (C) 2009 Cyrille Bagard + * Copyright (C) 2009-2012 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -24,7 +24,9 @@  #include "node.h" +#include <malloc.h>  #include <stdio.h> +#include <string.h>  #include "../common/extstr.h" @@ -39,7 +41,7 @@ struct _GGraphNode  {      GObject parent;                         /* A laisser en premier        */ -    GtkBinView *view;                       /* Morceau de code représenté  */ +    GtkWidget *view;                        /* Morceau de code représenté  */      char *name;                             /* Adresse sous forme humaine  */  }; @@ -159,7 +161,7 @@ static void g_graph_node_init(GGraphNode *node)  *                                                                             *  ******************************************************************************/ -GGraphNode *g_graph_node_new(GtkBinView *view) +GGraphNode *g_graph_node_new(GtkWidget *view)  {      GGraphNode *result;                     /* Structure à retourner       */      size_t len;                             /* Taille du nom               */ @@ -168,7 +170,7 @@ GGraphNode *g_graph_node_new(GtkBinView *view)      result->view = view; -    len = 3 + sizeof(GtkBinView *) * 2 + 1; +    len = 3 + sizeof(GtkWidget *) * 2 + 1;      result->name = (char *)calloc(len, sizeof(char));      snprintf(result->name, len, "_%p", result->view); @@ -196,7 +198,7 @@ char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds)      GtkRequisition requisition;             /* Taille à l'écran requise    */      char buffer[128]; -    gtk_widget_size_request(GTK_WIDGET(node->view), &requisition); +    gtk_widget_size_request(node->view, &requisition);      cmds = stradd(cmds, node->name);      cmds = stradd(cmds, " [shape=box, fixedsize "); @@ -240,12 +242,12 @@ void g_graph_node_place(const GGraphNode *node, GtkGraphView *view, gint x, gint  {      GtkRequisition requisition;             /* Taille à l'écran actuelle   */ -    gtk_widget_size_request(GTK_WIDGET(node->view), &requisition); +    gtk_widget_size_request(node->view, &requisition);      x -= requisition.width / 2;      y -= requisition.height / 2; -    gtk_graph_view_put(view, GTK_WIDGET(node->view), x, y); +    gtk_graph_view_put(view, node->view, x, y);  } @@ -270,9 +272,9 @@ void g_graph_node_place(const GGraphNode *node, GtkGraphView *view, gint x, gint  *                                                                             *  ******************************************************************************/ -GGraphNode *find_graph_node_by_name(const GGraphNode **nodes, size_t count, const char *target) +const GGraphNode *find_graph_node_by_name(GGraphNode **nodes, size_t count, const char *target)  { -    GGraphNode *result;                     /* Trouvaille à remonter       */ +    const GGraphNode *result;               /* Trouvaille à remonter       */      size_t i;                               /* Boucle de parcours          */      result = NULL; diff --git a/src/graph/node.h b/src/graph/node.h index 4998553..f8d0078 100644 --- a/src/graph/node.h +++ b/src/graph/node.h @@ -2,7 +2,7 @@  /* OpenIDA - Outil d'analyse de fichiers binaires   * node.h - prototypes pour les éléments de graphiques chez dot   * - * Copyright (C) 2009 Cyrille Bagard + * Copyright (C) 2009-2012 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -25,7 +25,6 @@  #define _GRAPH_NODE_H -#include "../gtkext/gtkbinview.h"  #include "../gtkext/gtkgraphview.h" @@ -51,7 +50,7 @@ typedef struct _GGraphNodeClass GGraphNodeClass;  GType g_graph_node_get_type(void);  /* Constitue un intermédiaire entre un noeud dot et du code. */ -GGraphNode *g_graph_node_new(GtkBinView *); +GGraphNode *g_graph_node_new(GtkWidget *);  /* Déclare l'intermédiaire en tant que noeud pour dot. */  char *g_graph_node_register_for_dot(const GGraphNode *, char *); @@ -65,7 +64,7 @@ void g_graph_node_place(const GGraphNode *, GtkGraphView *, gint , gint);  /* Recherche un noeud donné dans une série de noeuds. */ -GGraphNode *find_graph_node_by_name(const GGraphNode **, size_t, const char *); +const GGraphNode *find_graph_node_by_name(GGraphNode **, size_t, const char *); | 
