diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2012-10-18 00:28:06 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2012-10-18 00:28:06 (GMT) |
commit | f7d126acb7718d4a13ac64c0d71c7d019cc8c18c (patch) | |
tree | b4b32237b99344beba8c03333972efb8f108a5cf /src/arch/x86/operands/moffs.c | |
parent | 2cfb66fcd5e8293d1dd689691bdc8c3517dd183a (diff) |
Reorganized the code for the x86 architecture support.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@274 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/x86/operands/moffs.c')
-rw-r--r-- | src/arch/x86/operands/moffs.c | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/src/arch/x86/operands/moffs.c b/src/arch/x86/operands/moffs.c new file mode 100644 index 0000000..3754e79 --- /dev/null +++ b/src/arch/x86/operands/moffs.c @@ -0,0 +1,189 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * moffs.c - opérandes d'emplacements mémoire + * + * 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 "moffs.h" + + +#include "../../immediate.h" +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ +struct _GX86MOffsOperand +{ + GArchOperand parent; /* Instance parente */ + + GImmOperand *offset; /* Adresse mémoire visée */ + +}; + +/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ +struct _GX86MOffsOperandClass +{ + GArchOperandClass parent; /* Classe parente */ + +}; + + +/* Initialise la classe des opérandes d'emplacement mémoire x86. */ +static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *); + +/* Initialise une instance d'opérande d'emplacement mémoire x86. */ +static void g_x86_moffs_operand_init(GX86MOffsOperand *); + +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *, GRenderingOptions *, MainRendering, FILE *); + +/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *, GBufferLine *, GRenderingOptions *); + + + +/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ +G_DEFINE_TYPE(GX86MOffsOperand, g_x86_moffs_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des opérandes d'emplacement mémoire x86.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : operand = instance à initialiser. * +* * +* Description : Initialise une instance d'opérande d'emplacement mémoire x86.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_x86_moffs_operand_init(GX86MOffsOperand *operand) +{ + GContentExporter *parent; /* Instance parente */ + + parent = G_CONTENT_EXPORTER(operand); + + parent->add_text = (add_text_fc)g_x86_moffs_operand_add_text; + parent->export_buffer = (export_buffer_fc)g_x86_moffs_operand_to_buffer; + +} + + +/****************************************************************************** +* * +* Paramètres : data = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* len = taille totale des données à analyser. * +* size = taille de l'opérande, et donc du registre. * +* * +* Description : Crée un opérande d'emplacement mémoire x86. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size) +{ + GX86MOffsOperand *result; /* Structure à retourner */ + GImmOperand *offset; /* Emplacement lu */ + + result = NULL; + + offset = g_imm_operand_new_from_data(size, data, pos, len, SRE_LITTLE /* FIXME */); + + if (offset != NULL) + { + result = g_object_new(G_TYPE_X86_MOFFS_OPERAND, NULL); + result->offset = offset; + } + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à transcrire. * +* options = options de rendu. * +* rendering = support effectif final des lignes de code. * +* stream = flux ouvert en écriture. * +* * +* Description : Ajoute du texte simple à un fichier ouvert en écriture. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ + g_content_exporter_insert_text(G_CONTENT_EXPORTER(operand), stream, "ds:", 3, RTT_SEGMENT); + + g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->offset), options, rendering, stream); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à transcrire. * +* buffer = espace où placer ledit contenu. * +* options = options de rendu. * +* * +* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *operand, GBufferLine *buffer, GRenderingOptions *options) +{ + g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, + "ds:", 3, RTT_SEGMENT); + + g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->offset), buffer, options); + +} |