diff options
Diffstat (limited to 'src/analysis/blocks/virtual.c')
-rw-r--r-- | src/analysis/blocks/virtual.c | 244 |
1 files changed, 244 insertions, 0 deletions
diff --git a/src/analysis/blocks/virtual.c b/src/analysis/blocks/virtual.c new file mode 100644 index 0000000..113e333 --- /dev/null +++ b/src/analysis/blocks/virtual.c @@ -0,0 +1,244 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * virtual.c - encadrement des instructions par blocs virtuels + * + * Copyright (C) 2012 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "virtual.h" + + +#include <malloc.h> + + +#include "../block-int.h" + + + +/* Description d'un bloc d'exécution d'instructions (instance) */ +struct _GVirtualBlock +{ + GInstrBlock parent; /* A laisser en premier */ + + GArchInstruction *instrs; /* Liste complète d'instruct° */ + GArchInstruction *first; /* Première instruction */ + GArchInstruction *last; /* Dernière instruction */ + + reg_access *accesses; /* Commodités d'accès #1 */ + size_t count; /* Commodités d'accès #2 */ + + + GInstrBlock **children; /* Sous-blocs intégrés */ + size_t children_count; /* Nombre de ces sous-blocs */ + +}; + +/* Description d'un bloc d'exécution d'instructions (classe) */ +struct _GVirtualBlockClass +{ + GInstrBlockClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des blocs d'instructions. */ +static void g_virtual_block_class_init(GVirtualBlockClass *); + +/* Initialise un bloc d'instructions. */ +static void g_virtual_block_init(GVirtualBlock *); + +/* Supprime toutes les références externes. */ +static void g_virtual_block_dispose(GVirtualBlock *); + +/* Procède à la libération totale de la mémoire. */ +static void g_virtual_block_finalize(GVirtualBlock *); + +/* Fournit les différents accès aux registres. */ +static const reg_access *g_virtual_block_list_regs_accesses(const GVirtualBlock *, size_t *); + + + +/* Indique le type défini pour un bloc virtuel d'instructions. */ +G_DEFINE_TYPE(GVirtualBlock, g_virtual_block, G_TYPE_INSTR_BLOCK); + + +/****************************************************************************** +* * +* Paramètres : class = classe à initialiser. * +* * +* Description : Initialise la classe des blocs d'instructions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_virtual_block_class_init(GVirtualBlockClass *class) +{ + GObjectClass *object; /* Autre version de la classe */ + + object = G_OBJECT_CLASS(class); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_virtual_block_dispose; + object->finalize = (GObjectFinalizeFunc)g_virtual_block_finalize; + +} + + +/****************************************************************************** +* * +* Paramètres : block = instance à initialiser. * +* * +* Description : Initialise un bloc d'instructions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_virtual_block_init(GVirtualBlock *block) +{ + GInstrBlock *parent; /* Instance parente */ + + parent = G_INSTR_BLOCK(block); + + parent->list_regs = (list_regs_accesses_fc)g_virtual_block_list_regs_accesses; + +} + + +/****************************************************************************** +* * +* Paramètres : block = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_virtual_block_dispose(GVirtualBlock *block) +{ + size_t i; /* Boucle de parcours */ + + for (i = 0; i < block->children_count; i++) + g_object_unref(G_OBJECT(block->children[i])); + + G_OBJECT_CLASS(g_virtual_block_parent_class)->dispose(G_OBJECT(block)); + +} + + +/****************************************************************************** +* * +* Paramètres : block = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_virtual_block_finalize(GVirtualBlock *block) +{ + if (block->accesses != NULL) + free(block->accesses); + + if (block->children != NULL) + free(block->children); + + G_OBJECT_CLASS(g_virtual_block_parent_class)->finalize(G_OBJECT(block)); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée un bloc virtuel d'instructions. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GInstrBlock *g_virtual_block_new(void) +{ + GVirtualBlock *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_VIRTUAL_BLOCK, NULL); + + return G_INSTR_BLOCK(result); + +} + + +/****************************************************************************** +* * +* Paramètres : block = bloc d'instructions à consulter. * +* count = nombre de registres consignés. [OUT] * +* * +* Description : Fournit les différents accès aux registres. * +* * +* Retour : Liste des accès aux registres. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static const reg_access *g_virtual_block_list_regs_accesses(const GVirtualBlock *block, size_t *count) +{ + *count = 0; + + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : block = bloc d'instructions à compléter. * +* child = sous-bloc à insérer. * +* * +* Description : Ajoute un bloc au groupe courant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_virtual_block_add_child(GVirtualBlock *block, GInstrBlock *child) +{ + block->children = (GInstrBlock **)realloc(block->children, + ++block->children_count * sizeof(GInstrBlock *)); + + block->children[block->children_count - 1] = child; + + g_object_ref(G_OBJECT(child)); + +} |