summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/processor-int.h3
-rw-r--r--src/arch/processor.c5
-rw-r--r--src/arch/processor.h3
-rw-r--r--src/arch/x86/processor.c34
4 files changed, 34 insertions, 11 deletions
diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h
index 50837e1..5dc12ff 100644
--- a/src/arch/processor-int.h
+++ b/src/arch/processor-int.h
@@ -32,6 +32,7 @@
#include "operand.h" /* TODO: AsmSyntax ? */
#include "instruction.h"
#include "processor.h"
+#include "../format/exe_format.h"
@@ -41,7 +42,7 @@
typedef asm_instr * (* fetch_instruction) (const asm_processor *, const uint8_t *, off_t *, off_t, uint64_t);
/* Traduit une instruction en version humainement lisible. */
-typedef void (* print_instruction) (const asm_processor *, const asm_instr *, char *, size_t, AsmSyntax);
+typedef void (* print_instruction) (const asm_processor *, const exe_format *, const asm_instr *, char *, size_t, AsmSyntax);
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 31cfb3e..0afca2c 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -74,6 +74,7 @@ asm_instr *decode_instruction(const asm_processor *proc, const uint8_t *data, of
/******************************************************************************
* *
* Paramètres : proc = architecture visée par la procédure. *
+* format = format du binaire manipulé. *
* instr = instruction à traiter. *
* buffer = tampon de sortie mis à disposition. [OUT] *
* len = taille de ce tampon. *
@@ -87,9 +88,9 @@ asm_instr *decode_instruction(const asm_processor *proc, const uint8_t *data, of
* *
******************************************************************************/
-void print_hinstruction(const asm_processor *proc, const asm_instr *instr, char *buffer, size_t len, AsmSyntax syntax)
+void print_hinstruction(const asm_processor *proc, const exe_format *format, const asm_instr *instr, char *buffer, size_t len, AsmSyntax syntax)
{
- proc->print_instr(proc, instr, buffer, len, syntax);
+ proc->print_instr(proc, format, instr, buffer, len, syntax);
}
diff --git a/src/arch/processor.h b/src/arch/processor.h
index e147f38..287a761 100644
--- a/src/arch/processor.h
+++ b/src/arch/processor.h
@@ -30,6 +30,7 @@
#include "operand.h" /* AsmSyntax */
#include "instruction.h"
+#include "../format/exe_format.h"
@@ -42,7 +43,7 @@ typedef struct _asm_processor asm_processor;
asm_instr *decode_instruction(const asm_processor *, const uint8_t *, off_t *, off_t, uint64_t);
/* Traduit une instruction en version humainement lisible. */
-void print_hinstruction(const asm_processor *, const asm_instr *, char *, size_t, AsmSyntax);
+void print_hinstruction(const asm_processor *, const exe_format *, const asm_instr *, char *, size_t, AsmSyntax);
diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c
index 4326294..7243064 100644
--- a/src/arch/x86/processor.c
+++ b/src/arch/x86/processor.c
@@ -106,7 +106,7 @@ void x86_register_instructions(asm_x86_processor *);
asm_instr *x86_fetch_instruction(const asm_x86_processor *, const uint8_t *, off_t *, off_t, uint64_t);
/* Traduit une instruction en version humainement lisible. */
-void x86_print_instruction(const asm_x86_processor *, const asm_x86_instr *, char *, size_t, AsmSyntax);
+void x86_print_instruction(const asm_x86_processor *, const exe_format *, const asm_x86_instr *, char *, size_t, AsmSyntax);
@@ -356,6 +356,7 @@ asm_instr *x86_fetch_instruction(const asm_x86_processor *proc, const uint8_t *d
/******************************************************************************
* *
* Paramètres : proc = architecture visée par la procédure. *
+* format = format du binaire manipulé. *
* instr = instruction à traiter. *
* buffer = tampon de sortie mis à disposition. [OUT] *
* len = taille de ce tampon. *
@@ -369,10 +370,14 @@ asm_instr *x86_fetch_instruction(const asm_x86_processor *proc, const uint8_t *d
* *
******************************************************************************/
-void x86_print_instruction(const asm_x86_processor *proc, const asm_x86_instr *instr, char *buffer, size_t len, AsmSyntax syntax)
+void x86_print_instruction(const asm_x86_processor *proc, const exe_format *format, const asm_x86_instr *instr, char *buffer, size_t len, AsmSyntax syntax)
{
size_t i; /* Boucle de parcours */
- char opbuffer[3][64]; /* Tampon pour les textes */
+ char opbuffer[3][256]; /* Tampon pour les textes */
+ char *label; /* Etiquette de symbole */
+ SymbolType symtype; /* Type de symbole */
+ uint64_t offset; /* Décallage final constaté */
+ size_t oplen; /* Taille de description */
/* Impression des opérandes */
@@ -380,18 +385,33 @@ void x86_print_instruction(const asm_x86_processor *proc, const asm_x86_instr *i
switch (ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i])->type)
{
case AOT_NONE:
- print_db_operand(ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i]), opbuffer[i], 64, syntax);
+ print_db_operand(ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i]), opbuffer[i], 256, syntax);
break;
case AOT_IMM:
- print_imm_operand(ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i]), opbuffer[i], 64, syntax);
+ print_imm_operand(ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i]), opbuffer[i], 256, syntax);
+
+ offset = ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i])->value.val32; /* FIXME !!! */
+
+ if (ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i])->size == proc->operand_size
+ && resolve_exe_symbol(format, &label, &symtype, &offset))
+ {
+ oplen = strlen(opbuffer[i]);
+
+ if (offset == 0) snprintf(&opbuffer[i][oplen], 256 - oplen, " <%s>", label);
+ else snprintf(&opbuffer[i][oplen], 256 - oplen, " <%s+0x%llx>", label, offset);
+
+ free(label);
+
+ }
+
break;
case AOT_REG:
- x86_print_reg_operand(ASM_INSTRUCTION(instr)->operands[i], opbuffer[i], 64, syntax);
+ x86_print_reg_operand(ASM_INSTRUCTION(instr)->operands[i], opbuffer[i], 256, syntax);
break;
case AOT_MEM:
break;
case AOT_MOFFS:
- x86_print_moffs_operand(ASM_INSTRUCTION(instr)->operands[i], opbuffer[i], 64, syntax);
+ x86_print_moffs_operand(ASM_INSTRUCTION(instr)->operands[i], opbuffer[i], 256, syntax);
break;
}