summaryrefslogtreecommitdiff
path: root/src/format/symbol.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-07-12 22:26:49 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-07-12 22:26:49 (GMT)
commit7e1c5ac72a317d39952843239023c0fa506f2322 (patch)
tree206b4f7ca4165c22b796d90e3343f677296b0857 /src/format/symbol.c
parent254254db8c09eb4b4f8523e73551c13ec281d194 (diff)
Cleaned the code handling binary symbols.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@548 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/symbol.c')
-rw-r--r--src/format/symbol.c157
1 files changed, 71 insertions, 86 deletions
diff --git a/src/format/symbol.c b/src/format/symbol.c
index f676e9e..898f00d 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -36,13 +36,8 @@ struct _GBinSymbol
SymbolType type; /* Type du symbole */
- const char *name; /* Désignation du symbole */
- vmpa_t address; /* Adresse du symbole */
-
char *alt; /* Nom alternatif */
- char *tmp_label; /* REMME */
-
union
{
GArchInstruction *instr; /* Instruction correspondante */
@@ -68,6 +63,12 @@ static void g_binary_symbol_class_init(GBinSymbolClass *);
/* Initialise une instance de symbole d'exécutable. */
static void g_binary_symbol_init(GBinSymbol *);
+/* Supprime toutes les références externes. */
+static void g_binary_symbol_dispose(GBinSymbol *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_binary_symbol_finalize(GBinSymbol *);
+
/* Indique le type défini pour un symbole d'exécutable. */
@@ -88,6 +89,12 @@ G_DEFINE_TYPE(GBinSymbol, g_binary_symbol, G_TYPE_OBJECT);
static void g_binary_symbol_class_init(GBinSymbolClass *klass)
{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_symbol_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_binary_symbol_finalize;
}
@@ -112,9 +119,49 @@ static void g_binary_symbol_init(GBinSymbol *symbol)
/******************************************************************************
* *
-* Paramètres : type = type de symbole à créer. *
-* name = désignation humaine du symbole. *
-* address = adresse associée au symbole. *
+* Paramètres : symbol = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_symbol_dispose(GBinSymbol *symbol)
+{
+ /* TODO... */
+
+ G_OBJECT_CLASS(g_binary_symbol_parent_class)->dispose(G_OBJECT(symbol));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : symbol = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_symbol_finalize(GBinSymbol *symbol)
+{
+ free(symbol->alt);
+
+ G_OBJECT_CLASS(g_binary_symbol_parent_class)->finalize(G_OBJECT(symbol));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de symbole à créer. *
* *
* Description : Crée un nouveau symbole d'exécutable. *
* *
@@ -124,15 +171,13 @@ static void g_binary_symbol_init(GBinSymbol *symbol)
* *
******************************************************************************/
-GBinSymbol *g_binary_symbol_new(SymbolType type, const char *name, vmpa_t address)
+GBinSymbol *g_binary_symbol_new(SymbolType type)
{
GBinSymbol *result; /* Nouveau symbole à renvoyer */
result = g_object_new(G_TYPE_BIN_SYMBOL, NULL);
result->type = type;
- result->name = name;
- result->address = address;
return result;
@@ -214,17 +259,22 @@ SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol)
* *
* Paramètres : symbol = symbole à venir consulter. *
* *
-* Description : Fournit la description humaine du symbole. *
+* Description : Fournit un étiquette pour viser un symbole. *
* *
-* Retour : Nom du symbole sous forme de chaîne de caractères. *
+* Retour : Chaîne de caractères renvoyant au symbole. *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *g_binary_symbol_to_string(const GBinSymbol *symbol)
+const char *g_binary_symbol_get_label(const GBinSymbol *symbol)
{
- const char *result; /* Désignation à retourner */
+ const char *result; /* Etiquette à retourner */
+
+ if (symbol->alt != NULL)
+ return symbol->alt;
+
+ result = NULL;
switch (symbol->type)
{
@@ -235,7 +285,7 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol)
break;
default:
- result = (symbol->alt != NULL ? symbol->alt : symbol->name);
+ result = NULL;
break;
}
@@ -245,67 +295,22 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol)
}
-vmpa_t g_binary_symbol_get_address(const GBinSymbol *symbol)
-{
-
- return 0;
-
-}
-
-
-
-
-
-
-
-
-
-void g_binary_symbol_set_label(GBinSymbol *symbol, const char *lbl)
-{
- symbol->tmp_label = strdup(lbl);
-
-}
-
-
/******************************************************************************
* *
* Paramètres : symbol = symbole à venir consulter. *
+* alt = désignation humaine alternative à favoriser. *
* *
-* Description : Fournit un étiquette pour viser un symbole. *
+* Description : Définit un autre nom pour le symbole. *
* *
-* Retour : Chaîne de caractères renvoyant au symbole. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *g_binary_symbol_get_label(const GBinSymbol *symbol)
+void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt)
{
- const char *result; /* Etiquette à retourner */
-
- result = NULL;
-
-
- /* TODO : utiliser des types pour les instructions */
- if (symbol->tmp_label != NULL)
- return symbol->tmp_label;
-
-
- switch (symbol->type)
- {
- case STP_ROUTINE:
- case STP_ENTRY_POINT:
- case STP_CODE_LABEL:
- result = g_binary_routine_get_name(symbol->extra.routine);
- break;
-
- default:
- result = NULL;
- break;
-
- }
-
- return result;
+ symbol->alt = strdup(alt);
}
@@ -415,26 +420,6 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol)
/******************************************************************************
* *
-* Paramètres : symbol = symbole à venir consulter. *
-* alt = désignation humaine alternative à favoriser. *
-* *
-* Description : Définit un autre nom pour le symbole. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_binary_symbol_set_alt_name(GBinSymbol *symbol, char *alt)
-{
- symbol->alt = alt;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : symbol = symbole à venir consulter. *
* routine = prototype de la fonction représentée. *
* type = (nouveau) type du symbole attaché. *