summaryrefslogtreecommitdiff
path: root/src/arch
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
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')
-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, " &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;
}