summaryrefslogtreecommitdiff
path: root/src/arch/x86/operand.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-03-21 18:54:20 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-03-21 18:54:20 (GMT)
commit8123d9342f92a2cf6fd999b350252c001f403092 (patch)
tree5030aa5d40fa8551937649cdd3377062ec8991d0 /src/arch/x86/operand.c
parenta6acb5629572e6da4d72f4419b01672c2ea5ddf2 (diff)
Allowed a simple export of an assembly content.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@144 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/x86/operand.c')
-rw-r--r--src/arch/x86/operand.c225
1 files changed, 213 insertions, 12 deletions
diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c
index cf4c863..7d6437a 100644
--- a/src/arch/x86/operand.c
+++ b/src/arch/x86/operand.c
@@ -89,6 +89,9 @@ 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 texte GTK le contenu d'un opérande. */
static void g_x86_register_operand_add_to_gtk_buffer(const GX86RegisterOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -124,6 +127,9 @@ 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 texte GTK le contenu d'un opérande. */
static void g_x86_mod_rm_operand_add_to_gtk_buffer(const GX86ModRMOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -155,6 +161,9 @@ 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 texte GTK le contenu d'un opérande. */
static void g_x86_relative_operand_add_to_gtk_buffer(const GX86RelativeOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -186,6 +195,9 @@ 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 texte GTK le contenu d'un opérande. */
static void g_x86_moffs_operand_add_to_gtk_buffer(const GX86MOffsOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -218,6 +230,9 @@ 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 texte GTK le contenu d'un opérande. */
static void g_x86_data_operand_add_to_gtk_buffer(const GX86DataOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -314,6 +329,7 @@ static void g_x86_register_operand_init(GX86RegisterOperand *operand)
parent = G_CONTENT_EXPORTER(operand);
+ parent->add_text = (add_text_fc)g_x86_register_operand_add_text;
parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_register_operand_add_to_gtk_buffer;
}
@@ -438,6 +454,28 @@ GArchOperand *g_x86_register_operand_new_from_index(bin_t index, AsmOperandSize
/******************************************************************************
* *
* 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. *
* format = format du binaire manipulé. *
* syntax = type de représentation demandée. *
* buffer = zone de texte à venir compléter. *
@@ -504,6 +542,7 @@ static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand)
parent = G_CONTENT_EXPORTER(operand);
+ parent->add_text = (add_text_fc)g_x86_mod_rm_operand_add_text;
parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_mod_rm_operand_add_to_gtk_buffer;
}
@@ -614,11 +653,89 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len,
/******************************************************************************
* *
+* 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. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
-* buffer = zone de texte à venir compléter. *
-* iter = point d'insertion du nouveau texte. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
@@ -802,6 +919,7 @@ static void g_x86_relative_operand_init(GX86RelativeOperand *operand)
parent = G_CONTENT_EXPORTER(operand);
+ parent->add_text = (add_text_fc)g_x86_relative_operand_add_text;
parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_relative_operand_add_to_gtk_buffer;
}
@@ -863,11 +981,33 @@ GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t le
/******************************************************************************
* *
+* 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. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
-* buffer = zone de texte à venir compléter. *
-* iter = point d'insertion du nouveau texte. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
@@ -950,6 +1090,7 @@ static void g_x86_moffs_operand_init(GX86MOffsOperand *operand)
parent = G_CONTENT_EXPORTER(operand);
+ parent->add_text = (add_text_fc)g_x86_moffs_operand_add_text;
parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_moffs_operand_add_to_gtk_buffer;
}
@@ -992,6 +1133,30 @@ GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len,
/******************************************************************************
* *
+* 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. *
* format = format du binaire manipulé. *
* syntax = type de représentation demandée. *
@@ -1063,6 +1228,7 @@ static void g_x86_data_operand_init(GX86DataOperand *operand)
parent = G_CONTENT_EXPORTER(operand);
+ parent->add_text = (add_text_fc)g_x86_data_operand_add_text;
parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_data_operand_add_to_gtk_buffer;
}
@@ -1098,10 +1264,45 @@ GArchOperand *g_x86_data_operand_new(MemoryDataSize size, bool dest)
/******************************************************************************
* *
* Paramètres : operand = opérande à transcrire. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
-* buffer = zone de texte à venir compléter. *
-* iter = point d'insertion du nouveau texte. *
+* 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. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *