summaryrefslogtreecommitdiff
path: root/src/format
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
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')
-rw-r--r--src/format/dex/pool.c4
-rw-r--r--src/format/elf/helper_arm.c18
-rw-r--r--src/format/elf/helper_x86.c14
-rw-r--r--src/format/elf/strings.c2
-rw-r--r--src/format/elf/symbols.c4
-rw-r--r--src/format/symbol.c157
-rw-r--r--src/format/symbol.h27
7 files changed, 100 insertions, 126 deletions
diff --git a/src/format/dex/pool.c b/src/format/dex/pool.c
index 0c982cd..a869873 100644
--- a/src/format/dex/pool.c
+++ b/src/format/dex/pool.c
@@ -55,8 +55,8 @@ bool find_all_dex_strings(GDexFormat *format)
text = get_string_from_dex_pool(format, i);
if (text == NULL) continue;
- symbol = g_binary_symbol_new(STP_STRING, NULL, i);
- g_binary_symbol_set_alt_name(symbol, strdup(text));
+ symbol = g_binary_symbol_new(STP_STRING);
+ g_binary_symbol_set_alt_label(symbol, text);
g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
diff --git a/src/format/elf/helper_arm.c b/src/format/elf/helper_arm.c
index efc8a3d..c77df55 100644
--- a/src/format/elf/helper_arm.c
+++ b/src/format/elf/helper_arm.c
@@ -118,7 +118,7 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
g_binary_routine_set_range(routine, &range);
- symbol = g_binary_symbol_new(STP_ROUTINE, NULL, ~0);
+ symbol = g_binary_symbol_new(STP_ROUTINE);
g_binary_symbol_attach_routine(symbol, routine);
g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
@@ -131,7 +131,7 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
((unsigned int)ELF_SHDR(format, (*relxxx), sh_addr) + ELF_REL(format, reloc, r_offset)));
*/
- //symbol = g_binary_symbol_new(STP_FUNCTION, name, ELF_REL(format, reloc, r_offset));
+ //symbol = g_binary_symbol_new(STP_FUNCTION));
//g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
break;
@@ -269,7 +269,7 @@ bool load_elf_x86_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
name = "unknown";
}
- symbol = g_binary_symbol_new(STP_FUNCTION, name, ELF_REL(format, reloc, r_offset));
+ symbol = g_binary_symbol_new(STP_FUNCTION);
g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
break;
@@ -430,19 +430,19 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &symbols_count);
for (j = 0; j < symbols_count; j++)
- if (g_binary_symbol_get_address(symbols[j]) == address)
+ if (0 /* FIXME g_binary_symbol_get_address(symbols[j]) == address*/)
{
/* Nom final */
- new_len = strlen(g_binary_symbol_to_string(symbols[j])) + 4 + 1;
+ new_len = strlen(g_binary_symbol_get_label(symbols[j])) + 4 + 1;
new_name = calloc(new_len, sizeof(char));
- snprintf(new_name, new_len, "%s@plt", g_binary_symbol_to_string(symbols[j]));
+ snprintf(new_name, new_len, "%s@plt", g_binary_symbol_get_label(symbols[j]));
g_arch_instruction_get_location(instructions[i], NULL, NULL, &address);
/* Routine */
- routine = try_to_demangle_routine(g_binary_symbol_to_string(symbols[j]));
+ routine = try_to_demangle_routine(g_binary_symbol_get_label(symbols[j]));
///g_binary_routine_set_address(routine, address);
@@ -450,7 +450,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_FUNCTION, new_name, address);
+ symbol = g_binary_symbol_new(STP_FUNCTION);
g_binary_symbol_attach_routine(symbol, routine);
@@ -558,7 +558,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_FUNCTION, new_name, address);
+ symbol = g_binary_symbol_new(STP_FUNCTION);
g_binary_symbol_attach_routine(symbol, routine);
diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c
index 742d1c3..deb1ead 100644
--- a/src/format/elf/helper_x86.c
+++ b/src/format/elf/helper_x86.c
@@ -121,7 +121,7 @@ bool load_elf_x86_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
name = "unknown";
}
- symbol = g_binary_symbol_new(STP_FUNCTION, name, ELF_REL(format, reloc, r_offset));
+ symbol = g_binary_symbol_new(STP_FUNCTION);
g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
break;
@@ -282,19 +282,19 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &symbols_count);
for (j = 0; j < symbols_count; j++)
- if (g_binary_symbol_get_address(symbols[j]) == address)
+ if (0 /* FIXME g_binary_symbol_get_address(symbols[j]) == address*/)
{
/* Nom final */
- new_len = strlen(g_binary_symbol_to_string(symbols[j])) + 4 + 1;
+ new_len = strlen(g_binary_symbol_get_label(symbols[j])) + 4 + 1;
new_name = calloc(new_len, sizeof(char));
- snprintf(new_name, new_len, "%s@plt", g_binary_symbol_to_string(symbols[j]));
+ snprintf(new_name, new_len, "%s@plt", g_binary_symbol_get_label(symbols[j]));
g_arch_instruction_get_location(instructions[i], NULL, NULL, &address);
/* Routine */
- routine = try_to_demangle_routine(g_binary_symbol_to_string(symbols[j]));
+ routine = try_to_demangle_routine(g_binary_symbol_get_label(symbols[j]));
///g_binary_routine_set_address(routine, address);
@@ -302,7 +302,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_FUNCTION, new_name, address);
+ symbol = g_binary_symbol_new(STP_FUNCTION);
g_binary_symbol_attach_routine(symbol, routine);
@@ -410,7 +410,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_FUNCTION, new_name, address);
+ symbol = g_binary_symbol_new(STP_FUNCTION);
g_binary_symbol_attach_routine(symbol, routine);
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index c11d53b..6832f5b 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -209,7 +209,7 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a
label = create_string_label(G_BIN_FORMAT(format), &pos, &data[i], end - i);
- g_binary_symbol_set_label(symbol, label);
+ g_binary_symbol_set_alt_label(symbol, label);
free(label);
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 655eda1..1fa3d0e 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -201,7 +201,7 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le
g_binary_routine_set_range(routine, &range);
- symbol = g_binary_symbol_new(STP_ENTRY_POINT, "XXX", ~0);
+ symbol = g_binary_symbol_new(STP_ENTRY_POINT);
g_binary_symbol_attach_routine(symbol, routine);
_g_binary_format_add_symbol(base, symbol, false);
@@ -622,7 +622,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_ROUTINE, name, ~0);
+ symbol = g_binary_symbol_new(STP_ROUTINE);
g_binary_symbol_attach_routine(symbol, routine);
break;
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é. *
diff --git a/src/format/symbol.h b/src/format/symbol.h
index 49cde56..e0b657d 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -52,7 +52,8 @@ typedef enum _SymbolType
#define G_TYPE_BIN_SYMBOL g_binary_symbol_get_type()
#define G_BIN_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_binary_symbol_get_type(), GBinSymbol))
#define G_IS_BIN_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_binary_symbol_get_type()))
-#define G_BIN_SYMBOL_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_binary_symbol_get_type(), GBinSymbolIface))
+#define G_BIN_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_SYMBOL, GBinSymbolClass))
+#define G_IS_BIN_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_SYMBOL))
#define G_BIN_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_SYMBOL, GBinSymbolClass))
@@ -67,7 +68,7 @@ typedef struct _GBinSymbolClass GBinSymbolClass;
GType g_binary_symbol_get_type(void);
/* Crée un nouveau symbole d'exécutable. */
-GBinSymbol *g_binary_symbol_new(SymbolType, const char *, vmpa_t);
+GBinSymbol *g_binary_symbol_new(SymbolType);
/* Compare deux symboles d'exécutable selon leurs propriétés. */
int g_binary_symbol_cmp(const GBinSymbol **, const GBinSymbol **);
@@ -75,30 +76,18 @@ int g_binary_symbol_cmp(const GBinSymbol **, const GBinSymbol **);
/* Fournit le type du symbole. */
SymbolType g_binary_symbol_get_target_type(const GBinSymbol *);
-/* Fournit la description humaine du symbole. */
-const char *g_binary_symbol_to_string(const GBinSymbol *);
-
-/* Fournit l'adresse associée à un symbole. */
-vmpa_t g_binary_symbol_get_address(const GBinSymbol *); ///////////////////
-
-
-
-void g_binary_symbol_set_label(GBinSymbol *symbol, const char *lbl);
-
-
-
/* Fournit un étiquette pour viser un symbole. */
const char *g_binary_symbol_get_label(const GBinSymbol *);
+/* Définit un autre nom pour le symbole. */
+void g_binary_symbol_set_alt_label(GBinSymbol *, const char *);
+
/* Raffine la définition de l'emplacement d'un symbole. */
void g_binary_symbol_fix_range(GBinSymbol *, const vmpa2t *);
/* Fournit l'emplacement où se situe un symbole. */
const mrange_t *g_binary_symbol_get_range(const GBinSymbol *);
-/* Définit un autre nom pour le symbole. */
-void g_binary_symbol_set_alt_name(GBinSymbol *, char *);
-
/* Attache la routine associée au symbole. */
void _g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *, SymbolType);
@@ -137,7 +126,7 @@ GDbComment *g_binary_symbol_get_comment(const GBinSymbol *);
do \
{ \
_cmt = g_db_comment_new(_pos, _txt, true); \
- _sym = g_binary_symbol_new(STP_DATA, NULL, 0); \
+ _sym = g_binary_symbol_new(STP_DATA); \
g_binary_symbol_attach_instruction(_sym, _ins); \
g_binary_symbol_set_comment(_sym, _cmt); \
g_binary_format_add_symbol(G_BIN_FORMAT(_fmt), _sym); \
@@ -147,7 +136,7 @@ GDbComment *g_binary_symbol_get_comment(const GBinSymbol *);
#define ADD_STR_AS_SYM(_fmt, _sym, _ins) \
do \
{ \
- _sym = g_binary_symbol_new(STP_RO_STRING, NULL, 0); \
+ _sym = g_binary_symbol_new(STP_RO_STRING); \
g_binary_symbol_attach_instruction(_sym, _ins); \
g_binary_format_add_symbol(G_BIN_FORMAT(_fmt), _sym); \
} \