summaryrefslogtreecommitdiff
path: root/src/arch/x86/op_mov.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86/op_mov.c')
-rw-r--r--src/arch/x86/op_mov.c263
1 files changed, 45 insertions, 218 deletions
diff --git a/src/arch/x86/op_mov.c b/src/arch/x86/op_mov.c
index 8764526..01e04ff 100644
--- a/src/arch/x86/op_mov.c
+++ b/src/arch/x86/op_mov.c
@@ -49,34 +49,17 @@
asm_x86_instr *x86_read_instr_mov_al_to_moffs8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
- asm_x86_operand *value; /* Valeur portée */
- asm_x86_operand *reg; /* Registre de source */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- value = x86_create_moffs8_operand(data, pos, len);
- if (value == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_MOFFS8, X86_OTP_AL))
{
free(result);
return NULL;
}
- reg = x86_create_r8_operand(0x00, true);
- if (reg == NULL)
- {
- free(value);
- free(result);
- return NULL;
- }
-
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(value);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(reg);
-
return result;
}
@@ -102,42 +85,19 @@ asm_x86_instr *x86_read_instr_mov_e_ax_to_moffs1632(const uint8_t *data, off_t *
{
asm_x86_instr *result; /* Instruction à retourner */
AsmOperandSize oprsize; /* Taille des opérandes */
- asm_x86_operand *value; /* Valeur portée */
- asm_x86_operand *reg; /* Registre de source */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- /* Utilisation des registres 32 bits ? */
- if (data[*pos] == 0x66)
- {
- oprsize = switch_x86_operand_size(proc);
- (*pos)++;
- }
- else oprsize = get_x86_current_operand_size(proc);
+ oprsize = switch_x86_operand_size_if_needed(proc, data, pos);
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- value = x86_create_moffs1632_operand(data, pos, len, oprsize == AOS_32_BITS);
- if (value == NULL)
- {
- free(result);
- return NULL;
- }
-
- reg = x86_create_r1632_operand(0x00, oprsize == AOS_32_BITS, true);
- if (reg == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_MOFFS1632, X86_OTP_E_AX, oprsize))
{
- free(value);
free(result);
return NULL;
}
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(value);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(reg);
-
return result;
}
@@ -162,35 +122,17 @@ asm_x86_instr *x86_read_instr_mov_e_ax_to_moffs1632(const uint8_t *data, off_t *
asm_x86_instr *x86_read_instr_mov_imm8_to_rm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
- asm_x86_operand *reg; /* Registre de destination */
- asm_x86_operand *value; /* Valeur portée */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- reg = x86_create_rm8_operand(data, pos, len, true);
- if (reg == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))
{
free(result);
return NULL;
}
- value = create_new_x86_operand();
- if (!fill_imm_operand(ASM_OPERAND(value), AOS_8_BITS, data, pos, len))
- {
- free(reg);
- free(value);
- free(result);
- return NULL;
- }
-
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(reg);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(value);
-
return result;
}
@@ -204,7 +146,7 @@ asm_x86_instr *x86_read_instr_mov_imm8_to_rm8(const uint8_t *data, off_t *pos, o
* offset = adresse virtuelle de l'instruction. *
* proc = architecture ciblée par le désassemblage. *
* *
-* Description : Décode une instruction de type 'mov al, ...' (8 bits). *
+* Description : Décode une instruction de type 'mov' (16 ou 32 bits). *
* *
* Retour : Instruction mise en place ou NULL. *
* *
@@ -212,27 +154,44 @@ asm_x86_instr *x86_read_instr_mov_imm8_to_rm8(const uint8_t *data, off_t *pos, o
* *
******************************************************************************/
-asm_x86_instr *x86_read_instr_mov_moffs8_to_al(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
+asm_x86_instr *x86_read_instr_mov_imm1632_to_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
+ AsmOperandSize oprsize; /* Taille des opérandes */
asm_x86_operand *reg; /* Registre de destination */
asm_x86_operand *value; /* Valeur portée */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
+ oprsize = switch_x86_operand_size_if_needed(proc, data, pos);
- reg = x86_create_r8_operand(0x00, true);
+ ASM_INSTRUCTION(result)->opcode = data[*pos];
+
+
+ /*
+ if (!x86_read_one_operand(result, data, pos, len, X86_OTP_OP_R1632, oprsize, 0x40))
+ {
+ free(result);
+ return NULL;
+ }
+ */
+
+
+
+
+
+ reg = x86_create_reg1632_operand(data[(*pos)++], oprsize == AOS_32_BITS, 0xb8);
if (reg == NULL)
{
free(result);
return NULL;
}
- value = x86_create_moffs8_operand(data, pos, len);
- if (value == NULL)
+ value = create_new_x86_operand();
+ if (!fill_imm_operand(ASM_OPERAND(value), oprsize, data, pos, len))
{
free(reg);
+ free(value);
free(result);
return NULL;
}
@@ -256,7 +215,7 @@ asm_x86_instr *x86_read_instr_mov_moffs8_to_al(const uint8_t *data, off_t *pos,
* offset = adresse virtuelle de l'instruction. *
* proc = architecture ciblée par le désassemblage. *
* *
-* Description : Décode une instruction de type 'mov [e]ax, ...' (16/32 bits).*
+* Description : Décode une instruction de type 'mov' (16 ou 32 bits). *
* *
* Retour : Instruction mise en place ou NULL. *
* *
@@ -264,57 +223,28 @@ asm_x86_instr *x86_read_instr_mov_moffs8_to_al(const uint8_t *data, off_t *pos,
* *
******************************************************************************/
-asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
+asm_x86_instr *x86_read_instr_mov_imm1632_to_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
AsmOperandSize oprsize; /* Taille des opérandes */
- asm_x86_operand *reg; /* Registre de destination */
- asm_x86_operand *value; /* Valeur portée */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- /* Utilisation des registres 32 bits ? */
- if (data[*pos] == 0x66)
- {
- oprsize = switch_x86_operand_size(proc);
- (*pos)++;
- }
- else oprsize = get_x86_current_operand_size(proc);
+ oprsize = switch_x86_operand_size_if_needed(proc, data, pos);
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- reg = x86_create_r1632_operand(0x00, oprsize == AOS_32_BITS, true);
- if (reg == NULL)
- {
- free(result);
- return NULL;
- }
-
- value = x86_create_moffs1632_operand(data, pos, len, oprsize == AOS_32_BITS);
- if (value == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))
{
- free(reg);
free(result);
return NULL;
}
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(reg);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(value);
-
return result;
}
-
-
-
-
-
-
/******************************************************************************
* *
* Paramètres : data = flux de données à analyser. *
@@ -323,7 +253,7 @@ asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *data, off_t *
* offset = adresse virtuelle de l'instruction. *
* proc = architecture ciblée par le désassemblage. *
* *
-* Description : Décode une instruction de type 'mov' (16 ou 32 bits). *
+* Description : Décode une instruction de type 'mov al, ...' (8 bits). *
* *
* Retour : Instruction mise en place ou NULL. *
* *
@@ -331,52 +261,20 @@ asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *data, off_t *
* *
******************************************************************************/
-asm_x86_instr *x86_read_instr_mov_with_reg1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
+asm_x86_instr *x86_read_instr_mov_moffs8_to_al(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
- AsmOperandSize oprsize; /* Taille des opérandes */
- asm_x86_operand *reg2; /* Registre de source */
- asm_x86_operand *reg1; /* Registre de destination */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- /* Utilisation des registres 32 bits ? */
- if (data[*pos] == 0x66)
- {
- oprsize = switch_x86_operand_size(proc);
- (*pos)++;
- }
- else oprsize = get_x86_current_operand_size(proc);
-
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- reg2 = x86_create_reg1632_operand_from_modrm(data[*pos], oprsize == AOS_32_BITS, false);
- if (reg2 == NULL)
- {
- free(result);
- return NULL;
- }
-
- if ((data[*pos] & 0xc0) == 0xc0)
- {
- reg1 = x86_create_reg1632_operand_from_modrm(data[*pos], oprsize == AOS_32_BITS, true);
- (*pos)++;
- }
- else reg1 = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true);
-
- if (reg1 == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_MOFFS8))
{
free(result);
- free(reg2);
return NULL;
}
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(reg1);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(reg2);
-
return result;
}
@@ -390,7 +288,7 @@ asm_x86_instr *x86_read_instr_mov_with_reg1632(const uint8_t *data, off_t *pos,
* offset = adresse virtuelle de l'instruction. *
* proc = architecture ciblée par le désassemblage. *
* *
-* Description : Décode une instruction de type 'mov' (16 ou 32 bits). *
+* Description : Décode une instruction de type 'mov [e]ax, ...' (16/32 bits).*
* *
* Retour : Instruction mise en place ou NULL. *
* *
@@ -398,47 +296,23 @@ asm_x86_instr *x86_read_instr_mov_with_reg1632(const uint8_t *data, off_t *pos,
* *
******************************************************************************/
-asm_x86_instr *x86_read_instr_mov_to_1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
+asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
AsmOperandSize oprsize; /* Taille des opérandes */
- asm_x86_operand *reg; /* Registre de destination */
- asm_x86_operand *value; /* Valeur portée */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- /* Utilisation des registres 32 bits ? */
- if (data[*pos] == 0x66)
- {
- oprsize = switch_x86_operand_size(proc);
- (*pos)++;
- }
- else oprsize = get_x86_current_operand_size(proc);
+ oprsize = switch_x86_operand_size_if_needed(proc, data, pos);
- ASM_INSTRUCTION(result)->opcode = data[*pos];
+ ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- reg = x86_create_reg1632_operand(data[(*pos)++], oprsize == AOS_32_BITS, 0xb8);
- if (reg == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_MOFFS1632, oprsize))
{
free(result);
return NULL;
}
- value = create_new_x86_operand();
- if (!fill_imm_operand(ASM_OPERAND(value), oprsize, data, pos, len))
- {
- free(reg);
- free(value);
- free(result);
- return NULL;
- }
-
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(reg);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(value);
-
return result;
}
@@ -460,46 +334,23 @@ asm_x86_instr *x86_read_instr_mov_to_1632(const uint8_t *data, off_t *pos, off_t
* *
******************************************************************************/
-asm_x86_instr *x86_read_instr_mov_from_content_1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
+asm_x86_instr *x86_read_instr_mov_r1632_to_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
AsmOperandSize oprsize; /* Taille des opérandes */
- asm_x86_operand *reg1; /* Registre de destination */
- asm_x86_operand *reg2; /* Registre de source */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- /* Utilisation des registres 32 bits ? */
- if (data[*pos] == 0x66)
- {
- oprsize = switch_x86_operand_size(proc);
- (*pos)++;
- }
- else oprsize = get_x86_current_operand_size(proc);
+ oprsize = switch_x86_operand_size_if_needed(proc, data, pos);
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- reg1 = x86_create_reg1632_operand_from_modrm(data[*pos], oprsize == AOS_32_BITS, false);
- if (reg1 == NULL)
- {
- free(result);
- return NULL;
- }
-
- reg2 = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true);
- if (reg2 == NULL)
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))
{
free(result);
- free(reg1);
return NULL;
}
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(reg1);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(reg2);
-
return result;
}
@@ -521,47 +372,23 @@ asm_x86_instr *x86_read_instr_mov_from_content_1632(const uint8_t *data, off_t *
* *
******************************************************************************/
-asm_x86_instr *x86_read_instr_mov_to_content_1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
+asm_x86_instr *x86_read_instr_mov_rm1632_to_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc)
{
asm_x86_instr *result; /* Instruction à retourner */
AsmOperandSize oprsize; /* Taille des opérandes */
- asm_x86_operand *reg; /* Registre de destination */
- asm_x86_operand *value; /* Valeur portée */
result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr));
- /* Utilisation des registres 32 bits ? */
- if (data[*pos] == 0x66)
- {
- oprsize = switch_x86_operand_size(proc);
- (*pos)++;
- }
- else oprsize = get_x86_current_operand_size(proc);
+ oprsize = switch_x86_operand_size_if_needed(proc, data, pos);
ASM_INSTRUCTION(result)->opcode = data[(*pos)++];
- reg = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true);
- if (reg == NULL)
- {
- free(result);
- return NULL;
- }
-
- value = create_new_x86_operand();
- if (!fill_imm_operand(ASM_OPERAND(value), oprsize, data, pos, len))
+ if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize))
{
- free(reg);
- free(value);
free(result);
return NULL;
}
- ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *));
- ASM_INSTRUCTION(result)->operands_count = 2;
-
- ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(reg);
- ASM_INSTRUCTION(result)->operands[1] = ASM_OPERAND(value);
-
return result;
}