summaryrefslogtreecommitdiff
path: root/src/arch/instruction.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/instruction.c')
-rw-r--r--src/arch/instruction.c83
1 files changed, 79 insertions, 4 deletions
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index cfc8ace..677a1a3 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -39,10 +39,10 @@ static void g_arch_instruction_class_init(GArchInstructionClass *);
static void g_arch_instruction_init(GArchInstruction *);
/* Ajoute du texte simple à un fichier ouvert en écriture. */
-static void g_arch_instruction_add_text(const GArchInstruction *, GRenderingOptions *, MainRendering, FILE *);
+static void g_arch_instruction_add_text(const GArchInstruction *, GRenderingOptions *, MainRendering, FILE *) __attribute__ ((deprecated));
/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
-static void g_arch_instruction_to_buffer(const GArchInstruction *, GBufferLine *, GRenderingOptions *);
+static void g_arch_instruction_to_buffer(const GArchInstruction *, GBufferLine *, GRenderingOptions *) __attribute__ ((deprecated));
@@ -241,7 +241,7 @@ void g_arch_instruction_set_location(GArchInstruction *instr, off_t offset, off_
* *
******************************************************************************/
-void g_arch_instruction_get_location(GArchInstruction *instr, off_t *offset, off_t *length, vmpa_t *address)
+void g_arch_instruction_get_location(const GArchInstruction *instr, off_t *offset, off_t *length, vmpa_t *address)
{
if (offset != NULL) *offset = instr->offset;
if (length != NULL) *length = instr->length;
@@ -578,6 +578,81 @@ size_t g_arch_instruction_get_destinations(const GArchInstruction *instr, GArchI
/******************************************************************************
* *
+* Paramètres : instr = instruction d'assemblage à représenter. *
+* buffer = espace où placer ledit contenu. *
+* syntax = type de représentation demandée. *
+* *
+* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax)
+{
+ GBufferLine *line; /* Ligne de destination */
+ char address[VMPA_MAX_SIZE]; /* Adresse au format texte */
+ size_t len; /* Taille de l'élément inséré */
+ char *bin_code; /* Tampon du code binaire */
+ off_t i; /* Boucle de parcours #1 */
+ const char *key; /* Mot clef principal */
+ size_t klen; /* Taille de ce mot clef */
+ size_t j; /* Boucle de parcours #2 */
+
+ line = g_code_buffer_append_new_line(buffer);
+
+ /* Adresse virtuelle ou physique */
+
+ len = vmpa_to_string(instr->address, msize, address);
+
+ g_buffer_line_insert_text(line, BLC_ADDRESS, address, len, RTT_RAW);
+
+ /* Code brut */
+
+ bin_code = (char *)calloc(instr->length * 3, sizeof(char));
+
+ for (i = 0; i < instr->length; i++)
+ {
+ if ((i + 1) < instr->length)
+ snprintf(&bin_code[i * (2 + 1)], 4, "%02hhx ", content[instr->offset + i]);
+ else
+ snprintf(&bin_code[i * (2 + 1)], 3, "%02hhx", content[instr->offset + i]);
+ }
+
+ g_buffer_line_insert_text(line, BLC_BINARY,
+ bin_code, instr->length * 3 - 1, RTT_RAW_CODE);
+
+ free(bin_code);
+
+ /* Instruction proprement dite */
+
+ key = instr->get_text(instr, NULL/* FIXME */, 0/* FIXME */);
+ klen = strlen(key);
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, key, klen, RTT_INSTRUCTION);
+
+ if (instr->operands_count > 0)
+ {
+ g_arch_operand_print(instr->operands[0], line, syntax);
+
+ for (j = 1; j < instr->operands_count; j++)
+ {
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, ",", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, " ", 1, RTT_NONE);
+
+ g_arch_operand_print(instr->operands[j], line, syntax);
+
+ }
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : instr = instruction d'origine à convertir. *
* ctx = contexte de la phase de décompilation. *
* *
@@ -643,7 +718,7 @@ void g_arch_instruction_add_to_list(GArchInstruction **list, GArchInstruction *i
* *
******************************************************************************/
-GArchInstruction *g_arch_instruction_get_next_iter(GArchInstruction *list, const GArchInstruction *iter, vmpa_t max)
+GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *list, const GArchInstruction *iter, vmpa_t max)
{
GArchInstruction *result; /* Elément suivant à renvoyer */