From 92737ef0fa002248b0a656ca441ad5f018a12cf3 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Thu, 30 May 2019 13:03:07 +0200
Subject: Provided instruction iterators for basic blocks.

---
 src/analysis/disass/block.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 src/analysis/disass/block.h |  3 +++
 2 files changed, 49 insertions(+)

diff --git a/src/analysis/disass/block.c b/src/analysis/disass/block.c
index 8da671b..8cdbc8f 100644
--- a/src/analysis/disass/block.c
+++ b/src/analysis/disass/block.c
@@ -875,3 +875,49 @@ void g_basic_block_get_boundaries(const GBasicBlock *block, GArchInstruction **f
     }
 
 }
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : block = bloc d'instructions à consulter.                     *
+*                proc  = processeur contenant l'ensemble des instructions.    *
+*                                                                             *
+*  Description : Fournit un itérateur d'instructions limité au bloc basique.  *
+*                                                                             *
+*  Retour      : Itérateur mis en place ou NULL en cas d'échec.               *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+instr_iter_t *g_basic_block_get_iterator(const GBasicBlock *block, GArchProcessor *proc)
+{
+    instr_iter_t *result;                   /* Itérateur à renvoyer        */
+    const mrange_t *first_range;            /* Emplacement d'instruction #1*/
+    const vmpa2t *first_addr;               /* Point de départ associé     */
+    const mrange_t *last_range;             /* Emplacement d'instruction #2*/
+    phys_t length;                          /* Taille de la couverture     */
+    mrange_t range;                         /* Couverture du bloc          */
+
+    first_range = g_arch_instruction_get_range(block->first);
+
+    first_addr = get_mrange_addr(first_range);
+
+    result = g_arch_processor_get_iter_from_address(proc, first_addr);
+
+    if (result != NULL)
+    {
+        last_range = g_arch_instruction_get_range(block->last);
+
+        length = compute_vmpa_diff(first_addr, get_mrange_addr(last_range));
+        length += get_mrange_length(last_range);
+
+        init_mrange(&range, first_addr, length);
+
+        restrict_instruction_iterator(result, &range);
+
+    }
+
+    return result;
+
+}
diff --git a/src/analysis/disass/block.h b/src/analysis/disass/block.h
index a7c157d..f622b61 100644
--- a/src/analysis/disass/block.h
+++ b/src/analysis/disass/block.h
@@ -62,6 +62,9 @@ GCodeBlock *g_basic_block_new(GLoadedBinary *, GArchInstruction *, GArchInstruct
 /* Fournit les instructions limites d'un bloc basique. */
 void g_basic_block_get_boundaries(const GBasicBlock *, GArchInstruction **, GArchInstruction **);
 
+/* Fournit un itérateur d'instructions limité au bloc basique. */
+instr_iter_t *g_basic_block_get_iterator(const GBasicBlock *, GArchProcessor *);
+
 
 
 #endif  /* _ANALYSIS_DISASS_BLOCK_H */
-- 
cgit v0.11.2-87-g4458