summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2013-03-19 21:13:51 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2013-03-19 21:13:51 (GMT)
commitcf97db0ea4d1ea983db38df85984034b49fa4f77 (patch)
treeb6d69945b24ec8da93f0bef7ccf4dfdbe1d920a2
parente7a85861ba8bcd00ceb7bf9e47f4eadccd48ce3f (diff)
Defined the first steps towards new graph renderings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@345 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
-rw-r--r--ChangeLog77
-rw-r--r--configure.ac1
-rw-r--r--plugins/pychrysa/analysis/blocks/flow.c33
-rw-r--r--plugins/python/samples/basic_blocks.py7
-rw-r--r--src/analysis/blocks/flow.c154
-rw-r--r--src/analysis/blocks/flow.h15
-rw-r--r--src/analysis/blocks/virtual.c4
-rw-r--r--src/analysis/blocks/virtual.h4
-rw-r--r--src/analysis/disass/Makefile.am3
-rw-r--r--src/analysis/disass/disassembler.c13
-rw-r--r--src/analysis/disass/rank.c413
-rw-r--r--src/analysis/disass/rank.h41
-rw-r--r--src/arch/instruction.c36
-rw-r--r--src/arch/instruction.h3
-rwxr-xr-xsrc/gtkext/graph/Makefile.am12
-rw-r--r--src/gtkext/graph/dot.c12
-rw-r--r--src/gtkext/graph/edge.c400
-rw-r--r--src/gtkext/graph/edge.h80
-rw-r--r--src/gtkext/graph/layout.c403
-rw-r--r--src/gtkext/graph/layout.h42
-rw-r--r--src/gtkext/graph/node-int.h79
-rw-r--r--src/gtkext/graph/node.c313
-rw-r--r--src/gtkext/graph/node.h56
-rwxr-xr-xsrc/gtkext/graph/nodes/Makefile.am17
-rw-r--r--src/gtkext/graph/nodes/flow.c732
-rw-r--r--src/gtkext/graph/nodes/flow.h86
-rw-r--r--src/gtkext/graph/nodes/virtual.c593
-rw-r--r--src/gtkext/graph/nodes/virtual.h70
-rw-r--r--src/gtkext/graph/params.h44
-rw-r--r--src/gtkext/graph/ranks.c267
-rw-r--r--src/gtkext/graph/ranks.h63
-rw-r--r--src/gtkext/gtkgraphview.c32
-rw-r--r--src/gui/panels/panel.c1
33 files changed, 4036 insertions, 70 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f72869..976cd94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,80 @@
+13-03-19 Cyrille Bagard <nocbos@gmail.com>
+
+ * configure.ac:
+ Add the new Makfiles from the 'src/gtkext/graph/nodes' directories
+ to AC_CONFIG_FILES.
+
+ * plugins/pychrysa/analysis/blocks/flow.c:
+ Provide the rank of a flow block.
+
+ * plugins/python/samples/basic_blocks.py:
+ Display the rank of blocks.
+
+ * src/analysis/blocks/flow.c:
+ * src/analysis/blocks/flow.h:
+ Set and provide ranks for flow blocks. Determine if a flow block is
+ looping to another one.
+
+ * src/analysis/blocks/virtual.c:
+ * src/analysis/blocks/virtual.h:
+ Fix some prototypes.
+
+ * src/analysis/disass/disassembler.c:
+ Update code for computing ranks.
+
+ * src/analysis/disass/Makefile.am:
+ Add the 'rank.[ch]' files to libanalysisdisass_la_SOURCES.
+
+ * src/analysis/disass/rank.c:
+ * src/analysis/disass/rank.h:
+ New entries: compute ranks for blocks.
+
+ * src/arch/instruction.c:
+ * src/arch/instruction.h:
+ Add a function which helps to get the order index of a target in
+ a group of instructions.
+
+ * src/gtkext/graph/dot.c:
+ Add debug code.
+
+ * src/gtkext/graph/edge.c:
+ * src/gtkext/graph/edge.h:
+ New entries: define edges like dot's ones.
+
+ * src/gtkext/graph/layout.c:
+ * src/gtkext/graph/layout.h:
+ Introduce new GLib objects for graph rendering.
+
+ * src/gtkext/graph/Makefile.am:
+ Add the 'edges.[ch]', 'params.h' and 'ranks.[ch]' files
+ to libgtkextgraph_la_SOURCES, 'nodes/libgtkextgraphnodes.la' to
+ libgtkextgraph_la_LIBADD and 'nodes' to SUBDIRS.
+
+ * src/gtkext/graph/node.c:
+ * src/gtkext/graph/node.h:
+ Introduce new GLib objects for graph nodes.
+
+ * src/gtkext/graph/node-int.h:
+ * src/gtkext/graph/nodes/flow.c:
+ * src/gtkext/graph/nodes/flow.h:
+ * src/gtkext/graph/nodes/Makefile.am:
+ * src/gtkext/graph/nodes/virtual.c:
+ * src/gtkext/graph/nodes/virtual.h:
+ New entries: introduce new GLib objects for graph nodes.
+
+ * src/gtkext/graph/params.h:
+ Define some values for the graph rendering.
+
+ * src/gtkext/graph/ranks.c:
+ * src/gtkext/graph/ranks.h:
+ New entries: deal with the ranks of the nodes.
+
+ * src/gtkext/gtkgraphview.c:
+ Update code.
+
+ * src/gui/panels/panel.c:
+ Remove debug code.
+
13-03-10 Cyrille Bagard <nocbos@gmail.com>
* src/arch/instruction.c:
diff --git a/configure.ac b/configure.ac
index 1ed195d..51aa8e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -300,6 +300,7 @@ AC_CONFIG_FILES([Makefile
src/glibext/Makefile
src/gtkext/Makefile
src/gtkext/graph/Makefile
+ src/gtkext/graph/nodes/Makefile
src/gui/Makefile
src/gui/menus/Makefile
src/gui/panels/Makefile
diff --git a/plugins/pychrysa/analysis/blocks/flow.c b/plugins/pychrysa/analysis/blocks/flow.c
index 216156c..49f3003 100644
--- a/plugins/pychrysa/analysis/blocks/flow.c
+++ b/plugins/pychrysa/analysis/blocks/flow.c
@@ -40,6 +40,8 @@
/* Fournit les adresses limites d'un bloc d'exécution. */
static PyObject *py_flow_block_get_boundary_addresses(PyObject *, void *);
+/* Fournit le rang du bloc dans le flot d'exécution. */
+static PyObject *py_flow_block_get_rank(PyObject *, void *);
@@ -77,6 +79,33 @@ static PyObject *py_flow_block_get_boundary_addresses(PyObject *self, void *clos
}
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une instruction. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Fournit le rang du bloc dans le flot d'exécution. *
+* *
+* Retour : Valeur associée à la propriété consultée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_flow_block_get_rank(PyObject *self, void *closure)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GFlowBlock *block; /* Version native */
+
+ block = G_FLOW_BLOCK(pygobject_get(self));
+
+ result = Py_BuildValue("I", g_flow_block_get_rank(block));
+
+ return result;
+
+}
+
+
@@ -110,6 +139,10 @@ bool register_python_flow_block(PyObject *module)
"boundary_addresses", (getter)py_flow_block_get_boundary_addresses, (setter)NULL,
"Provide the boundary addresses of the current flow block.", NULL
},
+ {
+ "rank", (getter)py_flow_block_get_rank, (setter)NULL,
+ "Provide the rank of the current block in the execution flow.", NULL
+ },
{ NULL }
};
diff --git a/plugins/python/samples/basic_blocks.py b/plugins/python/samples/basic_blocks.py
index 583723c..90f3a2c 100644
--- a/plugins/python/samples/basic_blocks.py
+++ b/plugins/python/samples/basic_blocks.py
@@ -43,14 +43,17 @@ def visit_block(block, order, indent):
if isinstance(block, FlowBlock):
start, end = block.boundary_addresses
+ rank = block.rank
links = block.get_links_block()
if links != None:
laddr = get_c_address_of_pygobject(links)
- print '%s- flow %s : 0x%08lx -> 0x%08lx (links = %s)' % (padding, addr, start, end, laddr)
+ print '%s- flow %s (rank=%d) : 0x%08lx -> 0x%08lx (links = %s)' \
+ % (padding, addr, rank, start, end, laddr)
else:
- print '%s- flow %s : 0x%08lx -> 0x%08lx' % (padding, addr, start, end)
+ print '%s- flow %s (rank=%d) : 0x%08lx -> 0x%08lx' \
+ % (padding, addr, rank, start, end)
else:
diff --git a/src/analysis/blocks/flow.c b/src/analysis/blocks/flow.c
index 0b68a14..799931d 100644
--- a/src/analysis/blocks/flow.c
+++ b/src/analysis/blocks/flow.c
@@ -25,6 +25,7 @@
#include <malloc.h>
+#include <sys/param.h>
#include "../block-int.h"
@@ -36,6 +37,9 @@ struct _GFlowBlock
{
GInstrBlock parent; /* A laisser en premier */
+ unsigned int rank; /* Rang dans l'exécution */
+ unsigned int next_rank; /* Rang suivant de l'exécution */
+
GArchInstruction *instrs; /* Liste complète d'instruct° */
GArchInstruction *first; /* Première instruction */
GArchInstruction *last; /* Dernière instruction */
@@ -140,6 +144,8 @@ static void g_flow_block_init(GFlowBlock *block)
parent->list_leafs = (list_leafs_blocks_fc)g_flow_block_list_leafs_blocks;
//parent->list_regs = (list_regs_accesses_fc)g_flow_block_list_regs_accesses;
+ g_flow_block_set_rank(block, 0);
+
block->regs = g_raccess_list_new();
block->awaited = g_raccess_list_new();
@@ -209,22 +215,8 @@ GInstrBlock *g_flow_block_new(GArchInstruction *instrs, GArchInstruction *first,
{
GFlowBlock *result; /* Structure à retourner */
- //vmpa_t addr; /* Adresse de la destination */
-
-
result = g_object_new(G_TYPE_FLOW_BLOCK, NULL);
-
- /*
- g_arch_instruction_get_location(first, NULL, NULL, &addr);
- printf(" ! new block @ 0x%llx - ", addr);
-
- g_arch_instruction_get_location(last, NULL, NULL, &addr);
- printf("0x%llx\n", addr);
- */
-
-
-
result->instrs = instrs;
result->first = first;
result->last = last;
@@ -242,6 +234,85 @@ GInstrBlock *g_flow_block_new(GArchInstruction *instrs, GArchInstruction *first,
/******************************************************************************
* *
+* Paramètres : block = bloc d'instruction à consulter. *
+* *
+* Description : Fournit le rang du bloc dans le flot d'exécution. *
+* *
+* Retour : Indice supérieur ou égal à zéro. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+unsigned int g_flow_block_get_rank(const GFlowBlock *block)
+{
+ return block->rank;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instruction à consulter. *
+* rank = Indice supérieur à zéro à prendre en compte. *
+* *
+* Description : Définit le rang du bloc dans le flot d'exécution. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flow_block_set_rank(GFlowBlock *block, unsigned int rank)
+{
+ block->rank = MAX(block->rank, rank);
+ g_flow_block_set_next_rank(block, block->rank + 1);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instruction à consulter. *
+* *
+* Description : Fournit le rang minimal du bloc suivant pour l'exécution. *
+* *
+* Retour : Indice supérieur à zéro. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+unsigned int g_flow_block_get_next_rank(const GFlowBlock *block)
+{
+ return block->next_rank;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instruction à consulter. *
+* rank = Indice supérieur à zéro à prendre en compte. *
+* *
+* Description : Définit le rang minimal du bloc suivant pour l'exécution. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flow_block_set_next_rank(GFlowBlock *block, unsigned int rank)
+{
+ block->next_rank = MAX(block->next_rank, rank);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : block = bloc de départ des recherches. *
* addr = ensemble de blocs à parcourir. *
* final = indique si la cible ou le conteneur est renvoyée. *
@@ -508,6 +579,61 @@ void g_flow_block_get_boundary_addresses(const GFlowBlock *block, vmpa_t *start,
/******************************************************************************
* *
+* Paramètres : block = bloc d'instructions démarrant la visite. *
+* list = ensemble des blocs basiques à parcourir. *
+* target = bloc de fin de parcours. *
+* *
+* Description : Détermine si un bloc peut conduire à un autre. *
+* *
+* Retour : true si un lien existe entre les deux blocs fournis. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_flow_block_is_looping_to(GFlowBlock *block, const GInstrBlock *list, GFlowBlock *target)
+{
+ bool result; /* Bilan à retourner */
+ 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 i; /* Boucle de parcours */
+ vmpa_t addr; /* Adresse de la destination */
+ GInstrBlock *next; /* Bloc suivant à visiter */
+
+ result = (block == target);
+
+ dcount = g_arch_instruction_get_destinations(block->last, &dests, &types, NULL);
+
+ for (i = 0; i < dcount && !result; i++)
+ switch (types[i])
+ {
+ case ILT_EXEC_FLOW:
+ case ILT_JUMP:
+ case ILT_CASE_JUMP:
+ case ILT_JUMP_IF_TRUE:
+ case ILT_JUMP_IF_FALSE:
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+ next = g_instr_block_find_by_addr(list, addr, true);
+ result = g_flow_block_is_looping_to(G_FLOW_BLOCK(next), list, target);
+ break;
+
+ case ILT_LOOP:
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+ next = g_instr_block_find_by_addr(list, addr, true);
+ result = (G_FLOW_BLOCK(next) == target);
+ default:
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : block = bloc d'instructions démarrant la visite. *
* list = ensemble des blocs basiques à parcourir. *
* mask = points de passage à marquer. *
diff --git a/src/analysis/blocks/flow.h b/src/analysis/blocks/flow.h
index a01ef64..ab8fada 100644
--- a/src/analysis/blocks/flow.h
+++ b/src/analysis/blocks/flow.h
@@ -70,6 +70,18 @@ GType g_flow_block_get_type(void);
/* Crée un bloc d'exécution d'instructions. */
GInstrBlock *g_flow_block_new(GArchInstruction *, GArchInstruction *, GArchInstruction *);
+/* Fournit le rang du bloc dans le flot d'exécution. */
+unsigned int g_flow_block_get_rank(const GFlowBlock *);
+
+/* Définit le rang du bloc dans le flot d'exécution. */
+void g_flow_block_set_rank(GFlowBlock *, unsigned int);
+
+/* Fournit le rang minimal du bloc suivant pour l'exécution. */
+unsigned int g_flow_block_get_next_rank(const GFlowBlock *);
+
+/* Définit le rang minimal du bloc suivant pour l'exécution. */
+void g_flow_block_set_next_rank(GFlowBlock *, unsigned int);
+
/* Fournit la liste d'appartenance des instructions du bloc. */
GArchInstruction *g_flow_block_get_all_instructions_list(const GFlowBlock *);
@@ -79,6 +91,9 @@ void g_flow_block_get_boundary(const GFlowBlock *, GArchInstruction **, GArchIns
/* Fournit les adresses limites d'un bloc d'exécution. */
void g_flow_block_get_boundary_addresses(const GFlowBlock *, vmpa_t *, vmpa_t *);
+/* Détermine si un bloc peut conduire à un autre. */
+bool g_flow_block_is_looping_to(GFlowBlock *, const GInstrBlock *, GFlowBlock *);
+
/* Suit le flot d'excution bloc par bloc. */
bool g_flow_block_follow(GFlowBlock *, const GInstrBlock *, BlockFollowPosition, flow_block_follow_cb, void *);
diff --git a/src/analysis/blocks/virtual.c b/src/analysis/blocks/virtual.c
index 0cc6a0d..7f238d4 100644
--- a/src/analysis/blocks/virtual.c
+++ b/src/analysis/blocks/virtual.c
@@ -388,7 +388,7 @@ void g_virtual_block_add_child(GVirtualBlock *block, GInstrBlock *child)
* *
******************************************************************************/
-size_t g_virtual_block_count_children(GVirtualBlock *block)
+size_t g_virtual_block_count_children(const GVirtualBlock *block)
{
return block->children_count;
@@ -408,7 +408,7 @@ size_t g_virtual_block_count_children(GVirtualBlock *block)
* *
******************************************************************************/
-GInstrBlock *g_virtual_block_get_child(GVirtualBlock *block, size_t index)
+GInstrBlock *g_virtual_block_get_child(const GVirtualBlock *block, size_t index)
{
if (index >= block->children_count)
return NULL;
diff --git a/src/analysis/blocks/virtual.h b/src/analysis/blocks/virtual.h
index b254a27..1e4b51d 100644
--- a/src/analysis/blocks/virtual.h
+++ b/src/analysis/blocks/virtual.h
@@ -59,10 +59,10 @@ GInstrBlock *g_virtual_block_new(void);
void g_virtual_block_add_child(GVirtualBlock *, GInstrBlock *);
/* Compte le nombre de blocs contenus dans le groupe courant. */
-size_t g_virtual_block_count_children(GVirtualBlock *);
+size_t g_virtual_block_count_children(const GVirtualBlock *);
/* Renvoie un des blocs contenus dans le groupe courant. */
-GInstrBlock *g_virtual_block_get_child(GVirtualBlock *, size_t);
+GInstrBlock *g_virtual_block_get_child(const GVirtualBlock *, size_t);
diff --git a/src/analysis/disass/Makefile.am b/src/analysis/disass/Makefile.am
index 45fc3fd..0f58100 100644
--- a/src/analysis/disass/Makefile.am
+++ b/src/analysis/disass/Makefile.am
@@ -8,7 +8,8 @@ libanalysisdisass_la_SOURCES = \
links.h links.c \
loop.h loop.c \
macro.h macro.c \
- output.h output.c
+ output.h output.c \
+ rank.h rank.c
libanalysisdisass_la_LDFLAGS =
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 8c816f6..74b3add 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -38,6 +38,7 @@
#include "loop.h"
#include "macro.h"
#include "output.h"
+#include "rank.h"
#include "../../decomp/lang/asm.h"
#include "../../format/format.h"
#include "../../glibext/delayed-int.h"
@@ -279,6 +280,18 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta
/* Sixième étape */
+ id = gtk_extended_status_bar_push(statusbar, _("Ranking each instructions block..."), true);
+
+ qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_rcompare);
+
+ rank_routines_blocks(routines, routines_count, statusbar, id);
+
+ gtk_extended_status_bar_remove(statusbar, id);
+
+ run_plugins_on_binary(disass->binary, PGA_BINARY_GROUPED, true);
+
+ /* Septième étape */
+
id = gtk_extended_status_bar_push(statusbar, _("Printing disassembled code..."), true);
qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_compare);
diff --git a/src/analysis/disass/rank.c b/src/analysis/disass/rank.c
new file mode 100644
index 0000000..6f12f31
--- /dev/null
+++ b/src/analysis/disass/rank.c
@@ -0,0 +1,413 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * rank.c - classement des blocs d'instructions
+ *
+ * Copyright (C) 2013 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 "rank.h"
+
+
+#include "../blocks/flow.h"
+#include "../blocks/virtual.h"
+
+
+#if 0
+/* Marque la profondeur d'un bloc d'instructions. */
+static void rank_flow_block_content(GFlowBlock *, const GInstrBlock *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instructions démarrant la visite. *
+* list = ensemble des blocs basiques à parcourir. *
+* *
+* Description : Marque la profondeur d'un bloc d'instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void rank_flow_block_content(GFlowBlock *block, const GInstrBlock *list)
+{
+ GArchInstruction *last; /* Dernière instruction du bloc*/
+ 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 k; /* Boucle de parcours #1 */
+ size_t i; /* Boucle de parcours #2 */
+ vmpa_t addr; /* Adresse de la destination */
+ GInstrBlock *next; /* Bloc suivant à visiter */
+ bool loop; /* Détection de rebouclage */
+ //unsigned int old_rank; /* Rang avant intervention */
+
+ g_flow_block_get_boundary(block, NULL, &last);
+ dcount = g_arch_instruction_get_destinations(last, &dests, &types, NULL);
+
+ for (k = 0; k < 2; k++)
+ for (i = 0; i < dcount; i++)
+ switch (types[i])
+ {
+ case ILT_EXEC_FLOW:
+ case ILT_JUMP:
+ case ILT_CASE_JUMP:
+ case ILT_JUMP_IF_TRUE:
+ case ILT_JUMP_IF_FALSE:
+
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+ next = g_instr_block_find_by_addr(list, addr, true);
+
+ /**
+ * On traite en premier les liens qui conduisent à un rebouclage,
+ * afin d'avoir des indices importants à offrir pour les autres liens
+ * par la suite.
+ */
+ loop = g_flow_block_is_looping_to(G_FLOW_BLOCK(next), list, block);
+ //if (loop != (k == 0)) continue;
+
+ if (loop)
+ printf("next :: %u (i=%zu k=%zu)\n", g_flow_block_get_next_rank(block), i, k);
+
+
+ if (loop == (k == 0))
+ {
+ g_flow_block_set_rank(G_FLOW_BLOCK(next), g_flow_block_get_next_rank(block));
+
+ rank_flow_block_content(G_FLOW_BLOCK(next), list);
+ }
+ break;
+
+ case ILT_LOOP:
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+ next = g_instr_block_find_by_addr(list, addr, true);
+
+
+ /**
+ * On traite en premier les liens qui conduisent à un rebouclage,
+ * afin d'avoir des indices importants à offrir pour les autres liens
+ * par la suite.
+ */
+ loop = g_flow_block_is_looping_to(G_FLOW_BLOCK(next), list, block);
+ //if (loop != (k == 0)) continue;
+
+
+ if (loop == (k == 0))
+ {
+ printf("loop next :: %u (i=%zu k=%zu)\n", g_flow_block_get_next_rank(block), i, k);
+
+
+ g_flow_block_set_next_rank(G_FLOW_BLOCK(next),
+ g_flow_block_get_next_rank(block));
+
+ }
+
+ break;
+
+ default:
+ break;
+
+ }
+
+
+
+
+
+
+
+#if 0
+ /**
+ * Si un bloc contient un retour sur lui même, on définit l'indice pour les
+ * blocs suivants découlant de cette boucle avant de traiter ces blocs suivants.
+ */
+ for (i = 0; i < dcount; i++)
+ switch (types[i])
+ {
+ case ILT_LOOP:
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+ next = g_instr_block_find_by_addr(list, addr, true);
+ g_flow_block_set_next_rank(G_FLOW_BLOCK(next), g_flow_block_get_next_rank(block));
+ break;
+
+ default:
+ break;
+
+ }
+
+ for (i = 0; i < dcount; i++)
+ switch (types[i])
+ {
+ case ILT_EXEC_FLOW:
+ case ILT_JUMP:
+ case ILT_CASE_JUMP:
+ case ILT_JUMP_IF_TRUE:
+ case ILT_JUMP_IF_FALSE:
+
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+ next = g_instr_block_find_by_addr(list, addr, true);
+
+ old_rank = g_flow_block_get_rank(G_FLOW_BLOCK(next));
+ g_flow_block_set_rank(G_FLOW_BLOCK(next), g_flow_block_get_next_rank(block));
+
+ /* Si un traitement n'a pas déjà été fait... */
+ if (old_rank == 0 || 1)
+ rank_flow_block_content(G_FLOW_BLOCK(next), list);
+
+ default:
+ break;
+
+ }
+#endif
+
+}
+
+#endif
+
+
+
+
+/* Classe le contenu d'un bloc d'instructions exécutées. */
+static unsigned int rank_flow_block(GFlowBlock *, const GInstrBlock *, unsigned int);
+
+/* Classe le contenu d'un bloc d'instructions virtuel. */
+static unsigned int rank_virtual_block(GVirtualBlock *, const GInstrBlock *, unsigned int);
+
+/* Classe le contenu d'un bloc d'instructions quelconque. */
+static unsigned int rank_instructions_block(GInstrBlock *, const GInstrBlock *, unsigned int);
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instructions concerné par la visite. *
+* list = ensemble des blocs basiques à parcourir. *
+* rank = rang courant du classement en courant. *
+* *
+* Description : Classe le contenu d'un bloc d'instructions exécutées. *
+* *
+* Retour : Rang pour les blocs suivants. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static unsigned int rank_flow_block(GFlowBlock *block, const GInstrBlock *list, unsigned int rank)
+{
+ unsigned int result; /* Rang suivant à retourner */
+ GInstrBlock *links; /* Blocs liés au bloc courant */
+ GArchInstruction *last; /* Dernière instruction du bloc*/
+ 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 k; /* Boucle de parcours #1 */
+ size_t i; /* Boucle de parcours #2 */
+ vmpa_t addr; /* Adresse de la destination */
+ GInstrBlock *next; /* Bloc suivant à visiter */
+ bool loop; /* Détection de rebouclage */
+
+ /* On traite le bloc courant */
+
+ result = rank;
+ g_flow_block_set_rank(block, result++);
+
+ /* Viennent ensuite les blocs rattachés */
+
+ links = g_instr_block_get_links_block(G_INSTR_BLOCK(block));
+
+ if (links != NULL)
+ {
+ g_flow_block_get_boundary(block, NULL, &last);
+ dcount = g_arch_instruction_get_destinations(last, &dests, &types, NULL);
+
+ for (k = 0; k < 2; k++)
+ for (i = 0; i < dcount; i++)
+ switch (types[i])
+ {
+ case ILT_CASE_JUMP:
+ case ILT_JUMP_IF_TRUE:
+ case ILT_JUMP_IF_FALSE:
+
+ g_arch_instruction_get_location(dests[i], NULL, NULL, &addr);
+
+ next = g_instr_block_find_by_addr(links, addr, true);
+
+ /**
+ * En cas d'une branche unique, l'adresse peut ne pas être trouvée
+ * dans les sous-blocs ; logiquement, elle sera traitée plus tard,
+ * dans la continuité de ce bloc.
+ */
+ if (next == NULL) break;
+
+ /**
+ * On traite en premier les liens qui conduisent à un rebouclage,
+ * afin d'avoir des indices importants à offrir pour les autres liens
+ * par la suite.
+ */
+ loop = g_flow_block_is_looping_to(G_FLOW_BLOCK(next), list, block);
+ if (loop != (k == 0)) continue;
+
+ next = g_instr_block_find_by_addr(links, addr, false);
+ result = MAX(rank_instructions_block(next, list, rank + 1), result);
+
+ break;
+
+ default:
+ break;
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instructions concerné par la visite. *
+* list = ensemble des blocs basiques à parcourir. *
+* rank = rang courant du classement en courant. *
+* *
+* Description : Classe le contenu d'un bloc d'instructions virtuel. *
+* *
+* Retour : Rang pour les blocs suivants. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static unsigned int rank_virtual_block(GVirtualBlock *block, const GInstrBlock *list, unsigned int rank)
+{
+ unsigned int result; /* Rang suivant à retourner */
+ size_t max; /* Borne du parcours */
+ size_t i; /* Boucle de parcours */
+ GInstrBlock *child; /* Sous-bloc à traiter */
+
+ result = rank;
+
+ max = g_virtual_block_count_children(block);
+
+ for (i = 0; i < max; i++)
+ {
+ child = g_virtual_block_get_child(block, i);
+ if (!G_IS_FLOW_BLOCK(child)) continue;
+
+ result = rank_instructions_block(child, list, result);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instructions concerné par la visite. *
+* list = ensemble des blocs basiques à parcourir. *
+* rank = rang courant du classement en courant. *
+* *
+* Description : Classe le contenu d'un bloc d'instructions quelconque. *
+* *
+* Retour : Rang pour les blocs suivants. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static unsigned int rank_instructions_block(GInstrBlock *block, const GInstrBlock *list, unsigned int rank)
+{
+ unsigned int result; /* Rang suivant à retourner */
+
+ if (G_IS_VIRTUAL_BLOCK(block))
+ result = rank_virtual_block(G_VIRTUAL_BLOCK(block), list, rank);
+
+ else if (G_FLOW_BLOCK(block))
+ result = rank_flow_block(G_FLOW_BLOCK(block), list, rank);
+
+ else
+ result = rank;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : routine = routine à traiter. *
+* *
+* Description : Classe les blocs d'une routine donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void rank_routine_blocks(GBinRoutine *routine)
+{
+ GInstrBlock *list; /* Ensemble des blocs d'instr. */
+ //vmpa_t start; /* Adresse de départ */
+ //GFlowBlock *first; /* Premier bloc de la routine */
+
+ list = g_binary_routine_get_basic_blocks(routine);
+
+ rank_instructions_block(list, list, 0);
+
+ /*
+ start = g_binary_routine_get_address(routine);
+ first = G_FLOW_BLOCK(g_instr_block_find_by_addr(list, start, true));
+
+ rank_flow_block_content(first, list);
+ */
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = ensemble d'instructions à relier. *
+* routines = prototypes existants à insérer. *
+* count = quantité de ces prototypes. *
+* statusbar = barre de statut avec progression à mettre à jour.*
+* id = identifiant du message affiché à l'utilisateur. *
+* *
+* Description : Classe les blocs des routines. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void rank_routines_blocks(GBinRoutine **routines, size_t count, GtkExtStatusBar *statusbar, guint id)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < count; i++)
+ rank_routine_blocks(routines[i]);
+
+}
diff --git a/src/analysis/disass/rank.h b/src/analysis/disass/rank.h
new file mode 100644
index 0000000..04da689
--- /dev/null
+++ b/src/analysis/disass/rank.h
@@ -0,0 +1,41 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * rank.h - prototypes pour le classement des blocs d'instructions
+ *
+ * Copyright (C) 2013 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_DISASS_RANK_H
+#define _ANALYSIS_DISASS_RANK_H
+
+
+#include "../routine.h"
+#include "../../gtkext/gtkextstatusbar.h"
+
+
+
+/* Classe les blocs d'une routine donnée. */
+void rank_routine_blocks(GBinRoutine *);
+
+/* Classe les blocs des routines. */
+void rank_routines_blocks(GBinRoutine **, size_t, GtkExtStatusBar *, guint);
+
+
+
+#endif /* _ANALYSIS_DISASS_RANK_H */
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index c40ff51..3831ee4 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -533,6 +533,42 @@ GArchInstruction *g_arch_instruction_get_given_destination(const GArchInstructio
}
+/******************************************************************************
+* *
+* Paramètres : iter = membre du groupe donné en référence. *
+* list = liste des instructions à analyser. *
+* count = taille de cette liste. *
+* *
+* Description : Indique la position dans les instructions identiques. *
+* *
+* Retour : Indice dans les instructions identiques du groupe. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_arch_instruction_compute_group_index(GArchInstruction **iter, GArchInstruction **list, size_t count)
+{
+ size_t result; /* Valeur à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = 0;
+
+ for (i = 0; i < count; i++)
+ {
+ if ((list + i) == iter)
+ break;
+
+ if (list[i] == *iter)
+ result++;
+
+ }
+
+ return result;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* CONVERSIONS DU FORMAT DES INSTRUCTIONS */
diff --git a/src/arch/instruction.h b/src/arch/instruction.h
index c4b704e..a6a0422 100644
--- a/src/arch/instruction.h
+++ b/src/arch/instruction.h
@@ -130,6 +130,9 @@ size_t g_arch_instruction_get_destinations(const GArchInstruction *, GArchInstru
/* Fournit la destination d'une instruction et d'un type donné. */
GArchInstruction *g_arch_instruction_get_given_destination(const GArchInstruction *, InstructionLinkType);
+/* Indique la position dans les instructions identiques. */
+size_t g_arch_instruction_compute_group_index(GArchInstruction **, GArchInstruction **, size_t);
+
/* --------------------- CONVERSIONS DU FORMAT DES INSTRUCTIONS --------------------- */
diff --git a/src/gtkext/graph/Makefile.am b/src/gtkext/graph/Makefile.am
index a631a90..ead315a 100755
--- a/src/gtkext/graph/Makefile.am
+++ b/src/gtkext/graph/Makefile.am
@@ -3,10 +3,16 @@ noinst_LTLIBRARIES = libgtkextgraph.la
libgtkextgraph_la_SOURCES = \
dot.h dot.c \
+ edge.h edge.c \
layout.h layout.c \
- node.h node.c
+ node.h node.c \
+ params.h \
+ ranks.h ranks.c
-libgtkextgraph_la_LDFLAGS =
+libgtkextgraph_la_LIBADD = \
+ nodes/libgtkextgraphnodes.la
+
+libgtkextgraph_la_LDFLAGS =
INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBGRAPH_CFLAGS)
@@ -15,4 +21,4 @@ AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS =
+SUBDIRS = nodes
diff --git a/src/gtkext/graph/dot.c b/src/gtkext/graph/dot.c
index 18c4800..e7bbf84 100644
--- a/src/gtkext/graph/dot.c
+++ b/src/gtkext/graph/dot.c
@@ -69,7 +69,7 @@ graph_layout *create_graph_layout(char *cmds)
- //printf("CMDS =======\n%s\n\n=================\n", cmds);
+ printf("CMDS =======\n%s\n\n=================\n", cmds);
ret = gvLayout(result->context, result->graph, "dot");
if (ret != 0) goto cdl_error;
@@ -161,7 +161,12 @@ void place_nodes_of_graph_layout(const graph_layout *layout, GtkGraphView *view,
for (iter = agfstnode(layout->graph); iter != NULL; iter = agnxtnode(layout->graph, iter))
{
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);
+
+ /* S'il s'agit d'un noeud artificiel créé pour dot uniquement... */
+ if (node == NULL) continue;
+
+ g_graph_node_place_old(node, view, iter->u.coord.x, height - iter->u.coord.y);
+
}
}
@@ -233,6 +238,9 @@ GtkLinkRenderer **create_links_from_graph_layout(const graph_layout *layout, siz
node = find_graph_node_by_name(nodes, ncount, agtail(eiter)->name);
+ /* S'il s'agit d'un noeud artificiel créé pour dot uniquement... */
+ if (node == NULL) continue;
+
g_graph_node_connect(node,
lines->list[0].list[0].x,
height - lines->list[0].list[0].y,
diff --git a/src/gtkext/graph/edge.c b/src/gtkext/graph/edge.c
new file mode 100644
index 0000000..0eb0230
--- /dev/null
+++ b/src/gtkext/graph/edge.c
@@ -0,0 +1,400 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * edge.c - liens entre les noeuds d'un graphique
+ *
+ * Copyright (C) 2013 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 "edge.h"
+
+
+#include <math.h>
+
+
+
+/* Lien graphique entre deux noeuds graphiques (instance) */
+struct _GGraphEdge
+{
+ GObject parent; /* A laisser en premier */
+
+ GFlowNode *src_node; /* Bloc de départ du lien */
+ node_slot_t *src_slot; /* Numéro d'ancrage initial */
+ GFlowNode *dest_node; /* Bloc d'arrivée du lien */
+ node_slot_t *dest_slot; /* Numéro d'ancrage final */
+
+ EdgeColor color; /* Couleur du rendu */
+ GdkPoint *points; /* Points de la ligne dessinée */
+ size_t count; /* Quantité de ces points */
+
+};
+
+/* Lien graphique entre deux noeuds graphiques (classe) */
+struct _GGraphEdgeClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+};
+
+
+#define SLOT_VERT_SEP 20
+
+#define ARROW_LENGHT 10
+#define ARROW_DEGREES 10
+
+
+/* Initialise la classe des liens graphiques entre deux noeuds. */
+static void g_graph_edge_class_init(GGraphEdgeClass *);
+
+/* Initialise une encapsulation de bloc virtuel. */
+static void g_graph_edge_init(GGraphEdge *);
+
+/* Supprime toutes les références externes. */
+static void g_graph_edge_dispose(GGraphEdge *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_graph_edge_finalize(GGraphEdge *);
+
+/* Dessine une flèche au bout du lien représenté. */
+static void draw_link_arrow(cairo_t *, gint, gint, gint, gint);
+
+
+
+/* Indique le type définit par la GLib pour les liens graphiques entre noeuds. */
+G_DEFINE_TYPE(GGraphEdge, g_graph_edge, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des liens graphiques entre deux noeuds. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_edge_class_init(GGraphEdgeClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_graph_edge_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_graph_edge_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : edge = instance à initialiser. *
+* *
+* Description : Initialise un lien graphique entre deux noeuds graphiques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_edge_init(GGraphEdge *edge)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : edge = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_edge_dispose(GGraphEdge *edge)
+{
+ g_object_unref(G_OBJECT(edge->src_node));
+ g_object_unref(G_OBJECT(edge->dest_node));
+
+ G_OBJECT_CLASS(g_graph_edge_parent_class)->dispose(G_OBJECT(edge));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : edge = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_edge_finalize(GGraphEdge *edge)
+{
+ G_OBJECT_CLASS(g_graph_edge_parent_class)->finalize(G_OBJECT(edge));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : src_node = bloc de départ du lien. *
+* src_slot = point d'ancrage associé. *
+* dest_node = bloc d'arrivée du lien. *
+* dest_slot = point d'ancrage associé. *
+* color = couleur de rendu à l'écran. *
+* *
+* Description : Etablit un lien graphique entre deux noeuds graphiques. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphEdge *g_graph_edge_new(GFlowNode *src_node, node_slot_t *src_slot, GFlowNode *dest_node, node_slot_t *dest_slot, EdgeColor color)
+{
+ GGraphEdge *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_GRAPH_EDGE, NULL);
+
+ g_object_ref(G_OBJECT(src_node));
+ g_object_ref(G_OBJECT(dest_node));
+
+ result->src_node = src_node;
+ result->src_slot = src_slot;
+ result->dest_node = dest_node;
+ result->dest_slot = dest_slot;
+
+ result->color = color;
+
+ return G_GRAPH_EDGE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : edge = ligne de rendu à mettre à jour. *
+* *
+* Description : Etablit le tracé du lien graphique entre deux noeuds. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_edge_compute(GGraphEdge *edge)
+{
+ GdkPoint start; /* Point de départ */
+ GdkPoint end; /* Point d'arrivée */
+
+ start = g_flow_node_get_point_from_slot(edge->src_node, false, edge->src_slot);
+ end = g_flow_node_get_point_from_slot(edge->dest_node, true, edge->dest_slot);
+
+ printf(" -- (%d ; %d) - (%d ; %d)\n",
+ start.x, start.y,
+ end.x, end.y);
+
+
+ /* Point de départ */
+
+ edge->count = 2;
+ edge->points = (GdkPoint *)calloc(edge->count, sizeof(GdkPoint));
+
+ edge->points[0] = start;
+ edge->points[1] = start;
+ edge->points[1].y += SLOT_VERT_SEP;
+
+ /* Points de jonction */
+
+
+
+ /* Point d'arrivée */
+
+ edge->count += 2;
+ edge->points = (GdkPoint *)realloc(edge->points, edge->count * sizeof(GdkPoint));
+
+ edge->points[edge->count - 1] = end;
+ edge->points[edge->count - 2] = end;
+ edge->points[edge->count - 2].y -= SLOT_VERT_SEP;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : edge = ligne de rendu à manipuler. *
+* drawable = surface de rendu à utiliser. *
+* gc = contexte graphique du dessin. *
+* *
+* Description : Dessine les liens graphiques enregistrés dans le moteur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_edge_draw(const GGraphEdge *edge, GdkDrawable *drawable, GdkGC *gc)
+{
+ cairo_t *cairo; /* Gestionnaire de rendu */
+
+ cairo = gdk_cairo_create(drawable);
+
+ _g_graph_edge_draw(edge, cairo, true);
+
+ cairo_destroy(cairo);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : edge = ligne de rendu à manipuler. *
+* cairo = assistant pour le rendu graphique. *
+* arrow = indique le besoin en flèche à l'arrivée. *
+* *
+* Description : Dessine les liens graphiques enregistrés dans le moteur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void _g_graph_edge_draw(const GGraphEdge *edge, cairo_t *cairo, bool arrow)
+{
+ size_t i; /* Boucle de parcours */
+
+ switch (edge->color)
+ {
+ default:
+ case EGC_DEFAULT:
+ cairo_set_source_rgb(cairo, 0, 0, 0);
+ break;
+ case EGC_GREEN:
+ cairo_set_source_rgb(cairo, 0, 0.6, 0);
+ break;
+ case EGC_RED:
+ cairo_set_source_rgb(cairo, 0.8, 0, 0);
+ break;
+ case EGC_BLUE:
+ cairo_set_source_rgb(cairo, 0, 0, 0.8);
+ break;
+ case EGC_DASHED_GRAY:
+ cairo_set_source_rgb(cairo, 0.4, 0.4, 0.4);
+ break;
+ }
+
+ switch (edge->color)
+ {
+ default:
+ case EGC_DEFAULT:
+ case EGC_GREEN:
+ case EGC_RED:
+ case EGC_BLUE:
+ cairo_set_dash(cairo, (double []) { 6.0 }, 0, 0.0);
+ break;
+ case EGC_DASHED_GRAY:
+ cairo_set_dash(cairo, (double []) { 6.0 }, 1, 0.0);
+ break;
+ }
+
+ /**
+ * Si on ne veut pas de flèche, on doit se destiner à un aperçu...
+ * Dans ce cas, pour plus de lisibilité, on double la taille d'impression.
+ * Et pour faire ressortir les boucles, on double encore les liens associés.
+ */
+ cairo_set_line_width(cairo, arrow ? 1 : (edge->color == EGC_BLUE ? 4 : 2));
+
+ cairo_move_to(cairo, edge->points[0].x + 0.5, edge->points[0].y);
+
+ for (i = 1; i < edge->count; i++)
+ cairo_line_to(cairo, edge->points[i].x + 0.5, edge->points[i].y);
+
+ cairo_stroke(cairo);
+
+ if (arrow)
+ draw_link_arrow(cairo,
+ edge->points[edge->count - 2].x,
+ edge->points[edge->count - 2].y,
+ edge->points[edge->count - 1].x,
+ edge->points[edge->count - 1].y);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : cairo = gestionnaire de rendu graphique. *
+* start_x = abscisse du début du segment final. *
+* start_y = ordonnée du début du segment final. *
+* end_x = abscisse de fin de segment et pointe de flèche. *
+* end_y = ordonnée de fin de segment et pointe de flèche. *
+* *
+* Description : Dessine une flèche au bout du lien représenté. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void draw_link_arrow(cairo_t *cairo, gint start_x, gint start_y, gint end_x, gint end_y)
+{
+ double angle; /* Angle du triangle à remplir */
+ double factor_x; /* Direction de la flèche #1 */
+ double factor_y; /* Direction de la flèche #2 */
+ double x1; /* Abscisse du point n°1 */
+ double y1; /* Ordonnée du point n°1 */
+ double x2; /* Abscisse du point n°2 */
+ double y2; /* Ordonnée du point n°2 */
+
+ angle = atan2(end_y - start_y, end_x - start_x) + M_PI;
+
+ factor_x = -1;
+ factor_y = -1;
+
+ x1 = end_x + factor_x * ARROW_LENGHT * cos(angle - ARROW_DEGREES);
+ y1 = end_y + factor_y * ARROW_LENGHT * sin(angle - ARROW_DEGREES);
+ x2 = end_x + factor_x * ARROW_LENGHT * cos(angle + ARROW_DEGREES);
+ y2 = end_y + factor_y * ARROW_LENGHT * sin(angle + ARROW_DEGREES);
+
+ cairo_move_to(cairo, end_x, end_y);
+
+ cairo_line_to(cairo, x1, y1);
+ cairo_line_to(cairo, x2, y2);
+
+ cairo_move_to(cairo, end_x, end_y);
+
+ cairo_fill(cairo);
+
+}
diff --git a/src/gtkext/graph/edge.h b/src/gtkext/graph/edge.h
new file mode 100644
index 0000000..31e4a97
--- /dev/null
+++ b/src/gtkext/graph/edge.h
@@ -0,0 +1,80 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * edge.h - prototypes pour les liens entre les noeuds d'un graphique
+ *
+ * Copyright (C) 2013 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 _GTKEXT_GRAPH_EDGE_H
+#define _GTKEXT_GRAPH_EDGE_H
+
+
+#include <glib-object.h>
+
+
+#include "nodes/flow.h"
+
+
+
+#define G_TYPE_GRAPH_EDGE g_graph_edge_get_type()
+#define G_GRAPH_EDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_graph_edge_get_type(), GGraphEdge))
+#define G_IS_GRAPH_EDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_graph_edge_get_type()))
+#define G_GRAPH_EDGE_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_graph_edge_get_type(), GGraphEdgeIface))
+#define G_GRAPH_EDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_GRAPH_EDGE, GGraphEdgeClass))
+
+
+/* Lien graphique entre deux noeuds graphiques (instance) */
+typedef struct _GGraphEdge GGraphEdge;
+
+/* Lien graphique entre deux noeuds graphiques (classe) */
+typedef struct _GGraphEdgeClass GGraphEdgeClass;
+
+
+/* Couleur de représentation */
+typedef enum _EdgeColor
+{
+ EGC_DEFAULT, /* Noir, par défaut */
+ EGC_GREEN, /* Condition vérifiée */
+ EGC_RED, /* Condition non vérifiée */
+ EGC_BLUE, /* Boucle détectée */
+ EGC_DASHED_GRAY, /* Exception omniprésente */
+
+ EGC_COUNT
+
+} EdgeColor;
+
+
+/* Indique le type définit par la GLib pour les liens graphiques entre noeuds. */
+GType g_graph_edge_get_type(void);
+
+/* Etablit un lien graphique entre deux noeuds graphiques. */
+GGraphEdge *g_graph_edge_new(GFlowNode *, node_slot_t *, GFlowNode *, node_slot_t *, EdgeColor);
+
+/* Etablit le tracé du lien graphique entre deux noeuds. */
+void g_graph_edge_compute(GGraphEdge *);
+
+/* Dessine les liens graphiques enregistrés dans le moteur. */
+void g_graph_edge_draw(const GGraphEdge *, GdkDrawable *, GdkGC *);
+
+/* Dessine les liens graphiques enregistrés dans le moteur. */
+void _g_graph_edge_draw(const GGraphEdge *, cairo_t *, bool);
+
+
+
+#endif /* _GTKEXT_GRAPH_EDGE_H */
diff --git a/src/gtkext/graph/layout.c b/src/gtkext/graph/layout.c
index 1748c40..377ad52 100644
--- a/src/gtkext/graph/layout.c
+++ b/src/gtkext/graph/layout.c
@@ -31,6 +31,7 @@
#include "dot.h"
#include "node.h"
+#include "nodes/flow.h"
#include "../gtkbufferview.h"
#include "../../analysis/binary.h"
#include "../../analysis/blocks/flow.h"
@@ -38,6 +39,9 @@
+/* Taille maximale des noms de classement */
+#define RANK_DESC_LEN 128
+
/* Taille maximale des introductions aux clusters */
#define CLUSTER_DESC_LEN 128
@@ -51,12 +55,20 @@ typedef struct _visitor_dot_params
GGraphNode **nodes; /* Intermédiaires en place */
size_t count; /* Quantité de noeuds en place */
+ char **ranks; /* Profondeurs des blocs */
+
unsigned int level; /* Profondeur de la visite */
char *cmds; /* Description à envoyer à dot */
} visitor_dot_params;
+/* Construit les rangs pour dot en parcourant les noeuds. */
+static bool rank_graph_nodes(GInstrBlock *, BlockVisitOrder, visitor_dot_params *);
+
+/* Etablit le classement de tous les prochains noeuds pour dot. */
+static void build_graph_ranking(visitor_dot_params *);
+
/* Construit les commandes pour dot en parcourant les noeuds. */
static bool register_graph_nodes(GInstrBlock *, BlockVisitOrder, visitor_dot_params *);
@@ -100,6 +112,11 @@ bool build_graph_view(GtkGraphView *view, GInstrBlock *blocks, GtkViewPanel **vi
params.level = 1;
params.cmds = strdup("digraph G {\n overlap=false;\n splines=ortho;\n compound=true;\n");
+ params.ranks = (char **)calloc(count, sizeof(char *));
+
+ g_instr_block_visit(blocks, (instr_block_visitor_cb)rank_graph_nodes, &params);
+ build_graph_ranking(&params);
+
g_instr_block_visit(blocks, (instr_block_visitor_cb)register_graph_nodes, &params);
params.cmds = complete_graph_links(view, views, count, params.cmds);
@@ -133,6 +150,96 @@ bool build_graph_view(GtkGraphView *view, GInstrBlock *blocks, GtkViewPanel **vi
* order = position dans la visite. *
* params = informations à mettre à jour pour dot. *
* *
+* Description : Construit les rangs pour dot en parcourant les noeuds. *
+* *
+* Retour : true si le parcours a été jusqu'à son terme, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool rank_graph_nodes(GInstrBlock *block, BlockVisitOrder order, visitor_dot_params *params)
+{
+ vmpa_t start; /* Adresse de départ d'un bloc */
+ GGraphNode *node; /* Noeud rattaché */
+ unsigned int rank; /* Classement du bloc lié */
+
+ if (G_IS_FLOW_BLOCK(block))
+ {
+ g_flow_block_get_boundary_addresses(G_FLOW_BLOCK(block), &start, NULL);
+ node = find_graph_node_by_start_address(params->nodes, params->count, start);
+
+ rank = g_flow_block_get_rank(G_FLOW_BLOCK(block));
+ /* BUG_ON(count >= params->count) */
+
+ params->ranks[rank] = g_graph_node_append_name_to_rank(node, params->ranks[rank]);
+
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : params = informations à mettre à jour pour dot. *
+* *
+* Description : Etablit le classement de tous les prochains noeuds pour dot. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void build_graph_ranking(visitor_dot_params *params)
+{
+ unsigned int id; /* Identifiant unique */
+ size_t i; /* Boucle de parcours #1 */
+ char buffer[RANK_DESC_LEN]; /* Tampon pour les commandes */
+ unsigned int j; /* Boucle de parcours #2 */
+
+ id = 0;
+
+ for (i = 0; i < params->count; i++)
+ {
+ if (params->ranks[i] == NULL)
+ continue;
+
+ snprintf(buffer, CLUSTER_DESC_LEN, DOT_IDENT "{ rank = same; rk%u;", id++);
+ params->cmds = stradd(params->cmds, buffer);
+
+ params->cmds = stradd(params->cmds, params->ranks[i]);
+
+ params->cmds = stradd(params->cmds, " }\n");
+
+ }
+
+ params->cmds = stradd(params->cmds, DOT_IDENT);
+
+ for (j = 0; j < id; j++)
+ {
+ if (j == 0)
+ snprintf(buffer, CLUSTER_DESC_LEN, "rk%u", j);
+ else
+ snprintf(buffer, CLUSTER_DESC_LEN, " -> rk%u", j);
+
+ params->cmds = stradd(params->cmds, buffer);
+
+ }
+
+ params->cmds = stradd(params->cmds, "\n");
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'instructions concerné par la visite. *
+* order = position dans la visite. *
+* params = informations à mettre à jour pour dot. *
+* *
* Description : Construit les commandes pour dot en parcourant les noeuds. *
* *
* Retour : true si le parcours a été jusqu'à son terme, false sinon. *
@@ -312,3 +419,299 @@ static char *complete_graph_links(const GtkGraphView *view, GtkViewPanel **views
return desc;
}
+
+
+
+
+
+#include "ranks.h"
+#include "nodes/virtual.h"
+
+
+
+
+/* Mise en disposition de blocs en graphique (instance) */
+struct _GGraphLayout
+{
+ GObject parent; /* A laisser en premier */
+
+ GGraphNode *nodes; /* Noeuds graphiques gérés */
+ GGraphRanks *ranks; /* Classement en rangs */
+
+ GGraphEdge **edges; /* Liens entre les noeuds */
+ size_t edges_count; /* Quantité de ces liens */
+
+};
+
+/* Mise en disposition de blocs en graphique (classe) */
+struct _GGraphLayoutClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des mises en disposition graphique. */
+static void g_graph_layout_class_init(GGraphLayoutClass *);
+
+/* Initialise une mise en disposition de blocs en graphique. */
+static void g_graph_layout_init(GGraphLayout *);
+
+/* Supprime toutes les références externes. */
+static void g_graph_layout_dispose(GGraphLayout *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_graph_layout_finalize(GGraphLayout *);
+
+
+
+/* Indique le type définit par la GLib pour les mises en disposition graphique. */
+G_DEFINE_TYPE(GGraphLayout, g_graph_layout, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des mises en disposition graphique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_layout_class_init(GGraphLayoutClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_graph_layout_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_graph_layout_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = instance à initialiser. *
+* *
+* Description : Initialise une mise en disposition de blocs en graphique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_layout_init(GGraphLayout *layout)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_layout_dispose(GGraphLayout *layout)
+{
+ g_object_unref(G_OBJECT(layout->nodes));
+ g_object_unref(G_OBJECT(layout->ranks));
+
+ G_OBJECT_CLASS(g_graph_layout_parent_class)->dispose(G_OBJECT(layout));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_layout_finalize(GGraphLayout *layout)
+{
+ G_OBJECT_CLASS(g_graph_layout_parent_class)->finalize(G_OBJECT(layout));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : blocks = ensemble des blocs basiques déjà découpés. *
+* views = morceaux de code à afficher de façon organisée. *
+* count = quantité de ces morceaux de code. *
+* *
+* Description : Construit un graphique à partir de blocs basiques. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphLayout *g_graph_layout_new(GInstrBlock *blocks, GtkBufferView **views, size_t count)
+{
+ GGraphLayout *result; /* Structure à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = g_object_new(G_TYPE_GRAPH_LAYOUT, NULL);
+
+ result->nodes = convert_blocks_into_nodes(blocks, views, count);
+
+ /* Traitement des positions horizontales */
+
+ g_graph_node_set_position(result->nodes, (gint []) { 0 }, NULL);
+ g_virtual_node_organize_x_line(G_VIRTUAL_NODE(result->nodes));
+
+ /* Traitement des positions verticales */
+
+ result->ranks = g_graph_ranks_new(count);
+
+ bool _register_cb(GFlowNode *node, GGraphRanks *ranks)
+ {
+ g_flow_node_register_rank(node, ranks);
+ return true;
+ }
+
+ g_graph_node_visit_flow_nodes(result->nodes, (graph_node_visitor_cb)_register_cb, result->ranks);
+
+ g_graph_ranks_compute_y_line(result->ranks);
+
+ bool _apply_cb(GFlowNode *node, GGraphRanks *ranks)
+ {
+ g_flow_node_apply_rank(node, ranks);
+ return true;
+ }
+
+ g_graph_node_visit_flow_nodes(result->nodes, (graph_node_visitor_cb)_apply_cb, result->ranks);
+
+ /* Mise en place des liens */
+
+ bool _do_links_cb(GFlowNode *node, GGraphLayout *layout)
+ {
+ g_flow_node_link(node, layout, layout->nodes);
+ return true;
+ }
+
+ g_graph_node_visit_flow_nodes(result->nodes, (graph_node_visitor_cb)_do_links_cb, result);
+
+ for (i = 0; i < result->edges_count; i++)
+ g_graph_edge_compute(result->edges[i]);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = disposition en graphique à compléter. *
+* edge = lien entre noeuds à conserver. *
+* *
+* Description : Ajoute un lien entre deux noeuds au graphique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_layout_add_edge(GGraphLayout *layout, GGraphEdge *edge)
+{
+ layout->edges = (GGraphEdge **)realloc(layout->edges,
+ ++layout->edges_count * sizeof(GGraphEdge *));
+
+ layout->edges[layout->edges_count - 1] = edge;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = disposition en graphique prête. *
+* view = support de destination finale. *
+* *
+* Description : Dispose chaque noeud sur la surface de destination donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_layout_place(GGraphLayout *layout, GtkGraphView *view)
+{
+ bool _place_cb(GFlowNode *node, GtkGraphView *view)
+ {
+ g_flow_node_place(node, view);
+ return true;
+ }
+
+ g_graph_node_visit_flow_nodes(layout->nodes, (graph_node_visitor_cb)_place_cb, view);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = graphique à représenter. *
+* drawable = surface de rendu à utiliser. *
+* gc = contexte graphique du dessin. *
+* *
+* Description : Dessine les liens graphiques enregistrés dans le moteur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_layout_draw(const GGraphLayout *layout, GdkDrawable *drawable, GdkGC *gc)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < layout->edges_count; i++)
+ g_graph_edge_draw(layout->edges[i], drawable, gc);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = graphique à représenter. *
+* cairo = assistant pour le rendu graphique. *
+* arrow = indique le besoin en flèche à l'arrivée. *
+* *
+* Description : Dessine les liens graphiques enregistrés dans le moteur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void _g_graph_layout_draw(const GGraphLayout *layout, cairo_t *cairo, bool arrow)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < layout->edges_count; i++)
+ _g_graph_edge_draw(layout->edges[i], cairo, arrow);
+
+}
diff --git a/src/gtkext/graph/layout.h b/src/gtkext/graph/layout.h
index 7a3bf1e..6295cac 100644
--- a/src/gtkext/graph/layout.h
+++ b/src/gtkext/graph/layout.h
@@ -38,4 +38,46 @@ bool build_graph_view(GtkGraphView *, GInstrBlock *, GtkViewPanel **, size_t);
+
+
+#include "edge.h"
+#include "../gtkbufferview.h"
+
+
+
+
+#define G_TYPE_GRAPH_LAYOUT g_graph_layout_get_type()
+#define G_GRAPH_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_graph_layout_get_type(), GGraphLayout))
+#define G_IS_GRAPH_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_graph_layout_get_type()))
+#define G_GRAPH_LAYOUT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_graph_layout_get_type(), GGraphLayoutIface))
+#define G_GRAPH_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_GRAPH_LAYOUT, GGraphLayoutClass))
+
+
+/* Mise en disposition de blocs en graphique (instance) */
+typedef struct _GGraphLayout GGraphLayout;
+
+/* Mise en disposition de blocs en graphique (classe) */
+typedef struct _GGraphLayoutClass GGraphLayoutClass;
+
+
+/* Indique le type définit par la GLib pour les mises en disposition graphique. */
+GType g_graph_layout_get_type(void);
+
+/* Construit un graphique à partir de blocs basiques. */
+GGraphLayout *g_graph_layout_new(GInstrBlock *, GtkBufferView **, size_t);
+
+/* Ajoute un lien entre deux noeuds au graphique. */
+void g_graph_layout_add_edge(GGraphLayout *, GGraphEdge *);
+
+/* Dispose chaque noeud sur la surface de destination donnée. */
+void g_graph_layout_place(GGraphLayout *, GtkGraphView *);
+
+/* Dessine les liens graphiques enregistrés dans le moteur. */
+void g_graph_layout_draw(const GGraphLayout *, GdkDrawable *, GdkGC *);
+
+/* Dessine les liens graphiques enregistrés dans le moteur. */
+void _g_graph_layout_draw(const GGraphLayout *, cairo_t *, bool);
+
+
+
#endif /* _GRAPH_LAYOUT_H */
diff --git a/src/gtkext/graph/node-int.h b/src/gtkext/graph/node-int.h
new file mode 100644
index 0000000..9ecb072
--- /dev/null
+++ b/src/gtkext/graph/node-int.h
@@ -0,0 +1,79 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * node-int.h - prototypes pour la gestion élémentaire des blocs sous forme de noeuds
+ *
+ * Copyright (C) 2013 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 _GTKEXT_GRAPH_NODE_INT_H
+#define _GTKEXT_GRAPH_NODE_INT_H
+
+
+#include "node.h"
+
+
+
+/* Fournit le rang du noeud dans le graphique. */
+typedef unsigned int (* get_node_rank_fc) (const GGraphNode *);
+
+/* Altère la position du noeud d'encapsulation. */
+typedef void (* node_set_pos_fc) (GGraphNode *, gint *, gint *);
+
+/* Fournit la position du noeud d'encapsulation. */
+typedef void (* node_get_pos_fc) (const GGraphNode *, gint *, gint *);
+
+/* Indique l'espace requis pour un noeud d'encapsulation. */
+typedef GtkAllocation (* node_get_alloc_fc) (const GGraphNode *);
+
+/* Parcourt tous les noeuds graphiques dans un ordre donné. */
+typedef bool (* visit_flow_nodes_fc) (GGraphNode *, graph_node_visitor_cb, void *);
+
+
+/* Intermédiaire entre le noeud dot et la bribe de code (instance) */
+struct _GGraphNode
+{
+ GObject parent; /* A laisser en premier */
+
+ get_node_rank_fc get_rank; /* Premier rang d'appartenance */
+ node_set_pos_fc set_pos; /* Définit l'emplacement */
+ node_get_pos_fc get_pos; /* Fournit l'emplacement */
+ node_get_alloc_fc get_alloc; /* Fournit l'espace nécessaire */
+ visit_flow_nodes_fc visit; /* Visite des noeuds d'exécut° */
+
+ GtkWidget *view; /* Morceau de code représenté */
+ char name[NODE_NAME_LEN]; /* Adresse sous forme humaine */
+
+ GtkAllocation alloc; /* Emplacement du bloc rattaché*/
+
+};
+
+
+/* Intermédiaire entre le noeud dot et la bribe de code (classe) */
+struct _GGraphNodeClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ double dpi_x; /* Résolution en abscisse */
+ double dpi_y; /* Résolution en ordonnée */
+
+};
+
+
+
+#endif /* _GTKEXT_GRAPH_NODE_INT_H */
diff --git a/src/gtkext/graph/node.c b/src/gtkext/graph/node.c
index 879139a..bb8403f 100644
--- a/src/gtkext/graph/node.c
+++ b/src/gtkext/graph/node.c
@@ -29,7 +29,9 @@
#include <string.h>
-#include "../gtkbufferview.h"
+#include "node-int.h"
+#include "nodes/flow.h"
+#include "nodes/virtual.h"
#include "../../common/extstr.h"
@@ -37,30 +39,6 @@
/* -------------------------- GESTION DES NOEUDS A L'UNITE -------------------------- */
-/* Intermédiaire entre le noeud dot et la bribe de code (instance) */
-struct _GGraphNode
-{
- GObject parent; /* A laisser en premier */
-
- GtkWidget *view; /* Morceau de code représenté */
- char *name; /* Adresse sous forme humaine */
-
- GtkAllocation alloc; /* Emplacement du bloc rattaché*/
-
-};
-
-
-/* Intermédiaire entre le noeud dot et la bribe de code (classe) */
-struct _GGraphNodeClass
-{
- GObjectClass parent; /* A laisser en premier */
-
- double dpi_x; /* Résolution en abscisse */
- double dpi_y; /* Résolution en ordonnée */
-
-};
-
-
/* Taille maximale des lignes de description de noeud */
#define NODE_DESC_LEN 128
@@ -205,8 +183,6 @@ static void g_graph_node_dispose(GGraphNode *node)
static void g_graph_node_finalize(GGraphNode *node)
{
- free(node->name);
-
G_OBJECT_CLASS(g_graph_node_parent_class)->finalize(G_OBJECT(node));
}
@@ -227,23 +203,159 @@ static void g_graph_node_finalize(GGraphNode *node)
GGraphNode *g_graph_node_new(GtkWidget *view)
{
GGraphNode *result; /* Structure à retourner */
- size_t len; /* Taille du nom */
result = g_object_new(G_TYPE_GRAPH_NODE, NULL);
result->view = view;
g_object_ref(G_OBJECT(view));
- len = 3 + sizeof(GtkWidget *) * 2 + 1;
-
- result->name = (char *)calloc(len, sizeof(char));
- snprintf(result->name, len, "_%p", result->view);
+ snprintf(result->name, NODE_NAME_LEN, "_%p", result->view);
return result;
}
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* *
+* Description : Fournit le rang du noeud dans le graphique. *
+* *
+* Retour : Indice supérieur ou égal à zéro. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+unsigned int g_graph_node_get_rank(const GGraphNode *node)
+{
+ return node->get_rank(node);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à manipuler. *
+* x = éventuelle abscisse à intégrer ou NULL. *
+* y = éventuelle ordonnée à intégrer ou NULL. *
+* *
+* Description : Altère la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_node_set_position(GGraphNode *node, gint *x, gint *y)
+{
+ node->set_pos(node, x, y);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* x = éventuelle abscisse à recevoir ou NULL. [OUT] *
+* y = éventuelle ordonnée à recevoir ou NULL. [OUT] *
+* *
+* Description : Fournit la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_node_get_position(const GGraphNode *node, gint *x, gint *y)
+{
+ node->get_pos(node, x, y);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* *
+* Description : Indique l'espace requis pour un noeud d'encapsulation. *
+* *
+* Retour : Espace constitué, entièrement ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkAllocation g_graph_node_get_allocation(const GGraphNode *node)
+{
+ return node->get_alloc(node);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique démarrant la visite. *
+* callback = ensemble de blocs à parcourir. *
+* data = donnée utilisateur à associer au parcours. *
+* *
+* Description : Parcourt tous les noeuds graphiques dans un ordre donné. *
+* *
+* Retour : true si le parcours a été jusqu'à son terme, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_graph_node_visit_flow_nodes(GGraphNode *node, graph_node_visitor_cb callback, void *data)
+{
+ return node->visit(node, callback, data);
+
+}
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : node = intermédiaire à consulter. *
+* rank = description pour dot à compléter. *
+* *
+* Description : Inscrit le noeud au rang donné. *
+* *
+* Retour : Description dûment complétée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_graph_node_append_name_to_rank(const GGraphNode *node, char *rank)
+{
+ char buffer[NODE_DESC_LEN]; /* Tampon pour les commandes */
+
+ snprintf(buffer, NODE_DESC_LEN, " %s;", node->name);
+
+ if (rank == NULL)
+ rank = strdup(buffer);
+ else
+ rank = stradd(rank, buffer);
+
+ return rank;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : node = intermédiaire à consulter. *
@@ -318,7 +430,7 @@ char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds, unsigned
* *
******************************************************************************/
-void g_graph_node_place(GGraphNode *node, GtkGraphView *view, gint x, gint y)
+void g_graph_node_place_old(GGraphNode *node, GtkGraphView *view, gint x, gint y)
{
GtkRequisition requisition; /* Taille à l'écran actuelle */
@@ -396,6 +508,141 @@ void g_graph_node_connect(const GGraphNode *node, gint x, gint y, GdkPoint **poi
/******************************************************************************
* *
+* Paramètres : views = liste de vues à parcourir. *
+* count = taille de la liste. *
+* addrt = adresse de début du noeud recherché. *
+* *
+* Description : Recherche une vue donnée dans une série de vues. *
+* *
+* Retour : Vue trouvée ou NULL si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkBufferView *find_graph_view_by_start_address(GtkBufferView **views, size_t count, vmpa_t addr)
+{
+ GtkBufferView *result; /* Trouvaille à remonter */
+ size_t i; /* Boucle de parcours */
+ GBufferView *buffer; /* Tampon d'une partie de code */
+ vmpa_t start; /* Adresse de départ du tampon */
+
+ result = NULL;
+
+ for (i = 0; i < count && result == NULL; i++)
+ {
+ buffer = gtk_buffer_view_get_buffer(GTK_BUFFER_VIEW(views[i]));
+ g_buffer_view_get_restrictions(buffer, &start, NULL);
+
+ if (start == addr)
+ result = views[i];
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = ensemble des blocs basiques déjà découpés. *
+* views = morceaux de code à afficher de façon organisée. *
+* count = quantité de ces morceaux de code. *
+* *
+* Description : Réalise une conversion de blocs en noeuds. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *convert_blocks_into_nodes(GInstrBlock *block, GtkBufferView **views, size_t count)
+{
+ GGraphNode *result; /* Instance nouvelle à renvoyer*/
+ vmpa_t start; /* Adresse de départ */
+ GtkBufferView *view; /* Vue existante à retrouver */
+ size_t max; /* Nombre de blocs à gérer */
+ size_t i; /* Boucle de parcours */
+ GInstrBlock *sub_block; /* Sous-bloc intégré */
+ GGraphNode *child; /* Conversion à mémoriser */
+
+ result = NULL;
+
+ if (G_IS_FLOW_BLOCK(block))
+ {
+ g_flow_block_get_boundary_addresses(G_FLOW_BLOCK(block), &start, NULL);
+ view = find_graph_view_by_start_address(views, count, start);
+
+ result = g_flow_node_new(G_FLOW_BLOCK(block), view);
+
+ }
+ else if (G_IS_VIRTUAL_BLOCK(block))
+ {
+ result = g_virtual_node_new(G_VIRTUAL_BLOCK(block));
+
+ max = g_virtual_block_count_children(G_VIRTUAL_BLOCK(block));
+
+ for (i = 0; i < max; i++)
+ {
+ sub_block = g_virtual_block_get_child(G_VIRTUAL_BLOCK(block), i);
+ child = convert_blocks_into_nodes(sub_block, views, count);
+
+ g_virtual_node_add_child(G_VIRTUAL_NODE(result), child);
+
+ }
+
+ }
+ /*else BUG_ON(1); */
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : nodes = noeud au sommet de la hiérarchie. *
+* instr = instruction à retrouver. *
+* *
+* Description : Recherche le noeud contenant une instruction donnée. *
+* *
+* Retour : Noeud trouvé ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *find_node_for_instruction(GGraphNode *nodes, GArchInstruction *instr)
+{
+ GGraphNode *result; /* Trouvaille à retourner */
+ struct visit_params {
+ GArchInstruction *instr; /* Instruction recherchée */
+ GGraphNode *found; /* Remontée du noeud trouvé */
+ } params; /* Paramètres pour le parcours */
+
+ params.instr = instr;
+ params.found = NULL;
+
+ bool _find_node_cb(GFlowNode *node, struct visit_params *params)
+ {
+ if (g_flow_node_start_with(node, params->instr))
+ params->found = G_GRAPH_NODE(node);
+ return (params->found == NULL);
+ }
+
+ g_graph_node_visit_flow_nodes(nodes, (graph_node_visitor_cb)_find_node_cb, &params);
+
+ result = params.found;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : nodes = liste de noeuds à parcourir. *
* count = taille de la liste. *
* addrt = adresse de début du noeud recherché. *
diff --git a/src/gtkext/graph/node.h b/src/gtkext/graph/node.h
index 57d0932..ffe0a0d 100644
--- a/src/gtkext/graph/node.h
+++ b/src/gtkext/graph/node.h
@@ -25,14 +25,21 @@
#define _GRAPH_NODE_H
+#include "params.h"
+#include "ranks.h"
+#include "../gtkbufferview.h"
#include "../gtkgraphview.h"
-#include "../../arch/archbase.h"
+#include "../../arch/instruction.h"
+#include "../../analysis/block.h"
/* Indentation pour l'édition des commandes */
#define DOT_IDENT " "
+/* Taille maximale des noms de noeud ("_%p") */
+#define NODE_NAME_LEN (3 + sizeof(GtkWidget *) * 2 + 1)
+
/* -------------------------- GESTION DES NOEUDS A L'UNITE -------------------------- */
@@ -52,17 +59,50 @@ typedef struct _GGraphNode GGraphNode;
typedef struct _GGraphNodeClass GGraphNodeClass;
+/* Rappel à chaque noeud visité */
+typedef bool (* graph_node_visitor_cb) (GGraphNode *, void *);
+
+
/* Indique le type définit par la GLib pour le noeud. */
GType g_graph_node_get_type(void);
/* Constitue un intermédiaire entre un noeud dot et du code. */
GGraphNode *g_graph_node_new(GtkWidget *);
+
+
+/* Fournit le rang du noeud dans le graphique. */
+unsigned int g_graph_node_get_rank(const GGraphNode *);
+
+/* Altère la position du noeud d'encapsulation. */
+void g_graph_node_set_position(GGraphNode *, gint *, gint *);
+
+/* Fournit la position du noeud d'encapsulation. */
+void g_graph_node_get_position(const GGraphNode *, gint *, gint *);
+
+#define g_graph_node_has_x_position(node) \
+ ({ \
+ gint _x; \
+ g_graph_node_get_position(node, &_x, NULL); \
+ _x != UNINITIALIZED_NODE_POS; \
+ })
+
+/* Espace constitué, entièrement ou non. */
+GtkAllocation g_graph_node_get_allocation(const GGraphNode *);
+
+/* Parcourt tous les noeuds graphiques dans un ordre donné. */
+bool g_graph_node_visit_flow_nodes(GGraphNode *, graph_node_visitor_cb, void *);
+
+
+
+/* Inscrit le noeud au rang donné. */
+char *g_graph_node_append_name_to_rank(const GGraphNode *, char *);
+
/* Déclare l'intermédiaire en tant que noeud pour dot. */
char *g_graph_node_register_for_dot(const GGraphNode *, char *, unsigned int);
/* Place le morceau de code de l'intermédiaire à l'écran. */
-void g_graph_node_place(GGraphNode *, GtkGraphView *, gint , gint);
+void g_graph_node_place_old(GGraphNode *, GtkGraphView *, gint , gint);
/* Etablit une jonction ferme avec un noeud. */
void g_graph_node_connect(const GGraphNode *, gint, gint, GdkPoint **, size_t *);
@@ -72,6 +112,18 @@ void g_graph_node_connect(const GGraphNode *, gint, gint, GdkPoint **, size_t *)
/* ----------------------- MANIPULATION D'ENSEMBLES DE NOEUDS ----------------------- */
+/* Recherche une vue donnée dans une série de vues. */
+GtkBufferView *find_graph_view_by_start_address(GtkBufferView **, size_t, vmpa_t);
+
+/* Réalise une conversion de blocs en noeuds. */
+GGraphNode *convert_blocks_into_nodes(GInstrBlock *, GtkBufferView **, size_t);
+
+/* Recherche le noeud contenant une instruction donnée. */
+GGraphNode *find_node_for_instruction(GGraphNode *, GArchInstruction *);
+
+
+
+
/* Recherche un noeud donné dans une série de noeuds. */
GGraphNode *find_graph_node_by_start_address(GGraphNode **, size_t, vmpa_t);
diff --git a/src/gtkext/graph/nodes/Makefile.am b/src/gtkext/graph/nodes/Makefile.am
new file mode 100755
index 0000000..7bbe99a
--- /dev/null
+++ b/src/gtkext/graph/nodes/Makefile.am
@@ -0,0 +1,17 @@
+
+noinst_LTLIBRARIES = libgtkextgraphnodes.la
+
+libgtkextgraphnodes_la_SOURCES = \
+ flow.h flow.c \
+ virtual.h virtual.c
+
+libgtkextgraphnodes_la_LDFLAGS =
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS =
diff --git a/src/gtkext/graph/nodes/flow.c b/src/gtkext/graph/nodes/flow.c
new file mode 100644
index 0000000..d4506ea
--- /dev/null
+++ b/src/gtkext/graph/nodes/flow.c
@@ -0,0 +1,732 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * flow.c - encapsulation graphique des blocs d'exécution
+ *
+ * Copyright (C) 2013 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 "flow.h"
+
+
+#include "../layout.h"
+#include "../node-int.h"
+
+
+
+/* Type d'un accrochage pour lien */
+struct _node_slot_t
+{
+ GArchInstruction *instr; /* Instruction liée */
+ size_t group_index; /* Rang dans le grp d'origine */
+
+ InstructionLinkType type; /* Type de lien à représenter */
+ size_t slot_index; /* Position dans l'accroche */
+ gint x; /* Abscisse graphique du rendu */
+
+};
+
+/* Encapsulation graphique d'un bloc d'exécution (instance) */
+struct _GFlowNode
+{
+ GGraphNode parent; /* A laisser en premier */
+
+ GFlowBlock *block; /* Bloc d'exécution associé */
+ GtkBufferView *view; /* Représentation graphique */
+
+ GtkAllocation alloc; /* Emplacement du bloc rattaché*/
+
+ node_slot_t *entries; /* Positions des pts d'entrées */
+ size_t entries_count; /* Nombre de ces points */
+ node_slot_t *exits; /* Positions des pts de sorties*/
+ size_t exits_count; /* Nombre de ces points */
+
+};
+
+/* Encapsulation graphique d'un bloc d'exécution (classe) */
+struct _GFlowNodeClass
+{
+ GGraphNodeClass parent; /* A laisser en premier */
+
+};
+
+
+#define SPACE_BETWEEN_SLOT 15
+
+
+/* Initialise la classe des encapsulations de bloc d'exécution. */
+static void g_flow_node_class_init(GFlowNodeClass *);
+
+/* Initialise une encapsulation de bloc d'exécution. */
+static void g_flow_node_init(GFlowNode *);
+
+/* Supprime toutes les références externes. */
+static void g_flow_node_dispose(GFlowNode *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_flow_node_finalize(GFlowNode *);
+
+/* Fournit le rang du noeud dans le graphique. */
+static unsigned int g_flow_node_get_rank(const GFlowNode *);
+
+/* Altère la position du noeud d'encapsulation. */
+static void g_flow_node_set_position(GFlowNode *, gint *, gint *);
+
+/* Fournit la position du noeud d'encapsulation. */
+static void g_flow_node_get_position(const GFlowNode *, gint *, gint *);
+
+/* Indique l'espace requis pour un noeud d'encapsulation. */
+static GtkAllocation g_flow_node_get_allocation(const GFlowNode *);
+
+/* Parcourt tous les blocs d'instructions dans un ordre donné. */
+static bool g_flow_node_visit_flow_nodes(GFlowNode *, graph_node_visitor_cb, void *);
+
+
+
+/* ------------------------ GESTION DES ACCROCHES D'UN NOEUD ------------------------ */
+
+
+/* Prépare les points d'entrées du noeud. */
+static void g_flow_node_setup_entry_slots(GFlowNode *);
+
+/* Prépare les points de sorties du noeud. */
+static void g_flow_node_setup_exit_slots(GFlowNode *);
+
+/* Etablit un lien entre deux noeuds graphiques. */
+static node_slot_t *g_flow_node_get_slot(const GFlowNode *, bool, GArchInstruction *, size_t);
+
+
+
+/* Indique le type définit par la GLib pour l'encapsulation d'un bloc d'exécution. */
+G_DEFINE_TYPE(GFlowNode, g_flow_node, G_TYPE_GRAPH_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des encapsulations de bloc d'exécution. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_class_init(GFlowNodeClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_flow_node_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_flow_node_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance à initialiser. *
+* *
+* Description : Initialise une encapsulation de bloc d'exécution. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_init(GFlowNode *node)
+{
+ GGraphNode *base; /* Version basique */
+
+ base = G_GRAPH_NODE(node);
+
+ base->get_rank = (get_node_rank_fc)g_flow_node_get_rank;
+ base->set_pos = (node_set_pos_fc)g_flow_node_set_position;
+ base->get_pos = (node_get_pos_fc)g_flow_node_get_position;
+ base->get_alloc = (node_get_alloc_fc)g_flow_node_get_allocation;
+ base->visit = (visit_flow_nodes_fc)g_flow_node_visit_flow_nodes;
+
+ node->alloc.x = UNINITIALIZED_NODE_POS;
+ node->alloc.y = UNINITIALIZED_NODE_POS;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_dispose(GFlowNode *node)
+{
+ size_t i; /* Boucle de parcours */
+
+ g_object_unref(G_OBJECT(node->block));
+ g_object_unref(G_OBJECT(node->view));
+
+ for (i = 0; i < node->entries_count; i++)
+ g_object_unref(G_OBJECT(node->entries[i].instr));
+
+ for (i = 0; i < node->exits_count; i++)
+ g_object_unref(G_OBJECT(node->exits[i].instr));
+
+ G_OBJECT_CLASS(g_flow_node_parent_class)->dispose(G_OBJECT(node));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_finalize(GFlowNode *node)
+{
+ if (node->entries != NULL)
+ free(node->entries);
+
+ if (node->exits != NULL)
+ free(node->exits);
+
+ G_OBJECT_CLASS(g_flow_node_parent_class)->finalize(G_OBJECT(node));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc d'exécution représenté graphiquement. *
+* view = morceau d'affichage à représenter. *
+* *
+* Description : Encapsule graphiquement un bloc d'exécution. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *g_flow_node_new(GFlowBlock *block, GtkBufferView *view)
+{
+ GFlowNode *result; /* Structure à retourner */
+ GtkRequisition requisition; /* Taille à l'écran actuelle */
+
+ result = g_object_new(G_TYPE_FLOW_NODE, NULL);
+
+ g_object_ref(G_OBJECT(block));
+ g_object_ref(G_OBJECT(view));
+
+ result->block = block;
+ result->view = view;
+
+ gtk_widget_size_request(GTK_WIDGET(result->view), &requisition);
+
+ result->alloc.width = requisition.width;
+ result->alloc.height = requisition.height;
+
+ g_flow_node_setup_entry_slots(result);
+ g_flow_node_setup_exit_slots(result);
+
+ return G_GRAPH_NODE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* *
+* Description : Fournit le rang du noeud dans le graphique. *
+* *
+* Retour : Indice supérieur ou égal à zéro. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static unsigned int g_flow_node_get_rank(const GFlowNode *node)
+{
+ return g_flow_block_get_rank(node->block);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à manipuler. *
+* x = éventuelle abscisse à intégrer ou NULL. *
+* y = éventuelle ordonnée à intégrer ou NULL. *
+* *
+* Description : Altère la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_set_position(GFlowNode *node, gint *x, gint *y)
+{
+ if (x != NULL) node->alloc.x = *x;
+ if (y != NULL) node->alloc.y = *y;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* x = éventuelle abscisse à recevoir ou NULL. [OUT] *
+* y = éventuelle ordonnée à recevoir ou NULL. [OUT] *
+* *
+* Description : Fournit la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_get_position(const GFlowNode *node, gint *x, gint *y)
+{
+ if (x != NULL) *x = node->alloc.x;
+ if (y != NULL) *y = node->alloc.y;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* *
+* Description : Indique l'espace requis pour un noeud d'encapsulation. *
+* *
+* Retour : Espace constitué, entièrement ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GtkAllocation g_flow_node_get_allocation(const GFlowNode *node)
+{
+ GtkAllocation result; /* Valeurs à retourner */
+
+ result = node->alloc;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique démarrant la visite. *
+* callback = ensemble de blocs à parcourir. *
+* data = donnée utilisateur à associer au parcours. *
+* *
+* Description : Parcourt tous les blocs d'instructions dans un ordre donné. *
+* *
+* Retour : true si le parcours a été jusqu'à son terme, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_flow_node_visit_flow_nodes(GFlowNode *node, graph_node_visitor_cb callback, void *data)
+{
+ return callback(G_GRAPH_NODE(node), data);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* instr = instruction à considérer. *
+* *
+* Description : Précise si le noeud a pour première instruction celle donnée.*
+* *
+* Retour : true si la première instruction du noeud est celle indiquée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_flow_node_start_with(const GFlowNode *node, GArchInstruction *instr)
+{
+ GArchInstruction *first; /* Première instr. du noeud */
+
+ g_flow_block_get_boundary(node->block, &first, NULL);
+
+ /*
+ do
+ {
+ vmpa_t a1, a2;
+
+ g_arch_instruction_get_location(instr, NULL, NULL, &a1);
+ g_arch_instruction_get_location(first, NULL, NULL, &a2);
+
+ printf(" -- compare %p (0x%08lx) vs %p (0x%08lx)\n",
+ instr, a1, first, a2);
+
+ }
+ while (0);
+ */
+
+ return (first == instr);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* ranks = classement à mettre à jour. *
+* *
+* Description : Précise la hauteur minimale requise pour un noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flow_node_register_rank(const GFlowNode *node, GGraphRanks *ranks)
+{
+ unsigned int index; /* Indice du rang associé */
+
+ index = g_flow_block_get_next_rank(node->block);
+
+ g_graph_ranks_set_min_height(ranks, index, node->alloc.height);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à mettre à jour. *
+* ranks = classement à consulter. *
+* *
+* Description : Définit l'ordonnée de l'espace attribué à un noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flow_node_apply_rank(GFlowNode *node, GGraphRanks *ranks)
+{
+ unsigned int index; /* Indice du rang associé */
+
+ index = g_flow_block_get_next_rank(node->block);
+
+ node->alloc.y = g_graph_ranks_get_y_for_rank(ranks, index);
+
+}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à mettre à jour. *
+* layout = disposition globale du graphique. *
+* nodes = ensemble des noeuds en place. *
+* *
+* Description : Etablit les liaison entre un noeud et ses suivants. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flow_node_link(GFlowNode *node, GGraphLayout *layout, GGraphNode *nodes)
+{
+ GArchInstruction *last; /* Dernière instr. du noeud */
+ size_t i; /* Boucle de parcours */
+ GFlowNode *target; /* Bloc visé par le lien */
+ node_slot_t *dest_slot; /* Accrochage d'arrivée */
+ EdgeColor color; /* Couleur du lien à créer */
+ GGraphEdge *edge; /* Lien à mettre en place */
+
+ g_flow_block_get_boundary(node->block, NULL, &last);
+
+ for (i = 0; i < node->exits_count; i++)
+ {
+ target = G_FLOW_NODE(find_node_for_instruction(nodes, node->exits[i].instr));
+
+ dest_slot = g_flow_node_get_slot(target, true,
+ last, node->exits[i].group_index);
+
+ switch (node->exits[i].type)
+ {
+ case ILT_JUMP_IF_TRUE:
+ color = EGC_GREEN;
+ break;
+ case ILT_JUMP_IF_FALSE:
+ color = EGC_RED;
+ break;
+ case ILT_LOOP:
+ color = EGC_BLUE;
+ break;
+ case ILT_CATCH_EXCEPTION:
+ color = EGC_DASHED_GRAY;
+ break;
+ default:
+ color = EGC_DEFAULT;
+ break;
+
+ }
+
+ edge = g_graph_edge_new(node, &node->exits[i], target, dest_slot, color);
+ g_graph_layout_add_edge(layout, edge);
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = intermédiaire à consulter. *
+* view = support de destination. *
+* *
+* Description : Place un noeud sur son support final. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flow_node_place(const GFlowNode *node, GtkGraphView *view)
+{
+ printf("alloc %p :: (%d ; %d) - (%d ; %d)\n",
+ node->view,
+ node->alloc.x, node->alloc.y,
+ node->alloc.width, node->alloc.height);
+
+ gtk_graph_view_put(view, GTK_WIDGET(node->view), &node->alloc);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GESTION DES ACCROCHES D'UN NOEUD */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = intermédiaire à compléter. *
+* *
+* Description : Prépare les points d'entrées du noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_setup_entry_slots(GFlowNode *node)
+{
+ GArchInstruction *first; /* Première instr. du noeud */
+ GArchInstruction **instrs; /* Instr. visée par une autre */
+ InstructionLinkType *types; /* Type de lien entre lignes */
+ size_t icount; /* Nombre de liens de dest. */
+ size_t i; /* Boucle de parcours */
+
+ g_flow_block_get_boundary(node->block, &first, NULL);
+ icount = g_arch_instruction_get_sources(first, &instrs, &types);
+
+ node->entries = (node_slot_t *)calloc(icount, sizeof(node_slot_t));
+ node->entries_count = icount;
+
+ for (i = 0; i < icount; i++)
+ {
+ g_object_ref(instrs[i]);
+ node->entries[i].instr = instrs[i];
+
+ node->entries[i].type = types[i];
+ node->entries[i].group_index = g_arch_instruction_compute_group_index(&instrs[i],
+ instrs, icount);
+ node->entries[i].slot_index = i;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = intermédiaire à compléter. *
+* *
+* Description : Prépare les points de sorties du noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flow_node_setup_exit_slots(GFlowNode *node)
+{
+ GArchInstruction *last; /* Dernière instr. du noeud */
+ GArchInstruction **instrs; /* Instr. visée par une autre */
+ InstructionLinkType *types; /* Type de lien entre lignes */
+ size_t icount; /* Nombre de liens de dest. */
+ size_t i; /* Boucle de parcours */
+
+ g_flow_block_get_boundary(node->block, NULL, &last);
+ icount = g_arch_instruction_get_destinations(last, &instrs, &types, NULL);
+
+ node->exits = (node_slot_t *)calloc(icount, sizeof(node_slot_t));
+ node->exits_count = icount;
+
+ for (i = 0; i < icount; i++)
+ {
+ g_object_ref(instrs[i]);
+ node->exits[i].instr = instrs[i];
+
+ node->exits[i].type = types[i];
+ node->exits[i].group_index = g_arch_instruction_compute_group_index(&instrs[i],
+ instrs, icount);
+ node->exits[i].slot_index = i;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* entry = indique le type d'accrochage recherché. *
+* instr = instruction visée. *
+* index = indice de groupe pour départager au besoin. *
+* *
+* Description : Etablit un lien entre deux noeuds graphiques. *
+* *
+* Retour : Lien graphique mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static node_slot_t *g_flow_node_get_slot(const GFlowNode *node, bool entry, GArchInstruction *instr, size_t index)
+{
+ node_slot_t *result; /* Emplacement à retourner */
+ node_slot_t *list; /* Liste à parcourir */
+ size_t count; /* Taille de cette liste */
+ size_t i; /* Boucle de parcours */
+
+ if (entry)
+ {
+ list = node->entries;
+ count = node->entries_count;
+ }
+ else
+ {
+ list = node->exits;
+ count = node->exits_count;
+ }
+
+ for (i = 0; i < count; i++)
+ {
+ result = list + i;
+
+ if (result->instr == instr/* && result->group_index == index*/)
+ break;
+
+ }
+
+ return (i == count ? NULL : result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* entry = indique le type d'accrochage recherché. *
+* slot = accroche dont l'emplacement est à définir. *
+* *
+* Description : Localise un point d'accroche à un noeud graphique. *
+* *
+* Retour : Emplacement réservé pour l'accroche fournie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GdkPoint g_flow_node_get_point_from_slot(const GFlowNode *node, bool entry, const node_slot_t *slot)
+{
+ GdkPoint result; /* Position à retourner */
+ node_slot_t *slots; /* Accroches à parcourir */
+ size_t count; /* Nombre de ces points */
+ gint slots_width; /* Largeur des accroches */
+ gint slots_left; /* Abscisse de la première */
+ size_t index; /* Indice de l'accroche visée */
+
+ if (entry)
+ {
+ result.y = node->alloc.y;
+
+ slots = node->entries;
+ count = node->entries_count;
+
+ }
+ else
+ {
+ result.y = node->alloc.y + node->alloc.height;
+
+ slots = node->exits;
+ count = node->exits_count;
+
+ }
+
+ slots_width = (count - 1) * SPACE_BETWEEN_SLOT;
+ slots_left = node->alloc.x + (node->alloc.width - slots_width) / 2;
+
+ index = (slot - slots)/* / sizeof(node_slot_t)*/;
+ /* BUG_ON(index >= count); */
+
+ result.x = slots_left + index * SPACE_BETWEEN_SLOT;
+
+ return result;
+
+}
diff --git a/src/gtkext/graph/nodes/flow.h b/src/gtkext/graph/nodes/flow.h
new file mode 100644
index 0000000..5a6268e
--- /dev/null
+++ b/src/gtkext/graph/nodes/flow.h
@@ -0,0 +1,86 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * flow.h - prototypes pour l'encapsulation graphique des blocs d'exécution
+ *
+ * Copyright (C) 2013 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 _GTKEXT_GRAPH_NODES_FLOW_H
+#define _GTKEXT_GRAPH_NODES_FLOW_H
+
+
+#include "../node.h"
+#include "../../../analysis/blocks/flow.h"
+
+
+
+/* Redéfinition depuis layout.h pour contourner une boucle. */
+typedef struct _GGraphLayout GGraphLayout;
+
+
+
+#define G_TYPE_FLOW_NODE g_flow_node_get_type()
+#define G_FLOW_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_flow_node_get_type(), GFlowNode))
+#define G_IS_FLOW_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_flow_node_get_type()))
+#define G_FLOW_NODE_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_flow_node_get_type(), GFlowNodeIface))
+#define G_FLOW_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_FLOW_NODE, GFlowNodeClass))
+
+
+/* Type d'un accrochage pour lien */
+typedef struct _node_slot_t node_slot_t;
+
+/* Encapsulation graphique d'un bloc d'exécution (instance) */
+typedef struct _GFlowNode GFlowNode;
+
+/* Encapsulation graphique d'un bloc d'exécution (classe) */
+typedef struct _GFlowNodeClass GFlowNodeClass;
+
+
+/* Indique le type définit par la GLib pour l'encapsulation d'un bloc d'exécution. */
+GType g_flow_node_get_type(void);
+
+/* Encapsule graphiquement un bloc d'exécution. */
+GGraphNode *g_flow_node_new(GFlowBlock *, GtkBufferView *);
+
+/* Précise si le noeud a pour première instruction celle donnée. */
+bool g_flow_node_start_with(const GFlowNode *, GArchInstruction *);
+
+/* Précise la hauteur minimale requise pour un noeud. */
+void g_flow_node_register_rank(const GFlowNode *, GGraphRanks *);
+
+/* Définit l'ordonnée de l'espace attribué à un noeud. */
+void g_flow_node_apply_rank(GFlowNode *, GGraphRanks *);
+
+/* Etablit les liaison entre un noeud et ses suivants. */
+void g_flow_node_link(GFlowNode *, GGraphLayout *, GGraphNode *);
+
+/* Place un noeud sur son support final. */
+void g_flow_node_place(const GFlowNode *, GtkGraphView *);
+
+
+
+/* ------------------------ GESTION DES ACCROCHES D'UN NOEUD ------------------------ */
+
+
+/* Localise un point d'accroche à un noeud graphique. */
+GdkPoint g_flow_node_get_point_from_slot(const GFlowNode *, bool, const node_slot_t *);
+
+
+
+#endif /* _GTKEXT_GRAPH_NODES_FLOW_H */
diff --git a/src/gtkext/graph/nodes/virtual.c b/src/gtkext/graph/nodes/virtual.c
new file mode 100644
index 0000000..2781644
--- /dev/null
+++ b/src/gtkext/graph/nodes/virtual.c
@@ -0,0 +1,593 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * virtual.c - encapsulation graphique des blocs virtuels
+ *
+ * Copyright (C) 2013 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 "virtual.h"
+
+
+#include <malloc.h>
+#include <sys/param.h>
+
+
+#include "flow.h"
+#include "../node-int.h"
+
+
+
+/* Encapsulation graphique d'un bloc virtuel (instance) */
+struct _GVirtualNode
+{
+ GGraphNode parent; /* A laisser en premier */
+
+ GVirtualBlock *block; /* Bloc virtuel associé */
+
+ gint x; /* Abscisse du noeud */
+ gint y; /* Ordonnée du noeud */
+
+ GGraphNode **children; /* Noeuds englobés */
+ size_t count; /* Quantité de ces noeuds */
+
+};
+
+/* Encapsulation graphique d'un bloc virtuel (classe) */
+struct _GVirtualNodeClass
+{
+ GGraphNodeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des encapsulations de blocs virtuels. */
+static void g_virtual_node_class_init(GVirtualNodeClass *);
+
+/* Initialise une encapsulation de bloc virtuel. */
+static void g_virtual_node_init(GVirtualNode *);
+
+/* Supprime toutes les références externes. */
+static void g_virtual_node_dispose(GVirtualNode *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_virtual_node_finalize(GVirtualNode *);
+
+/* Fournit le rang du noeud dans le graphique. */
+static unsigned int g_virtual_node_get_rank(const GVirtualNode *);
+
+/* Altère la position du noeud d'encapsulation. */
+static void g_virtual_node_set_position(GVirtualNode *, gint *, gint *);
+
+/* Fournit la position du noeud d'encapsulation. */
+static void g_virtual_node_get_position(const GVirtualNode *, gint *, gint *);
+
+/* Indique l'espace requis pour un noeud d'encapsulation. */
+static GtkAllocation g_virtual_node_get_allocation(const GVirtualNode *);
+
+/* Parcourt tous les blocs d'instructions dans un ordre donné. */
+static bool g_virtual_node_visit_flow_nodes(GVirtualNode *, graph_node_visitor_cb, void *);
+
+/* Définit les abscisses relatives du contenu d'un noeud. */
+static void g_virtual_node_setup_x_line(GVirtualNode *);
+
+
+
+/* Indique le type définit par la GLib pour l'encapsulation d'un bloc virtuel. */
+G_DEFINE_TYPE(GVirtualNode, g_virtual_node, G_TYPE_GRAPH_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des encapsulations de blocs virtuels. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_class_init(GVirtualNodeClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_virtual_node_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_virtual_node_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance à initialiser. *
+* *
+* Description : Initialise une encapsulation de bloc virtuel. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_init(GVirtualNode *node)
+{
+ GGraphNode *base; /* Version basique */
+
+ base = G_GRAPH_NODE(node);
+
+ base->get_rank = (get_node_rank_fc)g_virtual_node_get_rank;
+ base->set_pos = (node_set_pos_fc)g_virtual_node_set_position;
+ base->get_pos = (node_get_pos_fc)g_virtual_node_get_position;
+ base->get_alloc = (node_get_alloc_fc)g_virtual_node_get_allocation;
+ base->visit = (visit_flow_nodes_fc)g_virtual_node_visit_flow_nodes;
+
+ node->x = UNINITIALIZED_NODE_POS;
+ node->y = UNINITIALIZED_NODE_POS;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_dispose(GVirtualNode *node)
+{
+ size_t i; /* Boucle de parcours */
+
+ g_object_unref(G_OBJECT(node->block));
+
+ for (i = 0; i < node->count; i++)
+ g_object_unref(G_OBJECT(node->children[i]));
+
+ if (node->children != NULL)
+ free(node->children);
+
+ G_OBJECT_CLASS(g_virtual_node_parent_class)->dispose(G_OBJECT(node));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_finalize(GVirtualNode *node)
+{
+ G_OBJECT_CLASS(g_virtual_node_parent_class)->finalize(G_OBJECT(node));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = bloc virtuel représenté graphiquement. *
+* view = morceau d'affichage à représenter. *
+* *
+* Description : Encapsule graphiquement un bloc virtuel. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *g_virtual_node_new(GVirtualBlock *block)
+{
+ GVirtualNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_VIRTUAL_NODE, NULL);
+
+ g_object_ref(G_OBJECT(block));
+
+ result->block = block;
+
+ return G_GRAPH_NODE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* *
+* Description : Fournit le rang du noeud dans le graphique. *
+* *
+* Retour : Indice supérieur ou égal à zéro. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static unsigned int g_virtual_node_get_rank(const GVirtualNode *node)
+{
+ /* BUG_ON(node->count == 0) */
+
+ return g_graph_node_get_rank(node->children[0]);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à manipuler. *
+* x = éventuelle abscisse à intégrer ou NULL. *
+* y = éventuelle ordonnée à intégrer ou NULL. *
+* *
+* Description : Altère la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_set_position(GVirtualNode *node, gint *x, gint *y)
+{
+ if (x != NULL) node->x = *x;
+ if (y != NULL) node->y = *y;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* x = éventuelle abscisse à recevoir ou NULL. [OUT] *
+* y = éventuelle ordonnée à recevoir ou NULL. [OUT] *
+* *
+* Description : Fournit la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_get_position(const GVirtualNode *node, gint *x, gint *y)
+{
+ if (x != NULL) *x = node->x;
+ if (y != NULL) *y = node->y;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à consulter. *
+* *
+* Description : Indique l'espace requis pour un noeud d'encapsulation. *
+* *
+* Retour : Espace constitué, entièrement ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GtkAllocation g_virtual_node_get_allocation(const GVirtualNode *node)
+{
+ GtkAllocation result; /* Valeurs à retourner */
+ size_t i; /* Boucle de parcours */
+ GtkAllocation alloc; /* Allocation d'un sous-noeud */
+
+ result.x = node->x;
+ result.y = node->y;
+
+ result.width = 0;
+ result.height = 0;
+
+ for (i = 0; i < node->count; i++)
+ {
+ alloc = g_graph_node_get_allocation(node->children[i]);
+
+ result.width += alloc.width;
+ result.height += alloc.height;
+
+ }
+
+ if (node->count > 1)
+ {
+ result.width += (node->count - 1) * NODE_TOP_MARGIN;
+ result.height += (node->count - 1) * NODE_TOP_MARGIN;
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique démarrant la visite. *
+* callback = ensemble de blocs à parcourir. *
+* data = donnée utilisateur à associer au parcours. *
+* *
+* Description : Parcourt tous les blocs d'instructions dans un ordre donné. *
+* *
+* Retour : true si le parcours a été jusqu'à son terme, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_virtual_node_visit_flow_nodes(GVirtualNode *node, graph_node_visitor_cb callback, void *data)
+{
+ bool result; /* Bilan à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = g_graph_node_visit_flow_nodes(node->children[i], callback, data);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à compléter. *
+* child = sous-noeud à insérer. *
+* *
+* Description : Ajoute un noeud au groupe courant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_virtual_node_add_child(GVirtualNode *node, GGraphNode *child)
+{
+ node->children = (GGraphNode **)realloc(node->children,
+ ++node->count * sizeof(GGraphNode *));
+
+ node->children[node->count - 1] = child;
+
+ g_object_ref(G_OBJECT(child));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à consulter. *
+* *
+* Description : Compte le nombre de noeuds contenus dans le groupe courant. *
+* *
+* Retour : Quantité normalement non nulle. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_virtual_node_count_children(const GVirtualNode *node)
+{
+ return node->count;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à consulter. *
+* index = indice du sous-bloc recherché. *
+* *
+* Description : Renvoie un des noeuds contenus dans le groupe courant. *
+* *
+* Retour : Un des blocs du groupe. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *g_virtual_node_get_child(const GVirtualNode *node, size_t index)
+{
+ if (index >= node->count)
+ return NULL;
+
+ else
+ return node->children[index];
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à traiter. *
+* *
+* Description : Organise le contenu du noeud selon l'axe des abscisses. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_virtual_node_organize_x_line(GVirtualNode *node)
+{
+ size_t i; /* Boucle de parcours */
+ gint min; /* Valeur minimale rencontrée */
+ gint x; /* Position d'un sous-noeud */
+
+ g_virtual_node_setup_x_line(node);
+
+ min = 0;
+
+ for (i = 0; i < node->count; i++)
+ {
+ g_graph_node_get_position(node->children[i], &x, NULL);
+ min = MIN(min, x);
+ }
+
+ printf("min =%d\n", min);
+
+ min = -min + GRAPH_LEFT_MARGIN;
+
+ g_virtual_node_offset_x_line(node, min);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à traiter. *
+* *
+* Description : Définit les abscisses relatives du contenu d'un noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_virtual_node_setup_x_line(GVirtualNode *node)
+{
+ unsigned int rank_0; /* Rang du premier sous-noeud */
+ unsigned int rank_1; /* Rang du second sous-noeud */
+ size_t i; /* Boucle de parcours */
+ GGraphNode *child; /* Raccourci confortable */
+ gint last_pos; /* Dernière position */
+ GtkAllocation alloc; /* Espace pour l'affichage */
+
+ /* Si le rang d'entrée contient tous les éléments... */
+ if (node->count > 1)
+ {
+ rank_0 = g_graph_node_get_rank(node->children[0]);
+ rank_1 = g_graph_node_get_rank(node->children[1]);
+
+ if (rank_0 == rank_1)
+ {
+ g_graph_node_set_position(node->children[0], (gint []) { -(alloc.width / 2) }, NULL);
+
+ for (i = 1; i < node->count; i++)
+ {
+ /* Récupération de la position précédente */
+
+ child = node->children[i - 1];
+
+ g_graph_node_get_position(child, &last_pos, NULL);
+ alloc = g_graph_node_get_allocation(child);
+
+ last_pos += alloc.width + NODE_LEFT_MARGIN;
+
+ /* Application sur le noeud courant */
+
+ child = node->children[i];
+
+ alloc = g_graph_node_get_allocation(child);
+
+ g_graph_node_set_position(child, &last_pos, NULL);
+
+ }
+
+ }
+
+ }
+
+ for (i = 0; i < node->count; i++)
+ {
+ child = node->children[i];
+
+ /* Emplacement du fils */
+
+ if (!g_graph_node_has_x_position(child))
+ {
+ alloc = g_graph_node_get_allocation(child);
+
+ printf("alloc ? %d\n", alloc.width);
+
+ g_graph_node_set_position(child, (gint []) { -(alloc.width / 2) }, NULL);
+ }
+
+ /* Définitions éventuelles des emplacements liés */
+
+ if (G_IS_FLOW_NODE(child))
+ {
+
+
+ ;
+
+
+ }
+ else if (G_IS_VIRTUAL_NODE(child))
+ g_virtual_node_organize_x_line(G_VIRTUAL_NODE(child));
+
+ /*else BUG_ON(1); */
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à traiter. *
+* xoffset = valeur du décallage. *
+* *
+* Description : Procède à un décallage du contenu sur l'axe des abscisses. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_virtual_node_offset_x_line(GVirtualNode *node, gint xoffset)
+{
+ size_t i; /* Boucle de parcours */
+ gint x; /* Position d'un sous-noeud */
+ GGraphNode *child; /* Raccourci confortable */
+
+ for (i = 0; i < node->count; i++)
+ {
+ child = node->children[i];
+
+ g_graph_node_get_position(child, &x, NULL);
+
+ printf("[%p] old=%d... ", child, x);
+
+ x += xoffset;
+ g_graph_node_set_position(child, &x, NULL);
+
+ printf("next=%d...\n", x);
+
+ }
+
+}
diff --git a/src/gtkext/graph/nodes/virtual.h b/src/gtkext/graph/nodes/virtual.h
new file mode 100644
index 0000000..440c675
--- /dev/null
+++ b/src/gtkext/graph/nodes/virtual.h
@@ -0,0 +1,70 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * virtual.h - prototypes pour l'encapsulation graphique des blocs virtuels
+ *
+ * Copyright (C) 2013 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 _GTKEXT_GRAPH_NODES_VIRTUAL_H
+#define _GTKEXT_GRAPH_NODES_VIRTUAL_H
+
+
+#include "../node.h"
+#include "../../../analysis/blocks/virtual.h"
+
+
+
+#define G_TYPE_VIRTUAL_NODE g_virtual_node_get_type()
+#define G_VIRTUAL_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_virtual_node_get_type(), GVirtualNode))
+#define G_IS_VIRTUAL_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_virtual_node_get_type()))
+#define G_VIRTUAL_NODE_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_virtual_node_get_type(), GVirtualNodeIface))
+#define G_VIRTUAL_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_VIRTUAL_NODE, GVirtualNodeClass))
+
+
+/* Encapsulation graphique d'un bloc virtuel (instance) */
+typedef struct _GVirtualNode GVirtualNode;
+
+/* Encapsulation graphique d'un bloc virtuel (classe) */
+typedef struct _GVirtualNodeClass GVirtualNodeClass;
+
+
+/* Indique le type définit par la GLib pour l'encapsulation d'un bloc virtuel. */
+GType g_virtual_node_get_type(void);
+
+/* Encapsule graphiquement un bloc virtuel. */
+GGraphNode *g_virtual_node_new(GVirtualBlock *);
+
+/* Ajoute un noeud au groupe courant. */
+void g_virtual_node_add_child(GVirtualNode *, GGraphNode *);
+
+/* Compte le nombre de noeuds contenus dans le groupe courant. */
+size_t g_virtual_node_count_children(const GVirtualNode *);
+
+/* Renvoie un des noeuds contenus dans le groupe courant. */
+GGraphNode *g_virtual_node_get_child(const GVirtualNode *, size_t);
+
+/* Organise le contenu du noeud selon l'axe des abscisses. */
+void g_virtual_node_organize_x_line(GVirtualNode *);
+
+/* Procède à un décallage du contenu sur l'axe des abscisses. */
+void g_virtual_node_offset_x_line(GVirtualNode *, gint);
+
+
+
+#endif /* _GTKEXT_GRAPH_NODES_VIRTUAL_H */
diff --git a/src/gtkext/graph/params.h b/src/gtkext/graph/params.h
new file mode 100644
index 0000000..63960b8
--- /dev/null
+++ b/src/gtkext/graph/params.h
@@ -0,0 +1,44 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * params.h - prototypes pour la modulation des paramètres de rendu
+ *
+ * Copyright (C) 2013 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 _GTKEXT_GRAPH_PARAMS_H
+#define _GTKEXT_GRAPH_PARAMS_H
+
+
+
+
+/* Coordonnés d'un noeud non initialisées */
+#define UNINITIALIZED_NODE_POS G_MININT
+
+
+
+#define GRAPH_LEFT_MARGIN 15
+#define GRAPH_TOP_MARGIN 15
+
+#define NODE_LEFT_MARGIN 25
+#define NODE_TOP_MARGIN 55
+
+
+
+
+#endif /* _GTKEXT_GRAPH_PARAMS_H */
diff --git a/src/gtkext/graph/ranks.c b/src/gtkext/graph/ranks.c
new file mode 100644
index 0000000..6121907
--- /dev/null
+++ b/src/gtkext/graph/ranks.c
@@ -0,0 +1,267 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * ranks.c - calcul de l'ordonnée des différents classements
+ *
+ * Copyright (C) 2013 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 "ranks.h"
+
+
+#include <malloc.h>
+#include <sys/param.h>
+
+
+#include "params.h"
+
+
+
+/* Information relatives à un rang de classement */
+typedef struct _rank_props
+{
+ gint top_margin; /* Espace supérieur pour liens */
+ gint height; /* Hauteur minimale */
+
+ gint final_y; /* Ordonnée finale */
+
+} rank_props;
+
+/* Calcul de l'ordonnée des différents classements (instance) */
+struct _GGraphRanks
+{
+ GObject parent; /* A laisser en premier */
+
+ rank_props *props; /* Propriétés des rangs */
+ unsigned int count; /* Nombre de rangs présents */
+
+};
+
+/* Calcul de l'ordonnée des différents classements (classe) */
+struct _GGraphRanksClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe de calcul de l'ordonnée des classements. */
+static void g_graph_ranks_class_init(GGraphRanksClass *);
+
+/* Initialise un calcul de l'ordonnée des classements. */
+static void g_graph_ranks_init(GGraphRanks *);
+
+/* Supprime toutes les références externes. */
+static void g_graph_ranks_dispose(GGraphRanks *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_graph_ranks_finalize(GGraphRanks *);
+
+
+
+/* Indique le type définit par la GLib pour le calcul de l'ordonnée des classements. */
+G_DEFINE_TYPE(GGraphRanks, g_graph_ranks, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe de calcul de l'ordonnée des classements.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_ranks_class_init(GGraphRanksClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_graph_ranks_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_graph_ranks_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ranks = instance à initialiser. *
+* *
+* Description : Initialise un calcul de l'ordonnée des classements. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_ranks_init(GGraphRanks *ranks)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_ranks_dispose(GGraphRanks *ranks)
+{
+ G_OBJECT_CLASS(g_graph_ranks_parent_class)->dispose(G_OBJECT(ranks));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ranks = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_ranks_finalize(GGraphRanks *ranks)
+{
+ if (ranks->props != NULL)
+ free(ranks->props);
+
+ G_OBJECT_CLASS(g_graph_ranks_parent_class)->finalize(G_OBJECT(ranks));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : count = nombre de rangs dans le classement au total. *
+* *
+* Description : Prépare de quoi se définir au mieux les ordonnées des noeuds.*
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphRanks *g_graph_ranks_new(unsigned int count)
+{
+ GGraphRanks *result; /* Structure à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = g_object_new(G_TYPE_GRAPH_RANKS, NULL);
+
+ result->count = count;
+ result->props = (rank_props *)calloc(count, sizeof(rank_props));
+
+ for (i = 0; i < count; i++)
+ if (i == 0)
+ result->props[i].top_margin = GRAPH_TOP_MARGIN;
+ else
+ result->props[i].top_margin = NODE_TOP_MARGIN;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ranks = ensemble des rangs de classement à manipuler. *
+* index = indice du rang visé. *
+* height = hauteur minimale requise pour le rang donné. *
+* *
+* Description : Note une hauteur minimale requise pour un rang du classement.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_ranks_set_min_height(GGraphRanks *ranks, unsigned int index, gint height)
+{
+ /*BUG_ON(index >= ranks->count) */
+
+ ranks->props[index].height = MAX(ranks->props[index].height, height);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ranks = ensemble des rangs de classement à manipuler. *
+* *
+* Description : Calcule l'ordonnée finale de chaque rang du classement. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_ranks_compute_y_line(GGraphRanks *ranks)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < ranks->count; i++)
+ {
+ ranks->props[i].final_y = ranks->props[i].top_margin;
+
+ if (i > 0)
+ ranks->props[i].final_y += ranks->props[i - 1].final_y + ranks->props[i - 1].height;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ranks = ensemble des rangs de classement à consulter. *
+* index = indice du rang visé. *
+* *
+* Description : Fournit la position verticale correspondant à un rang donné. *
+* *
+* Retour : Ordonnée à utiliser. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+gint g_graph_ranks_get_y_for_rank(const GGraphRanks *ranks, unsigned int index)
+{
+ /*BUG_ON(index >= ranks->count) */
+
+ return ranks->props[index].final_y;
+
+}
diff --git a/src/gtkext/graph/ranks.h b/src/gtkext/graph/ranks.h
new file mode 100644
index 0000000..627269f
--- /dev/null
+++ b/src/gtkext/graph/ranks.h
@@ -0,0 +1,63 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * ranks.h - prototypes pour le calcul de l'ordonnée des différents classements
+ *
+ * Copyright (C) 2013 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 _GTKEXT_GRAPH_RANKS_H
+#define _GTKEXT_GRAPH_RANKS_H
+
+
+#include <glib-object.h>
+
+
+
+#define G_TYPE_GRAPH_RANKS g_graph_ranks_get_type()
+#define G_GRAPH_RANKS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_graph_ranks_get_type(), GGraphRanks))
+#define G_IS_GRAPH_RANKS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_graph_ranks_get_type()))
+#define G_GRAPH_RANKS_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_graph_ranks_get_type(), GGraphRanksIface))
+#define G_GRAPH_RANKS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_GRAPH_RANKS, GGraphRanksClass))
+
+
+/* Calcul de l'ordonnée des différents classements (instance) */
+typedef struct _GGraphRanks GGraphRanks;
+
+/* Calcul de l'ordonnée des différents classements (classe) */
+typedef struct _GGraphRanksClass GGraphRanksClass;
+
+
+/* Indique le type définit par la GLib pour le calcul de l'ordonnée des classements. */
+GType g_graph_ranks_get_type(void);
+
+/* Prépare de quoi se définir au mieux les ordonnées des noeuds. */
+GGraphRanks *g_graph_ranks_new(unsigned int);
+
+/* Note une hauteur minimale requise pour un rang du classement. */
+void g_graph_ranks_set_min_height(GGraphRanks *, unsigned int, gint);
+
+/* Calcule l'ordonnée finale de chaque rang du classement. */
+void g_graph_ranks_compute_y_line(GGraphRanks *);
+
+/* Fournit la position verticale correspondant à un rang donné. */
+gint g_graph_ranks_get_y_for_rank(const GGraphRanks *, unsigned int);
+
+
+
+#endif /* _GTKEXT_GRAPH_RANKS_H */
diff --git a/src/gtkext/gtkgraphview.c b/src/gtkext/gtkgraphview.c
index aeb66ae..cb5c587 100644
--- a/src/gtkext/gtkgraphview.c
+++ b/src/gtkext/gtkgraphview.c
@@ -47,6 +47,8 @@ struct _GtkGraphView
GtkAllocation *allocs; /* Emplacements prévisibles */
size_t children_count; /* Taille de cette liste */
+ GGraphLayout *layout; /* Disposition en graphique */
+
GtkLinkRenderer **links; /* Liste des liens graphiques */
size_t links_count; /* Nombre de ces liens */
@@ -214,8 +216,10 @@ static void gtk_graph_view_size_request(GtkWidget *widget, GtkRequisition *requi
* On s'assure de ne couper aucun lien.
*/
+ /*
for (i = 0; i < view->links_count; i++)
gtk_link_renderer_size_request(view->links[i], requisition);
+ */
/**
* Traitement purement cosmétique : on ajoute la même bordure aux bords
@@ -333,12 +337,8 @@ static void gtk_graph_view_size_allocate(GtkWidget *widget, GtkAllocation *alloc
static gboolean gtk_graph_view_expose(GtkWidget *widget, GdkEventExpose *event, GtkGraphView *view)
{
- size_t i; /* Boucle de parcours */
-
- for (i = 0; i < view->links_count; i++)
- gtk_link_renderer_draw(view->links[i],
- GDK_DRAWABLE(widget->window),
- GTK_VIEW_PANEL(view)->gc);
+ if (view->layout != NULL)
+ g_graph_layout_draw(view->layout, GDK_DRAWABLE(widget->window), GTK_VIEW_PANEL(view)->gc);
return FALSE;
@@ -393,8 +393,22 @@ static void gtk_graph_view_define_main_address(GtkGraphView *view, vmpa_t addr)
view->allocs = (GtkAllocation *)calloc(view->children_count,
sizeof(GtkAllocation));
+
+ printf("Passage !!!\n");
+
+ /*
build_graph_view(view, g_binary_routine_get_basic_blocks(view->routine),
view->children, view->children_count);
+ */
+
+ view->layout = g_graph_layout_new(g_binary_routine_get_basic_blocks(view->routine),
+ view->children, view->children_count);
+
+ printf("----\n");
+
+ g_graph_layout_place(view->layout, view);
+
+ printf("--- done !!!\n");
break;
@@ -519,8 +533,8 @@ static void gtk_graph_view_cache_glance(GtkGraphView *view, cairo_t *cairo, cons
cairo_scale(cairo, scale, scale);
- for (i = 0; i < view->links_count; i++)
- _gtk_link_renderer_draw(view->links[i], cairo, false);
+ if (view->layout != NULL)
+ _g_graph_layout_draw(view->layout, cairo, false);
}
@@ -629,6 +643,7 @@ static void gtk_graph_view_reset(GtkGraphView *view)
view->start = VMPA_MAX;
view->end = VMPA_MAX;
+ /*
for (i = 0; i < view->links_count; i++)
gtk_object_destroy(GTK_OBJECT(view->links[i]));
@@ -640,6 +655,7 @@ static void gtk_graph_view_reset(GtkGraphView *view)
view->links_count = 0;
}
+ */
for (i = 0; i < view->children_count; i++)
gtk_widget_destroy(GTK_WIDGET(view->children[i]));
diff --git a/src/gui/panels/panel.c b/src/gui/panels/panel.c
index 6ccf14a..b178443 100644
--- a/src/gui/panels/panel.c
+++ b/src/gui/panels/panel.c
@@ -1078,7 +1078,6 @@ static void on_docking_to_main_panel(GtkDockStation *station, GtkWidget *widget,
{
- printf("docking.... %p\n", widget);
g_panel_item_undock(_welcome);