diff options
| -rw-r--r-- | ChangeLog | 12 | ||||
| -rw-r--r-- | src/arch/x86/instruction.h | 13 | ||||
| -rw-r--r-- | src/arch/x86/op_adc.c | 35 | ||||
| -rw-r--r-- | src/arch/x86/op_add.c | 108 | ||||
| -rw-r--r-- | src/arch/x86/op_and.c | 35 | ||||
| -rw-r--r-- | src/arch/x86/op_or.c | 70 | ||||
| -rw-r--r-- | src/arch/x86/op_sub.c | 35 | ||||
| -rw-r--r-- | src/arch/x86/opcodes.h | 24 | ||||
| -rw-r--r-- | src/arch/x86/processor.c | 14 | 
9 files changed, 343 insertions, 3 deletions
@@ -1,3 +1,15 @@ +2009-04-29  Cyrille Bagard <nocbos@gmail.com> + +	* src/arch/x86/op_and.c: +	* src/arch/x86/opcodes.h: +	* src/arch/x86/op_or.c: +	* src/arch/x86/processor.c: +	* src/arch/x86/instruction.h: +	* src/arch/x86/op_adc.c: +	* src/arch/x86/op_add.c: +	* src/arch/x86/op_sub.c: +	Support more x86 opcodes. +  2009-04-25  Cyrille Bagard <nocbos@gmail.com>  	* configure.ac: diff --git a/src/arch/x86/instruction.h b/src/arch/x86/instruction.h index c54d626..cbdbe2d 100644 --- a/src/arch/x86/instruction.h +++ b/src/arch/x86/instruction.h @@ -40,11 +40,22 @@ typedef enum _X86Opcodes  {      X86_OP_ADD_RM8_R8,                      /* add (0x00)                  */      X86_OP_ADD_RM1632_R1632,                /* add ([0x66] 0x01)           */ - +    X86_OP_ADD_R8_RM8,                      /* add (0x02)                  */      X86_OP_ADD_R1632_RM1632,                /* add ([0x66] 0x03)           */ +    X86_OP_ADD_AL_IMM8,                     /* add (0x04)                  */ +    X86_OP_ADD_E_AX_IMM1632,                /* sub ([0x66] 0x05)           */ + +    X86_OP_ADC_RM8_R8,                      /* adc (0x10)                  */ + +    X86_OP_OR_R8_RM8,                       /* or (0x0a)                   */ + +    X86_OP_OR_AL_IMM8,                      /* or (0x0c)                   */ + +    X86_OP_AND_RM8_R8,                      /* and (0x00)                  */      X86_OP_SUB_R1632_RM1632,                /* sub ([0x66] 0x29)           */ +    X86_OP_SUB_R8_RM8,                      /* add (0x2a)                  */      X86_OP_SUB_AL_IMM8,                     /* sub (0x2c)                  */      X86_OP_SUB_E_AX_IMM1632,                /* sub ([0x66] 0x2d)           */ diff --git a/src/arch/x86/op_adc.c b/src/arch/x86/op_adc.c index 7ac80f3..679bfb4 100644 --- a/src/arch/x86/op_adc.c +++ b/src/arch/x86/op_adc.c @@ -76,6 +76,41 @@ asm_x86_instr *x86_read_instr_adc_imm8_to_rm1632(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 'adc' (8 bits).               * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_adc_rm8_r8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +{ +    asm_x86_instr *result;                  /* Instruction à retourner     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             *  *  Description : Décode une instruction de type 'adc' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           * diff --git a/src/arch/x86/op_add.c b/src/arch/x86/op_add.c index a2d6a8d..98973cd 100644 --- a/src/arch/x86/op_add.c +++ b/src/arch/x86/op_add.c @@ -38,6 +38,79 @@  *                offset = adresse virtuelle de l'instruction.                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             * +*  Description : Décode une instruction de type 'add al, ...' (8 bits).       * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_add_al_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +{ +    asm_x86_instr *result;                  /* Instruction à retourner     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             * +*  Description : Décode une instruction de type 'add [e]ax, ...' (16/32 bits).* +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_add_e_ax_imm1632(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        */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_IMM1632, oprsize)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             *  *  Description : Décode une instruction de type 'add' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           * @@ -76,6 +149,41 @@ asm_x86_instr *x86_read_instr_add_imm8_to_rm1632(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 'add' (8 bits).               * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_add_r8_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     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             *  *  Description : Décode une instruction de type 'add' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           * diff --git a/src/arch/x86/op_and.c b/src/arch/x86/op_and.c index 2d877a6..bcea898 100644 --- a/src/arch/x86/op_and.c +++ b/src/arch/x86/op_and.c @@ -38,6 +38,41 @@  *                offset = adresse virtuelle de l'instruction.                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             * +*  Description : Décode une instruction de type 'and' (8 bits).               * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_and_rm8_r8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +{ +    asm_x86_instr *result;                  /* Instruction à retourner     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             *  *  Description : Décode une instruction de type 'and' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           * diff --git a/src/arch/x86/op_or.c b/src/arch/x86/op_or.c index 42fcfe5..198a0bb 100644 --- a/src/arch/x86/op_or.c +++ b/src/arch/x86/op_or.c @@ -38,6 +38,76 @@  *                offset = adresse virtuelle de l'instruction.                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             * +*  Description : Décode une instruction de type 'or al, ...' (8 bits).        * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_or_al_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +{ +    asm_x86_instr *result;                  /* Instruction à retourner     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             * +*  Description : Décode une instruction de type 'or' (8 bits).                * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_or_r8_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     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             *  *  Description : Décode une instruction de type 'or' (16 ou 32 bits).         *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           * diff --git a/src/arch/x86/op_sub.c b/src/arch/x86/op_sub.c index 6d264f5..bffc758 100644 --- a/src/arch/x86/op_sub.c +++ b/src/arch/x86/op_sub.c @@ -187,6 +187,41 @@ asm_x86_instr *x86_read_instr_sub_r1632_from_rm1632(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 'sub' (8 bits).               * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +asm_x86_instr *x86_read_instr_sub_r8_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     */ + +    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); + +    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    { +        free(result); +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                offset = adresse virtuelle de l'instruction.                 * +*                proc   = architecture ciblée par le désassemblage.           * +*                                                                             *  *  Description : Décode une instruction de type 'sub' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           * diff --git a/src/arch/x86/opcodes.h b/src/arch/x86/opcodes.h index 51af021..c16b9be 100644 --- a/src/arch/x86/opcodes.h +++ b/src/arch/x86/opcodes.h @@ -37,12 +37,24 @@  /* Décode une instruction de type 'adc' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_adc_imm8_to_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'adc' (8 bits). */ +asm_x86_instr *x86_read_instr_adc_rm8_r8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +  /* Décode une instruction de type 'adc' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_adc_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'add al, ...' (8 bits). */ +asm_x86_instr *x86_read_instr_add_al_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); + +/* Décode une instruction de type 'add [e]ax, ...' (16/32 bits). */ +asm_x86_instr *x86_read_instr_add_e_ax_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +  /* Décode une instruction de type 'add' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_add_imm8_to_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'add' (8 bits). */ +asm_x86_instr *x86_read_instr_add_r8_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +  /* Décode une instruction de type 'add' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_add_r1632_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); @@ -55,6 +67,9 @@ asm_x86_instr *x86_read_instr_add_rm1632_imm1632(const uint8_t *, off_t *, off_t  /* Décode une instruction de type 'add' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_add_rm1632_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'and' (8 bits). */ +asm_x86_instr *x86_read_instr_and_rm8_r8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +  /* Décode une instruction de type 'and' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_and_rm1632_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); @@ -169,6 +184,12 @@ asm_x86_instr *x86_read_instr_nop(const uint8_t *, off_t *, off_t, uint64_t, con  /* Décode une instruction de type 'not' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_not_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'or al, ...' (8 bits). */ +asm_x86_instr *x86_read_instr_or_al_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); + +/* Décode une instruction de type 'or' (8 bits). */ +asm_x86_instr *x86_read_instr_or_r8_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +  /* Décode une instruction de type 'or' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_or_rm1632_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); @@ -235,6 +256,9 @@ asm_x86_instr *x86_read_instr_sub_imm8_from_rm1632(const uint8_t *, off_t *, off  /* Décode une instruction de type 'sub' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_sub_r1632_from_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'sub' (8 bits). */ +asm_x86_instr *x86_read_instr_sub_r8_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +  /* Décode une instruction de type 'sub' (16 ou 32 bits). */  asm_x86_instr *x86_read_instr_sub_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c index b6f5c30..9187926 100644 --- a/src/arch/x86/processor.c +++ b/src/arch/x86/processor.c @@ -240,13 +240,23 @@ AsmOperandSize switch_x86_operand_size_if_needed(const asm_x86_processor *proc,  void x86_register_instructions(asm_x86_processor *proc)  {      register_opcode(proc->opcodes[X86_OP_ADD_RM8_R8], 0x00, "add", x86_read_instr_add_rm8_r8); -      register_opcode_1632(proc->opcodes[X86_OP_ADD_RM1632_R1632], 0x01, "add", x86_read_instr_add_rm1632_r1632); - +    register_opcode(proc->opcodes[X86_OP_ADD_R8_RM8], 0x02, "add", x86_read_instr_add_r8_rm8);      register_opcode_1632(proc->opcodes[X86_OP_ADD_R1632_RM1632], 0x03, "add", x86_read_instr_add_r1632_rm1632); +    register_opcode(proc->opcodes[X86_OP_ADD_AL_IMM8], 0x04, "add", x86_read_instr_add_al_imm8); +    register_opcode_1632(proc->opcodes[X86_OP_ADD_E_AX_IMM1632], 0x05, "add", x86_read_instr_add_e_ax_imm1632); + +    register_opcode(proc->opcodes[X86_OP_ADC_RM8_R8], 0x10, "adc", x86_read_instr_adc_rm8_r8); + +    register_opcode(proc->opcodes[X86_OP_OR_R8_RM8], 0x0a, "or", x86_read_instr_or_r8_rm8); + +    register_opcode(proc->opcodes[X86_OP_OR_AL_IMM8], 0x0c, "or", x86_read_instr_or_al_imm8); + +    register_opcode(proc->opcodes[X86_OP_AND_RM8_R8], 0x20, "and", x86_read_instr_and_rm8_r8);      register_opcode_1632(proc->opcodes[X86_OP_SUB_R1632_RM1632], 0x29, "sub", x86_read_instr_sub_r1632_from_rm1632); +    register_opcode(proc->opcodes[X86_OP_SUB_R8_RM8], 0x2a, "sub", x86_read_instr_sub_r8_rm8);      register_opcode(proc->opcodes[X86_OP_SUB_AL_IMM8], 0x2c, "sub", x86_read_instr_sub_al_with_imm8);      register_opcode_1632(proc->opcodes[X86_OP_SUB_E_AX_IMM1632], 0x2d, "sub", x86_read_instr_sub_e_ax_with_imm1632);  | 
