summaryrefslogtreecommitdiff
path: root/src/arch/x86
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86')
-rw-r--r--src/arch/x86/op_lea.c3
-rw-r--r--src/arch/x86/op_mov.c3
-rw-r--r--src/arch/x86/op_push.c1
-rw-r--r--src/arch/x86/processor.c9
4 files changed, 10 insertions, 6 deletions
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;
}