summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-07-04 12:39:01 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-07-04 12:39:01 (GMT)
commitade3ee4fd3b78e96deb08210838643969f2f6699 (patch)
tree09003a6f4ac00c09560de9ea9a91c125a7b14f68 /src/analysis
parenta0463dfa8fe232d01ea925668f393d7507fa787b (diff)
Updated the API for building symbol labels.
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/disass/output.c15
-rw-r--r--src/analysis/disass/routines.c16
-rw-r--r--src/analysis/routine.c164
-rw-r--r--src/analysis/routine.h3
4 files changed, 49 insertions, 149 deletions
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c
index 928ee16..b9b0f1f 100644
--- a/src/analysis/disass/output.c
+++ b/src/analysis/disass/output.c
@@ -83,6 +83,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
GLineGenerator *generator; /* Générateur de contenu ajouté*/
const vmpa2t *saddr; /* Adresse de symbole */
int compared; /* Bilan d'une comparaison */
+ char *label; /* Etiquette de symbole */
char *errmsg; /* Description d'une erreur */
SymbolType stype; /* Type de symbole trouvé */
vmpa2t intro_addr; /* Adresse de début de code */
@@ -212,12 +213,16 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
if (compared <= 0)
break;
- log_variadic_message(LMT_BAD_BINARY,
- _("Unable to find a proper location for symbol '%s' @ 0x%08x"),
- g_binary_symbol_get_label(symbol), get_phy_addr(saddr));
+ label = g_binary_symbol_get_label(symbol);
- asprintf(&errmsg, _("Unable to find a proper location for symbol '%s'"),
- g_binary_symbol_get_label(symbol));
+ if (label == NULL)
+ asprintf(&errmsg, _("Unable to find a proper location for symbol"));
+
+ else
+ {
+ asprintf(&errmsg, _("Unable to find a proper location for symbol '%s'"), label);
+ free(label);
+ }
g_arch_processor_add_error(proc, APE_LABEL, saddr, errmsg);
diff --git a/src/analysis/disass/routines.c b/src/analysis/disass/routines.c
index a0f756c..f04611f 100644
--- a/src/analysis/disass/routines.c
+++ b/src/analysis/disass/routines.c
@@ -24,6 +24,9 @@
#include "routines.h"
+#include <malloc.h>
+
+
#include "dragon.h"
#include "limit.h"
#include "loop.h"
@@ -336,6 +339,7 @@ void g_routines_study_handle_blocks(GRoutinesStudy *study, GBinRoutine *routine,
const mrange_t *range; /* Couverture d'une routine */
const vmpa2t *start; /* Adresse de départ */
const instr_coverage *coverage; /* Instructions couvertes */
+ char *label; /* Etiquette du symbole */
VMPA_BUFFER(loc); /* Position de la routine */
dragon_knight *knight; /* Complexité de code posée */
GBlockList *blocks; /* Liste de blocs basiques */
@@ -358,10 +362,18 @@ void g_routines_study_handle_blocks(GRoutinesStudy *study, GBinRoutine *routine,
*/
if (coverage == NULL)
{
+ label = g_binary_symbol_get_label(symbol);
+
vmpa2_to_string(start, MDS_UNDEFINED, loc, NULL);
- log_variadic_message(LMT_BAD_BINARY, _("Skipped out of bound routine '%s' @ %s"),
- g_binary_routine_get_name(routine), loc);
+ if (label == NULL)
+ log_variadic_message(LMT_BAD_BINARY, _("Skipped out of bound routine @ %s"), loc);
+
+ else
+ {
+ log_variadic_message(LMT_BAD_BINARY, _("Skipped out of bound routine '%s' @ %s"), label, loc);
+ free(label);
+ }
return;
diff --git a/src/analysis/routine.c b/src/analysis/routine.c
index 08160b8..43097cc 100644
--- a/src/analysis/routine.c
+++ b/src/analysis/routine.c
@@ -57,9 +57,6 @@ struct _GBinRoutine
GBinVariable **args; /* Arguments de la routines */
size_t args_count; /* Nombre d'arguments */
- char *cached_decl; /* Cache pour désignation #1 */
- char *cached_full_decl; /* Cache pour désignation #2 */
-
GBinVariable **locals; /* Variables locales du code */
size_t locals_count; /* Nombre de variables locales */
@@ -83,11 +80,8 @@ static void g_bin_routine_class_init(GBinRoutineClass *);
/* Initialise une instance représentation de routine. */
static void g_bin_routine_init(GBinRoutine *);
-/* Vide le cache des descriptions humaines. */
-static void g_binary_routine_reset_declarator(GBinRoutine *, bool);
-
/* Fournit une étiquette pour viser une routine. */
-static const char *g_binary_routine_get_label(const GBinRoutine *);
+static char *g_binary_routine_get_label(const GBinRoutine *);
@@ -263,8 +257,6 @@ void g_binary_routine_set_namespace(GBinRoutine *routine, GDataType *namespace,
routine->namespace = namespace;
routine->ns_sep = sep;
- g_binary_routine_reset_declarator(routine, false);
-
}
@@ -314,8 +306,6 @@ void g_binary_routine_set_name(GBinRoutine *routine, char *name)
routine->name = name;
- g_binary_routine_reset_declarator(routine, true);
-
}
@@ -358,8 +348,6 @@ void g_binary_routine_set_name_from_type(GBinRoutine *routine, GDataType *type)
routine->full_name = type;
- g_binary_routine_reset_declarator(routine, true);
-
}
@@ -377,7 +365,14 @@ void g_binary_routine_set_name_from_type(GBinRoutine *routine, GDataType *type)
GDataType *g_binary_routine_get_type_from_name(const GBinRoutine *routine)
{
- return routine->full_name;
+ GDataType *result; /* Type à retourner */
+
+ result = routine->full_name;
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ return result;
}
@@ -527,40 +522,9 @@ void g_binary_routine_remove_arg(GBinRoutine *routine, size_t index)
/******************************************************************************
* *
-* Paramètres : routine = routine à mettre à jour. *
-* full = indique la portée de la réinitialisation. *
-* *
-* Description : Vide le cache des descriptions humaines. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_binary_routine_reset_declarator(GBinRoutine *routine, bool full)
-{
- if (full && routine->cached_decl != NULL)
- {
- free(routine->cached_decl);
- routine->cached_decl = NULL;
- }
-
- if (routine->cached_full_decl != NULL)
- {
- free(routine->cached_full_decl);
- routine->cached_full_decl = NULL;
- }
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : routine = routine à mettre à jour. *
-* include = doit-on inclure les espaces de noms ? *
+* Paramètres : routine = routine à manipuler. *
* *
-* Description : Fournit le nom humain d'une routine. *
+* Description : Fournit une étiquette pour viser une routine. *
* *
* Retour : Désignation humainement lisible ou NULL si non définie. *
* *
@@ -568,98 +532,17 @@ static void g_binary_routine_reset_declarator(GBinRoutine *routine, bool full)
* *
******************************************************************************/
-const char *g_binary_routine_get_declarator(GBinRoutine *routine, bool include)
+static char *g_binary_routine_get_label(const GBinRoutine *routine)
{
- char *new; /* Nouvelle description */
- char *namespace; /* Groupe d'appartenance */
- size_t i; /* Boucle de parcours */
- char *typestr; /* Stockage de nom temporaire */
-
- if (routine->cached_decl == NULL)
- {
- if (routine->full_name != NULL)
- new = g_data_type_to_string(routine->full_name, include);
- else
- new = strdup(routine->name != NULL ? routine->name : "");
-
- if (routine->namespace != NULL)
- {
- namespace = g_data_type_to_string(routine->namespace, include);
-
- new = strprep(new, routine->ns_sep);
- new = strprep(new, namespace);
-
- free(namespace);
-
- }
-
- /* Mémorisation finale */
-
- routine->cached_decl = new;
-
- }
-
- if (include && routine->cached_full_decl == NULL)
- {
- /* Type de retour */
-
- if (routine->ret_type == NULL)
- new = strdup("??? ");
- else
- {
- new = g_data_type_to_string(routine->ret_type, include);
-
- if (!(g_data_type_is_pointer(routine->ret_type) || g_data_type_is_reference(routine->ret_type)))
- new = stradd(new, " ");
-
- }
-
- /* Nom de la routine */
-
- new = stradd(new, routine->cached_decl);
-
- /* Liste des arguments */
-
- new = stradd(new, "(");
-
- for (i = 0; i < routine->args_count; i++)
- {
- if (i > 0) new = stradd(new, ", ");
-
- typestr = g_binary_variable_to_string(routine->args[i], include);
- new = stradd(new, typestr);
- free(typestr);
-
- }
-
- new = stradd(new, ")");
-
- /* Mémorisation finale */
-
- routine->cached_full_decl = new;
-
- }
-
- return (include ? routine->cached_full_decl : routine->cached_decl);
-
-}
+ char *result; /* Etiquette à renvoyer */
+ if (routine->full_name != NULL)
+ result = g_data_type_to_string(routine->full_name, false);
-/******************************************************************************
-* *
-* Paramètres : routine = routine à manipuler. *
-* *
-* Description : Fournit une étiquette pour viser une routine. *
-* *
-* Retour : Désignation humainement lisible ou NULL si non définie. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ else
+ result = strdup(routine->name != NULL ? routine->name : "");
-static const char *g_binary_routine_get_label(const GBinRoutine *routine)
-{
- return g_binary_routine_get_declarator(routine, false);
+ return result;
}
@@ -874,7 +757,7 @@ char *g_binary_routine_to_string(const GBinRoutine *routine, bool include)
{
char *result; /* Chaîne à renvoyer */
char *namespace; /* Groupe d'appartenance */
- const char *name; /* Désignation de la routine */
+ char *name; /* Désignation de la routine */
size_t i; /* Boucle de parcours */
char *typestr; /* Stockage de nom temporaire */
@@ -883,12 +766,12 @@ char *g_binary_routine_to_string(const GBinRoutine *routine, bool include)
switch (routine->type)
{
case RTT_CONSTRUCTOR:
- result = strdup(g_binary_routine_get_name(routine));
+ result = g_binary_routine_get_label(routine);
result = stradd(result, "." /* FIXME */);
break;
case RTT_DESTRUCTOR:
- result = strdup(g_binary_routine_get_name(routine));
+ result = g_binary_routine_get_label(routine);
result = stradd(result, "::~");
break;
@@ -920,10 +803,13 @@ char *g_binary_routine_to_string(const GBinRoutine *routine, bool include)
}
- name = g_binary_routine_get_name(routine);
+ name = g_binary_routine_get_label(routine);
if (name != NULL)
+ {
result = stradd(result, name);
+ free(name);
+ }
/* Liste des arguments */
diff --git a/src/analysis/routine.h b/src/analysis/routine.h
index e1a3523..0a4917f 100644
--- a/src/analysis/routine.h
+++ b/src/analysis/routine.h
@@ -110,9 +110,6 @@ GBinVariable *g_binary_routine_get_arg(GBinRoutine *, size_t);
/* Retire un argument d'une routine. */
void g_binary_routine_remove_arg(GBinRoutine *, size_t);
-/* Fournit le nom humain d'une routine. */
-const char *g_binary_routine_get_declarator(GBinRoutine *, bool);
-
/* S'assure qu'une variable est bien associée à une routine. */
void g_binary_routine_register_if_needed(GBinRoutine *, size_t, bool);