summaryrefslogtreecommitdiff
path: root/src/arch/x86
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
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')
-rw-r--r--src/arch/x86/operand.c225
-rw-r--r--src/arch/x86/registers.c93
2 files changed, 290 insertions, 28 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. *
* *
diff --git a/src/arch/x86/registers.c b/src/arch/x86/registers.c
index 4e186ed..90346f7 100644
--- a/src/arch/x86/registers.c
+++ b/src/arch/x86/registers.c
@@ -106,6 +106,15 @@ struct _GX86RegisterClass
};
+#define MAX_REGNAME_LEN 5
+
+
+/* Construit la chaîne de caractères correspondant à l'opérande. */
+static void g_x86_register_to_string(const GX86Register *, AsmSyntax, char [MAX_REGNAME_LEN], size_t *);
+
+/* Ajoute du texte simple à un fichier ouvert en écriture. */
+static void g_x86_register_add_text(const GX86Register *, GRenderingOptions *, MainRendering, FILE *);
+
/* Ajoute à un texte GTK le contenu d'un opérande. */
static void g_x86_register_add_to_gtk_buffer(const GX86Register *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -151,6 +160,7 @@ static void g_x86_register_init(GX86Register *reg)
parent = G_CONTENT_EXPORTER(reg);
+ parent->add_text = (add_text_fc)g_x86_register_add_text;
parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_register_add_to_gtk_buffer;
}
@@ -232,15 +242,15 @@ GX86Register *g_x86_register_new(MemoryDataSize size, bin_t value)
}
+
/******************************************************************************
* *
* 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. *
+* syntax = type de représentation demandée. *
+* key = description humaine du registre. [OUT] *
+* klen = nombre de caractères utilisés. [OUT] *
* *
-* Description : Ajoute à un texte GTK le contenu d'un opérande. *
+* Description : Construit la chaîne de caractères correspondant à l'opérande.*
* *
* Retour : - *
* *
@@ -248,12 +258,9 @@ GX86Register *g_x86_register_new(MemoryDataSize size, bin_t value)
* *
******************************************************************************/
-static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
+static void g_x86_register_to_string(const GX86Register *reg, AsmSyntax syntax, char key[MAX_REGNAME_LEN], size_t *klen)
{
- char key[5]; /* Mot clef principal */
- size_t klen; /* Taille de ce mot clef */
-
- klen = 0;
+ *klen = 0;
switch (syntax)
{
@@ -261,7 +268,7 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
switch (reg->size)
{
case AOS_8_BITS:
- klen = 2;
+ *klen = 2;
switch (reg->reg.reg8)
{
case X86_REG8_AL:
@@ -295,7 +302,7 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
break;
case AOS_16_BITS:
- klen = 2;
+ *klen = 2;
switch (reg->reg.reg16)
{
case X86_REG16_AX:
@@ -329,7 +336,7 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
break;
case AOS_32_BITS:
- klen = 3;
+ *klen = 3;
switch (reg->reg.reg32)
{
case X86_REG32_EAX:
@@ -373,7 +380,7 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
switch (reg->size)
{
case AOS_8_BITS:
- klen = 3;
+ *klen = 3;
switch (reg->reg.reg8)
{
case X86_REG8_AL:
@@ -407,7 +414,7 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
break;
case AOS_16_BITS:
- klen = 3;
+ *klen = 3;
switch (reg->reg.reg16)
{
case X86_REG16_AX:
@@ -441,7 +448,7 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
break;
case AOS_32_BITS:
- klen = 4;
+ *klen = 4;
switch (reg->reg.reg32)
{
case X86_REG32_EAX:
@@ -485,6 +492,60 @@ static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExe
}
+}
+
+
+/******************************************************************************
+* *
+* 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_add_text(const GX86Register *reg, GRenderingOptions *options, MainRendering rendering, FILE *stream)
+{
+ char key[MAX_REGNAME_LEN]; /* Mot clef principal */
+ size_t klen; /* Taille de ce mot clef */
+
+ g_x86_register_to_string(reg, g_rendering_options_get_syntax(options), key, &klen);
+
+ g_content_exporter_insert_text(G_CONTENT_EXPORTER(reg), stream,
+ key, klen, RTT_REGISTER);
+
+}
+
+
+/******************************************************************************
+* *
+* 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. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
+{
+ char key[MAX_REGNAME_LEN]; /* Mot clef principal */
+ size_t klen; /* Taille de ce mot clef */
+
+ g_x86_register_to_string(reg, syntax, key, &klen);
+
g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(reg), buffer, iter,
key, klen, RTT_REGISTER);