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/operand.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/operand.c')
-rw-r--r-- | src/arch/x86/operand.c | 1305 |
1 files changed, 0 insertions, 1305 deletions
diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c index 36faa76..85f2fb9 100644 --- a/src/arch/x86/operand.c +++ b/src/arch/x86/operand.c @@ -23,1311 +23,6 @@ #include "operand.h" -#include <malloc.h> -#include <math.h> -#include <stdarg.h> -#include <stdio.h> - - -#include "../operand-int.h" -#include "../../common/extstr.h" - - - -/* ---------------------- COQUILLE VIDE POUR LES OPERANDES X86 ---------------------- */ - - -/* Définition d'un opérande de x86 (instance) */ -struct _GX86Operand -{ - GArchOperand parent; /* Instance parente */ - -}; - - -/* Définition d'un opérande de x86 (classe) */ -struct _GX86OperandClass -{ - GArchOperandClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des opérandes x86 de base. */ -static void g_x86_operand_class_init(GX86OperandClass *); - -/* Initialise une instance d'opérande de base pour x86. */ -static void g_x86_operand_init(GX86Operand *); - - - -/* ------------------------ OPERANDES VISANT UN REGISTRE X86 ------------------------ */ - - -/* Définition d'un opérande visant un registre x86 (instance) */ -struct _GX86RegisterOperand -{ - GX86Operand parent; /* Instance parente */ - - GX86Register *reg; /* Registre représenté */ - -}; - - -/* Définition d'un opérande visant un registre x86 (classe) */ -struct _GX86RegisterOperandClass -{ - GX86OperandClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des opérandes de registre x86. */ -static void g_x86_register_operand_class_init(GX86RegisterOperandClass *); - -/* Initialise une instance d'opérande de registre x86. */ -static void g_x86_register_operand_init(GX86RegisterOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_register_operand_add_text(const GX86RegisterOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ----------------------- OPERANDES COMPLEXES DE TYPE MOD/RM ----------------------- */ - - -/* Définition d'un opérande x86 de type ModRM (instance) */ -struct _GX86ModRMOperand -{ - GX86Operand parent; /* Instance parente */ - - uint8_t scale; /* Puissance de deux */ - GX86Register *index; /* Registre servant d'indice */ - GX86Register *base; /* Registre de base */ - GImmOperand *displacement; /* Décallage supplémentaire */ - -}; - - -/* Définition d'un opérande x86 de type ModRM (classe) */ -struct _GX86ModRMOperandClass -{ - GX86OperandClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des opérandes x86 de type ModRM. */ -static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *); - -/* Initialise une instance d'opérande x86 de type ModRM. */ -static void g_x86_mod_rm_operand_init(GX86ModRMOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ------------------------- OPERANDES D'ADRESSES RELATIVES ------------------------- */ - - -/* Définition d'un opérande x86 d'adresse relative (instance) */ -struct _GX86RelativeOperand -{ - GX86Operand parent; /* Instance parente */ - - GImmOperand *immediate; /* Adresse visée reconstituée */ - -}; - -/* Définition d'un opérande x86 d'adresse relative (classe) */ -struct _GX86RelativeOperandClass -{ - GX86OperandClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des opérandes x86 d'adresse relative. */ -static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *); - -/* Initialise une instance d'opérande x86 d'adresse relative. */ -static void g_x86_relative_operand_init(GX86RelativeOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_relative_operand_add_text(const GX86RelativeOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ - - -/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ -struct _GX86MOffsOperand -{ - GX86Operand 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 -{ - GX86OperandClass 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 *); - - - -/* ---------------------- OPERANDES DE MANIPULATION DE DONNEES ---------------------- */ - - -/* Définition d'un opérande x86 de manipulation de données (instance) */ -struct _GX86DataOperand -{ - GX86Operand parent; /* Instance parente */ - - GX86Register *reg; /* Registre représenté */ - bool dest; /* Déduction du type de segment*/ - -}; - -/* Définition d'un opérande x86 de manipulation de données (classe) */ -struct _GX86DataOperandClass -{ - GX86OperandClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des opérandes x86 pointant des données. */ -static void g_x86_data_operand_class_init(GX86DataOperandClass *); - -/* Initialise une instance d'opérande x86 pointant des données. */ -static void g_x86_data_operand_init(GX86DataOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_data_operand_add_text(const GX86DataOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_data_operand_to_buffer(const GX86DataOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ---------------------------------------------------------------------------------- */ -/* COQUILLE VIDE POUR LES OPERANDES X86 */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de x86. */ -G_DEFINE_TYPE(GX86Operand, g_x86_operand, G_TYPE_ARCH_OPERAND); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des opérandes x86 de base. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_operand_class_init(GX86OperandClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance à initialiser. * -* * -* Description : Initialise une instance d'opérande de base pour x86. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_operand_init(GX86Operand *operand) -{ - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* OPERANDES VISANT UN REGISTRE X86 */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de registre x86. */ -G_DEFINE_TYPE(GX86RegisterOperand, g_x86_register_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des opérandes de registre x86. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_register_operand_class_init(GX86RegisterOperandClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance à initialiser. * -* * -* Description : Initialise une instance d'opérande de registre x86. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_register_operand_init(GX86RegisterOperand *operand) -{ - GContentExporter *parent; /* Instance parente */ - - parent = G_CONTENT_EXPORTER(operand); - - parent->add_text = (add_text_fc)g_x86_register_operand_add_text; - parent->export_buffer = (export_buffer_fc)g_x86_register_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. * -* base = indice du premier registre. * -* * -* Description : Crée un opérande visant un registre x86. * -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bin_t base) -{ - GX86RegisterOperand *result; /* Structure à retourner */ - GX86Register *reg; /* Registre lu */ - - reg = g_x86_register_new(size, data[*pos] - base); - - if (reg != NULL) - { - (*pos)++; - - result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); - - result->reg = reg; - - } - else result = NULL; - - return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -* * -* 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. * -* first = indique la partie du ModR/M à traiter. * -* * -* Description : Crée un opérande visant un registre x86. * -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bool first) -{ - GX86RegisterOperand *result; /* Structure à retourner */ - bin_t index; /* Registre lu */ - GX86Register *reg; /* Registre créé */ - - if (first) index = data[*pos] & 0x07; - else index = (data[*pos] & 0x38) >> 3; - - reg = g_x86_register_new(size, index); - - if (reg != NULL) - { - (*pos)++; - - result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); - - result->reg = reg; - - } - else result = NULL; - - return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -* * -* Paramètres : index = indice du registre visé. * -* size = taille de l'opérande, et donc du registre. * -* * -* Description : Crée un opérande visant un registre x86 donné. * -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_x86_register_operand_new_from_index(bin_t index, MemoryDataSize size) -{ - GX86RegisterOperand *result; /* Structure à retourner */ - GX86Register *reg; /* Registre lu */ - - reg = g_x86_register_new(size, index); - - if (reg != NULL) - { - result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); - - result->reg = reg; - - } - else result = NULL; - - 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_register_operand_add_text(const GX86RegisterOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ - g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), 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_register_operand_to_buffer(const GX86RegisterOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ - g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* OPERANDES COMPLEXES DE TYPE MOD/RM */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ -G_DEFINE_TYPE(GX86ModRMOperand, g_x86_mod_rm_operand, G_TYPE_ARCH_OPERAND); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des opérandes x86 de type ModRM. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance à initialiser. * -* * -* Description : Initialise une instance d'opérande x86 de type ModRM. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand) -{ - GContentExporter *parent; /* Instance parente */ - - parent = G_CONTENT_EXPORTER(operand); - - parent->add_text = (add_text_fc)g_x86_mod_rm_operand_add_text; - parent->export_buffer = (export_buffer_fc)g_x86_mod_rm_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 x86 de type ModRM. * -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size) -{ - GX86ModRMOperand *result; /* Structure à retourner */ - uint8_t mod; /* Modificateur présent */ - GX86Register *reg; /* Registre lu */ - - mod = (data[*pos] & 0xc0); - - if (mod == 0xc0) - return g_x86_register_operand_new_from_mod_rm(data, pos, len, size, true); - - reg = g_x86_register_new(size, data[*pos] & 0x07); - if (reg == NULL) return NULL; - - (*pos)++; - - /* Vieille astuce de l'emplacement mémoire fixe ? */ - if (g_x86_register_is_base_pointer(reg) && mod == 0x00) - { - /* FIXME *///free_x86_register(reg); - return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE /*FIXME*/); - } - - result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL); - - /* A la recherche d'un SIB */ - if (g_x86_register_is_stack_pointer(reg)) - { - /* FIXME *///free_x86_register(reg); - - result->base = g_x86_register_new(size, data[*pos] & 0x07); - if (result->base == NULL) goto gxmron_error; - - result->index = g_x86_register_new(size, (data[*pos] & 0x38) >> 3); - if (result->index == NULL) goto gxmron_error; - - result->scale = ((data[*pos] & 0xc0) >> 6); - - if (g_x86_register_is_stack_pointer(result->index)) - { - /* FIXME *///free_x86_register(result->index); - result->index = result->base; - result->base = NULL; - } - - (*pos)++; - - } - - else result->index = reg; - - /* Décallage supplémentaire ? */ - switch (mod) - { - case 0x00: - if (result->base != NULL && g_x86_register_is_base_pointer(result->base)) - { - /* FIXME *///free_x86_register(result->base); - result->base = NULL; - - result->displacement = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE /* FIXME */); - if (result->displacement == NULL) goto gxmron_error; - - } - break; - - case 0x40: - result->displacement = g_imm_operand_new_from_data(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE /* FIXME */); - if (result->displacement == NULL) goto gxmron_error; - break; - - case 0x80: - result->displacement = g_imm_operand_new_from_data(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE /* FIXME */); - if (result->displacement == NULL) goto gxmron_error; - break; - - } - - return G_ARCH_OPERAND(result); - - gxmron_error: - - /* FIXME free(result);*/ - return NULL; - -} - - -/****************************************************************************** -* * -* 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_mod_rm_operand_add_text(const GX86ModRMOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ - GContentExporter *exporter; /* Autre vision de l'opérande */ - char tmp[2]; /* Echelle en puissance de 2 */ - - exporter = G_CONTENT_EXPORTER(operand); - - switch (g_rendering_options_get_syntax(options)) - { - case ASX_INTEL: - - g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK); - - if (operand->scale > 0) - { - snprintf(tmp, 2, "%d", (int)pow(2, operand->scale)); - - g_content_exporter_insert_text(exporter, stream, tmp, 1, RTT_IMMEDIATE); - - g_content_exporter_insert_text(exporter, stream, "*", 1, RTT_SIGNS); - - } - - g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->index), - options, rendering, stream); - - if (operand->base != NULL) - { - g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS); - - g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->base), - options, rendering, stream); - - } - - if (operand->displacement != NULL) - { - if (g_imm_operand_is_negative(operand->displacement)) - g_content_exporter_insert_text(exporter, stream, "-", 1, RTT_SIGNS); - else - g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS); - - g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->displacement), - options, rendering, stream); - - } - - g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK); - - break; - - case ASX_ATT: - - /* TODO */ - g_content_exporter_insert_text(exporter, stream, "[ModRM]", 7, RTT_HOOK); - - break; - - } - -} - - -/****************************************************************************** -* * -* 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_mod_rm_operand_to_buffer(const GX86ModRMOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ - GContentExporter *exporter; /* Autre vision de l'opérande */ - char tmp[2]; /* Echelle en puissance de 2 */ - - exporter = G_CONTENT_EXPORTER(operand); - - switch (g_rendering_options_get_syntax(options)) - { - case ASX_INTEL: - - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "[", 1, RTT_HOOK); - - if (operand->scale > 0) - { - snprintf(tmp, 2, "%d", (int)pow(2, operand->scale)); - - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - tmp, 1, RTT_IMMEDIATE); - - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "*", 1, RTT_SIGNS); - - } - - g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->index), buffer, options); - - if (operand->base != NULL) - { - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "+", 1, RTT_SIGNS); - - g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->base), buffer, options); - - } - - if (operand->displacement != NULL) - { - if (g_imm_operand_is_negative(operand->displacement)) - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "-", 1, RTT_SIGNS); - else - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "+", 1, RTT_SIGNS); - - g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->displacement), buffer, options); - - } - - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "]", 1, RTT_HOOK); - - break; - - case ASX_ATT: - - /* TODO */ - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "[ModRM]", 7, RTT_HOOK); - - break; - - } - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à consulter. * -* scale = facteur sous forme de puissance de deux. [OUT * -* index = register principal de l'opérande. [OUT] * -* * -* Description : Fournit l'indice et l'échelle d'un opérande x86 ModRM. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *scale, const GX86Register **index) -{ - *scale = operand->scale; - *index = operand->index; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à consulter. * -* * -* Description : Fournit le registre de base d'un opérande x86 ModRM. * -* * -* Retour : Registre de base de l'opérande. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *operand) -{ - return operand->base; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à consulter. * -* * -* Description : Fournit le décallage supplémentaire d'un opérande x86 ModRM. * -* * -* Retour : Décallage numérique pour l'opérande. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *operand) -{ - return operand->displacement; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* OPERANDES D'ADRESSES RELATIVES */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ -G_DEFINE_TYPE(GX86RelativeOperand, g_x86_relative_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des opérandes x86 d'adresse relative. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance à initialiser. * -* * -* Description : Initialise une instance d'opérande x86 d'adresse relative. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_relative_operand_init(GX86RelativeOperand *operand) -{ - GContentExporter *parent; /* Instance parente */ - - parent = G_CONTENT_EXPORTER(operand); - - parent->add_text = (add_text_fc)g_x86_relative_operand_add_text; - parent->export_buffer = (export_buffer_fc)g_x86_relative_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. * -* base = adresse de référence pour le calcul. * -* * -* Description : Crée un opérande X86 d'adresse relative. * -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, vmpa_t base) -{ - GX86RelativeOperand *result; /* Structure à retourner */ - off_t init_pos; /* Position avant lecture */ - int8_t val8; /* Valeur sur 8 bits */ - int16_t val16; /* Valeur sur 16 bits */ - int32_t val32; /* Valeur sur 32 bits */ - vmpa_t address; /* Adresse finale visée */ - - init_pos = *pos; - - switch (size) - { - case MDS_8_BITS_UNSIGNED: - read_s8(&val8, data, pos, len, SRE_LITTLE /* FIXME */); - address = base + (*pos - init_pos) + val8; - break; - case MDS_16_BITS_UNSIGNED: - read_s16(&val16, data, pos, len, SRE_LITTLE /* FIXME */); - address = base + (*pos - init_pos) + val16; - break; - case MDS_32_BITS_UNSIGNED: - read_s32(&val32, data, pos, len, SRE_LITTLE /* FIXME */); - address = base + (*pos - init_pos) + val32; - break; - default: - return NULL; - break; - } - - result = g_object_new(G_TYPE_X86_RELATIVE_OPERAND, NULL); - result->immediate = g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */); - - 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_relative_operand_add_text(const GX86RelativeOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ - g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->immediate), 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_relative_operand_to_buffer(const GX86RelativeOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ - g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->immediate), buffer, options); - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à traiter. * -* * -* Description : Fournit l'adresse représentée par une opérande X86. * -* * -* Retour : Valeur portée par l'opérande. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *operand) -{ - return operand->immediate; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* OPERANDES D'EMPLACEMENTS MEMOIRE */ -/* ---------------------------------------------------------------------------------- */ - - -/* 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_X86_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); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* OPERANDES DE MANIPULATION DE DONNEES */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */ -G_DEFINE_TYPE(GX86DataOperand, g_x86_data_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des opérandes x86 pointant des données. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_data_operand_class_init(GX86DataOperandClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance à initialiser. * -* * -* Description : Initialise une instance d'opérande pointant des données. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_x86_data_operand_init(GX86DataOperand *operand) -{ - GContentExporter *parent; /* Instance parente */ - - parent = G_CONTENT_EXPORTER(operand); - - parent->add_text = (add_text_fc)g_x86_data_operand_add_text; - parent->export_buffer = (export_buffer_fc)g_x86_data_operand_to_buffer; - -} - - -/****************************************************************************** -* * -* Paramètres : size = taille de l'opérande, et donc du registre. * -* dest = indique si la cible est une destination ou une source.* -* * -* Description : Crée un opérande x86 de manipulation de données. * -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_x86_data_operand_new(MemoryDataSize size, bool dest) -{ - GX86DataOperand *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_X86_DATA_OPERAND, NULL); - - result->reg = g_x86_register_new(MDS_32_BITS/* FIXME size*/, dest ? 0x07 : 0x06); - result->dest = dest; - - 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_data_operand_add_text(const GX86DataOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ - GContentExporter *exporter; /* Autre vision de l'opérande */ - - exporter = G_CONTENT_EXPORTER(operand); - - if (operand->dest) - g_content_exporter_insert_text(exporter, stream, "es:", 3, RTT_SEGMENT); - else - g_content_exporter_insert_text(exporter, stream, "ds:", 3, RTT_SEGMENT); - - g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK); - - g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); - - g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK); - -} - - -/****************************************************************************** -* * -* 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_data_operand_to_buffer(const GX86DataOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ - GContentExporter *exporter; /* Autre vision de l'opérande */ - - exporter = G_CONTENT_EXPORTER(operand); - - if (operand->dest) - g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, - "es:", 3, RTT_SEGMENT); - else - g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, - "ds:", 3, RTT_SEGMENT); - - g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, - "[", 1, RTT_HOOK); - - g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); - - g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, - "]", 1, RTT_HOOK); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* AIDE A LA CREATION D'OPERANDES */ -/* ---------------------------------------------------------------------------------- */ - /****************************************************************************** * * |