summaryrefslogtreecommitdiff
path: root/src/analysis/disass
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-03-18 23:18:26 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-03-18 23:18:26 (GMT)
commit4cef477cbdfd61a28ed6531d1e91d5a330a67704 (patch)
tree1b4708f624e0f3bdb26403ab06ac9689cf4cf583 /src/analysis/disass
parent5c1636199a06965c549f748014d582dcb85ba7df (diff)
Computed limits for all routines according to existing symbols.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@491 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/disass')
-rw-r--r--src/analysis/disass/area.c74
-rw-r--r--src/analysis/disass/disassembler.c23
-rw-r--r--src/analysis/disass/limit.c25
3 files changed, 121 insertions, 1 deletions
diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c
index 916918e..90738be 100644
--- a/src/analysis/disass/area.c
+++ b/src/analysis/disass/area.c
@@ -71,6 +71,11 @@ static bool mark_range_in_mem_area_as_processed(mem_area *, phys_t, phys_t, GArc
+/* S'assure de la présence d'un début de routine à un point. */
+static void update_address_as_routine(GBinFormat *, const vmpa2t *);
+
+
+
/* Procède au désassemblage d'un contenu binaire non exécutable. */
static void load_data_from_mem_area(mem_area *, mem_area *, size_t, const GLoadedBinary *, GProcContext *, const vmpa2t *, status_blob_info *);
@@ -377,6 +382,70 @@ static bool mark_range_in_mem_area_as_processed(mem_area *area, phys_t start, ph
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = format binaire en cours de traitement. *
+* addr = adresse d'une instruction présentée comme première. *
+* *
+* Description : S'assure de la présence d'un début de routine à un point. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void update_address_as_routine(GBinFormat *format, const vmpa2t *addr)
+{
+ GBinSymbol *symbol; /* Symbole présent ou créé */
+ phys_t offset; /* Décallage trouvé */
+ bool found; /* Détection de symbole */
+ SymbolType sym_type; /* Type de symbole en place */
+ bool wrong_type; /* Analyse plus fine de ce type*/
+ mrange_t range; /* Etendue du symbole à créer */
+ VMPA_BUFFER(loc); /* Traduction de l'adresse */
+ char name[5 + VMPA_MAX_LEN]; /* Nom de symbole nouveau */
+ GBinRoutine *routine; /* Nouvelle routine trouvée */
+
+ found = g_binary_format_resolve_symbol(format, addr, &symbol, &offset);
+
+ if (found)
+ {
+ sym_type = g_binary_symbol_get_target_type(symbol);
+ wrong_type = (sym_type != STP_ROUTINE && sym_type != STP_ENTRY_POINT);
+ }
+
+ if (!found || (found && offset == 0 && wrong_type))
+ {
+ init_mrange(&range, addr, 0);
+
+ vmpa2_virt_to_string(addr, MDS_UNDEFINED, loc, NULL);
+ snprintf(name, sizeof(name), "ZZZ_%s", loc + 2);
+
+ routine = g_binary_routine_new();
+ g_binary_routine_set_name(routine, strdup(name));
+
+ g_binary_routine_set_range(routine, &range);
+
+ if (!found)
+ {
+ symbol = g_binary_symbol_new(STP_ROUTINE, NULL, ~0);
+ g_binary_symbol_attach_routine(symbol, routine);
+ g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ }
+ else _g_binary_symbol_attach_routine(symbol, routine, STP_ROUTINE);
+
+ }
+
+}
+
+
/******************************************************************************
* *
* Paramètres : area = aire représentant à contenu à parcourir. *
@@ -489,6 +558,11 @@ bool load_code_from_mem_area(mem_area **list, size_t *count, size_t *index, cons
g_arch_instruction_set_range(instr, &range);
+ /* Enregistrement d'un éventuel début de routine */
+
+ if (g_arch_instruction_get_flags(instr) & AIF_ROUTINE_START)
+ update_address_as_routine(format, &prev);
+
/* Eventuel renvoi vers d'autres adresses */
g_arch_instruction_call_hook(instr, IPH_LINK, ctx, format);
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 37e6996..4b976c3 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -29,7 +29,7 @@
#include <string.h>
-#include <i18n.h> /////
+#include <i18n.h>
#include "fetch.h"
@@ -299,6 +299,27 @@ G_BIN_FORMAT(g_loaded_binary_get_format(disass->binary)
+ /* Troisième étape */
+
+ routines = g_binary_format_get_routines(G_BIN_FORMAT(disass->format), &routines_count);
+
+
+
+
+ //id = gtk_extended_status_bar_push(statusbar, _("Finding remaining limits..."), true);
+
+ //qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_rcompare);
+
+ limit_all_routines(disass->format, routines, routines_count, statusbar, id);
+
+ //gtk_extended_status_bar_remove(statusbar, id);
+
+ //run_plugins_on_binary(disass->binary, PGA_BINARY_BOUNDED, true);
+
+
+
+
+
/* Septième étape */
//id = gtk_extended_status_bar_push(statusbar, _("Printing disassembled code..."), true);
diff --git a/src/analysis/disass/limit.c b/src/analysis/disass/limit.c
index bb2c865..3810978 100644
--- a/src/analysis/disass/limit.c
+++ b/src/analysis/disass/limit.c
@@ -128,4 +128,29 @@ void limit_all_routines(GExeFormat *format, GBinRoutine **routines, size_t count
if (exe_ranges != NULL)
free(exe_ranges);
+
+
+
+ do
+ {
+ const mrange_t *_range;
+ vmpa2t _end;
+
+ printf("LIMIT == %zu routines\n", count);
+
+ for (i = 0; i < count; i++)
+ {
+ _range = g_binary_routine_get_range(routines[i]);
+ compute_mrange_end_addr(_range, &_end);
+
+ printf(" <LIMIT> 0x%08x <-> 0x%08x '%s'\n",
+ (unsigned int)((get_mrange_addr(_range))->virtual),
+ (unsigned int)_end.virtual,
+ g_binary_routine_to_string(routines[i]));
+
+ }
+
+ } while (0);
+
+
}