summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-01-29 20:56:31 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-01-29 21:04:47 (GMT)
commit6c51b9eed427fd55ce1457834853386cc8d543cd (patch)
tree47b8106bdb086278386d05c838178a06cc00f805 /src/format
parent8a7d7b3303dee1a381893391c04acab35dec6942 (diff)
Handled properly imported/exported ELF symbols, as well as all other symbols.
Diffstat (limited to 'src/format')
-rw-r--r--src/format/format-int.h5
-rw-r--r--src/format/format.c189
-rw-r--r--src/format/format.h14
-rw-r--r--src/format/symiter.c5
4 files changed, 206 insertions, 7 deletions
diff --git a/src/format/format-int.h b/src/format/format-int.h
index f377ca3..5c1ae07 100644
--- a/src/format/format-int.h
+++ b/src/format/format-int.h
@@ -39,6 +39,9 @@
/* Indique le boutisme employé par le format binaire analysé. */
typedef SourceEndian (* format_get_endian_fc) (const GBinFormat *);
+/* Réalise un traitement post-désassemblage. */
+typedef void (* format_complete_analysis_fc) (GBinFormat *, GtkStatusStack *);
+
/* Procède à la décompilation complète du format. */
typedef void (* format_decompile_fc) (const GBinFormat *, void/*GCodeBuffer*/ *, const char *);
@@ -105,6 +108,8 @@ struct _GBinFormatClass
format_get_endian_fc get_endian; /* Boutisme employé */
+ format_complete_analysis_fc complete; /* Terminaison d'analyse */
+
};
diff --git a/src/format/format.c b/src/format/format.c
index 5b96b59..88367f6 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -64,6 +64,9 @@ static void g_binary_format_delete_duplicated_symbols(GBinFormat *);
/* Recherche le symbole associé à une adresse. */
static bool _g_binary_format_find_symbol(const GBinFormat *, const vmpa2t *, __compar_fn_t, size_t *, GBinSymbol **);
+/* Recherche un symbole particulier. */
+static bool __g_binary_format_find_symbol(const GBinFormat *, const void *, __compar_fn_t, size_t *, GBinSymbol **);
+
/* Indique le type défini pour un format binaire générique. */
@@ -369,6 +372,31 @@ void g_binary_format_activate_disassembling_context(GBinFormat *format, GProcCon
}
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à manipuler. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Réalise un traitement post-désassemblage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_binary_format_complete_analysis(GBinFormat *format, GtkStatusStack *status)
+{
+ GBinFormatClass *class; /* Classe de l'instance */
+
+ class = G_BIN_FORMAT_GET_CLASS(format);
+
+ if (class->complete != NULL)
+ class->complete(format, status);
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* RASSEMBLEMENT ET GESTION DE SYMBOLES */
@@ -450,6 +478,26 @@ void g_binary_format_lock_unlock_symbols_wr(GBinFormat *format, bool state)
* *
* Paramètres : format = architecture à consulter via la procédure. *
* *
+* Description : Assure qu'un verrou est bien posé pour l'accès aux symboles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+#ifndef NDEBUG
+void g_binary_format_check_for_symbols_lock(const GBinFormat *format)
+{
+ assert(g_atomic_int_get(&format->sym_locked) > 0);
+
+}
+#endif
+
+
+/******************************************************************************
+* *
+* Paramètres : format = architecture à consulter via la procédure. *
+* *
* Description : Fournit la marque de dernière modification des symboles. *
* *
* Retour : Marque de la dernière modification de la liste de symboles. *
@@ -882,11 +930,6 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label,
static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t *addr, __compar_fn_t fn, size_t *index, GBinSymbol **symbol)
{
- bool result; /* Bilan à retourner */
- void *found; /* Résultat de recherches */
-
- assert(g_atomic_int_get(&format->sym_locked) > 0);
-
/**
* Pour ce qui est des justifications quant à la vérification suivante,
* se référer aux commentaires placés dans g_binary_format_add_symbol().
@@ -894,7 +937,35 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t
assert(has_phys_addr(addr));
- found = bsearch(addr, format->symbols, format->sym_count, sizeof(GBinSymbol *), fn);
+ return __g_binary_format_find_symbol(format, addr, fn, index, symbol);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* key = clef fournie pour distinguer les éléments. *
+* fn = méthode de comparaison des symboles. *
+* index = indice de l'éventuel symbole trouvé ou NULL. [OUT] *
+* symbol = éventuel symbole trouvé à déréfenrencer. [OUT] *
+* *
+* Description : Recherche un symbole particulier. *
+* *
+* Retour : true si l'opération a été un succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool __g_binary_format_find_symbol(const GBinFormat *format, const void *key, __compar_fn_t fn, size_t *index, GBinSymbol **symbol)
+{
+ bool result; /* Bilan à retourner */
+ void *found; /* Résultat de recherches */
+
+ assert(g_atomic_int_get(&format->sym_locked) > 0);
+
+ found = bsearch(key, format->symbols, format->sym_count, sizeof(GBinSymbol *), fn);
if (found != NULL)
{
@@ -913,8 +984,11 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t
else
{
- *symbol = NULL;
+ if (symbol != NULL)
+ *symbol = NULL;
+
result = false;
+
}
return result;
@@ -926,6 +1000,45 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t
* *
* Paramètres : format = informations chargées à consulter. *
* addr = adresse à cibler lors des recherches. *
+* index = indice de l'éventuel symbole trouvé. [OUT] *
+* *
+* Description : Recherche l'indice du symbole correspondant à une adresse. *
+* *
+* Retour : true si l'opération a été un succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr, size_t *index)
+{
+ bool result; /* Bilan à retourner */
+
+ int find_symbol(const vmpa2t *addr, const GBinSymbol **sym)
+ {
+ const mrange_t *range; /* Espace mémoire parcouru */
+
+ range = g_binary_symbol_get_range(*sym);
+
+ return cmp_vmpa(addr, get_mrange_addr(range));
+
+ }
+
+ g_binary_format_lock_symbols_rd(format);
+
+ result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, index, NULL);
+
+ g_binary_format_unlock_symbols_rd(format);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* addr = adresse à cibler lors des recherches. *
* symbol = éventuel symbole trouvé à déréfenrencer. [OUT] *
* *
* Description : Recherche le symbole correspondant à une adresse. *
@@ -1056,6 +1169,68 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr,
/******************************************************************************
* *
* Paramètres : format = informations chargées à consulter. *
+* range = zone à cibler lors des recherches. *
+* index = indice de l'éventuel symbole trouvé. [OUT] *
+* *
+* Description : Recherche le premier symbole inclus dans une zone mémoire. *
+* *
+* Retour : true si l'opération a été un succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t *range, size_t *index)
+{
+ bool result; /* Bilan à retourner */
+ const GBinSymbol *prev; /* Symbole précédent */
+ const mrange_t *srange; /* Espace mémoire associé */
+ int ret; /* Bilan de comparaison */
+
+ int find_symbol(const mrange_t *ref_range, const GBinSymbol **sym)
+ {
+ const mrange_t *sym_range; /* Espace mémoire parcouru */
+
+ int ret;
+
+ sym_range = g_binary_symbol_get_range(*sym);
+
+ ret = cmp_mrange_with_vmpa(ref_range, get_mrange_addr(sym_range));
+
+ ret *= -1;
+
+ return ret;
+
+ }
+
+ g_rw_lock_reader_lock(&format->syms_lock);
+
+ result = __g_binary_format_find_symbol(format, range, (__compar_fn_t)find_symbol, index, NULL);
+
+ if (result)
+ while (*index > 0)
+ {
+ prev = format->symbols[*index - 1];
+ srange = g_binary_symbol_get_range(prev);
+
+ ret = cmp_mrange_with_vmpa(range, get_mrange_addr(srange));
+ assert(ret <= 0);
+
+ if (ret < 0) break;
+ else (*index)--;
+
+ }
+
+ g_rw_lock_reader_unlock(&format->syms_lock);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
* addr = adresse à cibler lors des recherches. *
* strict = indication de tolérance acceptée. *
* symbol = éventuel symbole trouvé à déréfenrencer. [OUT] *
diff --git a/src/format/format.h b/src/format/format.h
index 9a3a6e3..4052482 100644
--- a/src/format/format.h
+++ b/src/format/format.h
@@ -70,6 +70,9 @@ void g_binary_format_preload_disassembling_context(GBinFormat *, GProcContext *,
/* Définit les points de départ d'un contexte de désassemblage. */
void g_binary_format_activate_disassembling_context(GBinFormat *, GProcContext *, GtkStatusStack *);
+/* Réalise un traitement post-désassemblage. */
+void g_binary_format_complete_analysis(GBinFormat *, GtkStatusStack *);
+
/* ---------------------- RASSEMBLEMENT ET GESTION DE SYMBOLES ---------------------- */
@@ -87,6 +90,11 @@ void g_binary_format_lock_unlock_symbols_wr(GBinFormat *, bool);
#define g_binary_format_lock_symbols_wr(f) g_binary_format_lock_unlock_symbols_wr(f, true)
#define g_binary_format_unlock_symbols_wr(f) g_binary_format_lock_unlock_symbols_wr(f, false)
+/* Assure qu'un verrou est bien posé pour l'accès aux symboles. */
+#ifndef NDEBUG
+void g_binary_format_check_for_symbols_lock(const GBinFormat *);
+#endif
+
/* Fournit la marque de dernière modification des symboles. */
unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *);
@@ -108,6 +116,9 @@ char *create_string_label(GBinFormat *, const vmpa2t *, size_t);
/* Recherche le symbole correspondant à une étiquette. */
bool g_binary_format_find_symbol_by_label(GBinFormat *, const char *, GBinSymbol **);
+/* Recherche l'indice du symbole correspondant à une adresse. */
+bool g_binary_format_find_symbol_index_at(GBinFormat *, const vmpa2t *, size_t *);
+
/* Recherche le symbole correspondant à une adresse. */
bool g_binary_format_find_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **);
@@ -117,6 +128,9 @@ bool g_binary_format_find_symbol_for(GBinFormat *, const vmpa2t *, GBinSymbol **
/* Recherche le symbole suivant celui lié à une adresse. */
bool g_binary_format_find_next_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **);
+/* Recherche le premier symbole inclus dans une zone mémoire. */
+bool g_binary_format_find_first_symbol_inside(GBinFormat *, const mrange_t *, size_t *);
+
/* Recherche le symbole correspondant à une adresse. */
bool g_binary_format_resolve_symbol(GBinFormat *, const vmpa2t *, bool, GBinSymbol **, phys_t *);
diff --git a/src/format/symiter.c b/src/format/symiter.c
index 74b4abb..230b4ac 100644
--- a/src/format/symiter.c
+++ b/src/format/symiter.c
@@ -63,6 +63,11 @@ sym_iter_t *create_symbol_iterator(GBinFormat *format, size_t index)
{
sym_iter_t *result; /* Structure à retourner */
+#ifndef NDEBUG
+ if (index > 0)
+ g_binary_format_check_for_symbols_lock(format);
+#endif
+
result = (sym_iter_t *)malloc(sizeof(sym_iter_t));
g_object_ref(G_OBJECT(format));