summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-01-13 22:37:31 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-01-13 22:37:31 (GMT)
commit23b9c6e68bbe5f0531f9a9408c2deb9f897701dc (patch)
tree3804d6c21c9cd5e291cb8c7853607cdda992d125 /src/analysis
parenta6975c1d754a1ba5bfb9e23f0b26692c746e6f9c (diff)
Created a real iterator for symbols.
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/disass/disassembler.c19
-rw-r--r--src/analysis/disass/output.c48
-rw-r--r--src/analysis/disass/routines.c42
-rw-r--r--src/analysis/disass/routines.h4
4 files changed, 73 insertions, 40 deletions
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index bb69c0e..ae60602 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -92,7 +92,7 @@ static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *, GBufferCa
static void process_all_instructions(wgroup_id_t, GtkStatusStack *, const char *, ins_fallback_cb, GArchProcessor *, GProcContext *, GExeFormat *);
/* Opère sur toutes les routines. */
-static void process_all_routines(wgroup_id_t, GtkStatusStack *, const char *, rtn_fallback_cb, GArchProcessor *, GExeFormat *);
+static void process_all_routines(wgroup_id_t, GtkStatusStack *, const char *, rtn_fallback_cb, GArchProcessor *, GBinFormat *);
/* Assure le désassemblage en différé. */
static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkStatusStack *);
@@ -318,10 +318,9 @@ 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)
+static void process_all_routines(wgroup_id_t gid, GtkStatusStack *status, const char *msg, rtn_fallback_cb fallback, GArchProcessor *proc, GBinFormat *format)
{
GBinPortion *portions; /* Couche première de portions */
- 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*/
@@ -332,9 +331,11 @@ static void process_all_routines(wgroup_id_t gid, GtkStatusStack *status, const
size_t end; /* Fin d'un bloc de traitement */
GRoutinesStudy *study; /* Tâche d'étude à programmer */
- portions = g_exe_format_get_portions(format);
+ portions = g_exe_format_get_portions(G_EXE_FORMAT(format));
- symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &sym_count);
+ g_binary_format_lock_symbols_rd(format);
+
+ sym_count = g_binary_format_count_symbols(format);
runs_count = g_get_num_processors();
@@ -353,7 +354,7 @@ static void process_all_routines(wgroup_id_t gid, GtkStatusStack *status, const
else
end = begin + run_size;
- study = g_routines_study_new(proc, portions, symbols, sym_count,
+ study = g_routines_study_new(proc, format, portions,
begin, end, id, fallback);
g_work_queue_schedule_work(queue, G_DELAYED_WORK(study), gid);
@@ -364,6 +365,8 @@ static void process_all_routines(wgroup_id_t gid, GtkStatusStack *status, const
gtk_status_stack_remove_activity(status, id);
+ g_binary_format_unlock_symbols_rd(format);
+
g_object_unref(G_OBJECT(portions));
}
@@ -471,7 +474,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkStatus
process_all_routines(gid, status,
_("Finding remaining limits..."),
- g_routines_study_compute_limits, proc, disass->format);
+ g_routines_study_compute_limits, proc, G_BIN_FORMAT(disass->format));
@@ -525,7 +528,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkStatus
#if 1
process_all_routines(gid, status,
_("Control-flow analysis for routines..."),
- g_routines_study_handle_blocks, proc, disass->format);
+ g_routines_study_handle_blocks, proc, G_BIN_FORMAT(disass->format));
#endif
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c
index 3cc282a..19c7de9 100644
--- a/src/analysis/disass/output.c
+++ b/src/analysis/disass/output.c
@@ -32,6 +32,7 @@
#include "../../core/logs.h"
#include "../../format/format.h"
+#include "../../format/symiter.h"
#include "../../glibext/generators/rborder.h"
@@ -60,9 +61,8 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
GBinPortion **portions; /* Morceaux d'encadrement */
size_t portions_count; /* Taille de cette liste */
size_t portion_index; /* Prochaine portion à traiter */
- GBinSymbol **symbols; /* Symboles à représenter */
- size_t sym_count; /* Qté de symboles présents */
- size_t sym_index; /* Prochain symbole non traité */
+ sym_iter_t *siter; /* Parcours des symboles */
+ GBinSymbol *symbol; /* Symbole manipulé */
MemoryDataSize msize; /* Taille du bus d'adresses */
const GBinContent *content; /* Contenu binaire global */
size_t count; /* Nombre total d'instructions */
@@ -127,8 +127,9 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
g_object_unref(G_OBJECT(root));
- symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &sym_count);
- sym_index = 0;
+ siter = create_symbol_iterator(G_BIN_FORMAT(format), 0);
+
+ symbol = get_symbol_iterator_current(siter);
msize = g_arch_processor_get_memory_size(proc);
@@ -205,21 +206,24 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
/* Début d'un nouveau symbole ? */
- if (sym_index == sym_count)
+ if (symbol == NULL)
compared = -1;
else
{
iaddr = get_mrange_addr(g_arch_instruction_get_range(instr));
- for ( ; sym_index < sym_count; sym_index++)
+ for ( ; symbol != NULL; symbol = get_symbol_iterator_next(siter))
{
- sym_status = g_binary_symbol_get_status(symbols[sym_index]);
+ sym_status = g_binary_symbol_get_status(symbol);
if (sym_status == SSS_IMPORTED)
+ {
+ g_object_unref(G_OBJECT(symbol));
continue;
+ }
- saddr = get_mrange_addr(g_binary_symbol_get_range(symbols[sym_index]));
+ saddr = get_mrange_addr(g_binary_symbol_get_range(symbol));
compared = cmp_vmpa(iaddr, saddr);
@@ -228,10 +232,10 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
log_variadic_message(LMT_BAD_BINARY,
_("Unable to find a proper location for symbol '%s' @ 0x%08x"),
- g_binary_symbol_get_label(symbols[sym_index]), get_phy_addr(saddr));
+ g_binary_symbol_get_label(symbol), get_phy_addr(saddr));
asprintf(&errmsg, _("Unable to find a proper location for symbol '%s'"),
- g_binary_symbol_get_label(symbols[sym_index]));
+ g_binary_symbol_get_label(symbol));
g_arch_processor_add_error(proc, APE_LABEL, saddr, errmsg);
@@ -239,22 +243,24 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
_missing++;
+ g_object_unref(G_OBJECT(symbol));
+
}
- if (sym_index == sym_count)
+ if (symbol == NULL)
goto no_more_symbol_finally;
if (compared == 0)
{
/* Coupure pour une nouvelle routine */
- stype = g_binary_symbol_get_target_type(symbols[sym_index]);
+ stype = g_binary_symbol_get_target_type(symbol);
if (stype == STP_ROUTINE || stype == STP_ENTRY_POINT)
{
/* Impression de la marque de début */
- copy_vmpa(&intro_addr, get_mrange_addr(g_binary_symbol_get_range(symbols[sym_index])));
+ copy_vmpa(&intro_addr, get_mrange_addr(g_binary_symbol_get_range(symbol)));
border = g_border_generator_new(lang, &intro_addr, true, msize);
g_buffer_cache_append(cache, G_LINE_GENERATOR(border), BLF_NONE);
@@ -273,7 +279,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
* est nécessaire pour imprimer cette marque de clôture.
*/
- compute_mrange_end_addr(g_binary_symbol_get_range(symbols[sym_index]), &outro_addr);
+ compute_mrange_end_addr(g_binary_symbol_get_range(symbol), &outro_addr);
expect_outro = true;
@@ -281,7 +287,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
/* Etiquette ? */
- generator = g_binary_symbol_produce_label(symbols[sym_index]);
+ generator = g_binary_symbol_produce_label(symbol);
if (generator != NULL)
g_buffer_cache_append(cache, generator, BLF_NONE);
@@ -298,7 +304,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
{
/* Point d'entrée ? */
- if (g_binary_symbol_get_target_type(symbols[sym_index]) == STP_ENTRY_POINT)
+ if (g_binary_symbol_get_target_type(symbol) == STP_ENTRY_POINT)
flags |= BLF_ENTRYPOINT;
/**
@@ -311,7 +317,8 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
flags |= BLF_WIDTH_MANAGER;
- sym_index++;
+ g_object_unref(G_OBJECT(symbol));
+ symbol = get_symbol_iterator_next(siter);
}
@@ -369,6 +376,11 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
g_object_unref(G_OBJECT(content));
+ if (symbol != NULL)
+ g_object_unref(G_OBJECT(symbol));
+
+ delete_symbol_iterator(siter);
+
if (portions != NULL)
free(portions);
diff --git a/src/analysis/disass/routines.c b/src/analysis/disass/routines.c
index bc4247c..661e136 100644
--- a/src/analysis/disass/routines.c
+++ b/src/analysis/disass/routines.c
@@ -38,12 +38,11 @@ struct _GRoutinesStudy
{
GDelayedWork parent; /* A laisser en premier */
- GArchProcessor *proc; /* Processeurs avec ses instr. */
-
+ GArchProcessor *proc; /* Processeur avec ses instr. */
+ GBinFormat *format; /* Format de fichier manipulé */
GBinPortion *portions; /* Couches de binaire bornées */
- GBinSymbol **symbols; /* Liste de symboles à traiter */
- size_t count; /* Taille de cette liste */
+ size_t count; /* Nombre de symboles à traiter*/
rtn_fallback_cb fallback; /* Routine de traitement finale*/
size_t begin; /* Point de départ du parcours */
@@ -148,6 +147,11 @@ static void g_routines_study_dispose(GRoutinesStudy *study)
{
g_object_unref(G_OBJECT(study->portions));
+ g_binary_format_unlock_symbols_rd(study->format);
+
+ g_object_unref(G_OBJECT(study->format));
+ g_object_unref(G_OBJECT(study->proc));
+
G_OBJECT_CLASS(g_routines_study_parent_class)->dispose(G_OBJECT(study));
}
@@ -175,9 +179,8 @@ static void g_routines_study_finalize(GRoutinesStudy *study)
/******************************************************************************
* *
* Paramètres : proc = ensemble d'instructions désassemblées. *
+* format = format de fichier à manipuler. *
* portions = ensemble de couches binaires bornées. *
-* 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. *
* id = identifiant du message affiché à l'utilisateur. *
@@ -191,19 +194,24 @@ static void g_routines_study_finalize(GRoutinesStudy *study)
* *
******************************************************************************/
-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 *g_routines_study_new(GArchProcessor *proc, GBinFormat *format, GBinPortion *portions, size_t begin, size_t end, activity_id_t id, rtn_fallback_cb fallback)
{
GRoutinesStudy *result; /* Tâche à retourner */
result = g_object_new(G_TYPE_ROUTINES_STUDY, NULL);
result->proc = proc;
+ g_object_ref(G_OBJECT(proc));
+
+ result->format = format;
+ g_object_ref(G_OBJECT(format));
result->portions = portions;
g_object_ref(G_OBJECT(portions));
- result->symbols = symbols;
- result->count = count;
+ g_binary_format_lock_symbols_rd(format);
+
+ result->count = g_binary_format_count_symbols(format);
result->fallback = fallback;
result->begin = begin;
@@ -238,12 +246,12 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat
for (i = study->begin; i < study->end; i++)
{
- symbol = study->symbols[i];
+ symbol = g_binary_format_get_symbol(study->format, i);
sym_status = g_binary_symbol_get_status(symbol);
if (sym_status == SSS_IMPORTED)
- continue;
+ goto grsp_next;
type = g_binary_symbol_get_target_type(symbol);
@@ -252,6 +260,10 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat
gtk_status_stack_update_activity_value(status, study->id, 1);
+ grsp_next:
+
+ g_object_unref(G_OBJECT(symbol));
+
}
}
@@ -274,6 +286,7 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat
void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine, size_t index)
{
GBinSymbol *symbol; /* Version alternative */
+ GBinSymbol *next_symbol; /* Eventuel symbole suivant */
const mrange_t *range; /* Zone du symbole suivant */
const vmpa2t *next; /* Début de la zone suivante */
@@ -281,8 +294,13 @@ void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine
if ((index + 1) < study->count)
{
- range = g_binary_symbol_get_range(study->symbols[index + 1]);
+ next_symbol = g_binary_format_get_symbol(study->format, index + 1);
+
+ range = g_binary_symbol_get_range(next_symbol);
next = get_mrange_addr(range);
+
+ g_object_unref(G_OBJECT(next_symbol));
+
}
else
diff --git a/src/analysis/disass/routines.h b/src/analysis/disass/routines.h
index 4b3efa9..db8144d 100644
--- a/src/analysis/disass/routines.h
+++ b/src/analysis/disass/routines.h
@@ -28,7 +28,7 @@
#include "../routine.h"
#include "../../arch/processor.h"
#include "../../format/executable.h"
-#include "../../format/symbol.h"
+#include "../../format/format.h"
#include "../../gtkext/gtkstatusstack.h"
@@ -53,7 +53,7 @@ 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 *, GBinSymbol **, size_t, size_t, size_t, activity_id_t, rtn_fallback_cb);
+GRoutinesStudy *g_routines_study_new(GArchProcessor *, GBinFormat *, GBinPortion *, 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 *, GBinRoutine *, size_t);