diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-03-11 21:57:05 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-03-11 21:57:05 (GMT) |
commit | 8088f1cbb4304c686ff41520099707a333084a4e (patch) | |
tree | 147411c3f90097dc1ae950ec390df2dfccf07ad7 /src/core/demanglers.c | |
parent | a33dd28e763e3a8b04145fb549aca9320e100a4b (diff) |
Defined a new Dex demangler with MUTF-8 support as plugin.
Diffstat (limited to 'src/core/demanglers.c')
-rw-r--r-- | src/core/demanglers.c | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/src/core/demanglers.c b/src/core/demanglers.c new file mode 100644 index 0000000..409018e --- /dev/null +++ b/src/core/demanglers.c @@ -0,0 +1,191 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * demanglers.c - enregistrement et fourniture des décodeurs proprosés + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "demanglers.h" + + +#include <string.h> + + + +/* Caractéristiques d'un processeur */ +typedef struct _demangler_t +{ + char *key; /* Clef pour un accès rapide */ + GType instance; /* Type à manipuler en interne */ + +} demangler_t; + + +/* Mémorisation des types de décodeurs enregistrés */ +static demangler_t *_demanglers_definitions = NULL; +static size_t _demanglers_definitions_count = 0; + +/* Verrou pour des accès atomiques */ +G_LOCK_DEFINE_STATIC(_ddef_access); + + +/* Retrouve l'enregistrement correspondant à un décodeur. */ +static demangler_t *find_demangler_by_key(const char *); + + + +/****************************************************************************** +* * +* Paramètres : key = désignation rapide et interne d'un décodeur. * +* instance = type GLib représentant le type à instancier. * +* * +* Description : Enregistre un décodeur répondant à une appellation donnée. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_demangler_type(const char *key, GType instance) +{ + bool result; /* Bilan à retourner */ + demangler_t *new; /* Nouvel élément à définir */ + + G_LOCK(_ddef_access); + + new = find_demangler_by_key(key); + + result = (new == NULL); + + if (result) + { + _demanglers_definitions = (demangler_t *)realloc(_demanglers_definitions, + ++_demanglers_definitions_count * sizeof(demangler_t)); + + new = &_demanglers_definitions[_demanglers_definitions_count - 1]; + + new->key = strdup(key); + new->instance = instance; + + } + + G_UNLOCK(_ddef_access); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Décharge toutes les définitions de décodeurs. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void unload_demanglers_definitions(void) +{ + size_t i; /* Boucle de parcours */ + + G_LOCK(_ddef_access); + + for (i = 0; i < _demanglers_definitions_count; i++) + free(_demanglers_definitions[i].key); + + if (_demanglers_definitions != NULL) + free(_demanglers_definitions); + + _demanglers_definitions = NULL; + _demanglers_definitions_count = 0; + + G_UNLOCK(_ddef_access); + +} + + +/****************************************************************************** +* * +* Paramètres : key = nom technique du décodeur recherché. * +* * +* Description : Retrouve l'enregistrement correspondant à un décodeur. * +* * +* Retour : Définition trouvée ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static demangler_t *find_demangler_by_key(const char *key) +{ + demangler_t *result; /* Trouvaille à retourner */ + size_t i; /* Boucle de parcours */ + + /** + * Le verrou d'accès global doit être posé ! + */ + + result = NULL; + + if (key != NULL) + for (i = 0; i < _demanglers_definitions_count; i++) + if (strcmp(_demanglers_definitions[i].key, key) == 0) + result = &_demanglers_definitions[i]; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : key = nom technique du décodeur recherché. * +* * +* Description : Fournit le décodeur de désignations correspondant à un type. * +* * +* Retour : Décodeur trouvé et mis en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GCompDemangler *get_compiler_demangler_for_type(const char *key) +{ + GCompDemangler *result; /* Instance à retourner */ + demangler_t *def; /* Définition de décodeur */ + + G_LOCK(_ddef_access); + + def = find_demangler_by_key(key); + + if (def == NULL) + result = NULL; + else + result = g_object_new(def->instance, NULL); + + G_UNLOCK(_ddef_access); + + return result; + +} |