summaryrefslogtreecommitdiff
path: root/src/core/formats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/formats.c')
-rw-r--r--src/core/formats.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/core/formats.c b/src/core/formats.c
index 891fc12..1326fc4 100644
--- a/src/core/formats.c
+++ b/src/core/formats.c
@@ -41,6 +41,7 @@
typedef struct _format_matcher_t
{
format_match_fc func; /* Recherche de correspondance */
+ void *data; /* Eventuelle donnée à y lier */
} format_matcher_t;
@@ -76,6 +77,7 @@ static format_loader_t *find_format_by_key(const char *);
/******************************************************************************
* *
* Paramètres : func = procédure de détection à utiliser. *
+* data = éventuelle donnée à associer aux opérations. *
* *
* Description : Enregistre un détection de format(s) binaire(s). *
* *
@@ -85,18 +87,24 @@ static format_loader_t *find_format_by_key(const char *);
* *
******************************************************************************/
-bool register_format_matcher(format_match_fc func)
+bool register_format_matcher(format_match_fc func, void *data)
{
bool result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
+ const format_matcher_t *cur; /* Elément parcouru et analysé */
format_matcher_t *new; /* Nouvel élément à définir */
g_rw_lock_writer_lock(&_formats_lock);
for (i = 0; i < _formats_matchers_count; i++)
- if (_formats_matchers[i].func == func)
+ {
+ cur = &_formats_matchers[i];
+
+ if (cur->func == func && cur->data == data)
break;
+ }
+
result = (i == _formats_matchers_count);
if (result)
@@ -107,6 +115,7 @@ bool register_format_matcher(format_match_fc func)
new = &_formats_matchers[_formats_matchers_count - 1];
new->func = func;
+ new->data = data;
}
@@ -186,9 +195,9 @@ bool load_hard_coded_formats_definitions(void)
/* Détections */
- result &= register_format_matcher(dwarf_is_matching);
+ result &= register_format_matcher(dwarf_is_matching, NULL);
- result &= register_format_matcher(elf_is_matching);
+ result &= register_format_matcher(elf_is_matching, NULL);
/* Chargements */
@@ -315,27 +324,32 @@ const char *get_binary_format_name(const char *key)
* *
* Paramètres : content = contenu binaire à parcourir. *
* parent = éventuel format exécutable déjà chargé. *
+* key = identifiant de format trouvé ou NULL. [OUT] *
* *
* Description : Identifie un format binaire par son contenu. *
* *
-* Retour : Identifiant du format binaire trouvé ou NULL si échec. *
+* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *find_matching_format(GBinContent *content, GExeFormat *parent)
+FormatMatchStatus find_matching_format(GBinContent *content, GExeFormat *parent, char **key)
{
- const char *result; /* Identifiant à retourner */
+ FormatMatchStatus result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
+ const format_matcher_t *cur; /* Elément parcouru et analysé */
- result = NULL;
+ result = FMS_UNKNOWN;
g_rw_lock_reader_lock(&_formats_lock);
- for (i = 0; i < _formats_matchers_count && result == NULL; i++)
+ for (i = 0; i < _formats_matchers_count && result == FMS_UNKNOWN; i++)
{
- result = _formats_matchers[i].func(content, parent);
+ cur = &_formats_matchers[i];
+
+ result = cur->func(content, parent, cur->data, key);
+
}
g_rw_lock_reader_unlock(&_formats_lock);