summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
Diffstat (limited to 'src/format')
-rw-r--r--src/format/dex/class.c16
-rw-r--r--src/format/dex/method.c4
-rw-r--r--src/format/dex/method.h1
-rw-r--r--src/format/dex/pool.c36
-rw-r--r--src/format/dex/pool.h2
-rw-r--r--src/format/dwarf/symbols.c10
-rw-r--r--src/format/elf/helper_arm.c17
-rw-r--r--src/format/elf/helper_x86.c6
-rw-r--r--src/format/elf/strings.c11
-rw-r--r--src/format/elf/symbols.c24
-rw-r--r--src/format/format.c9
-rw-r--r--src/format/symbol-int.h16
-rw-r--r--src/format/symbol.c244
-rw-r--r--src/format/symbol.h56
14 files changed, 138 insertions, 314 deletions
diff --git a/src/format/dex/class.c b/src/format/dex/class.c
index 897720a..eb2ba3f 100644
--- a/src/format/dex/class.c
+++ b/src/format/dex/class.c
@@ -196,11 +196,11 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
vmpa2t addr; /* Tête de lecture générique */
class_data_item data; /* Contenu de la classe */
GDataType *ctype; /* Type créé par la classe */
+ GBinFormat *base; /* Autre version du format */
uleb128_t index; /* Conservation du dernier id */
uleb128_t i; /* Boucle de parcours */
GDexMethod *method; /* Méthode chargée */
GBinRoutine *routine; /* Version interne de méthode */
- GBinSymbol *symbol; /* Nouveau symbole construit */
result = g_object_new(G_TYPE_DEX_CLASS, NULL);
@@ -235,6 +235,8 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
ctype = get_type_from_dex_pool(format, def->class_idx);
assert(ctype != NULL);
+ base = G_BIN_FORMAT(format);
+
index = 0;
result->dmethods_count = data.direct_methods_size;
@@ -255,10 +257,7 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
g_object_ref(G_OBJECT(ctype));
g_binary_routine_set_namespace(routine, ctype, ".");
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
-
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ g_binary_format_add_symbol(base, G_BIN_SYMBOL(routine));
}
@@ -284,10 +283,7 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
g_object_ref(G_OBJECT(ctype));
g_binary_routine_set_namespace(routine, ctype, ".");
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
-
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ g_binary_format_add_symbol(base, G_BIN_SYMBOL(routine));
}
@@ -493,7 +489,7 @@ const char *g_dex_class_get_source_file(const GDexClass *class, const GDexFormat
{
const char *result; /* Trouvaille à renvoyer */
- result = get_string_from_dex_pool(format, class->definition.source_file_idx);
+ result = get_string_from_dex_pool(format, class->definition.source_file_idx, NULL);
return result;
diff --git a/src/format/dex/method.c b/src/format/dex/method.c
index be99479..f487c0a 100644
--- a/src/format/dex/method.c
+++ b/src/format/dex/method.c
@@ -212,7 +212,7 @@ GDexMethod *g_dex_method_new_defined(GDexFormat *format, const encoded_method *s
result->offset = ins_offset;
init_mrange(&range, &addr, item.insns_size * sizeof(uint16_t));
- g_binary_routine_set_range(result->routine, &range);
+ g_binary_symbol_set_range(G_BIN_SYMBOL(result->routine), &range);
}
@@ -252,7 +252,7 @@ GDexMethod *g_dex_method_new_callable(GDexFormat *format, const method_id_item *
result = NULL;
- name = get_string_from_dex_pool(format, method_id->name_idx);
+ name = get_string_from_dex_pool(format, method_id->name_idx, NULL);
if (name == NULL) goto gdmne_exit;
routine = get_prototype_from_dex_pool(format, method_id->proto_idx);
diff --git a/src/format/dex/method.h b/src/format/dex/method.h
index e5b8634..47e90b8 100644
--- a/src/format/dex/method.h
+++ b/src/format/dex/method.h
@@ -30,6 +30,7 @@
#include "dex.h"
#include "dex_def.h"
+#include "../../analysis/routine.h"
diff --git a/src/format/dex/pool.c b/src/format/dex/pool.c
index 9a99cc8..0180b19 100644
--- a/src/format/dex/pool.c
+++ b/src/format/dex/pool.c
@@ -52,19 +52,29 @@
bool find_all_dex_strings(GDexFormat *format)
{
+ GBinFormat *base; /* Autre version du format */
uint32_t i; /* Boucle de parcours */
+ mrange_t range; /* Couverture associée */
const char *text; /* Texte issu du binaire */
GBinSymbol *symbol; /* Nouveau symbole construit */
+ char *label; /* Désignation de la chaîne */
+
+ base = G_BIN_FORMAT(format);
for (i = 0; i < format->header.string_ids_size; i++)
{
- text = get_string_from_dex_pool(format, i);
+ text = get_string_from_dex_pool(format, i, &range);
if (text == NULL) continue;
- symbol = g_binary_symbol_new(STP_STRING);
- g_binary_symbol_set_alt_label(symbol, text);
+ symbol = g_binary_symbol_new(&range, STP_STRING);
+
+ label = create_string_label(base, get_mrange_addr(&range), get_mrange_length(&range));
+
+ g_binary_symbol_set_alt_label(symbol, label);
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ free(label);
+
+ g_binary_format_add_symbol(base, symbol);
}
@@ -77,6 +87,7 @@ bool find_all_dex_strings(GDexFormat *format)
* *
* Paramètres : format = représentation interne du format DEX à consulter. *
* index = index du type recherchée. *
+* range = éventuelle couverture à renseigner ou NULL. [OUT] *
* *
* Description : Extrait une chaîne de caractères d'une table DEX. *
* *
@@ -86,12 +97,14 @@ bool find_all_dex_strings(GDexFormat *format)
* *
******************************************************************************/
-const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index)
+const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index, mrange_t *range)
{
off_t pos; /* Tête de lecture */
vmpa2t addr; /* Tête de lecture générique */
string_id_item str_id; /* Identifiant de chaîne */
string_data_item str_data; /* Description de chaîne */
+ vmpa2t start; /* Début de la chaîne */
+ phys_t diff; /* Avancée de tête de lecture */
if (index >= format->header.string_ids_size)
return NULL;
@@ -108,6 +121,15 @@ const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index)
if (!read_dex_string_data_item(format, &addr, &str_data))
return NULL;
+ if (range != NULL)
+ {
+ init_vmpa(&start, pos, VMPA_NO_VIRTUAL);
+ diff = compute_vmpa_diff(&start, &addr);
+
+ init_mrange(range, &start, diff);
+
+ }
+
return (const char *)str_data.data;
}
@@ -362,7 +384,7 @@ GBinVariable *get_field_from_dex_pool(GDexFormat *format, uint32_t index)
type = get_type_from_dex_pool(format, field_id.type_idx);
if (type == NULL) goto gffdp_error;
- name = get_string_from_dex_pool(format, field_id.name_idx);
+ name = get_string_from_dex_pool(format, field_id.name_idx, NULL);
if (name == NULL) goto gffdp_bad_name;
field = g_binary_variable_new(type);
@@ -452,7 +474,7 @@ GBinRoutine *get_prototype_from_dex_pool(GDexFormat *format, uint32_t index)
/* Nom de la méthode */
- name = get_string_from_dex_pool(format, proto_id.shorty_idx);
+ name = get_string_from_dex_pool(format, proto_id.shorty_idx, NULL);
/* Liste des arguments */
diff --git a/src/format/dex/pool.h b/src/format/dex/pool.h
index 68fecc3..207f88c 100644
--- a/src/format/dex/pool.h
+++ b/src/format/dex/pool.h
@@ -37,7 +37,7 @@
bool find_all_dex_strings(GDexFormat *);
/* Extrait une chaîne de caractères d'une table DEX. */
-const char *get_string_from_dex_pool(const GDexFormat *, uint32_t);
+const char *get_string_from_dex_pool(const GDexFormat *, uint32_t, mrange_t *);
diff --git a/src/format/dwarf/symbols.c b/src/format/dwarf/symbols.c
index 16ff087..d26cc3e 100644
--- a/src/format/dwarf/symbols.c
+++ b/src/format/dwarf/symbols.c
@@ -111,11 +111,9 @@ static bool load_routine_as_symbol_from_dwarf(GDwarfFormat *format, const dw_die
/* Intégration en bonne et due forme */
routine = try_to_demangle_routine(name);
+ symbol = G_BIN_SYMBOL(routine);
- g_binary_routine_set_range(routine, &range);
-
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
+ g_binary_symbol_set_range(symbol, &range);
g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
@@ -221,9 +219,9 @@ static bool load_object_as_symbol_from_dwarf(GDwarfFormat *format, const dw_die
/*
routine = try_to_demangle_routine(name);
- g_binary_routine_set_range(routine, &range);
+ g_binary_symbol_set_range(G_BIN_SYMBOL(routine), &range);
- symbol = g_binary_symbol_new(STP_OBJECT);
+ symbol = g_binary_symbol_new(NULL, STP_OBJECT);
g_binary_symbol_attach_routine(symbol, routine);
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 a08c473..734a2bb 100644
--- a/src/format/elf/helper_arm.c
+++ b/src/format/elf/helper_arm.c
@@ -55,6 +55,7 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
bool result; /* Bilan à retourner */
phys_t rel_start; /* Début de la zone à traiter */
phys_t rel_size; /* Taille de cette même zone */
+ GBinFormat *base; /* Autre version du format */
phys_t iter; /* Boucle de parcours */
elf_rel reloc; /* Infos de relocalisation */
off_t index; /* Indice de la portion visée */
@@ -67,9 +68,9 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
virt_t final_virt; /* Adresse virtuelle retenue */
bool status; /* Bilan d'une opération */
vmpa2t addr; /* Localisation d'une routine */
- mrange_t range; /* Couverture mémoire associée */
GBinRoutine *routine; /* Nouvelle routine trouvée */
GBinSymbol *symbol; /* Nouveau symbole construit */
+ mrange_t range; /* Couverture mémoire associée */
@@ -80,6 +81,7 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
get_elf_section_content(format, relxxx, &rel_start, &rel_size, NULL);
+ base = G_BIN_FORMAT(format);
for (iter = rel_start; iter < (rel_start + rel_size); )
{
@@ -110,17 +112,14 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
status = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), final_virt, &addr);
if (!status) continue;
- init_mrange(&range, &addr, 0);
-
routine = try_to_demangle_routine(name);
+ symbol = G_BIN_SYMBOL(routine);
- g_binary_routine_set_range(routine, &range);
-
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
+ init_mrange(&range, &addr, 0);
+ g_binary_symbol_set_range(symbol, &range);
/* Comptabilisation pour le désassemblage brut */
- g_binary_format_register_code_point(G_BIN_FORMAT(format), virt, false);
+ g_binary_format_register_code_point(base, virt, false);
break;
@@ -132,7 +131,7 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
}
if (symbol != NULL)
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ g_binary_format_add_symbol(base, symbol);
}
diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c
index 826ac40..ba37bcb 100644
--- a/src/format/elf/helper_x86.c
+++ b/src/format/elf/helper_x86.c
@@ -140,7 +140,7 @@ bool load_elf_x86_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx,
name = "unknown";
}
- symbol = g_binary_symbol_new(STP_ROUTINE);
+ symbol = g_binary_symbol_new(NULL, STP_ROUTINE);
g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
break;
@@ -323,7 +323,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_ROUTINE);
+ symbol = g_binary_symbol_new(NULL, STP_ROUTINE);
g_binary_symbol_attach_routine(symbol, routine);
@@ -431,7 +431,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru
/* Symbole uniquement */
- symbol = g_binary_symbol_new(STP_ROUTINE);
+ symbol = g_binary_symbol_new(NULL, STP_ROUTINE);
g_binary_symbol_attach_routine(symbol, routine);
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index d350200..53d4e92 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -159,6 +159,7 @@ static bool parse_elf_string_data(GElfFormat *format, phys_t start, phys_t size,
phys_t i; /* Boucle de parcours */
phys_t end; /* Position de fin de chaîne */
GArchInstruction *instr; /* Instruction décodée */
+ const mrange_t *range; /* Espace occupé par une chaîne*/
GBinSymbol *symbol; /* Symbole à intégrer */
char *label; /* Désignation de la chaîne */
@@ -204,16 +205,16 @@ static bool parse_elf_string_data(GElfFormat *format, phys_t start, phys_t size,
g_preload_info_add_instruction(base->info, instr);
- g_object_ref(G_OBJECT(instr));
- ADD_STR_AS_SYM(format, symbol, instr);
+ range = g_arch_instruction_get_range(instr);
+
+ symbol = g_binary_symbol_new(range, STP_RO_STRING);
+ g_binary_format_add_symbol(base, symbol);
/* Jointure avec la chaîne précédente ? */
if (cut)
{
- init_vmpa(&pos, start + i, address + i);
-
- label = create_string_label(base, &pos, end - i);
+ label = create_string_label(base, get_mrange_addr(range), end - i);
g_binary_symbol_set_alt_label(symbol, label);
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 8451911..62fae58 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -207,27 +207,19 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le
/* Comptabilisation en tant que symbole */
if (g_binary_format_find_symbol_at(G_BIN_FORMAT(format), &addr, &symbol))
- {
g_object_unref(G_OBJECT(routine));
- routine = g_binary_symbol_get_routine(symbol);
- g_object_ref(G_OBJECT(routine));
-
- _g_binary_symbol_attach_routine(symbol, routine, STP_ENTRY_POINT);
-
- g_object_unref(G_OBJECT(symbol));
-
- }
else
{
base = G_BIN_FORMAT(format);
init_mrange(&range, &addr, len);
- g_binary_routine_set_range(routine, &range);
+ symbol = G_BIN_SYMBOL(routine);
+
+ g_binary_symbol_set_range(symbol, &range);
+ g_binary_symbol_set_target_type(symbol, STP_ENTRY_POINT);
- symbol = g_binary_symbol_new(STP_ENTRY_POINT);
- g_binary_symbol_attach_routine(symbol, routine);
g_binary_format_add_symbol(base, symbol);
/* Comptabilisation pour le désassemblage brut */
@@ -652,13 +644,9 @@ static bool do_elf_internal_symbol_loading(GElfLoading *loading, GElfFormat *for
/* Routine */
routine = try_to_demangle_routine(name);
+ symbol = G_BIN_SYMBOL(routine);
- g_binary_routine_set_range(routine, &range);
-
- /* Symbole uniquement */
-
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
+ g_binary_symbol_set_range(symbol, &range);
/* Comptabilisation pour le désassemblage brut */
diff --git a/src/format/format.c b/src/format/format.c
index 4dc6416..5d845e4 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -320,7 +320,6 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol)
const vmpa2t *addr; /* Emplacement du symbole */
#endif
size_t index; /* Indice du point d'insertion */
- GBinRoutine *routine; /* Nouvelle routine à insérer */
/**
* Pour que les fonctions de recherche basées sur _g_binary_format_find_symbol()
@@ -396,17 +395,11 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol)
static void _g_binary_format_remove_symbol(GBinFormat *format, size_t index)
{
- GBinSymbol *symbol; /* Symbole visé par l'opération*/
- GBinRoutine *routine; /* Eventuelle routine associée */
- size_t i; /* Boucle de parcours */
-
/**
* TODO : envoyer un signal pour avertir les opérandes concernées.
* TODO : vérifier les conditions d'accès (verrou).
*/
- symbol = format->symbols[index];
-
assert(index < format->symbols_count);
if ((index + 1) < format->symbols_count)
@@ -436,6 +429,8 @@ void g_binary_format_remove_symbol(GBinFormat *format, GBinSymbol *symbol)
{
size_t i; /* Boucle de parcours */
+ // FIXME : dicho
+
for (i = 0; i < format->symbols_count; i++)
if (format->symbols[i] == symbol)
break;
diff --git a/src/format/symbol-int.h b/src/format/symbol-int.h
index 4a79a65..49a0b97 100644
--- a/src/format/symbol-int.h
+++ b/src/format/symbol-int.h
@@ -29,22 +29,21 @@
+/* Fournit une étiquette pour viser un symbole. */
+typedef const char * (* get_symbol_label_fc) (GBinSymbol *);
+
+
+
/* Symbole d'exécutable (instance) */
struct _GBinSymbol
{
GObject parent; /* A laisser en premier */
+ mrange_t range; /* Couverture mémoire */
SymbolType type; /* Type du symbole */
char *alt; /* Nom alternatif */
- union
- {
- GArchInstruction *instr; /* Instruction correspondante */
- GBinRoutine *routine; /* Compléments pour fonction */
-
- } extra;
-
};
/* Symbole d'exécutable (classe) */
@@ -52,8 +51,9 @@ struct _GBinSymbolClass
{
GObjectClass parent; /* A laisser en premier */
-};
+ get_symbol_label_fc get_label; /* Obtention d'une étiquette */
+};
diff --git a/src/format/symbol.c b/src/format/symbol.c
index ba0c327..0b300bd 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -121,6 +121,7 @@ static void g_binary_symbol_class_init(GBinSymbolClass *klass)
static void g_binary_symbol_init(GBinSymbol *symbol)
{
+ g_binary_symbol_set_target_type(symbol, STP_COUNT);
}
@@ -162,8 +163,6 @@ static void g_binary_symbol_interface_init(GLineGeneratorInterface *iface)
static void g_binary_symbol_dispose(GBinSymbol *symbol)
{
- /* TODO... */
-
G_OBJECT_CLASS(g_binary_symbol_parent_class)->dispose(G_OBJECT(symbol));
}
@@ -183,7 +182,8 @@ static void g_binary_symbol_dispose(GBinSymbol *symbol)
static void g_binary_symbol_finalize(GBinSymbol *symbol)
{
- free(symbol->alt);
+ if (symbol->alt != NULL)
+ free(symbol->alt);
G_OBJECT_CLASS(g_binary_symbol_parent_class)->finalize(G_OBJECT(symbol));
@@ -192,7 +192,8 @@ static void g_binary_symbol_finalize(GBinSymbol *symbol)
/******************************************************************************
* *
-* Paramètres : type = type de symbole à créer. *
+* Paramètres : range = espace couvert par le nouveau symbole. *
+* type = type de symbole à créer. *
* *
* Description : Crée un nouveau symbole d'exécutable. *
* *
@@ -202,13 +203,14 @@ static void g_binary_symbol_finalize(GBinSymbol *symbol)
* *
******************************************************************************/
-GBinSymbol *g_binary_symbol_new(SymbolType type)
+GBinSymbol *g_binary_symbol_new(const mrange_t *range, SymbolType type)
{
GBinSymbol *result; /* Nouveau symbole à renvoyer */
result = g_object_new(G_TYPE_BIN_SYMBOL, NULL);
- result->type = type;
+ g_binary_symbol_set_range(result, range);
+ g_binary_symbol_set_target_type(result, type);
return result;
@@ -231,23 +233,8 @@ GBinSymbol *g_binary_symbol_new(SymbolType type)
int g_binary_symbol_cmp(const GBinSymbol * const *a, const GBinSymbol * const *b)
{
int result; /* Bilan à retourner */
- const mrange_t *ra; /* Emplacement du symbole A */
- const mrange_t *rb; /* Emplacement du symbole B */
-
- ra = g_binary_symbol_get_range(*a);
- rb = g_binary_symbol_get_range(*b);
- if (ra == NULL && rb == NULL)
- result = 0;
-
- else if (ra != NULL && rb == NULL)
- result = 1;
-
- else if (ra == NULL && rb != NULL)
- result = -1;
-
- else
- result = cmp_mrange(ra, rb);
+ result = cmp_mrange(&(*a)->range, &(*b)->range);
return result;
@@ -270,15 +257,8 @@ int g_binary_symbol_cmp(const GBinSymbol * const *a, const GBinSymbol * const *b
int g_binary_symbol_cmp_with_vmpa(const GBinSymbol *symbol, const vmpa2t *addr)
{
int result; /* Bilan à retourner */
- const mrange_t *range; /* Emplacement du symbole */
-
- range = g_binary_symbol_get_range(symbol);
- if (range == NULL)
- result = 1;
-
- else
- result = cmp_mrange_with_vmpa(range, addr);
+ result = cmp_mrange_with_vmpa(&symbol->range, addr);
return result;
@@ -287,69 +267,10 @@ int g_binary_symbol_cmp_with_vmpa(const GBinSymbol *symbol, const vmpa2t *addr)
/******************************************************************************
* *
-* Paramètres : symbol = symbole à venir consulter. *
-* *
-* Description : Fournit le type du symbole. *
-* *
-* Retour : Type de symbole représenté. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol)
-{
- return symbol->type;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : symbol = symbole à venir consulter. *
+* Paramètres : symbol = symbole à mettre à jour. *
+* range = plage mémoire ou physique déclarée. *
* *
-* Description : Fournit un étiquette pour viser un symbole. *
-* *
-* Retour : Chaîne de caractères renvoyant au symbole. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-const char *g_binary_symbol_get_label(const GBinSymbol *symbol)
-{
- const char *result; /* Etiquette à retourner */
-
- if (symbol->alt != NULL)
- return symbol->alt;
-
- result = NULL;
-
- switch (symbol->type)
- {
- case STP_ROUTINE:
- case STP_ENTRY_POINT:
- case STP_CODE_LABEL:
- result = g_binary_routine_get_declarator(symbol->extra.routine, false);
- break;
-
- default:
- result = NULL;
- break;
-
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : symbol = symbole à venir consulter. *
-* alt = désignation humaine alternative à favoriser. *
-* *
-* Description : Définit un autre nom pour le symbole. *
+* Description : Définit la couverture physique / en mémoire d'un symbole. *
* *
* Retour : - *
* *
@@ -357,15 +278,9 @@ const char *g_binary_symbol_get_label(const GBinSymbol *symbol)
* *
******************************************************************************/
-void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt)
+void g_binary_symbol_set_range(GBinSymbol *symbol, const mrange_t *range)
{
- if (symbol->alt != NULL)
- free(symbol->alt);
-
- if (alt == NULL)
- symbol->alt = NULL;
- else
- symbol->alt = strdup(alt);
+ copy_mrange(&symbol->range, range);
}
@@ -384,42 +299,17 @@ void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt)
const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol)
{
- const mrange_t *result; /* Plage à retourner */
-
- result = NULL;
-
- switch (symbol->type)
- {
- case STP_DATA:
- case STP_RO_STRING:
- result = g_arch_instruction_get_range(symbol->extra.instr);
- break;
-
- case STP_ROUTINE:
- case STP_ENTRY_POINT:
- case STP_CODE_LABEL:
- result = g_binary_routine_get_range(symbol->extra.routine);
- break;
-
- default:
- /* FIXME : assert(0); */
- result = NULL;
- break;
-
- }
-
- return result;
+ return &symbol->range;
}
/******************************************************************************
* *
-* Paramètres : symbol = symbole à venir consulter. *
-* routine = prototype de la fonction représentée. *
-* type = (nouveau) type du symbole attaché. *
+* Paramètres : symbol = symbole à venir modifier. *
+* type = type de symbole représenté. *
* *
-* Description : Attache la routine associée au symbole. *
+* Description : Définit le type du symbole. *
* *
* Retour : - *
* *
@@ -427,83 +317,58 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol)
* *
******************************************************************************/
-void _g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine, SymbolType type)
+void g_binary_symbol_set_target_type(GBinSymbol *symbol, SymbolType type)
{
- if (symbol->extra.routine != NULL)
- g_object_unref(G_OBJECT(symbol->extra.routine));
-
symbol->type = type;
- symbol->extra.routine = routine;
-
}
/******************************************************************************
* *
-* Paramètres : symbol = symbole à venir consulter. *
-* routine = prototype de la fonction représentée. *
+* Paramètres : symbol = symbole à venir consulter. *
* *
-* Description : Attache la routine associée au symbole. *
+* Description : Fournit le type du symbole. *
* *
-* Retour : - *
+* Retour : Type de symbole représenté. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine)
+SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol)
{
- _g_binary_symbol_attach_routine(symbol, routine, symbol->type);
+ return symbol->type;
}
/******************************************************************************
* *
-* Paramètres : symbol = symbole à venir manipuler. *
-* instr = représentation du symbole associé. *
+* Paramètres : symbol = symbole à venir consulter. *
* *
-* Description : Attache l'instruction associée au symbole. *
+* Description : Fournit une étiquette pour viser un symbole. *
* *
-* Retour : - *
+* Retour : Chaîne de caractères renvoyant au symbole. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_binary_symbol_attach_instruction(GBinSymbol *symbol, GArchInstruction *instr)
+const char *g_binary_symbol_get_label(GBinSymbol *symbol)
{
- if (symbol->type != STP_RO_STRING)
- symbol->type = STP_DATA;
-
- symbol->extra.instr = instr;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : symbol = symbole à venir consulter. *
-* *
-* Description : Fournit l'éventuelle routine associée au symbole. *
-* *
-* Retour : Instance GLib en place ou NULL si aucune. *
-* *
-* Remarques : Il n'y a pas de transfert de propriété ici ! *
-* *
-******************************************************************************/
+ const char *result; /* Etiquette à retourner */
-GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol)
-{
- /* TODO : rajouter des assert() sur le type de symbole */
+ if (symbol->alt != NULL)
+ result = symbol->alt;
- /* TODO : ref() */
+ else if (G_BIN_SYMBOL_GET_CLASS(symbol)->get_label != NULL)
+ result = G_BIN_SYMBOL_GET_CLASS(symbol)->get_label(symbol);
- if (symbol->type != STP_ROUTINE && symbol->type != STP_ENTRY_POINT)
- return NULL;
+ else
+ result = NULL;
- return symbol->extra.routine;
+ return result;
}
@@ -511,22 +376,25 @@ GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol)
/******************************************************************************
* *
* Paramètres : symbol = symbole à venir consulter. *
+* alt = désignation humaine alternative à favoriser. *
* *
-* Description : Fournit l'éventuelle instruction associée au symbole. *
+* Description : Définit un autre nom pour le symbole. *
* *
-* Retour : Instance GLib en place ou NULL si aucune. *
+* Retour : - *
* *
-* Remarques : Il n'y a pas de transfert de propriété ici ! *
+* Remarques : - *
* *
******************************************************************************/
-GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *symbol)
+void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt)
{
- /* TODO : rajouter des assert() sur le type de symbole */
-
- /* TODO : ref() */
+ if (symbol->alt != NULL)
+ free(symbol->alt);
- return symbol->extra.instr;
+ if (alt == NULL)
+ symbol->alt = NULL;
+ else
+ symbol->alt = strdup(alt);
}
@@ -600,11 +468,7 @@ static size_t g_binary_symbol_count_lines(const GBinSymbol *symbol)
void g_binary_symbol_compute_addr(const GBinSymbol *symbol, gint x, vmpa2t *addr, size_t index, size_t repeat)
{
- const mrange_t *range; /* Emplacement à manipuler */
-
- range = g_binary_symbol_get_range(symbol);
-
- copy_vmpa(addr, get_mrange_addr(range));
+ copy_vmpa(addr, get_mrange_addr(&symbol->range));
}
@@ -627,11 +491,8 @@ void g_binary_symbol_compute_addr(const GBinSymbol *symbol, gint x, vmpa2t *addr
static int g_binary_symbol_contains_addr(const GBinSymbol *symbol, const vmpa2t *addr, size_t index, size_t repeat)
{
int result; /* Conclusion à retourner */
- const mrange_t *range; /* Emplacement à manipuler */
-
- range = g_binary_symbol_get_range(symbol);
- result = cmp_mrange_with_vmpa(range, addr);
+ result = cmp_mrange_with_vmpa(&symbol->range, addr);
return result;
@@ -677,12 +538,9 @@ static BufferLineFlags g_binary_symbol_get_flags(const GBinSymbol *symbol, size_
static void g_binary_symbol_print(GBinSymbol *symbol, GBufferLine *line, size_t index, size_t repeat, const GBinContent *content)
{
- const mrange_t *range; /* Emplacement à manipuler */
const char *label; /* Etiquette à insérer */
- range = g_binary_symbol_get_range(symbol);
-
- g_buffer_line_fill_vmpa(line, get_mrange_addr(range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED);
+ g_buffer_line_fill_vmpa(line, get_mrange_addr(&symbol->range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED);
label = g_binary_symbol_get_label(symbol);
diff --git a/src/format/symbol.h b/src/format/symbol.h
index 0d40529..da51262 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -28,10 +28,6 @@
#include <glib-object.h>
-#include "../analysis/routine.h"
-#include "../analysis/db/item.h"
-#include "../analysis/db/items/comment.h"
-#include "../arch/instruction.h"
#include "../glibext/linegen.h"
@@ -55,10 +51,6 @@ typedef enum _SymbolType
} SymbolType;
-#define HAS_DATA_INSTR(type) (type == STP_DATA || type == STP_RO_STRING)
-
-
-
#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()))
@@ -78,7 +70,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);
+GBinSymbol *g_binary_symbol_new(const mrange_t *, SymbolType);
/* Compare deux symboles d'exécutable selon leurs propriétés. */
int g_binary_symbol_cmp(const GBinSymbol * const *, const GBinSymbol * const *);
@@ -86,49 +78,23 @@ int g_binary_symbol_cmp(const GBinSymbol * const *, const GBinSymbol * const *);
/* Compare un symbole et une localisation. */
int g_binary_symbol_cmp_with_vmpa(const GBinSymbol *, const vmpa2t *);
-/* Fournit le type du symbole. */
-SymbolType g_binary_symbol_get_target_type(const GBinSymbol *);
-
-/* 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 *);
+/* Définit la couverture physique / en mémoire d'un symbole. */
+void g_binary_symbol_set_range(GBinSymbol *, const mrange_t *);
/* Fournit l'emplacement où se situe un symbole. */
const mrange_t *g_binary_symbol_get_range(const GBinSymbol *);
-/* Attache la routine associée au symbole. */
-void _g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *, SymbolType);
-
-/* Attache la routine associée au symbole. */
-void g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *);
-
-/* Attache l'instruction associée au symbole. */
-void g_binary_symbol_attach_instruction(GBinSymbol *, GArchInstruction *);
-
-/* Fournit l'éventuelle routine associée au symbole. */
-GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *);
-
-/* Fournit l'éventuelle instruction associée au symbole. */
-GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *);
-
-
-/**
- * Confort pour l'ajout de symboles basés sur des formats.
- */
-
+/* Définit le type du symbole. */
+void g_binary_symbol_set_target_type(GBinSymbol *, SymbolType);
+/* Fournit le type du symbole. */
+SymbolType g_binary_symbol_get_target_type(const GBinSymbol *);
+/* Fournit une étiquette pour viser un symbole. */
+const char *g_binary_symbol_get_label(GBinSymbol *);
-#define ADD_STR_AS_SYM(_fmt, _sym, _ins) \
- ({ \
- bool __result; \
- _sym = g_binary_symbol_new(STP_RO_STRING); \
- g_binary_symbol_attach_instruction(_sym, _ins); \
- __result = g_binary_format_add_symbol(G_BIN_FORMAT(_fmt), _sym); \
- __result; \
- })
+/* Définit un autre nom pour le symbole. */
+void g_binary_symbol_set_alt_label(GBinSymbol *, const char *);