From 83a9ca90e691614dd99d06b8391de216fc8ce727 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sun, 14 May 2017 23:20:42 +0200
Subject: Processed all the routines using the symbol list.

---
 ChangeLog                          | 12 +++++++++++
 src/analysis/disass/disassembler.c | 14 ++++++-------
 src/analysis/disass/limit.c        | 15 +++++--------
 src/analysis/disass/limit.h        |  2 +-
 src/analysis/disass/routines.c     | 43 +++++++++++++++++++++-----------------
 src/analysis/disass/routines.h     | 10 ++++-----
 src/format/symbol.c                |  3 +++
 7 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4b12204..f0cb810 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 17-05-14  Cyrille Bagard <nocbos@gmail.com>
 
+	* src/analysis/disass/disassembler.c:
+	* src/analysis/disass/limit.c:
+	* src/analysis/disass/limit.h:
+	* src/analysis/disass/routines.c:
+	* src/analysis/disass/routines.h:
+	Process all the routines using the symbol list.
+
+	* src/format/symbol.c:
+	Use g_binary_symbol_get_routine() to check to type of a symbol.
+
+17-05-14  Cyrille Bagard <nocbos@gmail.com>
+
 	* src/gtkext/gtkgraphdisplay.c:
 	Display a symbol instead of a routine in the graph view.
 
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 2f6b562..fc95a96 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -321,8 +321,8 @@ static void process_all_instructions(wgroup_id_t gid, GtkStatusStack *status, co
 static void process_all_routines(wgroup_id_t gid, GtkStatusStack *status, const char *msg, rtn_fallback_cb fallback, GArchProcessor *proc, GExeFormat *format)
 {
     GBinPortion *portions;                  /* Couche première de portions */
-    GBinRoutine **routines;                 /* Liste des routines trouvées */
-    size_t routines_count;                  /* Nombre de ces routines      */
+    GBinSymbol **symbols;                   /* Liste des symboles trouvés  */
+    size_t sym_count;                       /* Nombre de ces symboles      */
     guint runs_count;                       /* Qté d'exécutions parallèles */
     size_t run_size;                        /* Volume réparti par exécution*/
     GWorkQueue *queue;                      /* Gestionnaire de différés    */
@@ -334,26 +334,26 @@ static void process_all_routines(wgroup_id_t gid, GtkStatusStack *status, const
 
     portions = g_exe_format_get_portions(format);
 
-    routines = g_binary_format_get_routines(G_BIN_FORMAT(format), &routines_count);
+    symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &sym_count);
 
     runs_count = g_get_num_processors();
 
-    run_size = routines_count / runs_count;
+    run_size = sym_count / runs_count;
 
     queue = get_work_queue();
 
-    id = gtk_status_stack_add_activity(status, msg, routines_count);
+    id = gtk_status_stack_add_activity(status, msg, sym_count);
 
     for (i = 0; i < runs_count; i++)
     {
         begin = i * run_size;
 
         if ((i + 1) == runs_count)
-            end = routines_count;
+            end = sym_count;
         else
             end = begin + run_size;
 
-        study = g_routines_study_new(proc, portions, routines, routines_count,
+        study = g_routines_study_new(proc, portions, symbols, sym_count,
                                      begin, end, id, fallback);
 
         g_work_queue_schedule_work(queue, G_DELAYED_WORK(study), gid);
diff --git a/src/analysis/disass/limit.c b/src/analysis/disass/limit.c
index 2ae7ebb..df9f23c 100644
--- a/src/analysis/disass/limit.c
+++ b/src/analysis/disass/limit.c
@@ -28,7 +28,7 @@
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : routine  = routine dont les frontières sont à fixer.         *
-*                prev     = routine précédente dans les traitements.          *
+*                next     = adresse du prochain symbole présent.              *
 *                proc     = ensemble d'instructions désassemblées.            *
 *                portions = ensemble de couches binaires bornées.             *
 *                                                                             *
@@ -40,7 +40,7 @@
 *                                                                             *
 ******************************************************************************/
 
-void compute_routine_limit(GBinRoutine *routine, GBinRoutine *prev, GArchProcessor *proc, GBinPortion *portions)
+void compute_routine_limit(GBinRoutine *routine, const vmpa2t *next, GArchProcessor *proc, GBinPortion *portions)
 {
     const mrange_t *range;                  /* Emplacement courant         */
     vmpa2t addr;                            /* Adresse à conserver         */
@@ -70,14 +70,9 @@ void compute_routine_limit(GBinRoutine *routine, GBinRoutine *prev, GArchProcess
 
     g_object_unref(G_OBJECT(start));
 
-    /* Si on peut se raccrocher à la routine suivante... */
-    if (prev != NULL)
-    {
-        range = g_binary_routine_get_range(prev);
-
-        diff = compute_vmpa_diff(&addr, get_mrange_addr(range));
-
-    }
+    /* Si on peut se raccrocher à la prochaine adresse... */
+    if (next != NULL)
+        diff = compute_vmpa_diff(&addr, next);
 
     /* Sinon on va jusqu'à la fin de la zone ! */
     else
diff --git a/src/analysis/disass/limit.h b/src/analysis/disass/limit.h
index 9810ab8..c26b450 100644
--- a/src/analysis/disass/limit.h
+++ b/src/analysis/disass/limit.h
@@ -32,7 +32,7 @@
 
 
 /* S'assure qu'une routine est bien bornée. */
-void compute_routine_limit(GBinRoutine *, GBinRoutine *, GArchProcessor *, GBinPortion *);
+void compute_routine_limit(GBinRoutine *, const vmpa2t *, GArchProcessor *, GBinPortion *);
 
 
 
diff --git a/src/analysis/disass/routines.c b/src/analysis/disass/routines.c
index 32a2259..1150f08 100644
--- a/src/analysis/disass/routines.c
+++ b/src/analysis/disass/routines.c
@@ -41,7 +41,7 @@ struct _GRoutinesStudy
 
     GBinPortion *portions;                  /* Couches de binaire bornées  */
 
-    GBinRoutine **routines;                 /* Liste de routines à traiter */
+    GBinSymbol **symbols;                   /* Liste de symboles à traiter */
     size_t count;                           /* Taille de cette liste       */
 
     rtn_fallback_cb fallback;               /* Routine de traitement finale*/
@@ -175,7 +175,7 @@ static void g_routines_study_finalize(GRoutinesStudy *study)
 *                                                                             *
 *  Paramètres  : proc     = ensemble d'instructions désassemblées.            *
 *                portions = ensemble de couches binaires bornées.             *
-*                routines = prototypes existants à insérer.                   *
+*                symbols  = liste de symboles à parcourir.                    *
 *                count    = quantité de ces prototypes.                       *
 *                begin    = point de départ du parcours de liste.             *
 *                end      = point d'arrivée exclu du parcours.                *
@@ -190,7 +190,7 @@ static void g_routines_study_finalize(GRoutinesStudy *study)
 *                                                                             *
 ******************************************************************************/
 
-GRoutinesStudy *g_routines_study_new(GArchProcessor *proc, GBinPortion *portions, GBinRoutine **routines, size_t count, size_t begin, size_t end, activity_id_t id, rtn_fallback_cb fallback)
+GRoutinesStudy *g_routines_study_new(GArchProcessor *proc, GBinPortion *portions, GBinSymbol **symbols, size_t count, size_t begin, size_t end, activity_id_t id, rtn_fallback_cb fallback)
 {
     GRoutinesStudy *result;                /* Tâche à retourner           */
 
@@ -201,7 +201,7 @@ GRoutinesStudy *g_routines_study_new(GArchProcessor *proc, GBinPortion *portions
     result->portions = portions;
     g_object_ref(G_OBJECT(portions));
 
-    result->routines = routines;
+    result->symbols = symbols;
     result->count = count;
 
     result->fallback = fallback;
@@ -231,10 +231,14 @@ GRoutinesStudy *g_routines_study_new(GArchProcessor *proc, GBinPortion *portions
 static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *status)
 {
     size_t i;                               /* Boucle de parcours          */
+    GBinRoutine *routine;                   /* Routine à traiter           */
 
     for (i = study->begin; i < study->end; i++)
     {
-        study->fallback(study, i);
+        routine = g_binary_symbol_get_routine(study->symbols[i]);
+
+        if (routine != NULL)
+            study->fallback(study, routine, i);
 
         gtk_status_stack_update_activity_value(status, study->id, 1);
 
@@ -245,8 +249,9 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : study = étude de routines à mener.                           *
-*                index = indice de l'insruction visée.                        *
+*  Paramètres  : study   = étude de routines à mener.                         *
+*                routine = routine à traiter.                                 *
+*                index   = indice de l'insruction visée.                      *
 *                                                                             *
 *  Description : Détermine si besoin est les bornes des routines.             *
 *                                                                             *
@@ -256,15 +261,17 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat
 *                                                                             *
 ******************************************************************************/
 
-void g_routines_study_compute_limits(GRoutinesStudy *study, size_t index)
+void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine, size_t index)
 {
-    GBinRoutine *routine;                   /* Routine à traiter           */
-    GBinRoutine *next;                      /* Routine suivante éventuelle */
-
-    routine = study->routines[index];
+    const mrange_t *range;                  /* Zone du symbole suivant     */
+    const vmpa2t *next;                     /* Début de la zone suivante   */
 
     if ((index + 1) < study->count)
-        next = study->routines[index + 1];
+    {
+        range = g_binary_symbol_get_range(study->symbols[index + 1]);
+        next = get_mrange_addr(range);
+    }
+
     else
         next = NULL;
 
@@ -275,8 +282,9 @@ void g_routines_study_compute_limits(GRoutinesStudy *study, size_t index)
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : study = étude de routines à mener.                           *
-*                index = indice de l'insruction visée.                        *
+*  Paramètres  : study   = étude de routines à mener.                         *
+*                routine = routine à traiter.                                 *
+*                index   = indice de l'insruction visée.                      *
 *                                                                             *
 *  Description : Procède au traitement des blocs de routines.                 *
 *                                                                             *
@@ -286,17 +294,14 @@ void g_routines_study_compute_limits(GRoutinesStudy *study, size_t index)
 *                                                                             *
 ******************************************************************************/
 
-void g_routines_study_handle_blocks(GRoutinesStudy *study, size_t index)
+void g_routines_study_handle_blocks(GRoutinesStudy *study, GBinRoutine *routine, size_t index)
 {
-    GBinRoutine *routine;                   /* Routine à traiter           */
     const mrange_t *range;                  /* Couverture d'une routine    */
     const vmpa2t *start;                    /* Adresse de départ           */
     const instr_coverage *coverage;         /* Instructions couvertes      */
     dragon_knight *knight;                  /* Complexité de code posée    */
     GBlockList *blocks;                     /* Liste de blocs basiques     */
 
-    routine = study->routines[index];
-
     /* Préparatifs communs */
 
     range = g_binary_routine_get_range(routine);
diff --git a/src/analysis/disass/routines.h b/src/analysis/disass/routines.h
index 2821966..dc81bb1 100644
--- a/src/analysis/disass/routines.h
+++ b/src/analysis/disass/routines.h
@@ -25,9 +25,9 @@
 #define _ANALYSIS_DISASS_ROUTINES_H
 
 
-#include "../routine.h"
 #include "../../arch/processor.h"
 #include "../../format/executable.h"
+#include "../../format/symbol.h"
 #include "../../gtkext/gtkstatusstack.h"
 
 
@@ -48,17 +48,17 @@ typedef struct _GRoutinesStudyClass GRoutinesStudyClass;
 
 
 /* Assure l'étude des routines en différé. */
-typedef void (* rtn_fallback_cb) (GRoutinesStudy *, size_t);
+typedef void (* rtn_fallback_cb) (GRoutinesStudy *, GBinRoutine *, size_t);
 
 
 /* Crée une tâche d'étude de routines différée. */
-GRoutinesStudy *g_routines_study_new(GArchProcessor *, GBinPortion *, GBinRoutine **, size_t, size_t, size_t, activity_id_t, rtn_fallback_cb);
+GRoutinesStudy *g_routines_study_new(GArchProcessor *, GBinPortion *, GBinSymbol **, size_t, size_t, size_t, activity_id_t, rtn_fallback_cb);
 
 /* Détermine si besoin est les bornes des routines. */
-void g_routines_study_compute_limits(GRoutinesStudy *, size_t);
+void g_routines_study_compute_limits(GRoutinesStudy *, GBinRoutine *, size_t);
 
 /* Procède au traitement des blocs de routines. */
-void g_routines_study_handle_blocks(GRoutinesStudy *, size_t);
+void g_routines_study_handle_blocks(GRoutinesStudy *, GBinRoutine *, size_t);
 
 
 
diff --git a/src/format/symbol.c b/src/format/symbol.c
index 2611a40..ba0c327 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -500,6 +500,9 @@ GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol)
 
     /* TODO : ref() */
 
+    if (symbol->type != STP_ROUTINE && symbol->type != STP_ENTRY_POINT)
+        return NULL;
+
     return symbol->extra.routine;
 
 }
-- 
cgit v0.11.2-87-g4458