From b52f03ab912cd5e51dc2abea20edee6ad38c26fe Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 6 Sep 2008 22:07:54 +0000 Subject: Better handled the case where decoding fails. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@26 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 8 ++++++++ src/arch/x86/op_lea.c | 3 +-- src/arch/x86/op_mov.c | 3 +-- src/arch/x86/op_push.c | 1 - src/arch/x86/processor.c | 9 ++++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 09205e3..7fd494f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2008-09-06 Cyrille Bagard + * src/arch/x86/op_lea.c: + * src/arch/x86/op_mov.c: + * src/arch/x86/op_push.c: + * src/arch/x86/processor.c: + Better handle the case where decoding fails. + +2008-09-06 Cyrille Bagard + * src/arch/x86/instruction.h: Add more support for lea and push opcodes. diff --git a/src/arch/x86/op_lea.c b/src/arch/x86/op_lea.c index 2622ebf..c86c07f 100644 --- a/src/arch/x86/op_lea.c +++ b/src/arch/x86/op_lea.c @@ -68,7 +68,6 @@ asm_x86_instr *read_instr_lea(const uint8_t *data, off_t *pos, off_t len, uint64 reg1 = x86_create_reg1632_operand_from_modrm(data[*pos], oprsize == AOS_32_BITS, false); if (reg1 == NULL) { - (*pos)--; free(result); return NULL; } @@ -76,8 +75,8 @@ asm_x86_instr *read_instr_lea(const uint8_t *data, off_t *pos, off_t len, uint64 reg2 = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true); if (reg2 == NULL) { - (*pos)--; free(result); + free(reg1); return NULL; } diff --git a/src/arch/x86/op_mov.c b/src/arch/x86/op_mov.c index 60de5cf..db731bb 100644 --- a/src/arch/x86/op_mov.c +++ b/src/arch/x86/op_mov.c @@ -197,7 +197,6 @@ asm_x86_instr *read_instr_mov_from_content_1632(const uint8_t *data, off_t *pos, reg1 = x86_create_reg1632_operand_from_modrm(data[*pos], oprsize == AOS_32_BITS, false); if (reg1 == NULL) { - (*pos)--; free(result); return NULL; } @@ -205,8 +204,8 @@ asm_x86_instr *read_instr_mov_from_content_1632(const uint8_t *data, off_t *pos, reg2 = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true); if (reg2 == NULL) { - (*pos)--; free(result); + free(reg1); return NULL; } diff --git a/src/arch/x86/op_push.c b/src/arch/x86/op_push.c index b577177..c5d4c67 100644 --- a/src/arch/x86/op_push.c +++ b/src/arch/x86/op_push.c @@ -68,7 +68,6 @@ asm_x86_instr *read_instr_push_content(const uint8_t *data, off_t *pos, off_t le content = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true); if (content == NULL) { - (*pos)--; free(result); return NULL; } diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c index c7382ed..118dbd6 100644 --- a/src/arch/x86/processor.c +++ b/src/arch/x86/processor.c @@ -302,6 +302,7 @@ asm_instr *x86_fetch_instruction(const asm_x86_processor *proc, const uint8_t *d asm_x86_instr *result; /* Résultat à faire remonter */ X86Opcodes i; /* Boucle de parcours */ off_t tmp; /* Tête de lecture */ + off_t old_pos; /* Sauvegarde de la position */ result = NULL; @@ -326,9 +327,15 @@ asm_instr *x86_fetch_instruction(const asm_x86_processor *proc, const uint8_t *d if (proc->opcodes[i].has_op_ext && (data[tmp] & EXT_OPCODE_MASK) != proc->opcodes[i].op_ext) continue; + old_pos = *pos; + result = proc->opcodes[i].read(data, pos, len, offset, proc); if (result != NULL) result->type = i; - else printf("err while decoding :: [0x%02hhx] 0x%02hhx\n", proc->opcodes[i].prefix, proc->opcodes[i].opcode); + else + { + *pos = old_pos; + printf("err while decoding at 0x%08llx :: [0x%02hhx] 0x%02hhx\n", offset, proc->opcodes[i].prefix, proc->opcodes[i].opcode); + } break; } -- cgit v0.11.2-87-g4458