From 4691a434a34a19317156a761967f719e408b73bb Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 16 May 2017 23:56:55 +0200 Subject: Merged routines into symbols. --- ChangeLog | 43 +++++++ plugins/mobicore/symbols.c | 9 +- plugins/pychrysa/format/symbol.c | 95 +++------------ plugins/readdex/ids.c | 8 +- plugins/readelf/strtab.c | 14 ++- src/analysis/disass/area.c | 21 ++-- src/analysis/disass/limit.c | 8 +- src/analysis/disass/limit.h | 4 +- src/analysis/disass/routines.c | 20 +++- src/analysis/disass/routines.h | 1 + src/analysis/routine.c | 120 ++++++------------- src/analysis/routine.h | 6 - src/arch/arm/v7/post.c | 11 +- src/arch/dalvik/link.c | 1 + src/arch/dalvik/operands/pool.c | 2 +- src/arch/post.c | 20 ++-- src/arch/target.c | 10 +- src/format/dex/class.c | 16 +-- src/format/dex/method.c | 4 +- src/format/dex/method.h | 1 + src/format/dex/pool.c | 36 ++++-- src/format/dex/pool.h | 2 +- src/format/dwarf/symbols.c | 10 +- src/format/elf/helper_arm.c | 17 ++- src/format/elf/helper_x86.c | 6 +- src/format/elf/strings.c | 11 +- src/format/elf/symbols.c | 24 +--- src/format/format.c | 9 +- src/format/symbol-int.h | 16 +-- src/format/symbol.c | 244 ++++++++------------------------------- src/format/symbol.h | 56 ++------- src/gtkext/gtkgraphdisplay.c | 14 ++- 32 files changed, 311 insertions(+), 548 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3ec17c..906efaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,46 @@ +17-05-16 Cyrille Bagard + + + * plugins/mobicore/symbols.c: + * plugins/pychrysa/format/symbol.c: + * plugins/readdex/ids.c: + * plugins/readelf/strtab.c: + * src/analysis/disass/area.c: + * src/analysis/disass/limit.c: + * src/analysis/disass/limit.h: + * src/analysis/disass/routines.c: + * src/analysis/disass/routines.h: + Update code. + + * src/analysis/routine.c: + * src/analysis/routine.h: + Merge routines into symbols. + + * src/arch/arm/v7/post.c: + * src/arch/dalvik/operands/pool.c: + * src/arch/post.c: + * src/arch/target.c: + * src/format/dex/class.c: + * src/format/dex/method.c: + * src/format/dex/method.h: + * src/format/dex/pool.c: + * src/format/dex/pool.h: + * src/format/dwarf/symbols.c: + * src/format/elf/helper_arm.c: + * src/format/elf/helper_x86.c: + * src/format/elf/strings.c: + * src/format/elf/symbols.c: + * src/format/format.c: + Update code. + + * src/format/symbol-int.h: + * src/format/symbol.c: + * src/format/symbol.h: + Merge routines into symbols. + + * src/gtkext/gtkgraphdisplay.c: + Update code. + 17-05-14 Cyrille Bagard * src/format/format-int.h: diff --git a/plugins/mobicore/symbols.c b/plugins/mobicore/symbols.c index dc0a950..ec2dd34 100644 --- a/plugins/mobicore/symbols.c +++ b/plugins/mobicore/symbols.c @@ -79,12 +79,13 @@ static void register_mclf_entry_point(GMCLFFormat *format, virt_t vaddr, phys_t init_vmpa(&addr, vaddr - format->header.v1.text.start, vaddr); init_vmpa(&addr, VMPA_NO_PHYSICAL, vaddr); - init_mrange(&range, &addr, len); + 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); } diff --git a/plugins/pychrysa/format/symbol.c b/plugins/pychrysa/format/symbol.c index 008aeb3..e337ea1 100644 --- a/plugins/pychrysa/format/symbol.c +++ b/plugins/pychrysa/format/symbol.c @@ -48,9 +48,6 @@ static PyObject *py_binary_symbol_richcompare(PyObject *, PyObject *, int); /* Définit un autre nom pour le symbole. */ static PyObject *py_binary_symbol_set_alt_label(PyObject *, PyObject *); -/* Attache la routine associée au symbole. */ -static PyObject *py_binary_symbol_attach_routine(PyObject *, PyObject *); - /* Fournit le type du symbole. */ static PyObject *py_binary_symbol_get_target_type(PyObject *, void *); @@ -60,9 +57,6 @@ static PyObject *py_binary_symbol_get_label(PyObject *, void *); /* Fournit l'emplacement où se situe un symbole. */ static PyObject *py_binary_symbol_get_range(PyObject *, void *); -/* Fournit l'éventuelle routine associée au symbole. */ -static PyObject *py_binary_symbol_get_routine(PyObject *, void *); - /* Définit les constantes pour les symboles binaires. */ static bool py_binary_symbol_define_constants(PyTypeObject *); @@ -131,10 +125,12 @@ static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObje { PyObject *result; /* Bilan à retourner */ SymbolType stype; /* Type prévu pour le symbole */ + PyObject *range_obj; /* Objet pour la couverture */ int ret; /* Bilan de lecture des args. */ + mrange_t *range; /* Version native d'un espace */ GBinSymbol *symbol; /* Version GLib du symble */ - ret = PyArg_ParseTuple(args, "l", &stype); + ret = PyArg_ParseTuple(args, "lO", &stype, &range_obj); if (!ret) return NULL; if (stype >= STP_COUNT) @@ -143,7 +139,16 @@ static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObje return NULL; } - symbol = g_binary_symbol_new(stype); + ret = PyObject_IsInstance(range_obj, (PyObject *)get_python_mrange_type()); + if (!ret) + { + PyErr_SetString(PyExc_TypeError, _("The second argument must be an instance of mrange.")); + return NULL; + } + + range = get_internal_mrange(range_obj); + + symbol = g_binary_symbol_new(range, stype); result = pygobject_new(G_OBJECT(symbol)); g_object_unref(symbol); @@ -186,42 +191,6 @@ static PyObject *py_binary_symbol_set_alt_label(PyObject *self, PyObject *args) /****************************************************************************** * * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Attache la routine associée au symbole. * -* * -* Retour : None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_attach_routine(PyObject *self, PyObject *args) -{ - PyObject *py_routine; /* Routine version Python */ - int ret; /* Bilan de lecture des args. */ - GBinSymbol *symbol; /* Elément à consulter */ - GBinRoutine *routine; /* Routine à attacher */ - - ret = PyArg_ParseTuple(args, "O", &py_routine); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_routine, (PyObject *)get_python_binary_routine_type()); - if (!ret) return NULL; - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - routine = G_BIN_ROUTINE(pygobject_get(py_routine)); - - g_binary_symbol_attach_routine(symbol, routine); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * @@ -316,35 +285,6 @@ static PyObject *py_binary_symbol_get_range(PyObject *self, void *closure) /****************************************************************************** * * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit l'éventuelle routine associée au symbole. * -* * -* Retour : Instance en place ou None si aucune. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_get_routine(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBinSymbol *symbol; /* Elément à consulter */ - GBinRoutine *routine; /* Routine attachée */ - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - routine = g_binary_symbol_get_routine(symbol); - - result = pygobject_new(G_OBJECT(routine)); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : obj_type = type dont le dictionnaire est à compléter. * * * * Description : Définit les constantes pour les symboles binaires. * @@ -395,11 +335,6 @@ PyTypeObject *get_python_binary_symbol_type(void) METH_VARARGS, "set_alt_label($self, alt, /)\n--\n\nSet an alternative label for the symbol." }, - { - "attach_routine", py_binary_symbol_attach_routine, - METH_VARARGS, - "attach_routine($self, instr, /)\n--\n\nAttach a provided routine to the current symbol." - }, { NULL } }; @@ -416,10 +351,6 @@ PyTypeObject *get_python_binary_symbol_type(void) "range", py_binary_symbol_get_range, NULL, "Range covered by the symbol.", NULL }, - { - "routine", py_binary_symbol_get_routine, NULL, - "Potential routine attached to the symbol.", NULL - }, { NULL } }; diff --git a/plugins/readdex/ids.c b/plugins/readdex/ids.c index 14ad6fb..f65f5ec 100644 --- a/plugins/readdex/ids.c +++ b/plugins/readdex/ids.c @@ -254,6 +254,7 @@ bool annotate_dex_string_ids(const GDexFormat *format, GPreloadInfo *info, GtkSt vmpa2t item_pos; /* Position d'un élément */ uleb128_t length; /* Taille de la chaîne en cours*/ GArchInstruction *instr; /* Instruction décodée */ + const mrange_t *range; /* Espace occupé par une chaîne*/ GBinSymbol *symbol; /* Symbole à intégrer */ content = g_binary_format_get_content(G_BIN_FORMAT(format)); @@ -330,8 +331,11 @@ bool annotate_dex_string_ids(const GDexFormat *format, GPreloadInfo *info, GtkSt g_preload_info_add_instruction(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(bformat, symbol); + } diff --git a/plugins/readelf/strtab.c b/plugins/readelf/strtab.c index f8ab2c7..1564674 100644 --- a/plugins/readelf/strtab.c +++ b/plugins/readelf/strtab.c @@ -59,9 +59,11 @@ static void parse_elf_string_table(GElfFormat *format, GPreloadInfo *info, const vmpa2t pos; /* Tête de lecture */ const bin_t *data; /* Donnés à parcourir */ bool cut; /* Séparation nette ? */ + GBinFormat *base; /* Autre version du format */ phys_t i; /* Boucle de parcours */ phys_t end; /* Position de fin de chaîne */ GArchInstruction *instr; /* Instruction décodée */ + const mrange_t *irange; /* Espace occupé par une chaîne*/ GBinSymbol *symbol; /* Symbole à intégrer */ char *label; /* Désignation de la chaîne */ @@ -76,12 +78,12 @@ static void parse_elf_string_table(GElfFormat *format, GPreloadInfo *info, const */ if (data == NULL) return; - cut = true; - /* Boucle de parcours */ cut = true; + base = G_BIN_FORMAT(format); + for (i = 0; i < length; i++) if (isprint(data[i])) { @@ -103,8 +105,10 @@ static void parse_elf_string_table(GElfFormat *format, GPreloadInfo *info, const g_preload_info_add_instruction(info, instr); - g_object_ref(G_OBJECT(instr)); - ADD_STR_AS_SYM(format, symbol, instr); + irange = g_arch_instruction_get_range(instr); + + symbol = g_binary_symbol_new(irange, STP_RO_STRING); + g_binary_format_add_symbol(base, symbol); /* Jointure avec la chaîne précédente ? */ @@ -113,7 +117,7 @@ static void parse_elf_string_table(GElfFormat *format, GPreloadInfo *info, const copy_vmpa(&pos, get_mrange_addr(range)); advance_vmpa(&pos, i); - label = create_string_label(G_BIN_FORMAT(format), &pos, end - i); + label = create_string_label(base, get_mrange_addr(irange), end - i); g_binary_symbol_set_alt_label(symbol, label); diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c index 352069c..e19a4c0 100644 --- a/src/analysis/disass/area.c +++ b/src/analysis/disass/area.c @@ -32,7 +32,8 @@ #include -#include "../../analysis/contents/restricted.h" +#include "../routine.h" +#include "../contents/restricted.h" #include "../../arch/raw.h" #include "../../common/bits.h" #include "../../common/sort.h" @@ -654,27 +655,25 @@ static void update_address_as_routine(GBinFormat *format, const vmpa2t *addr) if (!found || (found && wrong_type)) { + if (found) + g_binary_format_remove_symbol(format, symbol); + init_mrange(&range, addr, 0); vmpa2_virt_to_string(addr, MDS_UNDEFINED, loc, NULL); snprintf(name, sizeof(name), "sub_%s", loc + 2); routine = g_binary_routine_new(); - g_binary_routine_set_name(routine, strdup(name)); + symbol = G_BIN_SYMBOL(routine); - g_binary_routine_set_range(routine, &range); + g_binary_routine_set_name(routine, strdup(name)); + g_binary_symbol_set_range(symbol, &range); - if (!found) - { - symbol = g_binary_symbol_new(STP_ROUTINE); - g_binary_symbol_attach_routine(symbol, routine); - g_binary_format_add_symbol(format, symbol); - } - else _g_binary_symbol_attach_routine(symbol, routine, STP_ROUTINE); + g_binary_format_add_symbol(format, symbol); } - if (found) + else g_object_unref(G_OBJECT(symbol)); } diff --git a/src/analysis/disass/limit.c b/src/analysis/disass/limit.c index df9f23c..bcc594f 100644 --- a/src/analysis/disass/limit.c +++ b/src/analysis/disass/limit.c @@ -27,7 +27,7 @@ /****************************************************************************** * * -* Paramètres : routine = routine dont les frontières sont à fixer. * +* Paramètres : symbol = routine dont les frontières sont à fixer. * * next = adresse du prochain symbole présent. * * proc = ensemble d'instructions désassemblées. * * portions = ensemble de couches binaires bornées. * @@ -40,7 +40,7 @@ * * ******************************************************************************/ -void compute_routine_limit(GBinRoutine *routine, const vmpa2t *next, GArchProcessor *proc, GBinPortion *portions) +void compute_routine_limit(GBinSymbol *symbol, const vmpa2t *next, GArchProcessor *proc, GBinPortion *portions) { const mrange_t *range; /* Emplacement courant */ vmpa2t addr; /* Adresse à conserver */ @@ -49,7 +49,7 @@ void compute_routine_limit(GBinRoutine *routine, const vmpa2t *next, GArchProces GBinPortion *portion; /* Conteneur avec limites */ mrange_t new; /* Nouvel emplacement taillé */ - range = g_binary_routine_get_range(routine); + range = g_binary_symbol_get_range(symbol); if (get_mrange_length(range) > 0) goto crl_skip; copy_vmpa(&addr, get_mrange_addr(range)); @@ -91,7 +91,7 @@ void compute_routine_limit(GBinRoutine *routine, const vmpa2t *next, GArchProces init_mrange(&new, &addr, diff); - g_binary_routine_set_range(routine, &new); + g_binary_symbol_set_range(symbol, &new); crl_skip: diff --git a/src/analysis/disass/limit.h b/src/analysis/disass/limit.h index c26b450..ce76a43 100644 --- a/src/analysis/disass/limit.h +++ b/src/analysis/disass/limit.h @@ -25,14 +25,14 @@ #define _ANALYSIS_DISASS_LIMIT_H -#include "../routine.h" #include "../../arch/processor.h" #include "../../format/executable.h" +#include "../../format/symbol.h" /* S'assure qu'une routine est bien bornée. */ -void compute_routine_limit(GBinRoutine *, const vmpa2t *, GArchProcessor *, GBinPortion *); +void compute_routine_limit(GBinSymbol *, const vmpa2t *, GArchProcessor *, GBinPortion *); diff --git a/src/analysis/disass/routines.c b/src/analysis/disass/routines.c index 1150f08..5d6dc42 100644 --- a/src/analysis/disass/routines.c +++ b/src/analysis/disass/routines.c @@ -231,14 +231,16 @@ GRoutinesStudy *g_routines_study_new(GArchProcessor *proc, GBinPortion *portions static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *status) { size_t i; /* Boucle de parcours */ - GBinRoutine *routine; /* Routine à traiter */ + GBinSymbol *symbol; /* Commodité d'accès */ + SymbolType type; /* Type de symbole rencontré */ for (i = study->begin; i < study->end; i++) { - routine = g_binary_symbol_get_routine(study->symbols[i]); + symbol = study->symbols[i]; + type = g_binary_symbol_get_target_type(symbol); - if (routine != NULL) - study->fallback(study, routine, i); + if (type == STP_ROUTINE || type == STP_ENTRY_POINT) + study->fallback(study, G_BIN_ROUTINE(symbol), i); gtk_status_stack_update_activity_value(status, study->id, 1); @@ -263,9 +265,12 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine, size_t index) { + GBinSymbol *symbol; /* Version alternative */ const mrange_t *range; /* Zone du symbole suivant */ const vmpa2t *next; /* Début de la zone suivante */ + symbol = G_BIN_SYMBOL(routine); + if ((index + 1) < study->count) { range = g_binary_symbol_get_range(study->symbols[index + 1]); @@ -275,7 +280,7 @@ void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine else next = NULL; - compute_routine_limit(routine, next, study->proc, study->portions); + compute_routine_limit(symbol, next, study->proc, study->portions); } @@ -296,6 +301,7 @@ void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine void g_routines_study_handle_blocks(GRoutinesStudy *study, GBinRoutine *routine, size_t index) { + GBinSymbol *symbol; /* Version alternative */ const mrange_t *range; /* Couverture d'une routine */ const vmpa2t *start; /* Adresse de départ */ const instr_coverage *coverage; /* Instructions couvertes */ @@ -304,7 +310,9 @@ void g_routines_study_handle_blocks(GRoutinesStudy *study, GBinRoutine *routine, /* Préparatifs communs */ - range = g_binary_routine_get_range(routine); + symbol = G_BIN_SYMBOL(routine); + + range = g_binary_symbol_get_range(symbol); start = get_mrange_addr(range); coverage = g_arch_processor_find_coverage_by_address(study->proc, start); diff --git a/src/analysis/disass/routines.h b/src/analysis/disass/routines.h index dc81bb1..4b3efa9 100644 --- a/src/analysis/disass/routines.h +++ b/src/analysis/disass/routines.h @@ -25,6 +25,7 @@ #define _ANALYSIS_DISASS_ROUTINES_H +#include "../routine.h" #include "../../arch/processor.h" #include "../../format/executable.h" #include "../../format/symbol.h" diff --git a/src/analysis/routine.c b/src/analysis/routine.c index c916c66..b882428 100644 --- a/src/analysis/routine.c +++ b/src/analysis/routine.c @@ -45,8 +45,6 @@ struct _GBinRoutine { GBinSymbol parent; /* A laisser en premier */ - mrange_t range; /* Couverture mémoire */ - RoutineType type; /* Type de routine */ GDataType *ret_type; /* Type retourné */ @@ -88,6 +86,9 @@ 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(GBinRoutine *); + /* Indique le type définit pour une représentation de routine. */ @@ -108,6 +109,11 @@ G_DEFINE_TYPE(GBinRoutine, g_bin_routine, G_TYPE_BIN_SYMBOL); static void g_bin_routine_class_init(GBinRoutineClass *klass) { + GBinSymbolClass *symbol; /* Autre version de la classe */ + + symbol = G_BIN_SYMBOL_CLASS(klass); + + symbol->get_label = (get_symbol_label_fc)g_binary_routine_get_label; } @@ -126,6 +132,11 @@ static void g_bin_routine_class_init(GBinRoutineClass *klass) static void g_bin_routine_init(GBinRoutine *routine) { + GBinSymbol *symbol; /* Autre version de l'instance */ + + symbol = G_BIN_SYMBOL(routine); + + g_binary_symbol_set_target_type(symbol, STP_ROUTINE); } @@ -212,85 +223,6 @@ void g_binary_routine_finalize(GBinRoutine *routine) /****************************************************************************** * * -* Paramètres : a = premières informations à consulter. * -* b = secondes informations à consulter. * -* * -* Description : Etablit la comparaison ascendante entre deux routines. * -* * -* Retour : Bilan : -1 (a < b), 0 (a == b) ou 1 (a > b). * -* * -* Remarques : - * -* * -******************************************************************************/ - -int g_binary_routine_compare(const GBinRoutine **a, const GBinRoutine **b) -{ - return cmp_mrange(&(*a)->range, &(*b)->range); - -} - - -/****************************************************************************** -* * -* Paramètres : a = premières informations à consulter. * -* b = secondes informations à consulter. * -* * -* Description : Etablit la comparaison descendante entre deux routines. * -* * -* Retour : Bilan : 1 (a < b), 0 (a == b) ou -1 (a > b). * -* * -* Remarques : - * -* * -******************************************************************************/ - -int g_binary_routine_rcompare(const GBinRoutine **a, const GBinRoutine **b) -{ - return (-1) * cmp_mrange(&(*a)->range, &(*b)->range); - -} - - -/****************************************************************************** -* * -* Paramètres : routine = routine à mettre à jour. * -* range = plage mémoire ou physique déclarée. * -* * -* Description : Définit la couverture physique / en mémoire d'une routine. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_binary_routine_set_range(GBinRoutine *routine, const mrange_t *range) -{ - copy_mrange(&routine->range, range); - -} - - -/****************************************************************************** -* * -* Paramètres : routine = routine à consulter. * -* * -* Description : Fournit la couverture physique / en mémoire d'une routine. * -* * -* Retour : Plage mémoire ou physique déclarée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const mrange_t *g_binary_routine_get_range(const GBinRoutine *routine) -{ - return &routine->range; - -} - - -/****************************************************************************** -* * * Paramètres : routine = routine à mettre à jour. * * type = type de routine spécifié. * * * @@ -699,6 +631,25 @@ const char *g_binary_routine_get_declarator(GBinRoutine *routine, bool full) /****************************************************************************** * * +* 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 : - * +* * +******************************************************************************/ + +static const char *g_binary_routine_get_label(GBinRoutine *routine) +{ + return g_binary_routine_get_declarator(routine, false); + +} + + +/****************************************************************************** +* * * Paramètres : routine = routine à mettre à jour. * * offset = position abstraite à retrouver. * * local = indique le type de variable à manipuler. * @@ -1125,6 +1076,7 @@ char *g_binary_routine_build_tooltip(const GBinRoutine *routine, const GLoadedBi char *string_info; /* Détails des chaînes */ GArchProcessor *proc; /* Architecture utilisée */ GBufferCache *cache; /* Tampon de désassemblage */ + const mrange_t *srange; /* Couverture de la routine */ instr_iter_t *iter; /* Parcours local d'adresses */ GArchInstruction *instr; /* Instruction correspondante */ size_t dcount; /* Nombre de liens de dest. */ @@ -1163,10 +1115,12 @@ char *g_binary_routine_build_tooltip(const GBinRoutine *routine, const GLoadedBi /* Parcours des instructions */ - iter = g_arch_processor_get_iter_from_address(proc, get_mrange_addr(&routine->range)); + srange = g_binary_symbol_get_range(G_BIN_SYMBOL(routine)); + + iter = g_arch_processor_get_iter_from_address(proc, get_mrange_addr(srange)); if (iter == NULL) goto gbrbt_no_iter; - restrict_instruction_iterator(iter, &routine->range); + restrict_instruction_iterator(iter, srange); for (instr = get_instruction_iterator_current(iter); instr != NULL; diff --git a/src/analysis/routine.h b/src/analysis/routine.h index b040c6c..48cec13 100644 --- a/src/analysis/routine.h +++ b/src/analysis/routine.h @@ -83,12 +83,6 @@ GBinRoutine *g_binary_routine_new(void); /* Crée une représentation de routine construisant une instance. */ GBinRoutine *g_binary_routine_new_constructor(GDataType *); -/* Etablit la comparaison ascendante entre deux routines. */ -int g_binary_routine_compare(const GBinRoutine **, const GBinRoutine **); - -/* Etablit la comparaison descendante entre deux routines. */ -int g_binary_routine_rcompare(const GBinRoutine **, const GBinRoutine **); - /* Définit la couverture physique / en mémoire d'une routine. */ void g_binary_routine_set_range(GBinRoutine *, const mrange_t *); diff --git a/src/arch/arm/v7/post.c b/src/arch/arm/v7/post.c index 4600700..415b278 100644 --- a/src/arch/arm/v7/post.c +++ b/src/arch/arm/v7/post.c @@ -53,7 +53,6 @@ void post_process_ldr_instructions(GArchInstruction *instr, GArchProcessor *proc mrange_t trange; /* Etendue du symbole à créer */ VMPA_BUFFER(loc); /* Espace pour une conversion */ char name[5 + VMPA_MAX_LEN]; /* Etiquette à constituer */ - GBinRoutine *routine; /* Nouvelle routine trouvée */ GBinSymbol *symbol; /* Nouveau symbole construit */ g_arch_instruction_lock_operands(instr); @@ -79,14 +78,8 @@ void post_process_ldr_instructions(GArchInstruction *instr, GArchProcessor *proc vmpa2_virt_to_string(&target, MDS_UNDEFINED, loc, NULL); snprintf(name, sizeof(name), "loc_%s", loc + 2); - routine = g_binary_routine_new(); - g_binary_routine_set_name(routine, strdup(name)); - //routine = try_to_demangle_routine(name); - - g_binary_routine_set_range(routine, &trange); - - symbol = g_binary_symbol_new(STP_CODE_LABEL); - g_binary_symbol_attach_routine(symbol, routine); + symbol = g_binary_symbol_new(&trange, STP_CODE_LABEL); + g_binary_symbol_set_alt_label(symbol, name); g_binary_format_add_symbol(bfmt, symbol); g_target_operand_resolve(&new, bfmt, true, NULL); diff --git a/src/arch/dalvik/link.c b/src/arch/dalvik/link.c index d1404d0..6508b03 100644 --- a/src/arch/dalvik/link.c +++ b/src/arch/dalvik/link.c @@ -35,6 +35,7 @@ #include "pseudo/switch.h" #include "../target.h" +#include "../../analysis/db/items/comment.h" #include "../../common/extstr.h" diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c index a450ffe..fa7ed54 100644 --- a/src/arch/dalvik/operands/pool.c +++ b/src/arch/dalvik/operands/pool.c @@ -340,7 +340,7 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBuff case DPT_STRING: - string = get_string_from_dex_pool(operand->format, operand->index); + string = get_string_from_dex_pool(operand->format, operand->index, NULL); if (string != NULL) { diff --git a/src/arch/post.c b/src/arch/post.c index 1463709..f8864aa 100644 --- a/src/arch/post.c +++ b/src/arch/post.c @@ -29,6 +29,7 @@ #include "processor.h" #include "target.h" +#include "../analysis/routine.h" @@ -79,16 +80,27 @@ void post_process_target_resolution(GArchInstruction *instr, GArchProcessor *pro if (!g_target_operand_resolve(&new, bfmt, true, NULL)) { + init_mrange(&trange, &target, 0); + vmpa2_to_string(&target, MDS_UNDEFINED, loc, NULL); switch (type) { case STP_ROUTINE: snprintf(name, sizeof(name), "sub_%s", loc + 2); + + routine = g_binary_routine_new(); + symbol = G_BIN_SYMBOL(routine); + + g_binary_symbol_set_range(symbol, &trange); + g_binary_routine_set_name(routine, strdup(name)); break; case STP_CODE_LABEL: snprintf(name, sizeof(name), "loc_%s", loc + 2); + + symbol = g_binary_symbol_new(&trange, type); + g_binary_symbol_set_alt_label(symbol, name); break; default: @@ -97,14 +109,6 @@ void post_process_target_resolution(GArchInstruction *instr, GArchProcessor *pro } - routine = g_binary_routine_new(); - g_binary_routine_set_name(routine, strdup(name)); - - init_mrange(&trange, &target, 0); - g_binary_routine_set_range(routine, &trange); - - symbol = g_binary_symbol_new(type); - g_binary_symbol_attach_routine(symbol, routine); g_binary_format_add_symbol(bfmt, symbol); g_target_operand_resolve(&new, bfmt, true, NULL); diff --git a/src/arch/target.c b/src/arch/target.c index a863d69..056ace3 100644 --- a/src/arch/target.c +++ b/src/arch/target.c @@ -34,6 +34,7 @@ #include "operand-int.h" #include "sharing/manager.h" +#include "../analysis/routine.h" #include "../common/extstr.h" #include "../format/format.h" @@ -433,7 +434,6 @@ static char *g_target_operand_build_tooltip(const GTargetOperand *operand, const { char *result; /* Description à retourner */ SymbolType stype; /* Type de symbole identifié */ - GBinRoutine *routine; /* Routine à manipuler */ const mrange_t *srange; /* Emplacement du symbole */ GBufferCache *cache; /* Tampon de désassemblage */ size_t index; /* Indice de ligne à traiter */ @@ -449,13 +449,7 @@ static char *g_target_operand_build_tooltip(const GTargetOperand *operand, const { case STP_ROUTINE: case STP_ENTRY_POINT: - - routine = g_binary_symbol_get_routine(operand->symbol); - - result = g_binary_routine_build_tooltip(routine, binary); - - //g_object_unref(G_OBJECT(routine)); // TODO - + result = g_binary_routine_build_tooltip(G_BIN_ROUTINE(operand->symbol), binary); break; case STP_STRING: 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 -#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 *); diff --git a/src/gtkext/gtkgraphdisplay.c b/src/gtkext/gtkgraphdisplay.c index 8139b3a..ee3853f 100644 --- a/src/gtkext/gtkgraphdisplay.c +++ b/src/gtkext/gtkgraphdisplay.c @@ -31,6 +31,7 @@ #include "gtkbufferdisplay.h" #include "gtkdisplaypanel-int.h" #include "graph/cluster.h" +#include "../analysis/routine.h" #include "../format/format.h" #include "../gui/editem.h" @@ -615,6 +616,7 @@ static void gtk_graph_display_define_main_address(GtkGraphDisplay *display, cons GExeFormat *format; /* Type de fichier chargé */ GBinSymbol *symbol; /* Symbole présent à l'adresse */ bool found; /* Bilan des recherches */ + SymbolType type; /* Type de symbole rencontré */ GBlockList *list; /* Liste de blocs basiques */ gint right; /* Abscisse du coin droit */ gint bottom; /* Ordonnée du coin inférieur */ @@ -639,15 +641,17 @@ static void gtk_graph_display_define_main_address(GtkGraphDisplay *display, cons if (!found) goto ggddma_done; - if (g_binary_symbol_get_routine(symbol) == NULL) - goto ggddma_done; + type = g_binary_symbol_get_target_type(symbol); + + if (type != STP_ROUTINE && type != STP_ENTRY_POINT) + goto ggddma_bad_type; display->routine = symbol; g_object_ref(G_OBJECT(symbol)); display->highlighted = init_segment_content_list(); - list = g_binary_routine_get_basic_blocks(g_binary_symbol_get_routine(symbol)); + list = g_binary_routine_get_basic_blocks(G_BIN_ROUTINE(symbol)); display->cluster = bootstrap_graph_cluster(GTK_DISPLAY_PANEL(display)->binary, list, display->highlighted); @@ -673,6 +677,10 @@ static void gtk_graph_display_define_main_address(GtkGraphDisplay *display, cons gtk_graph_display_update_support_margins(display, &allocation); + ggddma_bad_type: + + g_object_unref(G_OBJECT(symbol)); + ggddma_done: change_editor_items_current_view_content(GTK_DISPLAY_PANEL(display)); -- cgit v0.11.2-87-g4458