summaryrefslogtreecommitdiff
path: root/src/arch/x86
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2008-09-11 22:25:26 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2008-09-11 22:25:26 (GMT)
commitab1489b6a6ef1f09957f6f805f143fceb42f6a08 (patch)
treefd751d69dfde0539e9beb79cf33377572a3c36a2 /src/arch/x86
parent15387adcbd3e27fe581754c0ee56edc64272d58e (diff)
Provided capabilities to resolve symbols for given addresses.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@29 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/x86')
-rw-r--r--src/arch/x86/processor.c34
1 files changed, 27 insertions, 7 deletions
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, " &lt;%s&gt;", label);
+ else snprintf(&opbuffer[i][oplen], 256 - oplen, " &lt;%s+0x%llx&gt;", 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;
}