diff options
Diffstat (limited to 'src/arch')
58 files changed, 3176 insertions, 3852 deletions
diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am index 1fb49a8..0f4c9f5 100644 --- a/src/arch/Makefile.am +++ b/src/arch/Makefile.am @@ -14,7 +14,7 @@ libarch_la_SOURCES =					\  libarch_la_LIBADD =						\  	jvm/libarchjvm.la					\ -	x86/libarchx86.a +	x86/libarchx86.la  libarch_la_LDFLAGS =  @@ -26,4 +26,4 @@ AM_CPPFLAGS =  AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = jvm #x86 +SUBDIRS = jvm x86 diff --git a/src/arch/archbase.h b/src/arch/archbase.h index 02e4ae8..2a0c80e 100644 --- a/src/arch/archbase.h +++ b/src/arch/archbase.h @@ -60,5 +60,16 @@ typedef enum _MemoryDataSize  #define MDS_64_BITS MDS_64_BITS_UNSIGNED +/* Différentes formes de représentation humaine */ +typedef enum _AsmSyntax +{ +    ASX_INTEL,                              /* Syntaxe Intel               */ +    ASX_ATT,                                /* Syntaxte AT&T               */ + +    ASX_COUNT + +} AsmSyntax; + +  #endif  /* _ARCH_ARCHBASE_H */ diff --git a/src/arch/immediate.c b/src/arch/immediate.c index c1ad73c..876fa88 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -25,6 +25,7 @@  #include <malloc.h> +#include <stdarg.h>  #include <stdio.h> @@ -56,10 +57,10 @@ struct _GImmOperand      union      { -        uint8_t val8;                       /* Valeur sur 8 bits           */ -        uint16_t val16;                     /* Valeur sur 16 bits          */ -        uint32_t val32;                     /* Valeur sur 32 bits          */ -        uint64_t val64;                     /* Valeur sur 64 bits          */ +        int8_t val8;                        /* Valeur sur 8 bits           */ +        int16_t val16;                      /* Valeur sur 16 bits          */ +        int32_t val32;                      /* Valeur sur 32 bits          */ +        int64_t val64;                      /* Valeur sur 64 bits          */      } signed_imm; @@ -148,7 +149,7 @@ static void g_imm_operand_init(GImmOperand *operand)  GArchOperand *g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *data, off_t *pos, off_t len, SourceEndian endian)  { -    GImmOperand *result;                    /* Instruction à retourner     */ +    GImmOperand *result;                    /* Opérande à retourner        */      result = g_object_new(G_TYPE_IMM_OPERAND, NULL); @@ -161,8 +162,30 @@ GArchOperand *g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *data                  goto gionfd_error;              break; +        case AOS_16_BITS_UNSIGNED: +            if (!read_u16(&result->unsigned_imm.val16, data, pos, len, endian)) +                goto gionfd_error; +            break; + +        case AOS_32_BITS_UNSIGNED: +            if (!read_u32(&result->unsigned_imm.val32, data, pos, len, endian)) +                goto gionfd_error; +            break; + +        case AOS_8_BITS_SIGNED: +            if (!read_u8(&result->signed_imm.val8, data, pos, len, endian)) +                goto gionfd_error; +            break; +        case AOS_16_BITS_SIGNED: +            if (!read_u16(&result->signed_imm.val16, data, pos, len, endian)) +                goto gionfd_error; +            break; +        case AOS_32_BITS_SIGNED: +            if (!read_u32(&result->signed_imm.val32, data, pos, len, endian)) +                goto gionfd_error; +            break;      } @@ -179,6 +202,128 @@ GArchOperand *g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *data  /******************************************************************************  *                                                                             * +*  Paramètres  : size = taille de l'opérande souhaitée.                       * +*                ...  = valeur sur x bits à venir récupérer.                  * +*                                                                             * +*  Description : Crée un opérande réprésentant une valeur numérique.          * +*                                                                             * +*  Retour      : Instruction mise en place.                                   * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_imm_operand_new_from_value(AsmOperandSize size, ...) +{ +    GImmOperand *result;                    /* Opérande à retourner        */ +    va_list ap;                             /* Liste des compléments       */ +    uint8_t uval8;                          /* Valeur sur 8 bits           */ +    uint16_t uval16;                        /* Valeur sur 16 bits          */ +    uint32_t uval32;                        /* Valeur sur 32 bits          */ +    uint64_t uval64;                        /* Valeur sur 64 bits          */ +    int8_t sval8;                           /* Valeur sur 8 bits           */ +    int16_t sval16;                         /* Valeur sur 16 bits          */ +    int32_t sval32;                         /* Valeur sur 32 bits          */ +    int64_t sval64;                         /* Valeur sur 64 bits          */ + +    if (size == AOS_UNDEFINED) return NULL; + +    result = g_object_new(G_TYPE_IMM_OPERAND, NULL); + +    result->size = size; + +    va_start(ap, size); + +    switch (size) +    { +        /* Pour GCC... */ +        case AOS_UNDEFINED: +            break; +        case AOS_8_BITS_UNSIGNED: +            uval8 = (uint8_t)va_arg(ap, unsigned int); +            result->unsigned_imm.val8 = uval8; +            break; +        case AOS_16_BITS_UNSIGNED: +            uval16 = (uint16_t)va_arg(ap, unsigned int); +            result->unsigned_imm.val16 = uval16; +            break; +        case AOS_32_BITS_UNSIGNED: +            uval32 = (uint32_t)va_arg(ap, unsigned int); +            result->unsigned_imm.val32 = uval32; +            break; +        case AOS_64_BITS_UNSIGNED: +            uval64 = (uint64_t)va_arg(ap, unsigned int); +            result->unsigned_imm.val64 = uval64; +            break; +        case AOS_8_BITS_SIGNED: +            sval8 = (int8_t)va_arg(ap, int); +            result->signed_imm.val8 = sval8; +            break; +        case AOS_16_BITS_SIGNED: +            sval16 = (int16_t)va_arg(ap, int); +            result->signed_imm.val16 = sval16; +            break; +        case AOS_32_BITS_SIGNED: +            sval32 = (int32_t)va_arg(ap, int); +            result->signed_imm.val32 = sval32; +            break; +        case AOS_64_BITS_SIGNED: +            sval64 = (int64_t)va_arg(ap, int); +            result->signed_imm.val64 = sval64; +            break; +    } + +    va_end(ap); + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = structure dont le contenu est à définir.           * +*                                                                             * +*  Description : Indique le signe d'une valeur immédiate.                     * +*                                                                             * +*  Retour      : true si la valeur est strictement négative, false sinon.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_imm_operand_is_negative(const GImmOperand *operand) +{ +    bool result;                            /* Bilan à renvoyer            */ + +    result = false; + +    switch (operand->size) +    { +        case AOS_8_BITS_SIGNED: +            result = (operand->signed_imm.val8 & 0x80); +            break; +        case AOS_16_BITS_SIGNED: +            result = (operand->signed_imm.val16 & 0x8000); +            break; +        case AOS_32_BITS_SIGNED: +            result = (operand->signed_imm.val32 & 0x80000000); +            break; +        case AOS_64_BITS_SIGNED: +            result = (operand->signed_imm.val64 & 0x8000000000000000ll); +            break; +        default: +            /* Traitement non nécessaire */ +            break; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : operand = opérande à traiter.                                *  *                format  = format du binaire manipulé.                        *  *                syntax  = type de représentation demandée.                   * diff --git a/src/arch/immediate.h b/src/arch/immediate.h index 3fdab0d..1b77290 100644 --- a/src/arch/immediate.h +++ b/src/arch/immediate.h @@ -53,6 +53,12 @@ GType g_imm_operand_get_type(void);  /* Crée un opérande réprésentant une valeur numérique. */  GArchOperand *g_imm_operand_new_from_data(MemoryDataSize, const bin_t *, off_t *, off_t, SourceEndian); +/* Crée un opérande réprésentant une valeur numérique. */ +GArchOperand *g_imm_operand_new_from_value(AsmOperandSize, ...); + +/* Indique le signe d'une valeur immédiate. */ +bool g_imm_operand_is_negative(const GImmOperand *); +  #endif  /* _ARCH_IMMEDIATE_H */ diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h index c80c20a..f61485f 100644 --- a/src/arch/instruction-int.h +++ b/src/arch/instruction-int.h @@ -25,64 +25,8 @@  #define _ARCH_INSTRUCTION_INT_H -#include "instruction.h" - - -#include "operand-int.h"    /* TODO: remove me */ - - - - -#define MAX_OPERANDS    4 - - -#define DB_OPCODE   0x00 - - -#if 0 -/* Typage des instructions rencontrées */ -typedef enum _AsmInstrType -{ -    AIT_OTHER,                              /* Instruction inintéressante  */ - -    AIT_DB,                                 /* Instruction non décodée     */ - -    AIT_PUSH,                               /* Empilement de valeur        */ -    AIT_POP,                                /* Dépilement de valeur        */ -    AIT_JUMP,                               /* Saut à une adresse          */ - -    AIT_CALL                                /* Appel d'une fonction        */ - -} AsmInstrType; -#endif - - -/* Définition générique d'une instruction */ -struct _asm_instr -{ -    uint8_t opcode; - -    uint64_t vaddress;                      /* Adresse virtuelle associée  */ - -    off_t offset;                           /* Position physique de départ */ -    off_t length;                           /* Taille de l'instruction     */ - -    int/*AsmInstrType*/ type;                      /* Type d'instruction          */ - -    asm_operand **operands;                 /* Liste des opérandes         */ -    size_t operands_count;                  /* Nbre. d'opérandes utilisées */ - - -}; - -#define ASM_INSTRUCTION(instr) ((asm_instr *)instr) - - - - - -  #include "archbase.h" +#include "instruction.h" @@ -110,9 +54,6 @@ struct _GArchInstruction  }; - - -  /* Définition générique d'une instruction d'architecture (classe) */  struct _GArchInstructionClass  { @@ -122,16 +63,4 @@ struct _GArchInstructionClass - - - - - - - - - - - -  #endif  /* _ARCH_INSTRUCTION_INT_H */ diff --git a/src/arch/instruction.c b/src/arch/instruction.c index d3cc882..073f55c 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -154,6 +154,31 @@ void g_arch_instruction_attach_one_operand(GArchInstruction *instr, GArchOperand  /******************************************************************************  *                                                                             * +*  Paramètres  : instr    = instance à mettre à jour.                         * +*                operand1 = première instruction à venir associer.            * +*                operand2 = seconde instruction à venir associer.             * +*                                                                             * +*  Description : Attache deux opérandes à une instruction.                    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_arch_instruction_attach_two_operands(GArchInstruction *instr, GArchOperand *operand1, GArchOperand *operand2) +{ +    instr->operands = (GArchOperand **)calloc(2, sizeof(GArchOperand *)); +    instr->operands_count = 2; + +    instr->operands[0] = operand1; +    instr->operands[1] = operand2; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : instr  = instruction à traiter.                              *  *                format = format du binaire manipulé.                         *  *                syntax = type de représentation demandée.                    * diff --git a/src/arch/instruction.h b/src/arch/instruction.h index 2df38af..08f459f 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -25,19 +25,6 @@  #define _ARCH_INSTRUCTION_H -#include <stdint.h> -#include <sys/types.h> - - - -/* Définition générique d'une instruction */ -typedef struct _asm_instr asm_instr; - - - - - -  #include <glib-object.h>  #include <sys/types.h> @@ -89,6 +76,9 @@ void g_arch_instruction_get_location(GArchInstruction *, off_t *, off_t *, vmpa_  /* Attache une seule opérande à une instruction. */  void g_arch_instruction_attach_one_operand(GArchInstruction *, GArchOperand *); +/* Attache deux opérandes à une instruction. */ +void g_arch_instruction_attach_two_operands(GArchInstruction *, GArchOperand *, GArchOperand *); +  /* Traduit une instruction en version humainement lisible. */  char *g_arch_instruction_get_text(const GArchInstruction *, const exe_format *, AsmSyntax); diff --git a/src/arch/jvm/instruction.c b/src/arch/jvm/instruction.c index 7748624..9ada8f0 100644 --- a/src/arch/jvm/instruction.c +++ b/src/arch/jvm/instruction.c @@ -238,7 +238,7 @@ GArchInstruction *g_jvm_instruction_new(JvmOpcodes type)  /******************************************************************************  *                                                                             *  *  Paramètres  : data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * +*                pos  = position courante dans ce flux.                       *  *                len  = taille totale des données à analyser.                 *  *                wide = étendue de la future instruction. [OUT]               *  *                care = la lecture de l'instr. veut-elle les opcodes ? [OUT]  * @@ -251,16 +251,16 @@ GArchInstruction *g_jvm_instruction_new(JvmOpcodes type)  *                                                                             *  ******************************************************************************/ -JvmOpcodes jvm_guess_next_instruction(const bin_t *data, off_t *pos, off_t len, bool *wide, bool *care) +JvmOpcodes jvm_guess_next_instruction(const bin_t *data, off_t pos, off_t len, bool *wide, bool *care)  {      JvmOpcodes result;                      /* Identifiant à retourner     */      bin_t opcode;                           /* Opcode à trouver            */ -    *wide = (data[*pos] == 0xc4); +    *wide = (data[pos] == 0xc4); -    if (*wide && (*pos + 1) == len) return JOP_COUNT; +    if (*wide && (pos + 1) == len) return JOP_COUNT; -    opcode = data[*pos + (*wide ? 1 : 0)]; +    opcode = data[pos + (*wide ? 1 : 0)];      for (result = 0; result < JOP_COUNT; result++)      { diff --git a/src/arch/jvm/instruction.h b/src/arch/jvm/instruction.h index 36f2230..9387680 100644 --- a/src/arch/jvm/instruction.h +++ b/src/arch/jvm/instruction.h @@ -142,7 +142,7 @@ GArchInstruction *g_jvm_instruction_new(JvmOpcodes);  /* Recherche l'identifiant de la prochaine instruction. */ -JvmOpcodes jvm_guess_next_instruction(const bin_t *, off_t *, off_t, bool *, bool *); +JvmOpcodes jvm_guess_next_instruction(const bin_t *, off_t, off_t, bool *, bool *); diff --git a/src/arch/jvm/operand.c b/src/arch/jvm/operand.c index 7e9b08f..da95101 100644 --- a/src/arch/jvm/operand.c +++ b/src/arch/jvm/operand.c @@ -123,7 +123,7 @@ static void g_jvm_operand_class_init(GJvmOperandClass *klass)  /******************************************************************************  *                                                                             * -*  Paramètres  : proc = instance à initialiser.                               * +*  Paramètres  : operand = instance à initialiser.                            *  *                                                                             *  *  Description : Initialise une instance d'opérande de base pour la JVM.      *  *                                                                             * @@ -133,7 +133,7 @@ static void g_jvm_operand_class_init(GJvmOperandClass *klass)  *                                                                             *  ******************************************************************************/ -static void g_jvm_operand_init(GJvmOperand *proc) +static void g_jvm_operand_init(GJvmOperand *operand)  {  } @@ -197,10 +197,10 @@ static void g_jvm_ref_operand_init(GJvmRefOperand *operand)  /******************************************************************************  *                                                                             * -*  Paramètres  : data  = flux de données à analyser.                          * -*                pos   = position courante dans ce flux. [OUT]                * -*                len   = taille totale des données à analyser.                * -*                type  = type de l'opérande.                                  * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                type = type de l'opérande.                                   *  *                                                                             *  *  Description : Crée un opérande de référence pour la JVM.                   *  *                                                                             * diff --git a/src/arch/jvm/processor.c b/src/arch/jvm/processor.c index c7bfcf9..8226afc 100644 --- a/src/arch/jvm/processor.c +++ b/src/arch/jvm/processor.c @@ -129,11 +129,11 @@ GArchProcessor *g_jvm_processor_new(void)  /******************************************************************************  *                                                                             * -*  Paramètres  : proc   = architecture visée par la procédure.                * -*                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.                 * +*  Paramètres  : proc = architecture visée par la procédure.                  * +*                data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   *  *                                                                             *  *  Description : Décode une instruction dans un flux de données.              *  *                                                                             * @@ -150,7 +150,7 @@ static GArchInstruction *g_jvm_processor_decode_instruction(const GJvmProcessor      bool care;                              /* Traitement des opcodes      */      JvmOpcodes id;                          /* Identifiant d'instruction   */ -    id = jvm_guess_next_instruction(data, pos, len, &wide, &care); +    id = jvm_guess_next_instruction(data, *pos, len, &wide, &care);      if (id != JOP_COUNT && !care)      { diff --git a/src/arch/operand-int.h b/src/arch/operand-int.h index 4a515c3..8048548 100644 --- a/src/arch/operand-int.h +++ b/src/arch/operand-int.h @@ -25,68 +25,10 @@  #define _ARCH_OPERAND_INT_H -#include <stdint.h> - -  #include "operand.h" -/* Types d'opérandes rencontrables */ -typedef enum _AsmOperandType -{ -    AOT_NONE,                               /* Type d'opérande inconnu !   */ -    AOT_IMM,                                /* Valeur immédiate            */ -    AOT_REG,                                /* Registre quelconque         */ -    AOT_MEM,                                /* Accès à la mémoire          */ - -    /* X86 */ - -    AOT_MOFFS                               /* Emplacement mémoire         */ - -} AsmOperandType; - -/* Définition générique d'une opérande */ -struct _asm_operand -{ -    AsmOperandType type;                    /* Type d'opérande             */ -    AsmOperandSize size;                    /* Taille de l'opérande        */ - -    /** -     * Note : dans le cas d'une valeur signée, -     * signed_imm contient la valeur lue/donnée, et -     * unsigned_imm la valeur humainement lisible (ie. positive). -     */ - -    union -    { -        uint8_t val8;                       /* Valeur sur 8 bits           */ -        uint16_t val16;                     /* Valeur sur 16 bits          */ -        uint32_t val32;                     /* Valeur sur 32 bits          */ -        uint64_t val64;                     /* Valeur sur 64 bits          */ - -    } unsigned_imm; - -    union -    { -        uint8_t val8;                       /* Valeur sur 8 bits           */ -        uint16_t val16;                     /* Valeur sur 16 bits          */ -        uint32_t val32;                     /* Valeur sur 32 bits          */ -        uint64_t val64;                     /* Valeur sur 64 bits          */ - -    } signed_imm; - -}; - - -#define ASM_OPERAND(o) ((asm_operand *)o) - - - - - - -  /* Traduit un opérande en version humainement lisible. */  typedef char * (* get_operand_text_fc) (const GArchOperand *, const exe_format *, AsmSyntax); @@ -101,11 +43,6 @@ struct _GArchOperand  }; - - - - -  /* Définition générique d'un opérande d'architecture (classe) */  struct _GArchOperandClass  { @@ -115,11 +52,4 @@ struct _GArchOperandClass - - - - - - -  #endif  /* _ARCH_OPERAND_INT_H */ diff --git a/src/arch/operand.c b/src/arch/operand.c index 9d6fa28..0f488b3 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -24,808 +24,10 @@  #include "operand.h" -#include <stdarg.h> -#include <stdio.h> - -  #include "operand-int.h" -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                value   = valeur immédiate à renseigner.                     * -*                                                                             * -*  Description : Crée une opérande pour l'instruction 'db'.                   * -*                                                                             * -*  Retour      : true si l'opérande a été définie avec succès, false sinon.   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool fill_db_operand(asm_operand *operand, uint8_t value) -{ -    operand->type = AOT_NONE; -    operand->size = AOS_8_BITS_UNSIGNED; - -    operand->unsigned_imm.val8 = value; - -    return true; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instruction à traiter.                             * -*                buffer  = tampon de sortie mis à disposition. [OUT]          * -*                len     = taille de ce tampon.                               * -*                syntax  = type de représentation demandée.                   * -*                                                                             * -*  Description : Traduit une opérande de type 'db' en texte.                  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void print_db_operand(const asm_operand *operand, char *buffer, size_t len, AsmSyntax syntax) -{ -    switch (syntax) -    { -        case ASX_INTEL: -            snprintf(buffer, len, "0x%02hhx", operand->unsigned_imm.val8); -            break; - -        case ASX_ATT: -            snprintf(buffer, len, "$0x%02hhx", operand->unsigned_imm.val8); -            break; - -    } - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : size = taille de l'opérande souhaitée.                       * -*                data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * -*                len  = taille totale des données à analyser.                 * -*                ...  = adresse où placer la valeur lue. [OUT]                * -*                                                                             * -*  Description : Lit une valeur (signée ou non) sur x bits.                   * -*                                                                             * -*  Retour      : true si l'opération s'est effectuée avec succès, false sinon.* -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool read_imm_value(AsmOperandSize size, const uint8_t *data, off_t *pos, off_t len, ...) -{ -    va_list ap;                             /* Récupération d'argument     */ -    uint8_t *val8;                          /* Valeur sur 8 bits           */ -    uint16_t *val16;                        /* Valeur sur 16 bits          */ -    uint32_t *val32;                        /* Valeur sur 32 bits          */ -    uint64_t *val64;                        /* Valeur sur 64 bits          */ - -    /* Vérifications sanitaires */ -    switch (size) -    { -        case AOS_8_BITS_UNSIGNED: -        case AOS_8_BITS_SIGNED: -            if ((len - *pos) < 1) return false; -            break; -        case AOS_16_BITS_UNSIGNED: -        case AOS_16_BITS_SIGNED: -            if ((len - *pos) < 2) return false; -            break; -        case AOS_32_BITS_UNSIGNED: -        case AOS_32_BITS_SIGNED: -            if ((len - *pos) < 4) return false; -            break; -        case AOS_64_BITS_UNSIGNED: -        case AOS_64_BITS_SIGNED: -            if ((len - *pos) < 8) return false; -            break; -    } - -    va_start(ap, len); - -    switch (size) -    { -        case AOS_8_BITS_UNSIGNED: -        case AOS_8_BITS_SIGNED: -            val8 = va_arg(ap, uint8_t *); -            *val8 = data[*pos]; -            *pos += 1; -            break; -        case AOS_16_BITS_UNSIGNED: -        case AOS_16_BITS_SIGNED: -            val16 = va_arg(ap, uint16_t *); -            *val16 = data[*pos] | (uint16_t)data[*pos + 1] << 8; -            *pos += 2; -            break; -        case AOS_32_BITS_UNSIGNED: -        case AOS_32_BITS_SIGNED: -            val32 = va_arg(ap, uint32_t *); -            *val32 = data[*pos] | (uint32_t)data[*pos + 1] << 8 -                | (uint32_t)data[*pos + 2] << 16 | (uint32_t)data[*pos + 3] << 24; -            *pos += 4; -            break; -        case AOS_64_BITS_UNSIGNED: -        case AOS_64_BITS_SIGNED: -            val64 = va_arg(ap, uint64_t *); -            *val64 = data[*pos] | (uint64_t)data[*pos + 1] << 8 | (uint64_t)data[*pos + 2] << 16 -                | (uint64_t)data[*pos + 3] << 24 | (uint64_t)data[*pos + 4] << 32 | (uint64_t)data[*pos + 5] << 40 -                | (uint64_t)data[*pos + 6] << 48 | (uint64_t)data[*pos + 7] << 56; -            *pos += 8; -            break; -    } - -    va_end(ap); - -    return true; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                                                                             * -*  Description : Indique le signe d'une valeur immédiate.                     * -*                                                                             * -*  Retour      : true si la valeur est strictement négative, false sinon.     * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool is_imm_operand_negative(const asm_operand *operand) -{ -    bool result;                            /* Bilan à renvoyer            */ - -    result = false; - -    switch (operand->size) -    { -        case AOS_8_BITS_SIGNED: -            result = (operand->signed_imm.val8 & 0x80); -            break; -        case AOS_16_BITS_SIGNED: -            result = (operand->signed_imm.val16 & 0x8000); -            break; -        case AOS_32_BITS_SIGNED: -            result = (operand->signed_imm.val32 & 0x80000000); -            break; -        case AOS_64_BITS_SIGNED: -            result = (operand->signed_imm.val64 & 0x8000000000000000ll); -            break; -        default: -            /* Traitement non nécessaire */ -            break; -    } - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                size    = taille de l'opérande souhaitée.                    * -*                                                                             * -*  Description : Précalcule une valeur humaine lisible d'une valeur signée.   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void cache_signed_imm_value(asm_operand *operand, AsmOperandSize size) -{ -    int8_t val8;                            /* Valeur sur 8 bits           */ -    int16_t val16;                          /* Valeur sur 16 bits          */ -    int32_t val32;                          /* Valeur sur 32 bits          */ -    int64_t val64;                          /* Valeur sur 64 bits          */ - -    switch (size) -    { -        case AOS_8_BITS_SIGNED: -            if (operand->signed_imm.val8 & 0x80) -            { -                val8 = operand->signed_imm.val8 - 1; -                val8 = ~val8; -                operand->unsigned_imm.val8 = val8; -            } -            else operand->unsigned_imm.val8 = operand->signed_imm.val8; -            break; -        case AOS_16_BITS_SIGNED: -            if (operand->signed_imm.val16 & 0x8000) -            { -                val16 = operand->signed_imm.val16 - 1; -                val16 = ~val16; -                operand->unsigned_imm.val16 = val16; -            } -            else operand->unsigned_imm.val16 = operand->signed_imm.val16; -            break; -        case AOS_32_BITS_SIGNED: -            if (operand->signed_imm.val32 & 0x80000000) -            { -                val32 = operand->signed_imm.val32 - 1; -                val32 = ~val32; -                operand->unsigned_imm.val32 = val32; -            } -            else operand->unsigned_imm.val32 = operand->signed_imm.val32; -            break; -        case AOS_64_BITS_SIGNED: -            if (operand->signed_imm.val64 & 0x8000000000000000ll) -            { -                val64 = operand->signed_imm.val64 - 1; -                val64 = ~val64; -                operand->unsigned_imm.val64 = val64; -            } -            else operand->unsigned_imm.val64 = operand->signed_imm.val64; -            break; -        default: -            /* Traitement non nécessaire */ -            break; -    } - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                size    = taille de l'opérande souhaitée.                    * -*                data    = flux de données à analyser.                        * -*                pos     = position courante dans ce flux. [OUT]              * -*                len     = taille totale des données à analyser.              * -*                                                                             * -*  Description : Crée une opérande contenant une valeur sur x bits.           * -*                                                                             * -*  Retour      : true si l'opération s'est effectuée avec succès, false sinon.* -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool fill_imm_operand(asm_operand *operand, AsmOperandSize size, const uint8_t *data, off_t *pos, off_t len) -{ -    bool result;                            /* Bilan à retourner           */ - -    operand->type = AOT_IMM; -    operand->size = size; - -    switch (size) -    { -        case AOS_8_BITS_UNSIGNED: -            result = read_imm_value(size, data, pos, len, &operand->unsigned_imm.val8); -            break; -        case AOS_16_BITS_UNSIGNED: -            result = read_imm_value(size, data, pos, len, &operand->unsigned_imm.val16); -            break; -        case AOS_32_BITS_UNSIGNED: -            result = read_imm_value(size, data, pos, len, &operand->unsigned_imm.val32); -            break; -        case AOS_64_BITS_UNSIGNED: -            result = read_imm_value(size, data, pos, len, &operand->unsigned_imm.val64); -            break; -        case AOS_8_BITS_SIGNED: -            result = read_imm_value(size, data, pos, len, &operand->signed_imm.val8); -            cache_signed_imm_value(operand, size); -            break; -        case AOS_16_BITS_SIGNED: -            result = read_imm_value(size, data, pos, len, &operand->signed_imm.val16); -            cache_signed_imm_value(operand, size); -            break; -        case AOS_32_BITS_SIGNED: -            result = read_imm_value(size, data, pos, len, &operand->signed_imm.val32); -            cache_signed_imm_value(operand, size); -            break; -        case AOS_64_BITS_SIGNED: -            result = read_imm_value(size, data, pos, len, &operand->signed_imm.val64); -            cache_signed_imm_value(operand, size); -            break; -    } - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                size    = taille de l'opérande souhaitée.                    * -*                ...     = valeur à utiliser.                                 * -*                                                                             * -*  Description : Crée une opérande contenant une valeur sur x bits.           * -*                                                                             * -*  Retour      : true si l'opération s'est effectuée avec succès, false sinon.* -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool fill_imm_operand_with_value(asm_operand *operand, AsmOperandSize size, ...) -{ -    va_list ap;                             /* Récupération d'argument     */ -    const uint8_t *us_val8;                 /* Valeur sur 8 bits n.-s.     */ -    const uint16_t *us_val16;               /* Valeur sur 16 bits n.-s.    */ -    const uint32_t *us_val32;               /* Valeur sur 32 bits n.-s.    */ -    const uint64_t *us_val64;               /* Valeur sur 64 bits n.-s.    */ -    const int8_t *s_val8;                   /* Valeur sur 8 bits signés    */ -    const int16_t *s_val16;                 /* Valeur sur 16 bits signés   */ -    const int32_t *s_val32;                 /* Valeur sur 32 bits signés   */ -    const int64_t *s_val64;                 /* Valeur sur 64 bits signés   */ - -    operand->type = AOT_IMM; -    operand->size = size; - -    va_start(ap, size); - -    switch (size) -    { -        case AOS_8_BITS_UNSIGNED: -            us_val8 = va_arg(ap, const uint8_t *); -            operand->unsigned_imm.val8 = *us_val8; -            break; -        case AOS_16_BITS_UNSIGNED: -            us_val16 = va_arg(ap, const uint16_t *); -            operand->unsigned_imm.val16 = *us_val16; -            break; -        case AOS_32_BITS_UNSIGNED: -            us_val32 = va_arg(ap, const uint32_t *); -            operand->unsigned_imm.val32 = *us_val32; -            break; -        case AOS_64_BITS_UNSIGNED: -            us_val64 = va_arg(ap, const uint64_t *); -            operand->unsigned_imm.val64 = *us_val64; -            break; -        case AOS_8_BITS_SIGNED: -            s_val8 = va_arg(ap, const uint8_t *); -            operand->signed_imm.val8 = *s_val8; -            cache_signed_imm_value(operand, size); -            break; -        case AOS_16_BITS_SIGNED: -            s_val16 = va_arg(ap, const uint16_t *); -            operand->signed_imm.val16 = *s_val16; -            cache_signed_imm_value(operand, size); -            break; -        case AOS_32_BITS_SIGNED: -            s_val32 = va_arg(ap, const uint32_t *); -            operand->signed_imm.val32 = *s_val32; -            cache_signed_imm_value(operand, size); -            break; -        case AOS_64_BITS_SIGNED: -            s_val64 = va_arg(ap, const uint64_t *); -            operand->signed_imm.val64 = *s_val64; -            cache_signed_imm_value(operand, size); -            break; -    } - -    va_end(ap); - -    return true; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                size    = taille de l'opérande souhaitée.                    * -*                data    = flux de données à analyser.                        * -*                pos     = position courante dans ce flux. [OUT]              * -*                len     = taille totale des données à analyser.              * -*                ref     = adresse de référence.                              * -*                                                                             * -*  Description : Crée une opérande contenant une valeur relative sur x bits.  * -*                                                                             * -*  Retour      : true si l'opération s'est effectuée avec succès, false sinon.* -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool fill_relimm_operand(asm_operand *operand, AsmOperandSize size, const uint8_t *data, off_t *pos, off_t len, uint64_t ref) -{ -    bool result;                            /* Bilan à retourner           */ -    off_t old_pos;                          /* Sauvegarde de l'évolution   */ -    int8_t val8;                            /* Valeur sur 8 bits           */ -    int16_t val16;                          /* Valeur sur 16 bits          */ -    uint32_t val32;                          /* Valeur sur 32 bits          */ -    int64_t val64;                          /* Valeur sur 64 bits          */ - -    old_pos = *pos; -    result = fill_imm_operand(operand, size, data, pos, len); - -    if (result) -        switch (size) -        { -            case AOS_8_BITS: -                if (operand->unsigned_imm.val8 & 0x80) -                { -                    val8 = operand->unsigned_imm.val8 - 1; -                    val8 = ~val8; -                    operand->unsigned_imm.val8 = ref + (*pos - old_pos); -                    operand->unsigned_imm.val8 -= val8; -                } -                else operand->unsigned_imm.val8 += ref + (*pos - old_pos); -                break; -            case AOS_16_BITS: -                if (operand->unsigned_imm.val16 & 0x8000) -                { -                    val16 = operand->unsigned_imm.val16 - 1; -                    val16 = ~val16; -                    operand->unsigned_imm.val16 = ref + (*pos - old_pos); -                    operand->unsigned_imm.val16 -= val16; -                } -                else operand->unsigned_imm.val16 += ref + (*pos - old_pos); -                break; -            case AOS_32_BITS: -                if (operand->unsigned_imm.val32 & 0x80000000) -                { -                    val32 = operand->unsigned_imm.val32 - 1; -                    val32 = ~val32; -                    operand->unsigned_imm.val32 = ref + (*pos - old_pos); -                    operand->unsigned_imm.val32 -= val32; -                } -                else operand->unsigned_imm.val32 += ref + (*pos - old_pos); -                break; -            case AOS_64_BITS: -                if (operand->unsigned_imm.val64 & 0x8000000000000000ull) -                { -                    val64 = operand->unsigned_imm.val64 - 1; -                    val64 = ~val64; -                    operand->unsigned_imm.val64 = ref + (*pos - old_pos); -                    operand->unsigned_imm.val64 -= val64; -                } -                else operand->unsigned_imm.val64 += ref + (*pos - old_pos); -                break; -        } - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = structure dont le contenu est à définir.           * -*                size    = taille de l'opérande souhaitée.                    * -*                ...     = zone d'enregistrement prévue.                      * -*                                                                             * -*  Description : Récupère la valeur d'une opérande sur x bits.                * -*                                                                             * -*  Retour      : true si l'opération s'est effectuée avec succès, false sinon.* -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool get_imm_operand_value(asm_operand *operand, AsmOperandSize size, ...) -{ -    bool result;                            /* Bilan à retourner           */ -    va_list ap;                             /* Récupération d'argument     */ -    uint8_t *us_val8;                       /* Valeur sur 8 bits n.-s.     */ -    uint16_t *us_val16;                     /* Valeur sur 16 bits n.-s.    */ -    uint32_t *us_val32;                     /* Valeur sur 32 bits n.-s.    */ -    uint64_t *us_val64;                     /* Valeur sur 64 bits n.-s.    */ -    int8_t *s_val8;                         /* Valeur sur 8 bits signés    */ -    int16_t *s_val16;                       /* Valeur sur 16 bits signés   */ -    int32_t *s_val32;                       /* Valeur sur 32 bits signés   */ -    int64_t *s_val64;                       /* Valeur sur 64 bits signés   */ - -    result = true; - -    va_start(ap, size); - -    switch (size) -    { -        case AOS_8_BITS_UNSIGNED: -            us_val8 = va_arg(ap, uint8_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *us_val8 = operand->unsigned_imm.val8; -                    break; -                case AOS_8_BITS_SIGNED: -                    *us_val8 = operand->signed_imm.val8; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_16_BITS_UNSIGNED: -            us_val16 = va_arg(ap, uint16_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *us_val16 = operand->unsigned_imm.val8; -                    break; -                case AOS_16_BITS_UNSIGNED: -                    *us_val16 = operand->unsigned_imm.val16; -                    break; -                case AOS_8_BITS_SIGNED: -                    *us_val16 = operand->signed_imm.val8; -                    break; -                case AOS_16_BITS_SIGNED: -                    *us_val16 = operand->signed_imm.val16; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_32_BITS_UNSIGNED: -            us_val32 = va_arg(ap, uint32_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *us_val32 = operand->unsigned_imm.val8; -                    break; -                case AOS_16_BITS_UNSIGNED: -                    *us_val32 = operand->unsigned_imm.val16; -                    break; -                case AOS_32_BITS_UNSIGNED: -                    *us_val32 = operand->unsigned_imm.val32; -                    break; -                case AOS_8_BITS_SIGNED: -                    *us_val32 = operand->signed_imm.val8; -                    break; -                case AOS_16_BITS_SIGNED: -                    *us_val32 = operand->signed_imm.val16; -                    break; -                case AOS_32_BITS_SIGNED: -                    *us_val32 = operand->signed_imm.val32; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_64_BITS_UNSIGNED: -            us_val64 = va_arg(ap, uint64_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *us_val64 = operand->unsigned_imm.val8; -                    break; -                case AOS_16_BITS_UNSIGNED: -                    *us_val64 = operand->unsigned_imm.val16; -                    break; -                case AOS_32_BITS_UNSIGNED: -                    *us_val64 = operand->unsigned_imm.val32; -                    break; -                case AOS_64_BITS_UNSIGNED: -                    *us_val64 = operand->unsigned_imm.val64; -                    break; -                case AOS_8_BITS_SIGNED: -                    *us_val64 = operand->signed_imm.val8; -                    break; -                case AOS_16_BITS_SIGNED: -                    *us_val64 = operand->signed_imm.val16; -                    break; -                case AOS_32_BITS_SIGNED: -                    *us_val64 = operand->signed_imm.val32; -                    break; -                case AOS_64_BITS_SIGNED: -                    *us_val64 = operand->signed_imm.val64; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_8_BITS_SIGNED: -            s_val8 = va_arg(ap, int8_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *s_val8 = operand->unsigned_imm.val8; -                    break; -                case AOS_8_BITS_SIGNED: -                    *s_val8 = operand->signed_imm.val8; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_16_BITS_SIGNED: -            s_val16 = va_arg(ap, int16_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *s_val16 = operand->unsigned_imm.val8; -                    break; -                case AOS_16_BITS_UNSIGNED: -                    *s_val16 = operand->unsigned_imm.val16; -                    break; -                case AOS_8_BITS_SIGNED: -                    *s_val16 = operand->signed_imm.val8; -                    break; -                case AOS_16_BITS_SIGNED: -                    *s_val16 = operand->signed_imm.val16; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_32_BITS_SIGNED: -            s_val32 = va_arg(ap, int32_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *s_val32 = operand->unsigned_imm.val8; -                    break; -                case AOS_16_BITS_UNSIGNED: -                    *s_val32 = operand->unsigned_imm.val16; -                    break; -                case AOS_32_BITS_UNSIGNED: -                    *s_val32 = operand->unsigned_imm.val32; -                    break; -                case AOS_8_BITS_SIGNED: -                    *s_val32 = operand->signed_imm.val8; -                    break; -                case AOS_16_BITS_SIGNED: -                    *s_val32 = operand->signed_imm.val16; -                    break; -                case AOS_32_BITS_SIGNED: -                    *s_val32 = operand->signed_imm.val32; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        case AOS_64_BITS_SIGNED: -            s_val64 = va_arg(ap, int64_t *); -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                    *s_val64 = operand->unsigned_imm.val8; -                    break; -                case AOS_16_BITS_UNSIGNED: -                    *s_val64 = operand->unsigned_imm.val16; -                    break; -                case AOS_32_BITS_UNSIGNED: -                    *s_val64 = operand->unsigned_imm.val32; -                    break; -                case AOS_64_BITS_UNSIGNED: -                    *s_val64 = operand->unsigned_imm.val64; -                    break; -                case AOS_8_BITS_SIGNED: -                    *s_val64 = operand->signed_imm.val8; -                    break; -                case AOS_16_BITS_SIGNED: -                    *s_val64 = operand->signed_imm.val16; -                    break; -                case AOS_32_BITS_SIGNED: -                    *s_val64 = operand->signed_imm.val32; -                    break; -                case AOS_64_BITS_SIGNED: -                    *s_val64 = operand->signed_imm.val64; -                    break; -                default: -                    result = false; -                    break; -            } -            break; - -        default: -            result = false; -            break; - -    } - -    va_end(ap); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instruction à traiter.                             * -*                buffer  = tampon de sortie mis à disposition. [OUT]          * -*                len     = taille de ce tampon.                               * -*                syntax  = type de représentation demandée.                   * -*                                                                             * -*  Description : Traduit une opérande de valeur immédiate en texte.           * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void print_imm_operand(const asm_operand *operand, char *buffer, size_t len, AsmSyntax syntax) -{ -    switch (syntax) -    { -        case ASX_INTEL: -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                case AOS_8_BITS_SIGNED: -                    snprintf(buffer, len, "0x%hhx", operand->unsigned_imm.val8); -                    break; -                case AOS_16_BITS_UNSIGNED: -                case AOS_16_BITS_SIGNED: -                    snprintf(buffer, len, "0x%hx", operand->unsigned_imm.val16); -                    break; -                case AOS_32_BITS_UNSIGNED: -                case AOS_32_BITS_SIGNED: -                    snprintf(buffer, len, "0x%x", operand->unsigned_imm.val32); -                    break; -                case AOS_64_BITS_UNSIGNED: -                case AOS_64_BITS_SIGNED: -                    snprintf(buffer, len, "0x%llx", operand->unsigned_imm.val64); -                    break; -            } -            break; - -        case ASX_ATT: -            switch (operand->size) -            { -                case AOS_8_BITS_UNSIGNED: -                case AOS_8_BITS_SIGNED: -                    snprintf(buffer, len, "$0x%hhx", operand->unsigned_imm.val8); -                    break; -                case AOS_16_BITS_UNSIGNED: -                case AOS_16_BITS_SIGNED: -                    snprintf(buffer, len, "$0x%hx", operand->unsigned_imm.val16); -                    break; -                case AOS_32_BITS_UNSIGNED: -                case AOS_32_BITS_SIGNED: -                    snprintf(buffer, len, "$0x%x", operand->unsigned_imm.val32); -                    break; -                case AOS_64_BITS_UNSIGNED: -                case AOS_64_BITS_SIGNED: -                    snprintf(buffer, len, "$0x%llx", operand->unsigned_imm.val64); -                    break; -            } -            break; - -    } - -} - - - - - - - - - - - - - - -  /* Initialise la classe générique des opérandes. */  static void g_arch_operand_class_init(GArchOperandClass *); diff --git a/src/arch/operand.h b/src/arch/operand.h index e083668..cd7b213 100644 --- a/src/arch/operand.h +++ b/src/arch/operand.h @@ -26,8 +26,10 @@  #include <stdbool.h> -#include <stdint.h> -#include <sys/types.h> + + +#include "archbase.h" + @@ -55,48 +57,6 @@ typedef enum _AsmOperandSize  #define AOS_64_BITS AOS_64_BITS_UNSIGNED -/* Définition générique d'une opérande */ -typedef struct _asm_operand asm_operand; - - -/* Différentes formes de représentation humaine */ -typedef enum _AsmSyntax -{ -    ASX_INTEL,                              /* Syntaxe Intel               */ -    ASX_ATT                                 /* Syntaxte AT&T               */ - -} AsmSyntax; - - - -/* Crée une opérande pour l'instruction 'db'. */ -bool fill_db_operand(asm_operand *, uint8_t); - -/* Traduit une opérande de type 'db' en texte. */ -void print_db_operand(const asm_operand *, char *, size_t, AsmSyntax); - -/* Lit une valeur (signée ou non) sur x bits. */ -bool read_imm_value(AsmOperandSize, const uint8_t *, off_t *, off_t, ...); - -/* Indique le signe d'une valeur immédiate. */ -bool is_imm_operand_negative(const asm_operand *); - -/* Crée une opérande contenant une valeur sur x bits. */ -bool fill_imm_operand(asm_operand *, AsmOperandSize, const uint8_t *, off_t *, off_t); - -/* Crée une opérande contenant une valeur sur x bits. */ -bool fill_imm_operand_with_value(asm_operand *, AsmOperandSize, ...); - -/* Crée une opérande contenant une valeur relative sur x bits. */ -bool fill_relimm_operand(asm_operand *, AsmOperandSize, const uint8_t *, off_t *, off_t, uint64_t); - -/* Récupère la valeur d'une opérande sur x bits. */ -bool get_imm_operand_value(asm_operand *, AsmOperandSize, ...); - -/* Traduit une opérande de valeur immédiate en texte. */ -void print_imm_operand(const asm_operand *, char *, size_t, AsmSyntax); - -  #include <glib-object.h> diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h index 873ec72..bbe2384 100644 --- a/src/arch/processor-int.h +++ b/src/arch/processor-int.h @@ -29,7 +29,7 @@ - +/* TODO : nettoyer ! */  #include <stdint.h>  #include <sys/types.h> @@ -45,35 +45,6 @@ -/* Décode une instruction dans un flux de données. */ -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 exe_format *, const asm_instr *, char *, size_t, AsmSyntax); - - - -/* Définition générique d'une architecture */ -struct _asm_processor -{ - -    fetch_instruction_ fetch_instr;          /* Lecture d'une instruction   */ - -    print_instruction_ print_instr;          /* Version lisible d'une instr.*/ - - -}; - - -#define ASM_PROCESSOR(proc) ((asm_processor *)proc) - - - - -/* S'assure qu'une chaîne de caractère tient sur une ligne. */ -char *escape_crlf_bin_string(char *); - - diff --git a/src/arch/processor.c b/src/arch/processor.c index fb8b4de..191fa10 100644 --- a/src/arch/processor.c +++ b/src/arch/processor.c @@ -32,7 +32,6 @@  #include "processor-int.h" -#include "x86/processor.h" @@ -44,6 +43,7 @@  #include "artificial.h"  #include "jvm/processor.h" +#include "x86/processor.h" @@ -189,6 +189,7 @@ GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *proc  bool init_all_processors(void)  { +    _processors_list[APT_386] = g_x86_processor_new();      _processors_list[APT_JVM] = g_jvm_processor_new();      return true; diff --git a/src/arch/processor.h b/src/arch/processor.h index 0c6d852..c37811f 100644 --- a/src/arch/processor.h +++ b/src/arch/processor.h @@ -47,17 +47,6 @@ typedef enum _AdressMode -/* Définition générique d'une architecture */ -typedef struct _asm_processor asm_processor; - - - -asm_processor *create_processor(void); - - - - -  #include <glib-object.h> @@ -95,6 +84,7 @@ GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *, co  /* Type de processeurs disponibles */  typedef enum _ArchProcessorType  { +    APT_386,                                /* Intel 80386                 */      APT_JVM,                                /* Java Virtual Machine        */      APT_COUNT diff --git a/src/arch/x86/Makefile.am b/src/arch/x86/Makefile.am index 8f49e54..063a7ce 100644 --- a/src/arch/x86/Makefile.am +++ b/src/arch/x86/Makefile.am @@ -2,7 +2,7 @@  noinst_LTLIBRARIES = libarchx86.la  libarchx86_la_SOURCES =					\ -	instruction.h						\ +	instruction.h instruction.c			\  	op_adc.c							\  	op_add.c							\  	op_and.c							\ @@ -17,8 +17,6 @@ libarchx86_la_SOURCES =					\  	op_lea.c							\  	op_leave.c							\  	op_mov.c							\ -	op_movsx.c							\ -	op_movzx.c							\  	op_nop.c							\  	op_not.c							\  	op_or.c								\ @@ -35,10 +33,15 @@ libarchx86_la_SOURCES =					\  	op_shr.c							\  	op_sub.c							\  	op_test.c							\ +	op_xchg.c							\  	op_xor.c							\  	opcodes.h							\  	operand.h operand.c					\ -	processor.h processor.c +	processor.h processor.c				\ +	registers.h registers.c + +#	op_movsx.c +#	op_movzx.c  libarchx86_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/arch/x86/instruction.h b/src/arch/x86/instruction.h index cbdbe2d..1a65066 100644 --- a/src/arch/x86/instruction.h +++ b/src/arch/x86/instruction.h @@ -26,223 +26,250 @@  #include "../instruction.h" -#include "../instruction-int.h" - - - -/* Définition d'une instruction x86 */ -typedef struct _asm_x86_instr asm_x86_instr;  /* Enumération de tous les opcodes */  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)           */ - -    X86_OP_XOR_RM8_R8,                      /* xor (0x30)                  */ -    X86_OP_XOR_RM1632_R1632,                /* xor ([0x66] 0x31)           */ -    X86_OP_XOR_R8_RM8,                      /* xor (0x32)                  */ -    X86_OP_XOR_R1632_RM1632,                /* xor ([0x66] 0x33)           */ -    X86_OP_XOR_AL_IMM8,                     /* xor (0x34)                  */ -    X86_OP_XOR_E_AX_IMM1632,                /* xor ([0x66] 0x35)           */ - -    X86_OP_CMP_RM1632_R1632,                /* cmp ([0x66] 0x39)           */ - -    X86_OP_INC_E_AX,                        /* inc ([0x66] 0x40)           */ -    X86_OP_INC_E_CX,                        /* inc ([0x66] 0x41)           */ -    X86_OP_INC_E_DX,                        /* inc ([0x66] 0x42)           */ -    X86_OP_INC_E_BX,                        /* inc ([0x66] 0x43)           */ -    X86_OP_INC_E_SP,                        /* inc ([0x66] 0x44)           */ -    X86_OP_INC_E_BP,                        /* inc ([0x66] 0x45)           */ -    X86_OP_INC_E_SI,                        /* inc ([0x66] 0x46)           */ -    X86_OP_INC_E_DI,                        /* inc ([0x66] 0x47)           */ - -    X86_OP_DEC_E_AX,                        /* dec ([0x66] 0x48)           */ -    X86_OP_DEC_E_CX,                        /* dec ([0x66] 0x49)           */ -    X86_OP_DEC_E_DX,                        /* dec ([0x66] 0x4a)           */ -    X86_OP_DEC_E_BX,                        /* dec ([0x66] 0x4b)           */ -    X86_OP_DEC_E_SP,                        /* dec ([0x66] 0x4c)           */ -    X86_OP_DEC_E_BP,                        /* dec ([0x66] 0x4d)           */ -    X86_OP_DEC_E_SI,                        /* dec ([0x66] 0x4e)           */ -    X86_OP_DEC_E_DI,                        /* dec ([0x66] 0x4f)           */ - -    X86_OP_PUSH_E_AX,                       /* push ([0x66] 0x50)          */ -    X86_OP_PUSH_E_CX,                       /* push ([0x66] 0x51)          */ -    X86_OP_PUSH_E_DX,                       /* push ([0x66] 0x52)          */ -    X86_OP_PUSH_E_BX,                       /* push ([0x66] 0x53)          */ -    X86_OP_PUSH_E_SP,                       /* push ([0x66] 0x54)          */ -    X86_OP_PUSH_E_BP,                       /* push ([0x66] 0x55)          */ -    X86_OP_PUSH_E_SI,                       /* push ([0x66] 0x56)          */ -    X86_OP_PUSH_E_DI,                       /* push ([0x66] 0x57)          */ - -    X86_OP_POP_E_AX,                        /* pop ([0x66] 0x58)           */ -    X86_OP_POP_E_CX,                        /* pop ([0x66] 0x59)           */ -    X86_OP_POP_E_DX,                        /* pop ([0x66] 0x5a)           */ -    X86_OP_POP_E_BX,                        /* pop ([0x66] 0x5b)           */ -    X86_OP_POP_E_SP,                        /* pop ([0x66] 0x5c)           */ -    X86_OP_POP_E_BP,                        /* pop ([0x66] 0x5d)           */ -    X86_OP_POP_E_SI,                        /* pop ([0x66] 0x5e)           */ -    X86_OP_POP_E_DI,                        /* pop ([0x66] 0x5f)           */ +    XOP_ADD_RM8_R8,                         /* add (0x00)                  */ +    XOP_ADD_RM1632_R1632,                   /* add ([0x66] 0x01)           */ +    XOP_ADD_R8_RM8,                         /* add (0x02)                  */ +    XOP_ADD_R1632_RM1632,                   /* add ([0x66] 0x03)           */ +    XOP_ADD_AL_IMM8,                        /* add (0x04)                  */ +    XOP_ADD_E_AX_IMM1632,                   /* sub ([0x66] 0x05)           */ + +    XOP_OR_R8_RM8,                          /* or (0x0a)                   */ +    XOP_OR_AL_IMM8,                         /* or (0x0c)                   */ + +    XOP_ADC_RM8_R8,                         /* adc (0x10)                  */ + +    XOP_AND_RM8_R8,                         /* and (0x20)                  */ + +    XOP_SUB_RM1632_R1632,                   /* sub ([0x66] 0x29)           */ + +    XOP_SUB_R8_RM8,                         /* sub (0x2a)                  */ +    XOP_SUB_AL_IMM8,                        /* sub (0x2c)                  */ + +    XOP_SUB_E_AX_IMM1632,                   /* sub ([0x66] 0x2d)           */ + + +    XOP_XOR_RM8_R8,                         /* xor (0x30)                  */ +    XOP_XOR_RM1632_R1632,                   /* xor ([0x66] 0x31)           */ +    XOP_XOR_R8_RM8,                         /* xor (0x32)                  */ +    XOP_XOR_R1632_RM1632,                   /* xor ([0x66] 0x33)           */ +    XOP_XOR_AL_IMM8,                        /* xor (0x34)                  */ +    XOP_XOR_E_AX_IMM1632,                   /* xor ([0x66] 0x35)           */ + + +    XOP_CMP_RM1632_R1632,                   /* cmp ([0x66] 0x39)           */ +    XOP_INC_E_AX,                           /* inc ([0x66] 0x40)           */ +    XOP_INC_E_CX,                           /* inc ([0x66] 0x41)           */ +    XOP_INC_E_DX,                           /* inc ([0x66] 0x42)           */ +    XOP_INC_E_BX,                           /* inc ([0x66] 0x43)           */ +    XOP_INC_E_SP,                           /* inc ([0x66] 0x44)           */ +    XOP_INC_E_BP,                           /* inc ([0x66] 0x45)           */ +    XOP_INC_E_SI,                           /* inc ([0x66] 0x46)           */ +    XOP_INC_E_DI,                           /* inc ([0x66] 0x47)           */ +    XOP_DEC_E_AX,                           /* dec ([0x66] 0x48)           */ +    XOP_DEC_E_CX,                           /* dec ([0x66] 0x49)           */ +    XOP_DEC_E_DX,                           /* dec ([0x66] 0x4a)           */ +    XOP_DEC_E_BX,                           /* dec ([0x66] 0x4b)           */ +    XOP_DEC_E_SP,                           /* dec ([0x66] 0x4c)           */ +    XOP_DEC_E_BP,                           /* dec ([0x66] 0x4d)           */ +    XOP_DEC_E_SI,                           /* dec ([0x66] 0x4e)           */ +    XOP_DEC_E_DI,                           /* dec ([0x66] 0x4f)           */ +    XOP_PUSH_E_AX,                          /* push ([0x66] 0x50)          */ +    XOP_PUSH_E_CX,                          /* push ([0x66] 0x51)          */ +    XOP_PUSH_E_DX,                          /* push ([0x66] 0x52)          */ +    XOP_PUSH_E_BX,                          /* push ([0x66] 0x53)          */ +    XOP_PUSH_E_SP,                          /* push ([0x66] 0x54)          */ +    XOP_PUSH_E_BP,                          /* push ([0x66] 0x55)          */ +    XOP_PUSH_E_SI,                          /* push ([0x66] 0x56)          */ +    XOP_PUSH_E_DI,                          /* push ([0x66] 0x57)          */ +    XOP_POP_E_AX,                           /* pop ([0x66] 0x58)           */ +    XOP_POP_E_CX,                           /* pop ([0x66] 0x59)           */ +    XOP_POP_E_DX,                           /* pop ([0x66] 0x5a)           */ +    XOP_POP_E_BX,                           /* pop ([0x66] 0x5b)           */ +    XOP_POP_E_SP,                           /* pop ([0x66] 0x5c)           */ +    XOP_POP_E_BP,                           /* pop ([0x66] 0x5d)           */ +    XOP_POP_E_SI,                           /* pop ([0x66] 0x5e)           */ +    XOP_POP_E_DI,                           /* pop ([0x66] 0x5f)           */ + + +    XOP_PUSH_IMM1632,                       /* push ([0x66] 0x68)          */ + + +    XOP_JO_REL8,                            /* jo (0x70)                   */ +    XOP_JNO_REL8,                           /* jno (0x71)                  */ +    XOP_JB_REL8,                            /* jb (0x72)                   */ +    XOP_JNB_REL8,                           /* jnb (0x73)                  */ +    XOP_JE_REL8,                            /* je (0x74)                   */ +    XOP_JNE_REL8,                           /* jne (0x75)                  */ +    XOP_JNA_REL8,                           /* jna (0x76)                  */ +    XOP_JA_REL8,                            /* ja (0x77)                   */ +    XOP_JS_REL8,                            /* js (0x78)                   */ +    XOP_JNS_REL8,                           /* jns (0x79)                  */ +    XOP_JP_REL8,                            /* jp (0x7a)                   */ +    XOP_JNP_REL8,                           /* jnp (0x7b)                  */ +    XOP_JL_REL8,                            /* jl (0x7c)                   */ +    XOP_JNL_REL8,                           /* jnl (0x7d)                  */ +    XOP_JNG_REL8,                           /* jng (0x7e)                  */ +    XOP_JG_REL8,                            /* jg (0x7f)                   */ +    XOP_ADD_RM8_IMM8,                       /* add (0x80 0)                */ +    XOP_OR_RM8_IMM8,                        /* or (0x80 1)                 */ +    XOP_ADC_RM8_IMM8,                       /* adc (0x80 2)                */ +    XOP_SBB_RM8_IMM8,                       /* sbb (0x80 3)                */ +    XOP_AND_RM8_IMM8,                       /* and (0x80 4)                */ +    XOP_SUB_RM8_IMM8,                       /* sub (0x80 5)                */ +    XOP_XOR_RM8_IMM8,                       /* xor (0x80 6)                */ +    XOP_CMP_RM8_IMM8,                       /* cmp (0x80 7)                */ +    XOP_ADD_RM1632_IMM1632,                 /* add ([0x66] 0x81 0)         */ +    XOP_OR_RM1632_IMM1632,                  /* or ([0x66] 0x81 1)          */ +    XOP_ADC_RM1632_IMM1632,                 /* adc ([0x66] 0x81 2)         */ +    XOP_SBB_RM1632_IMM1632,                 /* sbb ([0x66] 0x81 3)         */ +    XOP_AND_RM1632_IMM1632,                 /* and ([0x66] 0x81 4)         */ +    XOP_SUB_RM1632_IMM1632,                 /* sub ([0x66] 0x81 5)         */ +    XOP_XOR_RM1632_IMM1632,                 /* xor ([0x66] 0x81 6)         */ +    XOP_CMP_RM1632_IMM1632,                 /* xor ([0x66] 0x81 7)         */ -    X86_OP_PUSH_IMM1632,                    /* push ([0x66] 0x68)          */ -    X86_OP_JB_REL8,                         /* jb (0x72)                   */ -    X86_OP_JNB_REL8,                        /* jnb (0x73)                  */ +    XOP_ADD_RM1632_IMM8,                    /* add ([0x66] 0x83 0)         */ +    XOP_OR_RM1632_IMM8,                     /* or ([0x66] 0x83 1)          */ +    XOP_ADC_RM1632_IMM8,                    /* adc ([0x66] 0x83 2)         */ +    XOP_SBB_RM1632_IMM8,                    /* sbb ([0x66] 0x83 3)         */ +    XOP_AND_RM1632_IMM8,                    /* and ([0x66] 0x83 4)         */ +    XOP_SUB_RM1632_IMM8,                    /* sub ([0x66] 0x83 5)         */ +    XOP_XOR_RM1632_IMM8,                    /* xor ([0x66] 0x83 6)         */ +    XOP_CMP_RM1632_IMM8,                    /* cmp ([0x66] 0x83 7)         */ -    X86_OP_JE_8,                            /* je (0x74)                   */ -    X86_OP_JNE_8,                           /* jne (0x75)                  */ -    X86_OP_JG_REL8,                         /* jg (0x7f)                   */ -    X86_OP_XOR_RM8_IMM8,                    /* xor (0x80 6)                */ -    X86_OP_CMP_RM8_IMM8,                    /* cmp (0x80 7)                */ +    XOP_TEST_RM8_R8,                        /* test (0x84)                 */ +    XOP_TEST_RM1632_R1632,                  /* test ([0x66] 0x85)          */ -    X86_OP_ADD_RM1632_IMM1632,              /* add ([0x66] 0x81 0)         */ -    X86_OP_OR_RM1632_IMM1632,               /* or ([0x66] 0x81 1)          */ -    X86_OP_ADC_RM1632_IMM1632,              /* adc ([0x66] 0x81 2)         */ -    X86_OP_SBB_RM1632_IMM1632,              /* sbb ([0x66] 0x81 3)         */ -    X86_OP_AND_RM1632_IMM1632,              /* and ([0x66] 0x81 4)         */ -    X86_OP_SUB_RM1632_IMM1632,              /* sub ([0x66] 0x81 5)         */ -    X86_OP_XOR_RM1632_IMM1632,              /* xor ([0x66] 0x81 6)         */ -    X86_OP_CMP_RM1632_IMM1632,              /* xor ([0x66] 0x81 7)         */ -    X86_OP_ADD_RM1632_IMM8,                 /* add ([0x66] 0x83 0)         */ -    X86_OP_OR_RM1632_IMM8,                  /* or ([0x66] 0x83 1)          */ -    X86_OP_ADC_RM1632_IMM8,                 /* adc ([0x66] 0x83 2)         */ -    X86_OP_SBB_RM1632_IMM8,                 /* sbb ([0x66] 0x83 3)         */ -    X86_OP_AND_RM1632_IMM8,                 /* and ([0x66] 0x83 4)         */ -    X86_OP_SUB_RM1632_IMM8,                 /* sub ([0x66] 0x83 5)         */ -    X86_OP_XOR_RM1632_IMM8,                 /* xor ([0x66] 0x83 6)         */ -    X86_OP_CMP_RM1632_IMM8,                 /* cmp ([0x66] 0x08 7)         */ -    X86_OP_TEST_RM8_R8,                     /* test ([0x66] 0x84)          */ -    X86_OP_TEST_RM1632_R1632,               /* test ([0x66] 0x85)          */ +    XOP_MOV_RM8_R8,                         /* mov (0x88)                  */ +    XOP_MOV_RM1632_R1632,                   /* mov ([0x66] 0x89)           */ -    X86_OP_MOV_RM8_R8,                      /* mov (0x88)                  */ -    X86_OP_MOV_RM1632_R1632,                /* mov ([0x66] 0x89)           */ +    XOP_MOV_R1632_RM1632,                   /* mov ([0x66] 0x8b)           */ -    X86_OP_MOV_R1632_RM1632,                /* mov ([0x66] 0x8b)           */ -    X86_OP_LEA,                             /* lea ([0x66] 0x8d)           */   /* 66 ? */ -    X86_OP_NOP,                             /* nop (0x90)                  */ +    XOP_LEA_R1632_M,                        /* lea ([0x66] 0x8d)           */ + + +    XOP_NOP,                                /* nop (0x90)                  */ -    X86_OP_MOV_MOFFS_TO_AL,                 /* mov (0xa0)                  */ -    X86_OP_MOV_MOFFS_TO_E_AX,               /* mov ([0x66] 0xa1)           */ -    X86_OP_MOV_AL_TO_MOFFS,                 /* mov (0xa2)                  */ -    X86_OP_MOV_E_AX_TO_MOFFS,               /* mov ([0x66] 0xa3)           */ -    X86_OP_TEST_AL,                         /* test (0xa8)                 */ -    X86_OP_TEST_E_AX,                       /* test ([0x66] 0xa9)          */ - -    X86_OP_MOV_E_AX,                        /* mov ([0x66] 0xb8)           */ -    X86_OP_MOV_E_CX,                        /* mov ([0x66] 0xb9)           */ -    X86_OP_MOV_E_DX,                        /* mov ([0x66] 0xba)           */ -    X86_OP_MOV_E_BX,                        /* mov ([0x66] 0xbb)           */ -    X86_OP_MOV_E_SP,                        /* mov ([0x66] 0xbc)           */ -    X86_OP_MOV_E_BP,                        /* mov ([0x66] 0xbd)           */ -    X86_OP_MOV_E_SI,                        /* mov ([0x66] 0xbe)           */ -    X86_OP_MOV_E_DI,                        /* mov ([0x66] 0xbf)           */ +    XOP_XCHG_R1632_E_AX,                    /* xchg ([0x66] 0x90)          */ +    XOP_XCHG_R1632_E_CX,                    /* xchg ([0x66] 0x91)          */ +    XOP_XCHG_R1632_E_DX,                    /* xchg ([0x66] 0x92)          */ +    XOP_XCHG_R1632_E_BX,                    /* xchg ([0x66] 0x93)          */ +    XOP_XCHG_R1632_E_SP,                    /* xchg ([0x66] 0x94)          */ +    XOP_XCHG_R1632_E_BP,                    /* xchg ([0x66] 0x95)          */ +    XOP_XCHG_R1632_E_SI,                    /* xchg ([0x66] 0x96)          */ +    XOP_XCHG_R1632_E_DI,                    /* xchg ([0x66] 0x97)          */ -    X86_OP_ROL_RM1632_IMM8,                 /* rol ([0x66] 0xc1 0)         */ -    X86_OP_ROR_RM1632_IMM8,                 /* ror ([0x66] 0xc1 1)         */ -    X86_OP_RCL_RM1632_IMM8,                 /* rcl ([0x66] 0xc1 2)         */ -    X86_OP_RCR_RM1632_IMM8,                 /* rcr ([0x66] 0xc1 3)         */ -    X86_OP_SHL_RM1632_IMM8,                 /* shl ([0x66] 0xc1 4)         */ -    X86_OP_SHR_RM1632_IMM8,                 /* shr ([0x66] 0xc1 5)         */ -    X86_OP_SAL_RM1632_IMM8,                 /* sal ([0x66] 0xc1 6)         */ -    X86_OP_SAR_RM1632_IMM8,                 /* sar ([0x66] 0xc1 7)         */ -    X86_OP_RET,                             /* ret (0xc3)                  */ +    XOP_MOV_AL_MOFFS8,                      /* mov (0xa0)                  */ +    XOP_MOV_E_AX_MOFFS1632,                 /* mov ([0x66] 0xa1)           */ +    XOP_MOV_MOFFS8_AL,                      /* mov (0xa2)                  */ +    XOP_MOV_MOFFS1632_E_AX,                 /* mov ([0x66] 0xa3)           */ -    X86_OP_MOV_IMM8_TO_RM8,                 /* mov (0xc6)                  */ -    X86_OP_MOV_IMM1632_TO_RM1632,           /* mov ([0x66] 0xc7)           */ -    X86_OP_LEAVE,                           /* leave (0xc9)                */ +    XOP_TEST_AL_IMM8,                       /* test (0xa8)                 */ +    XOP_TEST_E_AX_IMM1632,                  /* test ([0x66] 0xa9)          */ -    X86_OP_INT_3,                           /* int 3 (0xcc)                */ -    X86_OP_INT,                             /* int (0xcd)                  */ -    X86_OP_SHL_RM1632_CL,                   /* shl ([0x66] 0xd3 4)         */ +    XOP_MOV_E_AX_IMM1632,                   /* mov ([0x66] 0xb8)           */ +    XOP_MOV_E_CX_IMM1632,                   /* mov ([0x66] 0xb9)           */ +    XOP_MOV_E_DX_IMM1632,                   /* mov ([0x66] 0xba)           */ +    XOP_MOV_E_BX_IMM1632,                   /* mov ([0x66] 0xbb)           */ +    XOP_MOV_E_SP_IMM1632,                   /* mov ([0x66] 0xbc)           */ +    XOP_MOV_E_BP_IMM1632,                   /* mov ([0x66] 0xbd)           */ +    XOP_MOV_E_SI_IMM1632,                   /* mov ([0x66] 0xbe)           */ +    XOP_MOV_E_DI_IMM1632,                   /* mov ([0x66] 0xbf)           */ -    X86_OP_CALL_REL1632,                    /* call ([0x66] 0xe8)          */ -    X86_OP_JMP_REL1632,                     /* jmp ([0x66] 0xe9)           */ -    X86_OP_JMP_8,                           /* jmp (0xeb)                  */ +    XOP_ROL_RM1632_IMM8,                    /* rol ([0x66] 0xc1 0)         */ +    XOP_ROR_RM1632_IMM8,                    /* ror ([0x66] 0xc1 1)         */ +    XOP_RCL_RM1632_IMM8,                    /* rcl ([0x66] 0xc1 2)         */ +    XOP_RCR_RM1632_IMM8,                    /* rcr ([0x66] 0xc1 3)         */ +    XOP_SHL_RM1632_IMM8,                    /* shl ([0x66] 0xc1 4)         */ +    XOP_SHR_RM1632_IMM8,                    /* shr ([0x66] 0xc1 5)         */ +    XOP_SAL_RM1632_IMM8,                    /* sal ([0x66] 0xc1 6)         */ +    XOP_SAR_RM1632_IMM8,                    /* sar ([0x66] 0xc1 7)         */ -    X86_OP_HLT,                             /* hlt (0xf4)                  */ -    X86_OP_NOT_RM1632,                      /* not ([0x66] 0xf7 2)         */ +    XOP_RET,                                /* ret (0xc3)                  */ -    X86_OP_CLD,                             /* cld (0xfc)                  */ +    XOP_MOV_RM8_IMM8,                       /* mov (0xc6 0)                */ +    XOP_MOV_RM1632_IMM1632,                 /* mov ([0x66] 0xc7 0)         */ -    X86_OP_CALL_RM1632,                     /* call ([0x66] 0xff 2)        */ -    X86_OP_JMP_RM1632,                      /* jmp ([0x66] 0xff 4)         */ -    X86_OP_PUSH_RM1632,                     /* push ([0x66] 0xff 6)        */ +    XOP_LEAVE,                              /* leave (0xc9)                */ -    X86_OP_MOVZX_R1632_RM8,                 /* movzx ([0x66] 0x0f 0xb6)    */ +    XOP_INT_3,                              /* int 3 (0xcc)                */ +    XOP_INT,                                /* int (0xcd)                  */ -    X86_OP_MOVSX_R1632_RM8,                 /* movsx ([0x66] 0x0f 0xbe)    */ +    XOP_SHL_RM1632_CL,                      /* shl ([0x66] 0xd3 4)         */ -    X86_OP_COUNT +    XOP_CALL_REL1632,                       /* call ([0x66] 0xe8)          */ +    XOP_JMP_REL1632,                        /* jmp ([0x66] 0xe9)           */ -} X86Opcodes; +    XOP_JMP_REL8,                           /* jmp (0xeb)                  */ +    XOP_HLT,                                /* hlt (0xf4)                  */ +    XOP_NOT_RM1632,                         /* not ([0x66] 0xf7 2)         */ +    XOP_CLD,                                /* cld (0xfc)                  */ -/* Eventuel préfixe rencontré */ -typedef enum _X86Prefix -{ -    X86_PRE_NONE        = (0 << 0),         /* Aucun préfixe               */ +    XOP_CALL_RM1632,                        /* call ([0x66] 0xff 2)        */ +    XOP_JMP_RM1632,                         /* jmp ([0x66] 0xff 4)         */ +    XOP_PUSH_RM1632,                        /* push ([0x66] 0xff 6)        */ + +    XOP_COUNT +} X86Opcodes; -    /* Groupe 3 */ -    X86_PRE_OPSIZE      = (1 << 1),         /* Basculement des opérandes   */ +#define G_TYPE_X86_INSTRUCTION                 g_x86_instruction_get_type() +#define G_X86_INSTRUCTION(obj)                 (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_instruction_get_type(), GX86Instruction)) +#define G_IS_X86_INSTRUCTION(obj)              (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_instruction_get_type())) +#define G_X86_INSTRUCTION_GET_IFACE(inst)      (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_instruction_get_type(), GX86InstructionIface)) -    /* Autres */ -    X86_PRE_ESCAPE      = (1 << 3)          /* Opcode sur deux octets      */ +/* Définition générique d'une instruction d'architecture x86 (instance) */ +typedef struct _GX86Instruction GX86Instruction; -} X86Prefix; +/* Définition générique d'une instruction d'architecture x86 (classe) */ +typedef struct _GX86InstructionClass GX86InstructionClass; +/* Indique le type défini pour une instruction d'architecture x86. */ +GType g_x86_instruction_get_type(void); -/* Définition d'une instruction x86 */ -struct _asm_x86_instr -{ -    asm_instr base;                         /* A laisser en premier...     */ +/* Crée une instruction pour l'architecture x86. */ +GArchInstruction *g_x86_instruction_new(X86Opcodes); -    X86Opcodes type; -    X86Prefix prefix;                       /* Eventuel préfixe trouvé     */ +/* --------------------- AIDE A LA MISE EN PLACE D'INSTRUCTIONS --------------------- */ -}; +/* Types de préfixes pour x86 */ +typedef enum _X86Prefix +{ +    XPX_NONE                    = (0 << 0), /* Code d'instruction pur      */ + +    XPX_OPERAND_SIZE_OVERRIDE   = (1 << 0), /* Taille des opérandes        */ +} X86Prefix; +/* Recherche l'identifiant de la prochaine instruction. */ +X86Opcodes x86_guess_next_instruction(const bin_t *, off_t, off_t, X86Prefix *, bool *); diff --git a/src/arch/x86/op_adc.c b/src/arch/x86/op_adc.c index 679bfb4..6ee4ed3 100644 --- a/src/arch/x86/op_adc.c +++ b/src/arch/x86/op_adc.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        * +*  Description : Décode une instruction de type 'adc' (8 bits).               *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,15 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_adc_imm8_to_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_adc_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    GArchInstruction *result;               /* Instruction à retourner     */ -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(XOP_ADC_RM8_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -70,11 +65,6 @@ asm_x86_instr *x86_read_instr_adc_imm8_to_rm1632(const uint8_t *data, off_t *pos  /******************************************************************************  *                                                                             * -*  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' (8 bits).               *  *                                                                             * @@ -84,17 +74,15 @@ asm_x86_instr *x86_read_instr_adc_imm8_to_rm1632(const uint8_t *data, off_t *pos  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_adc_rm8_r8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_ADC_RM8_R8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,11 +93,11 @@ asm_x86_instr *x86_read_instr_adc_rm8_r8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -119,20 +107,54 @@ asm_x86_instr *x86_read_instr_adc_rm8_r8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_adc_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_adc_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_ADC_RM1632_IMM8); + +    oprsize = g_x86_processor_get_operand_size(proc, prefix); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize)) +    { +        /* TODO 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.                 * +*                addr = 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.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_adc_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(XOP_ADC_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_add.c b/src/arch/x86/op_add.c index 98973cd..93506a1 100644 --- a/src/arch/x86/op_add.c +++ b/src/arch/x86/op_add.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'add al, ...' (8 bits).       *  *                                                                             * @@ -46,17 +46,15 @@  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_add_al_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_ADD_AL_IMM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,11 +65,11 @@ asm_x86_instr *x86_read_instr_add_al_imm8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).*  *                                                                             * @@ -81,20 +79,18 @@ asm_x86_instr *x86_read_instr_add_al_imm8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_add_e_ax_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_ADD_E_AX_IMM1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,13 +101,13 @@ asm_x86_instr *x86_read_instr_add_e_ax_imm1632(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        * +*  Description : Décode une instruction de type 'add' (8 bits).               *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -119,20 +115,48 @@ asm_x86_instr *x86_read_instr_add_e_ax_imm1632(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_add_imm8_to_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_add_r8_rm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_ADD_R8_RM8); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    { +        /* TODO free(result);*/ +        return NULL; +    } -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    return result; -    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_RM1632, X86_OTP_IMM8, oprsize)) +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_add_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_ADD_RM8_IMM8); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -143,11 +167,11 @@ asm_x86_instr *x86_read_instr_add_imm8_to_rm1632(const uint8_t *data, off_t *pos  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'add' (8 bits).               *  *                                                                             * @@ -157,17 +181,15 @@ asm_x86_instr *x86_read_instr_add_imm8_to_rm1632(const uint8_t *data, off_t *pos  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_add_rm8_r8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_ADD_RM8_R8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -178,11 +200,11 @@ asm_x86_instr *x86_read_instr_add_r8_rm8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -192,20 +214,18 @@ asm_x86_instr *x86_read_instr_add_r8_rm8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_add_r1632_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_add_r1632_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_ADD_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -216,13 +236,13 @@ asm_x86_instr *x86_read_instr_add_r1632_rm1632(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'add' (8 bits).               * +*  Description : Décode une instruction de type 'add' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -230,17 +250,18 @@ asm_x86_instr *x86_read_instr_add_r1632_rm1632(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_add_rm8_r8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_add_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_ADD_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -251,11 +272,11 @@ asm_x86_instr *x86_read_instr_add_rm8_r8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -265,20 +286,18 @@ asm_x86_instr *x86_read_instr_add_rm8_r8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_add_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_add_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_ADD_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -289,11 +308,11 @@ asm_x86_instr *x86_read_instr_add_rm1632_imm1632(const uint8_t *data, off_t *pos  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -303,20 +322,18 @@ asm_x86_instr *x86_read_instr_add_rm1632_imm1632(const uint8_t *data, off_t *pos  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_add_rm1632_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_add_rm1632_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_ADD_RM1632_R1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_and.c b/src/arch/x86/op_and.c index bcea898..c923441 100644 --- a/src/arch/x86/op_and.c +++ b/src/arch/x86/op_and.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'and' (8 bits).               *  *                                                                             * @@ -46,17 +46,43 @@  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_and_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_AND_RM8_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*                                                                             * +*  Description : Décode une instruction de type 'and' (8 bits).               * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_and_rm8_r8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_AND_RM8_R8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,11 +93,11 @@ asm_x86_instr *x86_read_instr_and_rm8_r8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -81,20 +107,18 @@ asm_x86_instr *x86_read_instr_and_rm8_r8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_and_rm1632_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_and_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_AND_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,11 +129,11 @@ asm_x86_instr *x86_read_instr_and_rm1632_with_imm8(const uint8_t *data, off_t *p  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -119,20 +143,18 @@ asm_x86_instr *x86_read_instr_and_rm1632_with_imm8(const uint8_t *data, off_t *p  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_and_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_and_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_AND_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_call.c b/src/arch/x86/op_call.c index 7641214..f121dd3 100644 --- a/src/arch/x86/op_call.c +++ b/src/arch/x86/op_call.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'call' (16 ou 32 bits).       *  *                                                                             * @@ -46,22 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_call_rel1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_call_rel1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_CALL_REL1632); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    ASM_INSTRUCTION(result)->type = AIT_CALL; - -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL1632, oprsize, offset)) +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL1632, oprsize, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -72,11 +68,11 @@ asm_x86_instr *x86_read_instr_call_rel1632(const uint8_t *data, off_t *pos, off_  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'call' (16 ou 32 bits).       *  *                                                                             * @@ -86,22 +82,18 @@ asm_x86_instr *x86_read_instr_call_rel1632(const uint8_t *data, off_t *pos, off_  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_call_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_call_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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)++]; +    result = g_x86_instruction_new(XOP_CALL_RM1632); -    ASM_INSTRUCTION(result)->type = AIT_CALL; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_cld.c b/src/arch/x86/op_cld.c index c6d5411..fe59683 100644 --- a/src/arch/x86/op_cld.c +++ b/src/arch/x86/op_cld.c @@ -34,7 +34,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'cld'.                        * @@ -45,13 +46,11 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_cld(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_cld(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result; +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_CLD);      return result; diff --git a/src/arch/x86/op_cmp.c b/src/arch/x86/op_cmp.c index 95e1347..709054b 100644 --- a/src/arch/x86/op_cmp.c +++ b/src/arch/x86/op_cmp.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'cmp' (8 bits).               *  *                                                                             * @@ -46,17 +46,15 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_cmp_rm8_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_cmp_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_CMP_RM8_IMM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,13 +65,13 @@ asm_x86_instr *x86_read_instr_cmp_rm8_with_imm8(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'cmp' (8 bits).               * +*  Description : Décode une instruction de type 'cmp' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -81,20 +79,18 @@ asm_x86_instr *x86_read_instr_cmp_rm8_with_imm8(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_cmp_rm1632_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_cmp_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_CMP_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,11 +101,11 @@ asm_x86_instr *x86_read_instr_cmp_rm1632_with_imm8(const uint8_t *data, off_t *p  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'cmp' (16 ou 32 bits).        *  *                                                                             * @@ -119,20 +115,18 @@ asm_x86_instr *x86_read_instr_cmp_rm1632_with_imm8(const uint8_t *data, off_t *p  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_cmp_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_cmp_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_CMP_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -143,11 +137,11 @@ asm_x86_instr *x86_read_instr_cmp_rm1632_imm1632(const uint8_t *data, off_t *pos  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'cmp' (16 ou 32 bits).        *  *                                                                             * @@ -157,20 +151,18 @@ asm_x86_instr *x86_read_instr_cmp_rm1632_imm1632(const uint8_t *data, off_t *pos  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_cmp_rm1632_with_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_cmp_rm1632_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_CMP_RM1632_R1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_dec.c b/src/arch/x86/op_dec.c index dd3562e..f140b85 100644 --- a/src/arch/x86/op_dec.c +++ b/src/arch/x86/op_dec.c @@ -35,7 +35,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'dec' (16 ou 32 bits).        * @@ -46,20 +47,21 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_dec_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_dec_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    X86Opcodes opcode;                      /* Instruction effective       */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    opcode = XOP_DEC_E_AX + (data[*pos] - 0x48); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(opcode); -    ASM_INSTRUCTION(result)->opcode = data[*pos]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_OP_R1632, oprsize, 0x48))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_hlt.c b/src/arch/x86/op_hlt.c index b789dca..c38c1cc 100644 --- a/src/arch/x86/op_hlt.c +++ b/src/arch/x86/op_hlt.c @@ -34,7 +34,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'hlt'.                        * @@ -45,13 +46,11 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_hlt(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_hlt(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result; +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_HLT);      return result; diff --git a/src/arch/x86/op_inc.c b/src/arch/x86/op_inc.c index 912d432..b80e448 100644 --- a/src/arch/x86/op_inc.c +++ b/src/arch/x86/op_inc.c @@ -35,7 +35,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'inc' (16 ou 32 bits).        * @@ -46,20 +47,21 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_inc_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_inc_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    X86Opcodes opcode;                      /* Instruction effective       */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    opcode = XOP_INC_E_AX + (data[*pos] - 0x40); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(opcode); -    ASM_INSTRUCTION(result)->opcode = data[*pos]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_OP_R1632, oprsize, 0x40))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_int.c b/src/arch/x86/op_int.c index 4fdb73a..98b5ce9 100644 --- a/src/arch/x86/op_int.c +++ b/src/arch/x86/op_int.c @@ -27,6 +27,7 @@  #include "../instruction-int.h"  #include "opcodes.h"  #include "operand.h" +#include "../immediate.h" @@ -35,7 +36,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'int'.                        * @@ -46,19 +48,11 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_int(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_int(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    GArchInstruction *result;               /* Instruction à retourner     */ -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_IMM8)) -    { -        free(result); -        return NULL; -    } +    result = g_x86_instruction_new(XOP_INT);      return result; @@ -81,27 +75,15 @@ asm_x86_instr *x86_read_instr_int(const uint8_t *data, off_t *pos, off_t len, ui  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_int_3(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_int_3(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    asm_x86_operand *op;                    /* Opérande unique décodé      */ - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    op = create_new_x86_operand(); -    if (!fill_imm_operand_with_value(ASM_OPERAND(op), AOS_8_BITS, (int []) { 3 })) -    { -        free(op); -        free(result); -        return NULL; -    } +    GArchInstruction *result;               /* Instruction à retourner     */ +    GArchOperand *three;                    /* Argument artificiel         */ -    ASM_INSTRUCTION(result)->operands = (asm_operand **)calloc(1, sizeof(asm_operand *)); -    ASM_INSTRUCTION(result)->operands_count = 1; +    result = g_x86_instruction_new(XOP_INT_3); -    ASM_INSTRUCTION(result)->operands[0] = ASM_OPERAND(op); +    three = g_imm_operand_new_from_value(AOS_8_BITS, 3); +    g_arch_instruction_attach_one_operand(result, three);      return result; diff --git a/src/arch/x86/op_jump.c b/src/arch/x86/op_jump.c index 4a7fc72..709ff24 100644 --- a/src/arch/x86/op_jump.c +++ b/src/arch/x86/op_jump.c @@ -32,11 +32,44 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'ja' (saut 8b si supérieur).  * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_ja_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JA_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO 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.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'jb' (saut 8b si inférieur).  *  *                                                                             * @@ -46,19 +79,48 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jb_rel8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jb_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JB_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; + +} -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'je' (saut 8b si égal).       * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_je_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +    result = g_x86_instruction_new(XOP_JE_REL8); -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, offset)) +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -69,13 +131,13 @@ asm_x86_instr *x86_read_instr_jb_rel8(const uint8_t *data, off_t *pos, off_t len  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'je' (petit saut).            * +*  Description : Décode une instruction de type 'jg' (saut 8b si supérieur).  *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -83,19 +145,48 @@ asm_x86_instr *x86_read_instr_jb_rel8(const uint8_t *data, off_t *pos, off_t len  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_je_8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jg_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JG_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +} -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jl' (saut 8b si inférieur).  * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, offset)) +GArchInstruction *x86_read_instr_jl_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JL_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -106,13 +197,46 @@ asm_x86_instr *x86_read_instr_je_8(const uint8_t *data, off_t *pos, off_t len, u  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'jg' (saut 8b si supérieur).  * +*  Description : Décode une instruction de type 'jmp' (petit saut).           * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_jmp_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JMP_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO 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.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jmp' (grand saut relatif).   *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -120,19 +244,87 @@ asm_x86_instr *x86_read_instr_je_8(const uint8_t *data, off_t *pos, off_t len, u  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jg_rel8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jmp_rel1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ + +    result = g_x86_instruction_new(XOP_JMP_REL1632); + +    oprsize = g_x86_processor_get_operand_size(proc, prefix); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL1632, oprsize, addr)) +    { +        /* TODO 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.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jmp' (16 ou 32 bits).        * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_jmp_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ + +    result = g_x86_instruction_new(XOP_JMP_RM1632); + +    oprsize = g_x86_processor_get_operand_size(proc, prefix); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_RM1632, oprsize)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; + +} + -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jna' (saut 8b si !supérieur).* +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +GArchInstruction *x86_read_instr_jna_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +    result = g_x86_instruction_new(XOP_JNA_REL8); -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, offset)) +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -143,11 +335,11 @@ asm_x86_instr *x86_read_instr_jg_rel8(const uint8_t *data, off_t *pos, off_t len  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'jnb' (saut 8b si !inférieur).*  *                                                                             * @@ -157,19 +349,48 @@ asm_x86_instr *x86_read_instr_jg_rel8(const uint8_t *data, off_t *pos, off_t len  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jnb_rel8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jnb_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JNB_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jne' (saut 8b si !égal).     * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +GArchInstruction *x86_read_instr_jne_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +    result = g_x86_instruction_new(XOP_JNE_REL8); -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, offset)) +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -180,13 +401,13 @@ asm_x86_instr *x86_read_instr_jnb_rel8(const uint8_t *data, off_t *pos, off_t le  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'jne' (petit saut).           * +*  Description : Décode une instruction de type 'jng' (saut 8b si !supérieur).*  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -194,19 +415,48 @@ asm_x86_instr *x86_read_instr_jnb_rel8(const uint8_t *data, off_t *pos, off_t le  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jne_8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jng_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JNG_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; + +} -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jnl' (saut 8b si !inférieur).* +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_jnl_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +    result = g_x86_instruction_new(XOP_JNL_REL8); -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, offset)) +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -217,13 +467,13 @@ asm_x86_instr *x86_read_instr_jne_8(const uint8_t *data, off_t *pos, off_t len,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'jmp' (petit saut).           * +*  Description : Décode une instruction de type 'jno' (saut 8b si !débordemt).*  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -231,19 +481,48 @@ asm_x86_instr *x86_read_instr_jne_8(const uint8_t *data, off_t *pos, off_t len,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jmp_8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jno_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_JNO_REL8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jnp' (saut 8b si !parité).   * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_jnp_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JNP_REL8); -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, offset)) +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -254,13 +533,13 @@ asm_x86_instr *x86_read_instr_jmp_8(const uint8_t *data, off_t *pos, off_t len,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'jmp' (grand saut relatif).   * +*  Description : Décode une instruction de type 'jns' (saut 8b si !signée).   *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -268,22 +547,48 @@ asm_x86_instr *x86_read_instr_jmp_8(const uint8_t *data, off_t *pos, off_t len,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jmp_rel1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jns_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_JNS_REL8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    return result; + +} -    ASM_INSTRUCTION(result)->type = AIT_JUMP; -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL1632, oprsize, offset)) +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'jo' (saut 8b si débordement).* +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_jo_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JO_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -294,13 +599,13 @@ asm_x86_instr *x86_read_instr_jmp_rel1632(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'jmp' (saut en mémoire).      * +*  Description : Décode une instruction de type 'jp' (saut 8b si parité).     *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -308,22 +613,48 @@ asm_x86_instr *x86_read_instr_jmp_rel1632(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_jmp_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_jp_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_JP_REL8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr)) +    { +        /* TODO free(result);*/ +        return NULL; +    } -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    return result; -    ASM_INSTRUCTION(result)->type = AIT_JUMP; +} -    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_RM1632, oprsize)) + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'js' (saut 8b si signée).     * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_js_rel8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_JS_REL8); + +    if (!x86_read_one_operand(result, data, pos, len, X86_OTP_REL8, addr))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_lea.c b/src/arch/x86/op_lea.c index bf63818..4ea1943 100644 --- a/src/arch/x86/op_lea.c +++ b/src/arch/x86/op_lea.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'lea' (16 ou 32 bits).        *  *                                                                             * @@ -46,40 +46,21 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_lea(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_lea_r1632_m(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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)); +    result = g_x86_instruction_new(XOP_LEA_R1632_M); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    reg1 = x86_create_reg1632_operand_from_modrm(data[*pos], oprsize == AOS_32_BITS, false); -    if (reg1 == NULL) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } -    reg2 = x86_create_content1632_operand(data, pos, len, oprsize == AOS_32_BITS, true); -    if (reg2 == NULL) -    { -        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;  } diff --git a/src/arch/x86/op_leave.c b/src/arch/x86/op_leave.c index 550d4dc..05d347a 100644 --- a/src/arch/x86/op_leave.c +++ b/src/arch/x86/op_leave.c @@ -34,7 +34,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'leave'.                      * @@ -45,13 +46,11 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_leave(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_leave(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result; +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_LEAVE);      return result; diff --git a/src/arch/x86/op_mov.c b/src/arch/x86/op_mov.c index efa23c4..4828ba1 100644 --- a/src/arch/x86/op_mov.c +++ b/src/arch/x86/op_mov.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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 al, ...' (8 bits).       *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,17 +46,15 @@  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_mov_al_moffs8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_MOV_AL_MOFFS8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_MOFFS8, X86_OTP_AL)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_MOFFS8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,13 +65,13 @@ asm_x86_instr *x86_read_instr_mov_al_to_moffs8(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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 [e]ax, ...' (16/32 bits).*  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -81,20 +79,18 @@ asm_x86_instr *x86_read_instr_mov_al_to_moffs8(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_mov_e_ax_to_moffs1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_mov_e_ax_moffs1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_MOV_E_AX_MOFFS1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_MOFFS1632, X86_OTP_E_AX, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_MOFFS1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,13 +101,13 @@ asm_x86_instr *x86_read_instr_mov_e_ax_to_moffs1632(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'mov' (8 bits).               * +*  Description : Décode une instruction de type 'mov ..., al' (8 bits).       *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -119,17 +115,15 @@ 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) +GArchInstruction *x86_read_instr_mov_moffs8_al(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_MOV_MOFFS8_AL); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_MOFFS8, X86_OTP_AL))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -140,13 +134,13 @@ asm_x86_instr *x86_read_instr_mov_imm8_to_rm8(const uint8_t *data, off_t *pos, o  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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.                           *  *                                                                             * @@ -154,54 +148,21 @@ 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_imm1632_to_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_mov_moffs1632_e_ax(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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)); - -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[*pos]; +    result = g_x86_instruction_new(XOP_MOV_MOFFS1632_E_AX); -    /* -    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; -    } +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    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_MOFFS1632, X86_OTP_E_AX, oprsize))      { -        free(reg); -        free(value); -        free(result); +        /* TODO 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;  } @@ -209,11 +170,11 @@ asm_x86_instr *x86_read_instr_mov_imm1632_to_r1632(const uint8_t *data, off_t *p  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -223,20 +184,21 @@ asm_x86_instr *x86_read_instr_mov_imm1632_to_r1632(const uint8_t *data, off_t *p  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_mov_r1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    X86Opcodes opcode;                      /* Instruction effective       */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    opcode = XOP_MOV_E_AX_IMM1632 + (data[*pos] - 0xb8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(opcode); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_OP_R1632, X86_OTP_IMM1632, oprsize, 0xb8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -247,13 +209,13 @@ asm_x86_instr *x86_read_instr_mov_imm1632_to_rm1632(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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.                           *  *                                                                             * @@ -261,17 +223,18 @@ asm_x86_instr *x86_read_instr_mov_imm1632_to_rm1632(const uint8_t *data, off_t *  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_mov_r1632_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_MOV_R1632_RM1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_MOFFS8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -282,13 +245,13 @@ asm_x86_instr *x86_read_instr_mov_moffs8_to_al(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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' (8 bits).               *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -296,20 +259,15 @@ 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) +GArchInstruction *x86_read_instr_mov_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_MOV_RM8_IMM8); -    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_MOFFS1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -320,13 +278,8 @@ asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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 'mov' (16 ou 32 bits).        * +*  Description : Décode une instruction de type 'mov' (8 bits).               *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -334,20 +287,15 @@ asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *data, off_t *  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_mov_rm8_r8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    GArchInstruction *result;               /* Instruction à retourner     */ -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(XOP_MOV_RM8_R8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -358,11 +306,11 @@ asm_x86_instr *x86_read_instr_mov_r1632_to_rm1632(const uint8_t *data, off_t *po  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -372,20 +320,18 @@ asm_x86_instr *x86_read_instr_mov_r1632_to_rm1632(const uint8_t *data, off_t *po  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_mov_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_MOV_RM1632_IMM1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -396,13 +342,13 @@ asm_x86_instr *x86_read_instr_mov_rm1632_to_r1632(const uint8_t *data, off_t *po  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'mov' (8 bits).               * +*  Description : Décode une instruction de type 'mov' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -410,17 +356,18 @@ asm_x86_instr *x86_read_instr_mov_rm1632_to_r1632(const uint8_t *data, off_t *po  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_mov_rm8_r8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_mov_rm1632_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_MOV_RM1632_R1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_movsx.c b/src/arch/x86/op_movsx.c index 461309f..e75f1a1 100644 --- a/src/arch/x86/op_movsx.c +++ b/src/arch/x86/op_movsx.c @@ -59,13 +59,13 @@ asm_x86_instr *x86_read_instr_movsx_r1632_rm8(const uint8_t *data, off_t *pos, o      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_R1632, X86_OTP_RM8, oprsize))      {          free(result);          return NULL;      } - +    */      return result;  } diff --git a/src/arch/x86/op_movzx.c b/src/arch/x86/op_movzx.c index 4df1303..c1629d9 100644 --- a/src/arch/x86/op_movzx.c +++ b/src/arch/x86/op_movzx.c @@ -59,13 +59,13 @@ asm_x86_instr *x86_read_instr_movzx_r1632_rm8(const uint8_t *data, off_t *pos, o      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_R1632, X86_OTP_RM8, oprsize))      {          free(result);          return NULL;      } - +    */      return result;  } diff --git a/src/arch/x86/op_nop.c b/src/arch/x86/op_nop.c index 3c1b989..1c2d4c1 100644 --- a/src/arch/x86/op_nop.c +++ b/src/arch/x86/op_nop.c @@ -21,9 +21,6 @@   */ -#include <malloc.h> - -  #include "../instruction-int.h"  #include "opcodes.h" @@ -34,7 +31,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'nop'.                        * @@ -45,13 +43,11 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_nop(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_nop(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result; - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    GArchInstruction *result;               /* Instruction à retourner     */ -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_NOP);      return result; diff --git a/src/arch/x86/op_not.c b/src/arch/x86/op_not.c index 6deb61c..f57c754 100644 --- a/src/arch/x86/op_not.c +++ b/src/arch/x86/op_not.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'not' (16 ou 32 bits).        *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_not_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_not_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_NOT_RM1632); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_or.c b/src/arch/x86/op_or.c index 198a0bb..1f1e78d 100644 --- a/src/arch/x86/op_or.c +++ b/src/arch/x86/op_or.c @@ -32,11 +32,6 @@  /******************************************************************************  *                                                                             * -*  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 al, ...' (8 bits).        *  *                                                                             * @@ -46,17 +41,15 @@  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_or_al_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_OR_AL_IMM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,11 +60,6 @@ asm_x86_instr *x86_read_instr_or_al_imm8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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).                *  *                                                                             * @@ -81,17 +69,15 @@ asm_x86_instr *x86_read_instr_or_al_imm8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_or_r8_rm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    GArchInstruction *result;               /* Instruction à retourner     */ -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_OR_R8_RM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -102,11 +88,44 @@ asm_x86_instr *x86_read_instr_or_r8_rm8(const uint8_t *data, off_t *pos, off_t l  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_or_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_OR_RM8_IMM8); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8)) +    { +        /* TODO 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.                 * +*                addr = 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).         *  *                                                                             * @@ -116,20 +135,18 @@ asm_x86_instr *x86_read_instr_or_r8_rm8(const uint8_t *data, off_t *pos, off_t l  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_or_rm1632_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_or_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_OR_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -140,11 +157,11 @@ asm_x86_instr *x86_read_instr_or_rm1632_with_imm8(const uint8_t *data, off_t *po  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).         *  *                                                                             * @@ -154,20 +171,18 @@ asm_x86_instr *x86_read_instr_or_rm1632_with_imm8(const uint8_t *data, off_t *po  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_or_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_or_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_OR_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_pop.c b/src/arch/x86/op_pop.c index ab0d278..c362898 100644 --- a/src/arch/x86/op_pop.c +++ b/src/arch/x86/op_pop.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'pop' (16 ou 32 bits).        *  *                                                                             * @@ -46,20 +46,21 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_pop_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_pop_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    X86Opcodes opcode;                      /* Instruction effective       */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    opcode = XOP_POP_E_AX + (data[*pos] - 0x58); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(opcode); -    ASM_INSTRUCTION(result)->opcode = data[*pos]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_OP_R1632, oprsize, 0x58))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_push.c b/src/arch/x86/op_push.c index f51bd6f..0e0d100 100644 --- a/src/arch/x86/op_push.c +++ b/src/arch/x86/op_push.c @@ -27,7 +27,6 @@  #include "../instruction-int.h"  #include "opcodes.h"  #include "operand.h" -#include "processor.h" @@ -36,7 +35,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'push' (16 ou 32 bits).       * @@ -47,22 +47,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_push_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_push_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_PUSH_IMM1632); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    ASM_INSTRUCTION(result)->type = AIT_PUSH; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -76,7 +72,8 @@ asm_x86_instr *x86_read_instr_push_imm1632(const uint8_t *data, off_t *pos, off_  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'push' (16 ou 32 bits).       * @@ -87,22 +84,21 @@ asm_x86_instr *x86_read_instr_push_imm1632(const uint8_t *data, off_t *pos, off_  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_push_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_push_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    X86Opcodes opcode;                      /* Instruction effective       */      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); +    opcode = XOP_PUSH_E_AX + (data[*pos] - 0x50); -    ASM_INSTRUCTION(result)->opcode = data[*pos]; +    result = g_x86_instruction_new(opcode); -    ASM_INSTRUCTION(result)->type = AIT_PUSH; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_OP_R1632, oprsize, 0x50))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -113,11 +109,11 @@ asm_x86_instr *x86_read_instr_push_r1632(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'push' (16 ou 32 bits).       *  *                                                                             * @@ -127,22 +123,18 @@ asm_x86_instr *x86_read_instr_push_r1632(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_push_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_push_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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)++]; +    result = g_x86_instruction_new(XOP_PUSH_RM1632); -    ASM_INSTRUCTION(result)->type = AIT_PUSH; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_one_operand(result, data, pos, len, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_rcl.c b/src/arch/x86/op_rcl.c index ab0fd05..e3d95b3 100644 --- a/src/arch/x86/op_rcl.c +++ b/src/arch/x86/op_rcl.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'rcl' (8 bits).               * +*  Description : Décode une instruction de type 'rcl' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_rcl_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_rcl_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_RCL_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_rcr.c b/src/arch/x86/op_rcr.c index 78807f9..028a53c 100644 --- a/src/arch/x86/op_rcr.c +++ b/src/arch/x86/op_rcr.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'rcr' (8 bits).               * +*  Description : Décode une instruction de type 'rcr' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_rcr_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_rcr_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_RCR_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_ret.c b/src/arch/x86/op_ret.c index 8f2a54a..fcb4d6d 100644 --- a/src/arch/x86/op_ret.c +++ b/src/arch/x86/op_ret.c @@ -34,7 +34,8 @@  *  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.                 * +*                addr   = adresse virtuelle de l'instruction.                 * +*                prefix = éventuel(s) préfixe(s) remarqué(s).                 *  *                proc   = architecture ciblée par le désassemblage.           *  *                                                                             *  *  Description : Décode une instruction de type 'ret'.                        * @@ -45,13 +46,11 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_ret(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_ret(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result; +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_RET);      return result; diff --git a/src/arch/x86/op_rol.c b/src/arch/x86/op_rol.c index 047f7cd..9f42ada 100644 --- a/src/arch/x86/op_rol.c +++ b/src/arch/x86/op_rol.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'rol' (8 bits).               * +*  Description : Décode une instruction de type 'rol' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_rol_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_rol_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_ROL_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_ror.c b/src/arch/x86/op_ror.c index 5dca287..5220259 100644 --- a/src/arch/x86/op_ror.c +++ b/src/arch/x86/op_ror.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'ror' (8 bits).               * +*  Description : Décode une instruction de type 'ror' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_ror_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_ror_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_ROR_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_sar.c b/src/arch/x86/op_sar.c index 5e82cd8..2d7dc30 100644 --- a/src/arch/x86/op_sar.c +++ b/src/arch/x86/op_sar.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'sar' (8 bits).               * +*  Description : Décode une instruction de type 'sar' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sar_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sar_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_SAR_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_sbb.c b/src/arch/x86/op_sbb.c index 20619cc..24c70e7 100644 --- a/src/arch/x86/op_sbb.c +++ b/src/arch/x86/op_sbb.c @@ -32,11 +32,44 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'sbb' (8 bits).               * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_sbb_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_SBB_RM8_IMM8); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8)) +    { +        /* TODO 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.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'sbb' (16 ou 32 bits).        *  *                                                                             * @@ -46,20 +79,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sbb_rm1632_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sbb_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_SBB_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -70,11 +101,11 @@ asm_x86_instr *x86_read_instr_sbb_rm1632_with_imm8(const uint8_t *data, off_t *p  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'sbb' (16 ou 32 bits).        *  *                                                                             * @@ -84,20 +115,18 @@ asm_x86_instr *x86_read_instr_sbb_rm1632_with_imm8(const uint8_t *data, off_t *p  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sbb_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sbb_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_SBB_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_shl.c b/src/arch/x86/op_shl.c index fbcb0db..f6d9a77 100644 --- a/src/arch/x86/op_shl.c +++ b/src/arch/x86/op_shl.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'shl'.                        * +*  Description : Décode une instruction de type 'shl' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_shl_rm1632_cl(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_shl_rm1632_cl(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_SHL_RM1632_CL); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_CL, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -70,13 +68,13 @@ asm_x86_instr *x86_read_instr_shl_rm1632_cl(const uint8_t *data, off_t *pos, off  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'shl' (8 bits).               * +*  Description : Décode une instruction de type 'shl' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -84,20 +82,18 @@ asm_x86_instr *x86_read_instr_shl_rm1632_cl(const uint8_t *data, off_t *pos, off  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_shl_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_shl_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_SHL_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_shr.c b/src/arch/x86/op_shr.c index 0ba8c4e..e6b4edf 100644 --- a/src/arch/x86/op_shr.c +++ b/src/arch/x86/op_shr.c @@ -32,13 +32,13 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'shr' (8 bits).               * +*  Description : Décode une instruction de type 'shr' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -46,20 +46,18 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_shr_rm1632_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_shr_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_SHR_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_sub.c b/src/arch/x86/op_sub.c index bffc758..192c848 100644 --- a/src/arch/x86/op_sub.c +++ b/src/arch/x86/op_sub.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'sub al, ...' (8 bits).       *  *                                                                             * @@ -46,17 +46,15 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sub_al_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sub_al_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_SUB_RM8_IMM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,11 +65,11 @@ asm_x86_instr *x86_read_instr_sub_al_with_imm8(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'sub [e]ax, ...' (16/32 bits).*  *                                                                             * @@ -81,20 +79,18 @@ asm_x86_instr *x86_read_instr_sub_al_with_imm8(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sub_e_ax_with_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sub_e_ax_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_SUB_E_AX_IMM1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,13 +101,13 @@ asm_x86_instr *x86_read_instr_sub_e_ax_with_imm1632(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        * +*  Description : Décode une instruction de type 'sub' (8 bits).               *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -119,20 +115,48 @@ asm_x86_instr *x86_read_instr_sub_e_ax_with_imm1632(const uint8_t *data, off_t *  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sub_imm8_from_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sub_r8_rm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_SUB_RM8_IMM8); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    { +        /* TODO free(result);*/ +        return NULL; +    } -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    return result; -    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_RM1632, X86_OTP_IMM8, oprsize)) +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_sub_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ + +    result = g_x86_instruction_new(XOP_SUB_RM8_IMM8); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -143,11 +167,11 @@ asm_x86_instr *x86_read_instr_sub_imm8_from_rm1632(const uint8_t *data, off_t *p  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -157,20 +181,18 @@ asm_x86_instr *x86_read_instr_sub_imm8_from_rm1632(const uint8_t *data, off_t *p  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sub_r1632_from_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sub_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_SUB_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -181,13 +203,13 @@ asm_x86_instr *x86_read_instr_sub_r1632_from_rm1632(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'sub' (8 bits).               * +*  Description : Décode une instruction de type 'sub' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -195,17 +217,18 @@ asm_x86_instr *x86_read_instr_sub_r1632_from_rm1632(const uint8_t *data, off_t *  *                                                                             *  ******************************************************************************/ -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) +GArchInstruction *x86_read_instr_sub_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_SUB_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -216,11 +239,11 @@ asm_x86_instr *x86_read_instr_sub_r8_rm8(const uint8_t *data, off_t *pos, off_t  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = 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).        *  *                                                                             * @@ -230,20 +253,18 @@ asm_x86_instr *x86_read_instr_sub_r8_rm8(const uint8_t *data, off_t *pos, off_t  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_sub_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_sub_rm1632_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_SUB_RM1632_R1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_test.c b/src/arch/x86/op_test.c index 1d8d18a..39f5777 100644 --- a/src/arch/x86/op_test.c +++ b/src/arch/x86/op_test.c @@ -46,17 +46,15 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_test_al(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_test_al_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_TEST_AL_IMM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -81,20 +79,18 @@ asm_x86_instr *x86_read_instr_test_al(const uint8_t *data, off_t *pos, off_t len  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_test_e_ax(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_test_e_ax_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_TEST_E_AX_IMM1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -119,17 +115,15 @@ asm_x86_instr *x86_read_instr_test_e_ax(const uint8_t *data, off_t *pos, off_t l  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_test_rm8_with_r8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_test_rm8_r8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_TEST_RM8_R8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -154,20 +148,18 @@ asm_x86_instr *x86_read_instr_test_rm8_with_r8(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_test_rm1632_with_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_test_rm1632_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_TEST_RM1632_R1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/op_xchg.c b/src/arch/x86/op_xchg.c new file mode 100644 index 0000000..7a7d71b --- /dev/null +++ b/src/arch/x86/op_xchg.c @@ -0,0 +1,69 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * op_xchg.c - décodage des échanges de contenu de regitres + * + * Copyright (C) 2009 Cyrille Bagard + * + *  This file is part of OpenIDA. + * + *  OpenIDA is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  OpenIDA is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#include <malloc.h> + + +#include "../instruction-int.h" +#include "opcodes.h" +#include "operand.h" + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             * +*                                                                             * +*  Description : Décode une instruction de type 'xchg' (16 ou 32 bits).       * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchInstruction *x86_read_instr_xchg_r1632_e_ax(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc) +{ +    GArchInstruction *result;               /* Instruction à retourner     */ +    X86Opcodes opcode;                      /* Instruction effective       */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ + +    opcode = XOP_XCHG_R1632_E_AX + (data[*pos] - 0x90); + +    result = g_x86_instruction_new(opcode); + +    oprsize = g_x86_processor_get_operand_size(proc, prefix); + +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_OP_R1632, X86_OTP_E_AX, oprsize, 0x90)) +    { +        /* TODO free(result);*/ +        return NULL; +    } + +    return result; + +} diff --git a/src/arch/x86/op_xor.c b/src/arch/x86/op_xor.c index eabb88e..b6e690b 100644 --- a/src/arch/x86/op_xor.c +++ b/src/arch/x86/op_xor.c @@ -32,11 +32,11 @@  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor al, ...' (8 bits).       *  *                                                                             * @@ -46,17 +46,15 @@  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_al_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_al_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    result = g_x86_instruction_new(XOP_XOR_AL_IMM8);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_AL, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -67,11 +65,11 @@ asm_x86_instr *x86_read_instr_xor_al_with_imm8(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor [e]ax, ...' (16/32 bits).*  *                                                                             * @@ -81,20 +79,18 @@ asm_x86_instr *x86_read_instr_xor_al_with_imm8(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_e_ax_with_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_e_ax_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_XOR_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_E_AX, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -105,11 +101,11 @@ asm_x86_instr *x86_read_instr_xor_e_ax_with_imm1632(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor' (8 bits).               *  *                                                                             * @@ -119,20 +115,15 @@ asm_x86_instr *x86_read_instr_xor_e_ax_with_imm1632(const uint8_t *data, off_t *  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_rm8_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_r8_rm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_XOR_R8_RM8); -    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_RM8, X86_OTP_IMM8, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -143,11 +134,11 @@ asm_x86_instr *x86_read_instr_xor_rm8_with_imm8(const uint8_t *data, off_t *pos,  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor' (8 bits).               *  *                                                                             * @@ -157,17 +148,15 @@ asm_x86_instr *x86_read_instr_xor_rm8_with_imm8(const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_r8_with_rm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_rm8_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_XOR_RM8_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R8, X86_OTP_RM8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_IMM8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -178,13 +167,13 @@ asm_x86_instr *x86_read_instr_xor_r8_with_rm8(const uint8_t *data, off_t *pos, o  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'xor' (16 ou 32 bits).        * +*  Description : Décode une instruction de type 'xor' (8 bits).               *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -192,20 +181,15 @@ asm_x86_instr *x86_read_instr_xor_r8_with_rm8(const uint8_t *data, off_t *pos, o  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_r1632_with_rm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_rm8_r8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ -    AsmOperandSize oprsize;                 /* Taille des opérandes        */ - -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    GArchInstruction *result;               /* Instruction à retourner     */ -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); +    result = g_x86_instruction_new(XOP_XOR_RM8_R8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; - -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -216,13 +200,13 @@ asm_x86_instr *x86_read_instr_xor_r1632_with_rm1632(const uint8_t *data, off_t *  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             * -*  Description : Décode une instruction de type 'xor' (8 bits).               * +*  Description : Décode une instruction de type 'xor' (16 ou 32 bits).        *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -230,17 +214,18 @@ asm_x86_instr *x86_read_instr_xor_r1632_with_rm1632(const uint8_t *data, off_t *  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_rm8_with_r8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_r1632_rm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */ +    AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_XOR_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix); -    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM8, X86_OTP_R8)) +    if (!x86_read_two_operands(result, data, pos, len, X86_OTP_R1632, X86_OTP_RM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -251,11 +236,11 @@ asm_x86_instr *x86_read_instr_xor_rm8_with_r8(const uint8_t *data, off_t *pos, o  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor' (16 ou 32 bits).        *  *                                                                             * @@ -265,20 +250,18 @@ asm_x86_instr *x86_read_instr_xor_rm8_with_r8(const uint8_t *data, off_t *pos, o  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_rm1632_with_imm8(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_rm1632_imm8(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_XOR_RM1632_IMM8); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM8, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -289,11 +272,11 @@ asm_x86_instr *x86_read_instr_xor_rm1632_with_imm8(const uint8_t *data, off_t *p  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor' (16 ou 32 bits).        *  *                                                                             * @@ -303,20 +286,18 @@ asm_x86_instr *x86_read_instr_xor_rm1632_with_imm8(const uint8_t *data, off_t *p  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_rm1632_imm1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_rm1632_imm1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *result;               /* Instruction à retourner     */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    result = (asm_x86_instr *)calloc(1, sizeof(asm_x86_instr)); +    result = g_x86_instruction_new(XOP_XOR_RM1632_IMM8); -    oprsize = switch_x86_operand_size_if_needed(proc, data, pos); - -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_IMM1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } @@ -327,11 +308,11 @@ asm_x86_instr *x86_read_instr_xor_rm1632_imm1632(const uint8_t *data, off_t *pos  /******************************************************************************  *                                                                             * -*  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.           * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   * +*                proc = architecture ciblée par le désassemblage.             *  *                                                                             *  *  Description : Décode une instruction de type 'xor' (16 ou 32 bits).        *  *                                                                             * @@ -341,20 +322,18 @@ asm_x86_instr *x86_read_instr_xor_rm1632_imm1632(const uint8_t *data, off_t *pos  *                                                                             *  ******************************************************************************/ -asm_x86_instr *x86_read_instr_xor_rm1632_with_r1632(const uint8_t *data, off_t *pos, off_t len, uint64_t offset, const asm_x86_processor *proc) +GArchInstruction *x86_read_instr_xor_rm1632_r1632(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, X86Prefix prefix, const GX86Processor *proc)  { -    asm_x86_instr *result;                  /* Instruction à retourner     */ +    GArchInstruction *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); +    result = g_x86_instruction_new(XOP_XOR_RM1632_R1632); -    ASM_INSTRUCTION(result)->opcode = data[(*pos)++]; +    oprsize = g_x86_processor_get_operand_size(proc, prefix);      if (!x86_read_two_operands(result, data, pos, len, X86_OTP_RM1632, X86_OTP_R1632, oprsize))      { -        free(result); +        /* TODO free(result);*/          return NULL;      } diff --git a/src/arch/x86/opcodes.h b/src/arch/x86/opcodes.h index c16b9be..212d1bc 100644 --- a/src/arch/x86/opcodes.h +++ b/src/arch/x86/opcodes.h @@ -25,281 +25,325 @@  #define _ARCH_X86_OPCODES_H -#include <stdint.h> -#include <sys/types.h> - -  #include "processor.h"  #include "instruction.h" -/* 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). */ +GArchInstruction *x86_read_instr_adc_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_adc_rm8_r8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_adc_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'adc' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_adc_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_add_al_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_add_e_ax_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* 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). */ +GArchInstruction *x86_read_instr_add_r8_rm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'add' (8 bits). */ +GArchInstruction *x86_read_instr_add_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_add_rm8_r8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_add_r1632_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'add' (8 bits). */ -asm_x86_instr *x86_read_instr_add_rm8_r8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'add' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_add_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'add' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_add_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_add_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_add_rm1632_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'and' (8 bits). */ +GArchInstruction *x86_read_instr_and_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_and_rm8_r8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_and_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'and' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_and_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_and_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'call'. */ -asm_x86_instr *x86_read_instr_call_rel1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_call_rel1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'call' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_call_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_call_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'cld'. */ -asm_x86_instr *x86_read_instr_cld(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); - -/*  Décode une instruction de type 'cmp' (8 bits). */ -asm_x86_instr *x86_read_instr_cmp_rm8_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_cld(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'cmp' (8 bits). */ -asm_x86_instr *x86_read_instr_cmp_rm1632_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_cmp_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'cmp' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_cmp_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'cmp' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_cmp_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_cmp_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'cmp' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_cmp_rm1632_with_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_cmp_rm1632_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'dec'. */ -asm_x86_instr *x86_read_instr_dec_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'dec' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_dec_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'hlt'. */ -asm_x86_instr *x86_read_instr_hlt(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_hlt(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'inc'. */ -asm_x86_instr *x86_read_instr_inc_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'inc' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_inc_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'int'. */ +GArchInstruction *x86_read_instr_int(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'int 3'. */ -asm_x86_instr *x86_read_instr_int_3(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_int_3(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'int'. */ -asm_x86_instr *x86_read_instr_int(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'ja' (saut 8b si supérieur). */ +GArchInstruction *x86_read_instr_ja_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'jb' (saut 8b si inférieur). */ -asm_x86_instr *x86_read_instr_jb_rel8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_jb_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'je' (petit saut). */ -asm_x86_instr *x86_read_instr_je_8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'je' (saut 8b si égal). */ +GArchInstruction *x86_read_instr_je_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'jg' (saut 8b si supérieur). */ -asm_x86_instr *x86_read_instr_jg_rel8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_jg_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jl' (saut 8b si inférieur). */ +GArchInstruction *x86_read_instr_jl_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jna' (saut 8b si !supérieur). */ +GArchInstruction *x86_read_instr_jna_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'jnb' (saut 8b si !inférieur). */ -asm_x86_instr *x86_read_instr_jnb_rel8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_jnb_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jne' (saut 8b si !égal). */ +GArchInstruction *x86_read_instr_jne_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jng' (saut 8b si !supérieur). */ +GArchInstruction *x86_read_instr_jng_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jnl' (saut 8b si !inférieur). */ +GArchInstruction *x86_read_instr_jnl_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jno' (saut 8b si !débordemt). */ +GArchInstruction *x86_read_instr_jno_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jnp' (saut 8b si !parité). */ +GArchInstruction *x86_read_instr_jnp_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jns' (saut 8b si !signée). */ +GArchInstruction *x86_read_instr_jns_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'jne' (petit saut). */ -asm_x86_instr *x86_read_instr_jne_8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'jo' (saut 8b si débordement). */ +GArchInstruction *x86_read_instr_jo_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'jp' (saut 8b si parité). */ +GArchInstruction *x86_read_instr_jp_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'js' (saut 8b si signée). */ +GArchInstruction *x86_read_instr_js_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'jump' (petit saut). */ -asm_x86_instr *x86_read_instr_jmp_8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_jmp_rel8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'jmp' (grand saut relatif). */ -asm_x86_instr *x86_read_instr_jmp_rel1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_jmp_rel1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'jmp' (saut en mémoire). */ -asm_x86_instr *x86_read_instr_jmp_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'jmp' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_jmp_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'lea' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_lea(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_lea_r1632_m(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'leave'. */ -asm_x86_instr *x86_read_instr_leave(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_leave(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'mov al, ...' (8 bits). */ +GArchInstruction *x86_read_instr_mov_al_moffs8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'mov [e]ax, ...' (16/32 bits). */ +GArchInstruction *x86_read_instr_mov_e_ax_moffs1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov ..., al' (8 bits). */ -asm_x86_instr *x86_read_instr_mov_al_to_moffs8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_moffs8_al(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov ..., [e]ax' (16/32 bits). */ -asm_x86_instr *x86_read_instr_mov_e_ax_to_moffs1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); - -/* Décode une instruction de type 'mov' (8 bits). */ -asm_x86_instr *x86_read_instr_mov_imm8_to_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_moffs1632_e_ax(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_mov_imm1632_to_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_r1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_mov_imm1632_to_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); - -/* Décode une instruction de type 'mov al, ...' (8 bits). */ -asm_x86_instr *x86_read_instr_mov_moffs8_to_al(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_r1632_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'mov [e]ax, ...' (16/32 bits). */ -asm_x86_instr *x86_read_instr_mov_moffs1632_to_e_ax(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'mov' (8 bits). */ +GArchInstruction *x86_read_instr_mov_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_mov_r1632_to_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_mov_rm1632_to_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_rm1632_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'mov' (8 bits). */ -asm_x86_instr *x86_read_instr_mov_rm8_r8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); - -/* Décode une instruction de type 'movsx' (8 bits). */ -asm_x86_instr *x86_read_instr_movsx_r1632_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); - -/* Décode une instruction de type 'movzx' (8 bits). */ -asm_x86_instr *x86_read_instr_movzx_r1632_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_mov_rm8_r8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'nop'. */ -asm_x86_instr *x86_read_instr_nop(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_nop(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_not_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_or_al_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_or_r8_rm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'or' (8 bits). */ +GArchInstruction *x86_read_instr_or_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_or_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'or' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_or_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_or_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'pop' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_pop_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_pop_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'push' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_push_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_push_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'push' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_push_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_push_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'push' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_push_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_push_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'rcl' (8 bits). */ -asm_x86_instr *x86_read_instr_rcl_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'rcl' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_rcl_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'rcr' (8 bits). */ -asm_x86_instr *x86_read_instr_rcr_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'rcr' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_rcr_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'ret'. */ -asm_x86_instr *x86_read_instr_ret(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_ret(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'rol' (8 bits). */ -asm_x86_instr *x86_read_instr_rol_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'rol' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_rol_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'ror' (8 bits). */ -asm_x86_instr *x86_read_instr_ror_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'ror' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_ror_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'sal' (8 bits). */ +/* Décode une instruction de type 'sal' (16 ou 32 bits). */  #define x86_read_instr_sal_rm1632_imm8 x86_read_instr_shl_rm1632_imm8 -/* Décode une instruction de type 'sar' (8 bits). */ -asm_x86_instr *x86_read_instr_sar_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'sar' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_sar_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'sbb' (8 bits). */ +GArchInstruction *x86_read_instr_sbb_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'sbb'. */ -asm_x86_instr *x86_read_instr_sbb_rm1632_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_sbb_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'sbb' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_sbb_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_sbb_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'shl'. */ -asm_x86_instr *x86_read_instr_shl_rm1632_cl(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'shl' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_shl_rm1632_cl(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'shl' (8 bits). */ -asm_x86_instr *x86_read_instr_shl_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'shl' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_shl_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); -/* Décode une instruction de type 'shr' (8 bits). */ -asm_x86_instr *x86_read_instr_shr_rm1632_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +/* Décode une instruction de type 'shr' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_shr_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'sub al, ...' (8 bits). */ -asm_x86_instr *x86_read_instr_sub_al_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_sub_al_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'sub [e]ax, ...' (16/32 bits). */ -asm_x86_instr *x86_read_instr_sub_e_ax_with_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_sub_e_ax_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'sub' (8 bits). */ +GArchInstruction *x86_read_instr_sub_r8_rm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'sub' (8 bits). */ +GArchInstruction *x86_read_instr_sub_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'sub'. */ -asm_x86_instr *x86_read_instr_sub_imm8_from_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_sub_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_sub_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* 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 *); +GArchInstruction *x86_read_instr_sub_rm1632_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'test al, ...' (8 bits). */ -asm_x86_instr *x86_read_instr_test_al(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_test_al_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'test [e]ax, ...' (16/32b). */ -asm_x86_instr *x86_read_instr_test_e_ax(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_test_e_ax_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'test' (8 bits). */ -asm_x86_instr *x86_read_instr_test_rm8_with_r8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_test_rm8_r8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'test' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_test_rm1632_with_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_test_rm1632_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'xchg' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_xchg_r1632_e_ax(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor al, ...' (8 bits). */ -asm_x86_instr *x86_read_instr_xor_al_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_al_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor [e]ax, ...' (16/32 bits). */ -asm_x86_instr *x86_read_instr_xor_e_ax_with_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_e_ax_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor' (8 bits). */ -asm_x86_instr *x86_read_instr_xor_rm8_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_r8_rm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor' (8 bits). */ -asm_x86_instr *x86_read_instr_xor_r8_with_rm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); - -/* Décode une instruction de type 'xor' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_xor_r1632_with_rm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_rm8_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor' (8 bits). */ -asm_x86_instr *x86_read_instr_xor_rm8_with_r8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_rm8_r8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); + +/* Décode une instruction de type 'xor' (16 ou 32 bits). */ +GArchInstruction *x86_read_instr_xor_r1632_rm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_xor_rm1632_with_imm8(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_rm1632_imm8(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_xor_rm1632_imm1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_rm1632_imm1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *);  /* Décode une instruction de type 'xor' (16 ou 32 bits). */ -asm_x86_instr *x86_read_instr_xor_rm1632_with_r1632(const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); +GArchInstruction *x86_read_instr_xor_rm1632_r1632(const bin_t *, off_t *, off_t, vmpa_t, X86Prefix, const GX86Processor *); diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c index 38e1468..1424b3e 100644 --- a/src/arch/x86/operand.c +++ b/src/arch/x86/operand.c @@ -29,1315 +29,868 @@  #include <stdio.h> +#include "registers.h" +#include "../immediate.h"  #include "../operand.h"  #include "../operand-int.h" +#include "../../common/extstr.h" -#define MAX(a, b) ((a) > (b) ? (a) : (b)) +/* ---------------------- COQUILLE VIDE POUR LES OPERANDES X86 ---------------------- */ - -/* Liste des registres 8 bits */ -typedef enum _X868bRegister +/* Définition d'un opérande de la x86 (instance) */ +struct _GX86Operand  { -    X86_REG8_AL = 0,                        /* Registre AL                 */ -    X86_REG8_CL = 1,                        /* Registre AL                 */ -    X86_REG8_DL = 2,                        /* Registre AL                 */ -    X86_REG8_BL = 3,                        /* Registre AL                 */ -    X86_REG8_AH = 4,                        /* Registre AH                 */ -    X86_REG8_CH = 5,                        /* Registre AH                 */ -    X86_REG8_DH = 6,                        /* Registre AH                 */ -    X86_REG8_BH = 7,                        /* Registre AH                 */ +    GArchOperand parent;                    /* Instance parente            */ -    X86_REG8_NONE                           /* Aucun registre              */ +}; -} X868bRegister; -/* Liste des registres 16 bits */ -typedef enum _X8616bRegister +/* Définition d'un opérande de la x86 (classe) */ +struct _GX86OperandClass  { -    X86_REG16_AX = 0,                       /* Registre AX                 */ -    X86_REG16_CX = 1,                       /* Registre AX                 */ -    X86_REG16_DX = 2,                       /* Registre AX                 */ -    X86_REG16_BX = 3,                       /* Registre AX                 */ -    X86_REG16_SP = 4,                       /* Registre SP                 */ -    X86_REG16_BP = 5,                       /* Registre BP                 */ -    X86_REG16_SI = 6,                       /* Registre SI                 */ -    X86_REG16_DI = 7,                       /* Registre DI                 */ +    GArchOperandClass parent;               /* Classe parente              */ -    X86_REG16_NONE                          /* Aucun registre              */ +}; -} X8616bRegister; -/* Liste des registres 32 bits */ -typedef enum _X8632bRegister -{ -    X86_REG32_EAX = 0,                      /* Registre EAX                */ -    X86_REG32_ECX = 1,                      /* Registre EAX                */ -    X86_REG32_EDX = 2,                      /* Registre EAX                */ -    X86_REG32_EBX = 3,                      /* Registre EAX                */ -    X86_REG32_ESP = 4,                      /* Registre ESP                */ -    X86_REG32_EBP = 5,                      /* Registre EBP                */ -    X86_REG32_ESI = 6,                      /* Registre ESI                */ -    X86_REG32_EDI = 7,                      /* Registre EDI                */ +/* Initialise la classe des opérandes x86 de base. */ +static void g_x86_operand_class_init(GX86OperandClass *); -    X86_REG32_NONE                          /* Aucun registre              */ +/* Initialise une instance d'opérande de base pour la x86. */ +static void g_x86_operand_init(GX86Operand *); -} X8632bRegister; -/* Registre X86 */ -typedef union _x86_register -{ -    X868bRegister reg8;                     /* Registre 8 bits             */ -    X8616bRegister reg16;                   /* Registre 16 bits            */ -    X8632bRegister reg32;                   /* Registre 32 bits            */ +/* ------------------------ OPERANDES VISANT UN REGISTRE X86 ------------------------ */ + -} x86_register; +/* Définition d'un opérande visant un registre x86 (instance) */ +struct _GX86RegisterOperand +{ +    GX86Operand parent;                     /* Instance parente            */ +    x86_register *reg;                      /* Registre représenté         */ +}; -/* Définition d'une opérande x86 */ -struct _asm_x86_operand +/* Définition d'un opérande visant un registre x86 (classe) */ +struct _GX86RegisterOperandClass  { -    asm_operand base;                       /* A laisser en premier        */ +    GX86OperandClass parent;                /* Classe parente              */ -    x86_register rindex;                    /* Registre servant d'indice   */ +}; -    bool content;                           /* Contenu d'un registre       */ -    uint8_t scale;                          /* Puissance de deux           */ -    x86_register rbase;                     /* Registre de base            */ -    asm_operand *displacement;              /* Décallage supplémentaire    */ +/* Initialise la classe des opérandes de registre x86. */ +static void g_x86_register_operand_class_init(GX86RegisterOperandClass *); -}; +/* Initialise une instance d'opérande de registre x86. */ +static void g_x86_register_operand_init(GX86RegisterOperand *); +/* Traduit un opérande en version humainement lisible. */ +static char *g_x86_register_operand_get_text(const GX86RegisterOperand *, const exe_format *, AsmSyntax); -#define NULL ((void *)0) +/* ----------------------- OPERANDES COMPLEXES DE TYPE MOD/RM ----------------------- */ -/* Récupère l'indentifiant interne d'un registre. */ -bool get_x86_register(x86_register *, AsmOperandSize, uint8_t); +/* Définition d'un opérande x86 de type ModRM (instance) */ +struct _GX86ModRMOperand +{ +    GX86Operand parent;                     /* Instance parente            */ +    uint8_t scale;                          /* Puissance de deux           */ +    x86_register *index;                    /* Registre servant d'indice   */ +    x86_register *base;                     /* Registre de base            */ +    GImmOperand *displacement;              /* Décallage supplémentaire    */ -/* Traduit une opérande de registre en texte. */ -void _x86_print_reg_operand(const x86_register *reg, AsmOperandSize, char *, size_t, AsmSyntax); +}; +/* Définition d'un opérande x86 de type ModRM (classe) */ +struct _GX86ModRMOperandClass +{ +    GX86OperandClass parent;                /* Classe parente              */ +}; -/* Crée une opérande renvoyant vers un registre 16 ou 32 bits. */ -asm_x86_operand *x86_create_r1632_operand_from_opcode(uint8_t, bool, uint8_t); +/* Initialise la classe des opérandes x86 de type ModRM. */ +static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *); +/* Initialise une instance d'opérande x86 de type ModRM. */ +static void g_x86_mod_rm_operand_init(GX86ModRMOperand *); +/* Traduit un opérande en version humainement lisible. */ +static char *g_x86_mod_rm_operand_get_text(const GX86ModRMOperand *, const exe_format *, AsmSyntax); -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Crée une opérande vierge pour x86.                           * -*                                                                             * -*  Retour      : Opérande nouvellement créée.                                 * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +/* ------------------------- OPERANDES D'ADRESSES RELATIVES ------------------------- */ -asm_x86_operand *create_new_x86_operand(void) + +/* Définition d'un opérande x86 d'adresse relative (instance) */ +struct _GX86RelativeOperand  { -    asm_x86_operand *result;                /* Structure à retourner       */ +    GX86Operand parent;                     /* Instance parente            */ -    result = (asm_x86_operand *)calloc(1, sizeof(asm_x86_operand)); +    GImmOperand *immediate;                 /* Adresse visée reconstituée  */ -    result->scale = 0; -    result->rbase.reg32 = X86_REG32_NONE; +}; -    return result; +/* Définition d'un opérande x86 d'adresse relative (classe) */ +struct _GX86RelativeOperandClass +{ +    GX86OperandClass parent;                /* Classe parente              */ -} +}; +/* Initialise la classe des opérandes x86 d'adresse relative. */ +static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *); +/* Initialise une instance d'opérande x86 d'adresse relative. */ +static void g_x86_relative_operand_init(GX86RelativeOperand *); +/* Traduit un opérande en version humainement lisible. */ +static char *g_x86_relative_operand_get_text(const GX86RelativeOperand *, const exe_format *, AsmSyntax); -/****************************************************************************** -*                                                                             * -*  Paramètres  : reg   = registre à définir. [OUT]                            * -*                size  = indique la taille du registre.                       * -*                value = valeur correspondant au registre.                    * -*                                                                             * -*  Description : Récupère l'indentifiant interne d'un registre.               * -*                                                                             * -*  Retour      : true si la définition est opérée, false sinon.               * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +/* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ + -bool get_x86_register(x86_register *reg, AsmOperandSize size, uint8_t value) +/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ +struct _GX86MOffsOperand  { -    switch (size) -    { -        case AOS_8_BITS: -            switch (value) -            { -                case 0 ... 7: -                    reg->reg8 = (X868bRegister)value; -                    break; -                default: -                    return false; -                    break; -            } -            break; +    GX86Operand parent;                     /* Instance parente            */ -        case AOS_16_BITS: -            switch (value) -            { -                case 0 ... 7: -                    reg->reg16 = (X8616bRegister)value; -                    break; -                default: -                    return false; -                    break; -            } -            break; +    GImmOperand *offset;                    /* Adresse mémoire visée       */ -        case AOS_32_BITS: -            switch (value) -            { -                case 0 ... 7: -                    reg->reg32 = (X8632bRegister)value; -                    break; -                default: -                    return false; -                    break; -            } -            break; +}; -        case AOS_64_BITS: -            return false; -            break; +/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ +struct _GX86MOffsOperandClass +{ +    GX86OperandClass parent;                /* Classe parente              */ -    } +}; -    return true; -} +/* Initialise la classe des opérandes d'emplacement mémoire x86. */ +static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *); + +/* Initialise une instance d'opérande d'emplacement mémoire x86. */ +static void g_x86_moffs_operand_init(GX86MOffsOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static char *g_x86_moffs_operand_get_text(const GX86MOffsOperand *, const exe_format *, AsmSyntax); +/* ---------------------------------------------------------------------------------- */ +/*                        COQUILLE VIDE POUR LES OPERANDES X86                        */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini par la GLib pour un opérande de x86. */ +G_DEFINE_TYPE(GX86Operand, g_x86_operand, G_TYPE_ARCH_OPERAND);  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = donnée à analyser.                                * -*                is_reg32 = indique si le registre est un registre 32 bits.   * -*                base     = valeur du premier registre.                       * +*  Paramètres  : klass = classe à initialiser.                                *  *                                                                             * -*  Description : Crée une opérande renvoyant vers un registre 16 ou 32 bits.  * +*  Description : Initialise la classe des opérandes x86 de base.              *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_reg1632_operand(uint8_t data, bool is_reg32, uint8_t base) +static void g_x86_operand_class_init(GX86OperandClass *klass)  { -    asm_x86_operand *result;                /* Registre à retourner        */ - -    result = create_new_x86_operand(); - -    ASM_OPERAND(result)->type = AOT_REG; -    ASM_OPERAND(result)->size = (is_reg32 ? AOS_32_BITS : AOS_16_BITS); - -    if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, data - base)) -    { -        free(result); -        return NULL; -    } - -    return result;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = donnée à analyser.                                * -*                is_reg32 = indique si le registre est un registre 32 bits.   * -*                first    = indique la partie du ModR/M à traiter.            * +*  Paramètres  : operand = instance à initialiser.                            *  *                                                                             * -*  Description : Crée une opérande renvoyant vers un registre 16 ou 32 bits.  * +*  Description : Initialise une instance d'opérande de registre x86.          *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_reg1632_operand_from_modrm(uint8_t data, bool is_reg32, bool first) +static void g_x86_operand_init(GX86Operand *operand)  { -    asm_x86_operand *result;                /* Registre à retourner        */ -    uint8_t reg;                            /* Transcription du registre   */ -    if (first) reg = data & 0x07; -    else reg = (data & 0x38) >> 3; +} -    result = create_new_x86_operand(); -    ASM_OPERAND(result)->type = AOT_REG; -    ASM_OPERAND(result)->size = (is_reg32 ? AOS_32_BITS : AOS_16_BITS); -    if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, reg)) -    { -        free(result); -        return NULL; -    } +/* ---------------------------------------------------------------------------------- */ +/*                          OPERANDES VISANT UN REGISTRE X86                          */ +/* ---------------------------------------------------------------------------------- */ -    return result; -} +/* Indique le type défini par la GLib pour un opérande de registre x86. */ +G_DEFINE_TYPE(GX86RegisterOperand, g_x86_register_operand, G_TYPE_X86_OPERAND);  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = flux de données à analyser.                       * -*                pos      = position courante dans ce flux. [OUT]             * -*                len      = taille totale des données à analyser.             * -*                is_reg32 = indique si le registre est un registre 32 bits.   * -*                first    = indique la partie du ModR/M à traiter.            * +*  Paramètres  : klass = classe à initialiser.                                *  *                                                                             * -*  Description : Crée une opérande renvoyant vers un contenu 16 ou 32 bits.   * +*  Description : Initialise la classe des opérandes de registre x86.          *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_content1632_operand(const uint8_t *data, off_t *pos, off_t len, bool is_reg32, bool first) +static void g_x86_register_operand_class_init(GX86RegisterOperandClass *klass)  { -    asm_x86_operand *result;                /* Registre à retourner        */ -    uint8_t mod;                            /* Modificateur présent        */ -    /* Pas de contenu */ -    mod = (data[*pos] & 0xc0); -    if (mod == 0xc0) return NULL; - -    result = x86_create_reg1632_operand_from_modrm(data[*pos], is_reg32, first); -    if (result == NULL) return NULL; - -    result->content = true; - -    (*pos)++; +} -    /* Vieille astuce de l'emplacement mémoire fixe ? */ -    if (result->rindex.reg32 == X86_REG32_EBP && mod == 0x00) -    { -        free(result); -        result = create_new_x86_operand(); -        if (!fill_imm_operand(ASM_OPERAND(result), AOS_32_BITS/* FIXME ? */, data, pos, len)) -        { -            (*pos)--; -            free(result); -            return NULL; -        } +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande de registre x86.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -        return result; +static void g_x86_register_operand_init(GX86RegisterOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ -    } +    parent = G_ARCH_OPERAND(operand); -    /* A la recherche d'un SIB */ -    if (result->rindex.reg32 == X86_REG32_ESP) -    { -        if (!get_x86_register(&result->rbase, ASM_OPERAND(result)->size, data[*pos] & 0x07)) -        { -            (*pos)--; -            free(result); -            return NULL; -        } +    parent->get_text = (get_operand_text_fc)g_x86_register_operand_get_text; -        if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, (data[*pos] & 0x38) >> 3)) -        { -            (*pos)--; -            free(result); -            return NULL; -        } +} -        result->scale = ((data[*pos] & 0xc0) >> 6); -        if (result->rindex.reg32 == X86_REG32_ESP) -        { -            result->rindex.reg32 = result->rbase.reg32; -            result->rbase.reg32 = X86_REG32_NONE; -        } +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            * +*                base = indice du premier registre.                           * +*                                                                             * +*  Description : Crée un opérande visant un registre X86.                     * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -        (*pos)++; +GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *data, off_t *pos, off_t len, AsmOperandSize size, bin_t base) +{ +    GX86RegisterOperand *result;            /* Structure à retourner       */ +    x86_register *reg;                      /* Registre lu                 */ -    } +    reg = get_x86_register(size, data[*pos] - base); -    /* Décallage supplémentaire ? */ -    switch (mod) +    if (reg != NULL)      { -        case 0x00: -            if (result->rbase.reg32 == X86_REG32_EBP) -            { -                result->rbase.reg32 = X86_REG32_NONE; +        (*pos)++; -                result->displacement = create_new_x86_operand(); -                if (!fill_imm_operand(ASM_OPERAND(result->displacement), ASM_OPERAND(result)->size, data, pos, len)) -                { -                    (*pos) -= 2; -                    free(result->displacement); -                    free(result); -                    return NULL; -                } +        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); -            } -            break; - -        case 0x40: -            result->displacement = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(result->displacement), AOS_8_BITS_SIGNED, data, pos, len)) -            { -                (*pos) -= 2; -                free(result->displacement); -                free(result); -                return NULL; -            } -            break; - -        case 0x80: -            result->displacement = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(result->displacement), AOS_32_BITS_SIGNED, data, pos, len)) -            { -                (*pos) -= 2; -                free(result->displacement); -                free(result); -                return NULL; -            } -            break; +        result->reg = reg;      } +    else result = NULL; -    return result; +    return G_ARCH_OPERAND(result);  } - - -  /******************************************************************************  *                                                                             * -*  Paramètres  : data  = donnée à analyser.                                   * +*  Paramètres  : data  = flux de données à analyser.                          * +*                pos   = position courante dans ce flux. [OUT]                * +*                len   = taille totale des données à analyser.                * +*                size  = taille de l'opérande, et donc du registre.           *  *                first = indique la partie du ModR/M à traiter.               *  *                                                                             * -*  Description : Crée une opérande renvoyant vers un registre 8 bits.         * +*  Description : Crée un opérande visant un registre X86.                     *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : Opérande mis en place.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_r8_operand(uint8_t data, bool first) +GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *pos, off_t len, AsmOperandSize size, bool first)  { -    asm_x86_operand *result;                /* Registre à retourner        */ -    uint8_t reg;                            /* Transcription du registre   */ +    GX86RegisterOperand *result;            /* Structure à retourner       */ +    bin_t index;                            /* Registre lu                 */ +    x86_register *reg;                      /* Registre créé               */ -    if (first) reg = data & 0x07; -    else reg = (data & 0x38) >> 3; +    if (first) index = data[*pos] & 0x07; +    else index = (data[*pos] & 0x38) >> 3; -    result = create_new_x86_operand(); +    reg = get_x86_register(size, index); -    ASM_OPERAND(result)->type = AOT_REG; -    ASM_OPERAND(result)->size = AOS_8_BITS; - -    if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, reg)) +    if (reg != NULL)      { -        free(result); -        return NULL; +        (*pos)++; + +        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); + +        result->reg = reg; +      } +    else result = NULL; -    return result; +    return G_ARCH_OPERAND(result);  }  /******************************************************************************  *                                                                             * -*  Paramètres  : data  = flux de données à analyser.                          * -*                pos   = position courante dans ce flux. [OUT]                * -*                len   = taille totale des données à analyser.                * +*  Paramètres  : index = indice du registre visé.                             * +*                size  = taille de l'opérande, et donc du registre.           *  *                                                                             * -*  Description : Crée une opérande à partir d'un registre/une mémoire 8 bits. * +*  Description : Crée un opérande visant un registre X86 donnée.              *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : Opérande mis en place.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_rm8_operand(const uint8_t *data, off_t *pos, off_t len, ...) +GArchOperand *g_x86_register_operand_new_from_index(bin_t index, AsmOperandSize size)  { -    asm_x86_operand *result;                /* Registre à retourner        */ -    uint8_t mod;                            /* Modificateur présent        */ - -    /* Registre simple... */ +    GX86RegisterOperand *result;            /* Structure à retourner       */ +    x86_register *reg;                      /* Registre lu                 */ -    result = x86_create_r8_operand(data[*pos], true); -    if (result == NULL) return NULL; +    reg = get_x86_register(size, index); -    mod = (data[*pos] & 0xc0); - -    (*pos)++; - -    if (mod == 0xc0) return result; - -    result->content = true; - -    /* Vieille astuce de l'emplacement mémoire fixe ? */ -    if (result->rindex.reg8 == X86_REG8_CH && mod == 0x00) +    if (reg != NULL)      { -        free(result); +        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); -        result = create_new_x86_operand(); -        if (!fill_imm_operand(ASM_OPERAND(result), AOS_32_BITS/* FIXME! 16/32 */, data, pos, len)) -        { -            free(result); -            return NULL; -        } - -        return result; +        result->reg = reg;      } +    else result = NULL; -    /* A la recherche d'un SIB */ -    if (result->rindex.reg8 == X86_REG8_AH) -    { -        if (!get_x86_register(&result->rbase, ASM_OPERAND(result)->size, data[*pos] & 0x07)) -        { -            free(result); -            return NULL; -        } +    return G_ARCH_OPERAND(result); -        if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, (data[*pos] & 0x38) >> 3)) -        { -            free(result); -            return NULL; -        } - -        result->scale = ((data[*pos] & 0xc0) >> 6); +} -        if (result->rindex.reg8 == X86_REG8_AH) -        { -            result->rindex.reg8 = result->rbase.reg8; -            result->rbase.reg8 = X86_REG8_NONE; -        } -        (*pos)++; +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                format  = format du binaire manipulé.                        * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : Chaîne de caractères à libérer de la mémoire.                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    } +static char *g_x86_register_operand_get_text(const GX86RegisterOperand *operand, const exe_format *format, AsmSyntax syntax) +{ +    char *result;                           /* Chaîne à retourner          */ -    /* Décallage supplémentaire ? */ -    switch (mod) -    { -        case 0x00: -            if (result->rbase.reg8 == X86_REG8_CH) -            { -                result->rbase.reg8 = X86_REG8_NONE; +    result = x86_register_as_text(operand->reg, syntax); -                result->displacement = create_new_x86_operand(); -                if (!fill_imm_operand(ASM_OPERAND(result->displacement), ASM_OPERAND(result)->size, data, pos, len)) -                { -                    free(result->displacement); -                    free(result); -                    return NULL; -                } +    return result; -            } -            break; +} -        case 0x40: -            result->displacement = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(result->displacement), AOS_8_BITS_SIGNED, data, pos, len)) -            { -                free(result->displacement); -                free(result); -                return NULL; -            } -            break; -        case 0x80: -            result->displacement = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(result->displacement), AOS_32_BITS/* FIXME ! 16/32 */, data, pos, len)) -            { -                free(result->displacement); -                free(result); -                return NULL; -            } -            break; -    } +/* ---------------------------------------------------------------------------------- */ +/*                         OPERANDES COMPLEXES DE TYPE MOD/RM                         */ +/* ---------------------------------------------------------------------------------- */ -    return result; -} +/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ +G_DEFINE_TYPE(GX86ModRMOperand, g_x86_mod_rm_operand, G_TYPE_ARCH_OPERAND);  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = donnée à analyser.                                * -*                is_reg32 = indique si le registre est un registre 32 bits.   * -*                first    = indique la partie du ModR/M à traiter.            * +*  Paramètres  : klass = classe à initialiser.                                *  *                                                                             * -*  Description : Crée une opérande renvoyant vers un registre 16 ou 32 bits.  * +*  Description : Initialise la classe des opérandes x86 de type ModRM.        *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_r1632_operand(uint8_t data, bool is_reg32, bool first) +static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *klass)  { -    asm_x86_operand *result;                /* Registre à retourner        */ -    uint8_t reg;                            /* Transcription du registre   */ - -    if (first) reg = data & 0x07; -    else reg = (data & 0x38) >> 3; - -    result = create_new_x86_operand(); - -    ASM_OPERAND(result)->type = AOT_REG; -    ASM_OPERAND(result)->size = (is_reg32 ? AOS_32_BITS : AOS_16_BITS); - -    if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, reg)) -    { -        free(result); -        return NULL; -    } - -    return result;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = donnée à analyser.                                * -*                is_reg32 = indique si le registre est un registre 32 bits.   * -*                base     = valeur du premier registre.                       * +*  Paramètres  : operand = instance à initialiser.                            *  *                                                                             * -*  Description : Crée une opérande renvoyant vers un registre 16 ou 32 bits.  * +*  Description : Initialise une instance d'opérande x86 de type ModRM.        *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_r1632_operand_from_opcode(uint8_t data, bool is_reg32, uint8_t base) +static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand)  { -    asm_x86_operand *result;                /* Registre à retourner        */ - -    result = create_new_x86_operand(); +    GArchOperand *parent;                   /* Instance parente            */ -    ASM_OPERAND(result)->type = AOT_REG; -    ASM_OPERAND(result)->size = (is_reg32 ? AOS_32_BITS : AOS_16_BITS); +    parent = G_ARCH_OPERAND(operand); -    if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, data - base)) -    { -        free(result); -        return NULL; -    } - -    return result; +    parent->get_text = (get_operand_text_fc)g_x86_mod_rm_operand_get_text;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = flux de données à analyser.                       * -*                pos      = position courante dans ce flux. [OUT]             * -*                len      = taille totale des données à analyser.             * -*                is_reg32 = indique si le registre est un registre 32 bits.   * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            *  *                                                                             * -*  Description : Crée une opérande à partir d'un registre/une mémoire 16/32b. * +*  Description : Crée un opérande x86 de type ModRM.                          *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : Opérande mis en place.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_rm1632_operand(const uint8_t *data, off_t *pos, off_t len, bool is_reg32, ...) +GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, AsmOperandSize size)  { -    asm_x86_operand *result;                /* Registre à retourner        */ +    GX86ModRMOperand *result;               /* Structure à retourner       */      uint8_t mod;                            /* Modificateur présent        */ - -    /* Registre simple... */ - -    result = x86_create_r1632_operand(data[*pos], is_reg32, true); -    if (result == NULL) return NULL; +    x86_register *reg;                      /* Registre lu                 */      mod = (data[*pos] & 0xc0); -    (*pos)++; +    if (mod == 0xc0) +        return g_x86_register_operand_new_from_mod_rm(data, pos, len, size, true); -    if (mod == 0xc0) return result; +    reg = get_x86_register(size, data[*pos] & 0x07); +    if (reg == NULL) return NULL; -    result->content = true; +    (*pos)++;      /* Vieille astuce de l'emplacement mémoire fixe ? */ -    if (result->rindex.reg32 == X86_REG32_EBP && mod == 0x00) -    { -        free(result); - -        result = create_new_x86_operand(); -        if (!fill_imm_operand(ASM_OPERAND(result), AOS_32_BITS/* FIXME ? */, data, pos, len)) -        { -            free(result); -            return NULL; -        } +    if (is_x86_register_base_pointer(reg) && mod == 0x00) +        return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE); -        return result; - -    } +    result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL);      /* A la recherche d'un SIB */ -    if (result->rindex.reg32 == X86_REG32_ESP) +    if (is_x86_register_stack_pointer(reg))      { -        if (!get_x86_register(&result->rbase, ASM_OPERAND(result)->size, data[*pos] & 0x07)) -        { -            free(result); -            return NULL; -        } +        free_x86_register(reg); -        if (!get_x86_register(&result->rindex, ASM_OPERAND(result)->size, (data[*pos] & 0x38) >> 3)) -        { -            free(result); -            return NULL; -        } +        result->base = get_x86_register(size, data[*pos] & 0x07); +        if (result->base == NULL) goto gxmron_error; + +        result->index = get_x86_register(size, (data[*pos] & 0x38) >> 3); +        if (result->base == NULL) goto gxmron_error;          result->scale = ((data[*pos] & 0xc0) >> 6); -        if (result->rindex.reg32 == X86_REG32_ESP) +        if (is_x86_register_stack_pointer(result->index))          { -            result->rindex.reg32 = result->rbase.reg32; -            result->rbase.reg32 = X86_REG32_NONE; +            result->index = result->base; +            free_x86_register(result->base); +            result->base = NULL;          }          (*pos)++;      } +    else result->index = reg; +      /* Décallage supplémentaire ? */      switch (mod)      {          case 0x00: -            if (result->rbase.reg32 == X86_REG32_EBP) +            if (result->base != NULL && is_x86_register_base_pointer(result->base))              { -                result->rbase.reg32 = X86_REG32_NONE; +                free_x86_register(result->base); +                result->base = NULL; -                result->displacement = create_new_x86_operand(); -                if (!fill_imm_operand(ASM_OPERAND(result->displacement), ASM_OPERAND(result)->size, data, pos, len)) -                { -                    free(result->displacement); -                    free(result); -                    return NULL; -                } +                result->displacement = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE); +                if (result->displacement == NULL) goto gxmron_error;              }              break;          case 0x40: -            result->displacement = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(result->displacement), AOS_8_BITS_SIGNED, data, pos, len)) -            { -                free(result->displacement); -                free(result); -                return NULL; -            } +            result->displacement = g_imm_operand_new_from_data(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE); +            if (result->displacement == NULL) goto gxmron_error;              break;          case 0x80: -            result->displacement = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(result->displacement), AOS_32_BITS_SIGNED, data, pos, len)) -            { -                free(result->displacement); -                free(result); -                return NULL; -            } +            result->displacement = g_imm_operand_new_from_data(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE); +            if (result->displacement == NULL) goto gxmron_error;              break;      } -    return result; - -} - - - - - - - - +    return G_ARCH_OPERAND(result); + gxmron_error: - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : reg    = registre à imprimer.                                * -*                size   = indique la taille du registre.                      * -*                buffer = tampon de sortie mis à disposition. [OUT]           * -*                len    = taille de ce tampon.                                * -*                syntax = type de représentation demandée.                    * -*                                                                             * -*  Description : Traduit une opérande de registre en texte.                   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void _x86_print_reg_operand(const x86_register *reg, AsmOperandSize size, char *buffer, size_t len, AsmSyntax syntax) -{ -    switch (syntax) -    { -        case ASX_INTEL: -            switch (size) -            { -                case AOS_8_BITS: -                    switch (reg->reg8) -                    { -                        case X86_REG8_AL: -                            snprintf(buffer, len, "al"); -                            break; -                        case X86_REG8_CL: -                            snprintf(buffer, len, "cl"); -                            break; -                        case X86_REG8_DL: -                            snprintf(buffer, len, "dl"); -                            break; -                        case X86_REG8_BL: -                            snprintf(buffer, len, "bl"); -                            break; -                        case X86_REG8_AH: -                            snprintf(buffer, len, "ah"); -                            break; -                        case X86_REG8_CH: -                            snprintf(buffer, len, "ch"); -                            break; -                        case X86_REG8_DH: -                            snprintf(buffer, len, "dh"); -                            break; -                        case X86_REG8_BH: -                            snprintf(buffer, len, "bh"); -                            break; -                        case X86_REG8_NONE: -                            /* Ne devrait jamais arriver */ -                            break; -                    } -                    break; - -                case AOS_16_BITS: -                    switch (reg->reg16) -                    { -                        case X86_REG16_AX: -                            snprintf(buffer, len, "ax"); -                            break; -                        case X86_REG16_CX: -                            snprintf(buffer, len, "cx"); -                            break; -                        case X86_REG16_DX: -                            snprintf(buffer, len, "dx"); -                            break; -                        case X86_REG16_BX: -                            snprintf(buffer, len, "bx"); -                            break; -                        case X86_REG16_SP: -                            snprintf(buffer, len, "sp"); -                            break; -                        case X86_REG16_BP: -                            snprintf(buffer, len, "bp"); -                            break; -                        case X86_REG16_SI: -                            snprintf(buffer, len, "si"); -                            break; -                        case X86_REG16_DI: -                            snprintf(buffer, len, "di"); -                            break; -                        case X86_REG16_NONE: -                            /* Ne devrait jamais arriver */ -                            break; -                    } -                    break; - -                case AOS_32_BITS: -                    switch (reg->reg32) -                    { -                        case X86_REG32_EAX: -                            snprintf(buffer, len, "eax"); -                            break; -                        case X86_REG32_ECX: -                            snprintf(buffer, len, "ecx"); -                            break; -                        case X86_REG32_EDX: -                            snprintf(buffer, len, "edx"); -                            break; -                        case X86_REG32_EBX: -                            snprintf(buffer, len, "ebx"); -                            break; -                        case X86_REG32_ESP: -                            snprintf(buffer, len, "esp"); -                            break; -                        case X86_REG32_EBP: -                            snprintf(buffer, len, "ebp"); -                            break; -                        case X86_REG32_ESI: -                            snprintf(buffer, len, "esi"); -                            break; -                        case X86_REG32_EDI: -                            snprintf(buffer, len, "edi"); -                            break; -                        case X86_REG32_NONE: -                            /* Ne devrait jamais arriver */ -                            break; -                    } -                    break; - -                case AOS_64_BITS: -                    break; - -            } -            break; - -        case ASX_ATT: -            switch (size) -            { -                case AOS_8_BITS: -                    switch (reg->reg8) -                    { -                        case X86_REG8_AL: -                            snprintf(buffer, len, "%%al"); -                            break; -                        case X86_REG8_CL: -                            snprintf(buffer, len, "%%cl"); -                            break; -                        case X86_REG8_DL: -                            snprintf(buffer, len, "%%dl"); -                            break; -                        case X86_REG8_BL: -                            snprintf(buffer, len, "%%bl"); -                            break; -                        case X86_REG8_AH: -                            snprintf(buffer, len, "%%ah"); -                            break; -                        case X86_REG8_CH: -                            snprintf(buffer, len, "%%ch"); -                            break; -                        case X86_REG8_DH: -                            snprintf(buffer, len, "%%dh"); -                            break; -                        case X86_REG8_BH: -                            snprintf(buffer, len, "%%bh"); -                            break; -                        case X86_REG8_NONE: -                            /* Ne devrait jamais arriver */ -                            break; -                    } -                    break; - -                case AOS_16_BITS: -                    switch (reg->reg16) -                    { -                        case X86_REG16_AX: -                            snprintf(buffer, len, "%%ax"); -                            break; -                        case X86_REG16_CX: -                            snprintf(buffer, len, "%%cx"); -                            break; -                        case X86_REG16_DX: -                            snprintf(buffer, len, "%%dx"); -                            break; -                        case X86_REG16_BX: -                            snprintf(buffer, len, "%%bx"); -                            break; -                        case X86_REG16_SP: -                            snprintf(buffer, len, "%%sp"); -                            break; -                        case X86_REG16_BP: -                            snprintf(buffer, len, "%%bp"); -                            break; -                        case X86_REG16_SI: -                            snprintf(buffer, len, "%%si"); -                            break; -                        case X86_REG16_DI: -                            snprintf(buffer, len, "%%di"); -                            break; -                        case X86_REG16_NONE: -                            /* Ne devrait jamais arriver */ -                            break; -                    } -                    break; - -                case AOS_32_BITS: -                    switch (reg->reg32) -                    { -                        case X86_REG32_EAX: -                            snprintf(buffer, len, "%%eax"); -                            break; -                        case X86_REG32_ECX: -                            snprintf(buffer, len, "%%ecx"); -                            break; -                        case X86_REG32_EDX: -                            snprintf(buffer, len, "%%edx"); -                            break; -                        case X86_REG32_EBX: -                            snprintf(buffer, len, "%%ebx"); -                            break; -                        case X86_REG32_ESP: -                            snprintf(buffer, len, "%%esp"); -                            break; -                        case X86_REG32_EBP: -                            snprintf(buffer, len, "%%ebp"); -                            break; -                        case X86_REG32_ESI: -                            snprintf(buffer, len, "%%esi"); -                            break; -                        case X86_REG32_EDI: -                            snprintf(buffer, len, "%%edi"); -                            break; -                        case X86_REG32_NONE: -                            /* Ne devrait jamais arriver */ -                            break; -                    } -                    break; - -                case AOS_64_BITS: -                    break; - -            } -            break; - -    } +    /* FIXME free(result);*/ +    return NULL;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : operand = instruction à traiter.                             * -*                buffer  = tampon de sortie mis à disposition. [OUT]          * -*                len     = taille de ce tampon.                               * +*  Paramètres  : operand = opérande à traiter.                                * +*                format  = format du binaire manipulé.                        *  *                syntax  = type de représentation demandée.                   *  *                                                                             * -*  Description : Traduit une opérande de registre en texte.                   * +*  Description : Traduit un opérande en version humainement lisible.          *  *                                                                             * -*  Retour      : -                                                            * +*  Retour      : Chaîne de caractères à libérer de la mémoire.                *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -void x86_print_reg_operand(const asm_x86_operand *operand, char *buffer, size_t len, AsmSyntax syntax) +static char *g_x86_mod_rm_operand_get_text(const GX86ModRMOperand *operand, const exe_format *format, AsmSyntax syntax)  { -    size_t pos;                             /* Position de traitement      */ +    char *result;                           /* Chaîne à retourner          */ +    char *tmp;                              /* Chaîne de registre          */      switch (syntax)      {          case ASX_INTEL: -            if (operand->content) -            { -                strcpy(buffer, "["); +            result = (char *)calloc(1 + 10 + 2, sizeof(char)); -                if (operand->scale > 0) -                    snprintf(&buffer[1], len - 1, "%d*", (int)pow(2, operand->scale));  +            strcpy(result, "["); -                pos = strlen(buffer); +            if (operand->scale > 0) +                snprintf(&result[1], 12, "%d*", (int)pow(2, operand->scale));  -            } -            else pos = 0; +            tmp = x86_register_as_text(operand->index, syntax); +            result = stradd(result, tmp); +            free(tmp); - -            _x86_print_reg_operand(&operand->rindex, ASM_OPERAND(operand)->size, &buffer[pos], len - pos, syntax); - -            if (operand->rbase.reg32 != X86_REG32_NONE) +            if (operand->base != NULL)              { -                strcat(buffer, "+");    /* TODO: n */ -                pos = strlen(buffer); +                result = stradd(result, "+"); -                _x86_print_reg_operand(&operand->rbase, ASM_OPERAND(operand)->size, &buffer[pos], len - pos, syntax); +                tmp = x86_register_as_text(operand->base, syntax); +                result = stradd(result, tmp); +                free(tmp);              } -              if (operand->displacement != NULL)              { -                if (is_imm_operand_negative(operand->displacement)) strcat(buffer, "-"); -                else strcat(buffer, "+"); -                pos = strlen(buffer); +                if (g_imm_operand_is_negative(operand->displacement)) result = stradd(result, "-"); +                else result = stradd(result, "+"); -                print_imm_operand(operand->displacement, &buffer[pos], len - pos, syntax); +                tmp = g_arch_operand_get_text(G_ARCH_OPERAND(operand->displacement), format, syntax); +                result = stradd(result, tmp); +                free(tmp);              } - - -            if (operand->content) strcat(buffer, "]"); +            result = stradd(result, "]");              break;          case ASX_ATT: +            result = strdup("[modRM]");              break;      } -} +    return result; +} +/* ---------------------------------------------------------------------------------- */ +/*                           OPERANDES D'ADRESSES RELATIVES                           */ +/* ---------------------------------------------------------------------------------- */ +/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ +G_DEFINE_TYPE(GX86RelativeOperand, g_x86_relative_operand, G_TYPE_X86_OPERAND); +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes x86 d'adresse relative.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ +static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *klass) +{ -/* ---------------------------------------------------------------------------------- */ -/*                          OPERANDES D'EMPLACEMENTS MEMOIRE                          */ -/* ---------------------------------------------------------------------------------- */ +}  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = flux de données à analyser.                       * -*                pos      = position courante dans ce flux. [OUT]             * -*                len      = taille totale des données à analyser.             * +*  Paramètres  : operand = instance à initialiser.                            *  *                                                                             * -*  Description : Crée une opérande à partir d'un emplacement mémoire 8 bits.  * +*  Description : Initialise une instance d'opérande x86 d'adresse relative.   *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_moffs8_operand(const uint8_t *data, off_t *pos, off_t len) +static void g_x86_relative_operand_init(GX86RelativeOperand *operand)  { -    asm_x86_operand *result;                /* Emplacement à retourner     */ - -    result = create_new_x86_operand(); - -    if (!fill_imm_operand(ASM_OPERAND(result), AOS_8_BITS, data, pos, len)) -    { -        free(result); -        return NULL; -    } +    GArchOperand *parent;                   /* Instance parente            */ -    ASM_OPERAND(result)->type = AOT_MOFFS; +    parent = G_ARCH_OPERAND(operand); -    return result; +    parent->get_text = (get_operand_text_fc)g_x86_relative_operand_get_text;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = flux de données à analyser.                       * -*                pos      = position courante dans ce flux. [OUT]             * -*                len      = taille totale des données à analyser.             * -*                is_reg32 = indique si le registre est un registre 32 bits.   * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            * +*                base = indice du premier registre.                           *  *                                                                             * -*  Description : Crée une opérande à partir d'un emplacement mémoire 16/32b.  * +*  Description : Crée un opérande X86 d'adresse relative.                     *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : Opérande mis en place.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_moffs1632_operand(const uint8_t *data, off_t *pos, off_t len, bool is_reg32) +GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t len, AsmOperandSize size, vmpa_t base)  { -    asm_x86_operand *result;                /* Emplacement à retourner     */ +    GX86RelativeOperand *result;            /* Structure à retourner       */ +    off_t init_pos;                         /* Position avant lecture      */ +    uint8_t val8;                           /* Valeur sur 8 bits           */ +    uint16_t val16;                         /* Valeur sur 16 bits          */ +    uint32_t val32;                         /* Valeur sur 32 bits          */ +    uint32_t address32;                     /* Adresse finale visée        */ -    result = create_new_x86_operand(); +    init_pos = *pos; -    if (!fill_imm_operand(ASM_OPERAND(result), is_reg32 ? AOS_32_BITS : AOS_16_BITS, data, pos, len)) +    switch (size)      { -        free(result); -        return NULL; +        case AOS_8_BITS_UNSIGNED: +            read_u8(&val8, data, pos, len, SRE_LITTLE); +            address32 = val8; +            break; +        case AOS_16_BITS_UNSIGNED: +            read_u16(&val16, data, pos, len, SRE_LITTLE); +            address32 = val16; +            break; +        case AOS_32_BITS_UNSIGNED: +            read_u32(&val32, data, pos, len, SRE_LITTLE); +            address32 = val32; +            break; +        default: +            return NULL; +            break;      } -    ASM_OPERAND(result)->type = AOT_MOFFS; +    address32 += base + (*pos - init_pos); -    return result; +    result = g_object_new(G_TYPE_X86_RELATIVE_OPERAND, NULL); +    result->immediate = g_imm_operand_new_from_value(AOS_32_BITS/*FIXME*/, address32); + +    return G_ARCH_OPERAND(result);  }  /******************************************************************************  *                                                                             * -*  Paramètres  : operand = instruction à traiter.                             * -*                buffer  = tampon de sortie mis à disposition. [OUT]          * -*                len     = taille de ce tampon.                               * +*  Paramètres  : operand = opérande à traiter.                                * +*                format  = format du binaire manipulé.                        *  *                syntax  = type de représentation demandée.                   *  *                                                                             * -*  Description : Traduit une opérande d'emplacement mémoire en texte.         * +*  Description : Traduit un opérande en version humainement lisible.          *  *                                                                             * -*  Retour      : -                                                            * +*  Retour      : Chaîne de caractères à libérer de la mémoire.                *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -void x86_print_moffs_operand(const asm_x86_operand *operand, char *buffer, size_t len, AsmSyntax syntax) +static char *g_x86_relative_operand_get_text(const GX86RelativeOperand *operand, const exe_format *format, AsmSyntax syntax)  { -    switch (syntax) -    { -        case ASX_INTEL: -            if (len > 3) -            { -                strcpy(buffer, "ds:"); -                print_imm_operand(ASM_OPERAND(operand), &buffer[3], len - 3, ASX_INTEL); -            } -            break; +    char *result;                           /* Chaîne à retourner          */ -        case ASX_ATT: -            print_imm_operand(ASM_OPERAND(operand), buffer, len, ASX_INTEL); -            break; +    result = g_arch_operand_get_text(operand->immediate, format, syntax); -    } +    return result;  }  /* ---------------------------------------------------------------------------------- */ -/*                           OPERANDES D'ADRESSES RELATIVES                           */ +/*                          OPERANDES D'EMPLACEMENTS MEMOIRE                          */  /* ---------------------------------------------------------------------------------- */ +/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ +G_DEFINE_TYPE(GX86MOffsOperand, g_x86_moffs_operand, G_TYPE_X86_OPERAND); + +  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = flux de données à analyser.                       * -*                pos      = position courante dans ce flux. [OUT]             * -*                len      = taille totale des données à analyser.             * +*  Paramètres  : klass = classe à initialiser.                                *  *                                                                             * -*  Description : Crée une opérande à partir d'une adresse relative (8 bits).  * +*  Description : Initialise la classe des opérandes d'emplacement mémoire x86.*  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_rel8_operand_in_32b(uint64_t base, const uint8_t *data, off_t *pos, off_t len) +static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *klass)  { -    asm_x86_operand *result;                /* Emplacement à retourner     */ -    off_t init_pos;                         /* Position avant lecture      */ -    int8_t offset;                          /* Décallage à appliquer       */ -    uint32_t address;                       /* Adresse finale visée        */ -    result = create_new_x86_operand(); +} -    init_pos = *pos; -    address = base; -    if (!read_imm_value(AOS_8_BITS, data, pos, len, &offset)) -    { -        free(result); -        return NULL; -    } +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande d'emplacement mémoire x86.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    address = base + (*pos - init_pos) + offset; +static void g_x86_moffs_operand_init(GX86MOffsOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ -    if (!fill_imm_operand_with_value(ASM_OPERAND(result), AOS_32_BITS, &address)) -    { -        free(result); -        return NULL; -    } +    parent = G_ARCH_OPERAND(operand); -    return result; +    parent->get_text = (get_operand_text_fc)g_x86_moffs_operand_get_text;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : data     = flux de données à analyser.                       * -*                pos      = position courante dans ce flux. [OUT]             * -*                len      = taille totale des données à analyser.             * -*                is_reg32 = indique si le registre est un registre 32 bits.   * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            *  *                                                                             * -*  Description : Crée une opérande à partir d'une adresse relative (16/32b).  * +*  Description : Crée un opérande d'emplacement mémoire x86.                  *  *                                                                             * -*  Retour      : Opérande mise en place ou NULL.                              * +*  Retour      : Opérande mis en place.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_x86_operand *x86_create_rel1632_operand_in_32b(uint64_t base, const uint8_t *data, off_t *pos, off_t len, bool is_reg32) +GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len, AsmOperandSize size)  { -    asm_x86_operand *result;                /* Emplacement à retourner     */ -    off_t init_pos;                         /* Position avant lecture      */ -    int32_t offset32;                       /* Décallage 32b à appliquer   */ -    int16_t offset16;                       /* Décallage 16b à appliquer   */ -    uint32_t address;                       /* Adresse finale visée        */ +    GX86MOffsOperand *result;               /* Structure à retourner       */ +    GImmOperand *offset;                    /* Emplacement lu              */ -    result = create_new_x86_operand(); +    result = NULL; -    init_pos = *pos; -    address = base; +    offset = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE); -    if (is_reg32) +    if (offset != NULL)      { -        if (!read_imm_value(AOS_32_BITS, data, pos, len, &offset32)) -        { -            free(result); -            return NULL; -        } +        result = g_object_new(G_TYPE_X86_MOFFS_OPERAND, NULL); +        result->offset = offset; +    } -        address = base + (*pos - init_pos) + offset32; +    return G_ARCH_OPERAND(result); -    } -    else -    { -        if (!read_imm_value(AOS_16_BITS, data, pos, len, &offset16)) -        { -            free(result); -            return NULL; -        } +} -        address = base + (*pos - init_pos) + offset16; -    } +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                format  = format du binaire manipulé.                        * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : Chaîne de caractères à libérer de la mémoire.                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    if (!fill_imm_operand_with_value(ASM_OPERAND(result), AOS_32_BITS, &address)) -    { -        free(result); -        return NULL; -    } +static char *g_x86_moffs_operand_get_text(const GX86MOffsOperand *operand, const exe_format *format, AsmSyntax syntax) +{ +    char *result;                           /* Chaîne à retourner          */ + +    result = g_arch_operand_get_text(operand->offset, format, syntax); + +    result = strprep(result, "ds:");      return result; @@ -1367,13 +920,13 @@ asm_x86_operand *x86_create_rel1632_operand_in_32b(uint64_t base, const uint8_t  *                                                                             *  ******************************************************************************/ -bool x86_read_one_operand(asm_x86_instr *instr, const uint8_t *data, off_t *pos, off_t len, X86OperandType type, ...) +bool x86_read_one_operand(GArchInstruction *instr, const bin_t *data, off_t *pos, off_t len, X86OperandType type, ...)  {      va_list ap;                             /* Liste des compléments       */      AsmOperandSize oprsize;                 /* Taille des opérandes        */ -    uint64_t offset;                        /* Adresse courante            */ -    uint8_t base;                           /* Indice du premier registre  */ -    asm_x86_operand *op;                    /* Opérande unique décodé      */ +    vmpa_t offset;                          /* Adresse courante            */ +    bin_t base;                             /* Indice du premier registre  */ +    GArchOperand *op;                       /* Opérande unique décodé      */      va_start(ap, type); @@ -1382,72 +935,60 @@ bool x86_read_one_operand(asm_x86_instr *instr, const uint8_t *data, off_t *pos,      switch (type)      {          case X86_OTP_IMM8: -            op = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(op), AOS_8_BITS, data, pos, len)) -            { -                free(op); -                op = NULL; -            } +            op = g_imm_operand_new_from_data(MDS_8_BITS, data, pos, len, SRE_LITTLE);              break;          case X86_OTP_IMM1632: -            oprsize = va_arg(ap, AsmOperandSize); -            op = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(op), oprsize, data, pos, len)) -            { -                free(op); -                op = NULL; -            } +            if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); +            op = g_imm_operand_new_from_data(oprsize == AOS_32_BITS ? MDS_32_BITS : MDS_16_BITS, data, pos, len, SRE_LITTLE);              break;          case X86_OTP_REL8: -            offset = va_arg(ap, uint64_t); -            /* TODO : 64bits */ -            op = x86_create_rel8_operand_in_32b(offset + 1, data, pos, len); +            offset = va_arg(ap, vmpa_t); +            op = g_x86_relative_operand_new(data, pos, len, AOS_8_BITS, offset + 1);              break;          case X86_OTP_REL1632:              oprsize = va_arg(ap, AsmOperandSize); -            offset = va_arg(ap, uint64_t); -            /* TODO : 64bits */ -            op = x86_create_rel1632_operand_in_32b(offset + 1, data, pos, len, oprsize == AOS_32_BITS); +            offset = va_arg(ap, vmpa_t); +            op = g_x86_relative_operand_new(data, pos, len, oprsize, offset + 1);              break;          case X86_OTP_R8: -            op = x86_create_r8_operand(data[(*pos)++], true); +            op = g_x86_register_operand_new_from_mod_rm(data, pos, len, AOS_8_BITS, true);              break;          case X86_OTP_R1632:              oprsize = va_arg(ap, AsmOperandSize); -            op = x86_create_r1632_operand(data[(*pos)++], oprsize == AOS_32_BITS, true); +            op = g_x86_register_operand_new_from_mod_rm(data, pos, len, oprsize, true);              break;          case X86_OTP_OP_R1632:              oprsize = va_arg(ap, AsmOperandSize); -            base = (uint8_t)va_arg(ap, int); -            op = x86_create_r1632_operand_from_opcode(data[(*pos)++], oprsize == AOS_32_BITS, base); +            base = (bin_t)va_arg(ap, int); +            op = g_x86_register_operand_new_from_opcode(data, pos, len, oprsize, base);              break;          case X86_OTP_RM8: -            op = x86_create_rm8_operand(data, pos, len); +            op = g_x86_mod_rm_operand_new(data, pos, len, AOS_8_BITS);              break;          case X86_OTP_RM1632:              oprsize = va_arg(ap, AsmOperandSize); -            op = x86_create_rm1632_operand(data, pos, len, oprsize == AOS_32_BITS); +            op = g_x86_mod_rm_operand_new(data, pos, len, oprsize);              break;          case X86_OTP_CL: -            op = x86_create_r8_operand(0x01, true); +            op = g_x86_register_operand_new_from_index(0x01, AOS_8_BITS);              break;          case X86_OTP_AL: -            op = x86_create_r8_operand(0x00, true); +            op = g_x86_register_operand_new_from_index(0x00, AOS_8_BITS);              break;          case X86_OTP_E_AX:              oprsize = va_arg(ap, AsmOperandSize); -            op = x86_create_r1632_operand(0x00, oprsize == AOS_32_BITS, true); +            op = g_x86_register_operand_new_from_index(0x00, oprsize);              break;      } @@ -1456,12 +997,7 @@ bool x86_read_one_operand(asm_x86_instr *instr, const uint8_t *data, off_t *pos,      if (op == NULL) return false; -    /* Assemblage final */ - -    ASM_INSTRUCTION(instr)->operands = (asm_operand **)calloc(1, sizeof(asm_operand *)); -    ASM_INSTRUCTION(instr)->operands_count = 1; - -    ASM_INSTRUCTION(instr)->operands[0] = ASM_OPERAND(op); +    g_arch_instruction_attach_one_operand(instr, op);      return true; @@ -1486,16 +1022,17 @@ bool x86_read_one_operand(asm_x86_instr *instr, const uint8_t *data, off_t *pos,  *                                                                             *  ******************************************************************************/ -bool x86_read_two_operands(asm_x86_instr *instr, const uint8_t *data, off_t *pos, off_t len, X86OperandType type1, X86OperandType type2, ...) +bool x86_read_two_operands(GArchInstruction *instr, const bin_t *data, off_t *pos, off_t len, X86OperandType type1, X86OperandType type2, ...)  {      va_list ap;                             /* Liste des compléments       */      AsmOperandSize oprsize;                 /* Taille des opérandes        */      bool op1_first;                         /* Position de l'opérande  #1  */      bool op2_first;                         /* Position de l'opérande  #2  */      off_t op1_pos;                          /* Position après lecture #1   */ -    asm_x86_operand *op1;                   /* Premier opérande décodé     */ +    bin_t base;                             /* Indice du premier registre  */ +    GArchOperand *op1;                      /* Premier opérande décodé     */      off_t op2_pos;                          /* Position après lecture #2   */ -    asm_x86_operand *op2;                   /* Second opérande décodé      */ +    GArchOperand *op2;                      /* Second opérande décodé      */      va_start(ap, type2); @@ -1523,44 +1060,59 @@ bool x86_read_two_operands(asm_x86_instr *instr, const uint8_t *data, off_t *pos      switch (type1)      { +        case X86_OTP_IMM8: +            op1 = g_imm_operand_new_from_data(MDS_8_BITS, data, &op1_pos, len, SRE_LITTLE); +            break; + +        case X86_OTP_IMM1632: +            if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); +            op1 = g_imm_operand_new_from_data(oprsize == AOS_32_BITS ? MDS_32_BITS : MDS_16_BITS, data, &op1_pos, len, SRE_LITTLE); +            break; +          case X86_OTP_MOFFS8: -            op1 = x86_create_moffs8_operand(data, &op1_pos, len); +            op1 = g_x86_moffs_operand_new(data, &op1_pos, len, AOS_8_BITS);              break;          case X86_OTP_MOFFS1632:              oprsize = va_arg(ap, AsmOperandSize); -            op1 = x86_create_moffs1632_operand(data, &op1_pos, len, oprsize == AOS_32_BITS); +            op1 = g_x86_moffs_operand_new(data, &op1_pos, len, oprsize);              break;          case X86_OTP_R8: -            op1 = x86_create_r8_operand(data[op1_pos++], op1_first); +            op1 = g_x86_register_operand_new_from_mod_rm(data, &op1_pos, len, AOS_8_BITS, op1_first);              break;          case X86_OTP_R1632:              oprsize = va_arg(ap, AsmOperandSize); -            op1 = x86_create_r1632_operand(data[op1_pos++], oprsize == AOS_32_BITS, op1_first); +            op1 = g_x86_register_operand_new_from_mod_rm(data, &op1_pos, len, oprsize, op1_first); +            break; + +        case X86_OTP_OP_R1632: +            oprsize = va_arg(ap, AsmOperandSize); +            base = (bin_t)va_arg(ap, int); +            op1 = g_x86_register_operand_new_from_opcode(data, &op1_pos, len, oprsize, base);              break;          case X86_OTP_RM8: -            op1 = x86_create_rm8_operand(data, &op1_pos, len); +            op1 = g_x86_mod_rm_operand_new(data, &op1_pos, len, AOS_8_BITS);              break;          case X86_OTP_RM1632:              oprsize = va_arg(ap, AsmOperandSize); -            op1 = x86_create_rm1632_operand(data, &op1_pos, len, oprsize == AOS_32_BITS); +            op1 = g_x86_mod_rm_operand_new(data, &op1_pos, len, oprsize);              break;          case X86_OTP_CL: -            op1 = x86_create_r8_operand(0x01, op1_first); +            op1 = g_x86_register_operand_new_from_index(0x01, AOS_8_BITS);              break;          case X86_OTP_AL: -            op1 = x86_create_r8_operand(0x00, op1_first); +            op1 = g_x86_register_operand_new_from_index(0x00, AOS_8_BITS);              break;          case X86_OTP_E_AX:              oprsize = va_arg(ap, AsmOperandSize); -            op1 = x86_create_r1632_operand(0x00, oprsize == AOS_32_BITS, op1_first); +            op1 = g_x86_register_operand_new_from_index(0x00, oprsize);              break;      } @@ -1580,62 +1132,52 @@ bool x86_read_two_operands(asm_x86_instr *instr, const uint8_t *data, off_t *pos      switch (type2)      {          case X86_OTP_IMM8: -            op2 = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(op2), AOS_8_BITS, data, &op2_pos, len)) -            { -                free(op2); -                op2 = NULL; -            } +            op2 = g_imm_operand_new_from_data(MDS_8_BITS, data, &op2_pos, len, SRE_LITTLE);              break;          case X86_OTP_IMM1632:              if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); -            op2 = create_new_x86_operand(); -            if (!fill_imm_operand(ASM_OPERAND(op2), oprsize, data, &op2_pos, len)) -            { -                free(op2); -                op2 = NULL; -            } +            op2 = g_imm_operand_new_from_data(oprsize == AOS_32_BITS ? MDS_32_BITS : MDS_16_BITS, data, &op2_pos, len, SRE_LITTLE);              break;          case X86_OTP_MOFFS8: -            op2 = x86_create_moffs8_operand(data, &op2_pos, len); +            op2 = g_x86_moffs_operand_new(data, &op2_pos, len, AOS_8_BITS);              break;          case X86_OTP_MOFFS1632:              if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); -            op2 = x86_create_moffs1632_operand(data, &op2_pos, len, oprsize == AOS_32_BITS); +            op2 = g_x86_moffs_operand_new(data, &op2_pos, len, oprsize);              break;          case X86_OTP_R8: -            op2 = x86_create_r8_operand(data[op2_pos++], op2_first); +            op2 = g_x86_register_operand_new_from_mod_rm(data, &op2_pos, len, AOS_8_BITS, op2_first);              break;          case X86_OTP_R1632:              if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); -            op2 = x86_create_r1632_operand(data[op2_pos++], oprsize == AOS_32_BITS, op2_first); +            op2 = g_x86_register_operand_new_from_mod_rm(data, &op2_pos, len, oprsize, op2_first);              break;          case X86_OTP_RM8: -            op2 = x86_create_rm8_operand(data, &op2_pos, len); +            op2 = g_x86_mod_rm_operand_new(data, &op2_pos, len, AOS_8_BITS);              break;          case X86_OTP_RM1632:              if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); -            op2 = x86_create_rm1632_operand(data, &op2_pos, len, oprsize == AOS_32_BITS); +            op2 = g_x86_mod_rm_operand_new(data, &op2_pos, len, oprsize);              break;          case X86_OTP_CL: -            op2 = x86_create_r8_operand(0x01, op2_first); +            op2 = g_x86_register_operand_new_from_index(0x01, AOS_8_BITS);              break;          case X86_OTP_AL: -            op2 = x86_create_r8_operand(0x00, op2_first); +            op2 = g_x86_register_operand_new_from_index(0x00, AOS_8_BITS);              break;          case X86_OTP_E_AX:              if (oprsize == AOS_UNDEFINED) oprsize = va_arg(ap, AsmOperandSize); -            op2 = x86_create_r1632_operand(0x00, oprsize == AOS_32_BITS, op2_first); +            op2 = g_x86_register_operand_new_from_index(0x00, oprsize);              break;      } @@ -1653,11 +1195,7 @@ bool x86_read_two_operands(asm_x86_instr *instr, const uint8_t *data, off_t *pos      *pos = MAX(op1_pos, op2_pos); -    ASM_INSTRUCTION(instr)->operands = (asm_operand **)calloc(2, sizeof(asm_operand *)); -    ASM_INSTRUCTION(instr)->operands_count = 2; - -    ASM_INSTRUCTION(instr)->operands[0] = ASM_OPERAND(op1); -    ASM_INSTRUCTION(instr)->operands[1] = ASM_OPERAND(op2); +    g_arch_instruction_attach_two_operands(instr, op1, op2);      return true; diff --git a/src/arch/x86/operand.h b/src/arch/x86/operand.h index c9ade39..bc495a0 100644 --- a/src/arch/x86/operand.h +++ b/src/arch/x86/operand.h @@ -26,75 +26,132 @@  #include <stdbool.h> -#include <stdint.h> -#include "instruction.h" +#include "../instruction.h" -/* Définition d'une opérande x86 */ -typedef struct _asm_x86_operand asm_x86_operand; +/* ---------------------- COQUILLE VIDE POUR LES OPERANDES X86 ---------------------- */ +#define G_TYPE_X86_OPERAND                  g_x86_operand_get_type() +#define G_X86_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_operand_get_type(), GX86Operand)) +#define G_IS_X86_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_operand_get_type())) +#define G_X86_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_operand_get_type(), GX86OperandIface)) -/* Crée une opérande vierge pour x86. */ -asm_x86_operand *create_new_x86_operand(void); +/* Définition d'un opérande de la x86 (instance) */ +typedef struct _GX86Operand GX86Operand; +/* Définition d'un opérande de la x86 (classe) */ +typedef struct _GX86OperandClass GX86OperandClass; -/* Crée une opérande renvoyant vers un registre 16 ou 32 bits. */ -asm_x86_operand *x86_create_reg1632_operand(uint8_t, bool, uint8_t); -/* Crée une opérande renvoyant vers un registre 16 ou 32 bits. */ -asm_x86_operand *x86_create_reg1632_operand_from_modrm(uint8_t, bool, bool); +/* Indique le type défini par la GLib pour un opérande de x86. */ +GType g_x86_operand_get_type(void); -/* Crée une opérande renvoyant vers un contenu 16 ou 32 bits. */ -asm_x86_operand *x86_create_content1632_operand(const uint8_t *, off_t *, off_t, bool, bool); +/* ------------------------ OPERANDES VISANT UN REGISTRE X86 ------------------------ */ -/* Crée une opérande renvoyant vers un registre 8 bits. */ -asm_x86_operand *x86_create_r8_operand(uint8_t, bool); -/* Crée une opérande à partir d'un registre/une mémoire 8 bits. */ -asm_x86_operand *x86_create_rm8_operand(const uint8_t *, off_t *, off_t, ...); +#define G_TYPE_X86_REGISTER_OPERAND                  g_x86_register_operand_get_type() +#define G_X86_REGISTER_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_register_operand_get_type(), GX86RegisterOperand)) +#define G_IS_X86_REGISTER_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_register_operand_get_type())) +#define G_X86_REGISTER_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_register_operand_get_type(), GX86RegisterOperandIface)) -/* Crée une opérande renvoyant vers un registre 16 ou 32 bits. */ -asm_x86_operand *x86_create_r1632_operand(uint8_t, bool, bool); -/* Crée une opérande à partir d'un registre/une mémoire 16/32b. */ -asm_x86_operand *x86_create_rm1632_operand(const uint8_t *, off_t *, off_t, bool, ...); +/* Définition d'un opérande visant un registre x86 (instance) */ +typedef struct _GX86RegisterOperand GX86RegisterOperand; +/* Définition d'un opérande visant un registre x86 (classe) */ +typedef struct _GX86RegisterOperandClass GX86RegisterOperandClass; -/* Traduit une opérande de registre en texte. */ -void x86_print_reg_operand(const asm_x86_operand *, char *, size_t, AsmSyntax); +/* Indique le type défini par la GLib pour un opérande de registre x86. */ +GType g_x86_register_operand_get_type(void); +/* Crée un opérande visant un registre X86. */ +GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *, off_t *, off_t, AsmOperandSize, bin_t); +/* Crée un opérande visant un registre X86. */ +GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *, off_t *, off_t, AsmOperandSize, bool); + +/* Crée un opérande visant un registre X86 donnée. */ +GArchOperand *g_x86_register_operand_new_from_index(bin_t, AsmOperandSize); + + + +/* ----------------------- OPERANDES COMPLEXES DE TYPE MOD/RM ----------------------- */ + + +#define G_TYPE_X86_MOD_RM_OPERAND                  g_x86_mod_rm_operand_get_type() +#define G_X86_MOD_RM_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_mod_rm_operand_get_type(), GX86ModRmOperand)) +#define G_IS_X86_MOD_RM_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_mod_rm_operand_get_type())) +#define G_X86_MOD_RM_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_mod_rm_operand_get_type(), GX86ModRmOperandIface)) -/* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ +/* Définition d'un opérande x86 de type ModRM (instance) */ +typedef struct _GX86ModRMOperand GX86ModRMOperand; -/* Crée une opérande à partir d'un emplacement mémoire 8 bits. */ -asm_x86_operand *x86_create_moffs8_operand(const uint8_t *, off_t *, off_t); +/* Définition d'un opérande x86 de type ModRM (classe) */ +typedef struct _GX86ModRMOperandClass GX86ModRMOperandClass; -/* Crée une opérande à partir d'un emplacement mémoire 16/32b. */ -asm_x86_operand *x86_create_moffs1632_operand(const uint8_t *, off_t *, off_t, bool); -/* Traduit une opérande d'emplacement mémoire en texte. */ -void x86_print_moffs_operand(const asm_x86_operand *, char *, size_t, AsmSyntax); +/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ +GType g_x86_mod_rm_operand_get_type(void); + +/* Crée un opérande x86 de type ModRM. */ +GArchOperand *g_x86_mod_rm_operand_new(const bin_t *, off_t *, off_t, AsmOperandSize);  /* ------------------------- OPERANDES D'ADRESSES RELATIVES ------------------------- */ -/* Crée une opérande à partir d'une adresse relative (8 bits). */ -asm_x86_operand *x86_create_rel8_operand_in_32b(uint64_t, const uint8_t *, off_t *, off_t); +#define G_TYPE_X86_RELATIVE_OPERAND                  g_x86_relative_operand_get_type() +#define G_X86_RELATIVE_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_relative_operand_get_type(), GX86RelativeOperand)) +#define G_IS_X86_RELATIVE_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_relative_operand_get_type())) +#define G_X86_RELATIVE_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_relative_operand_get_type(), GX86RelativeOperandIface)) + + +/* Définition d'un opérande x86 d'adresse relative (instance) */ +typedef struct _GX86RelativeOperand GX86RelativeOperand; + +/* Définition d'un opérande x86 d'adresse relative (classe) */ +typedef struct _GX86RelativeOperandClass GX86RelativeOperandClass; + + +/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ +GType g_x86_relative_operand_get_type(void); + +/* Crée un opérande X86 d'adresse relative. */ +GArchOperand *g_x86_relative_operand_new(const bin_t *, off_t *, off_t, AsmOperandSize, vmpa_t); + + + +/* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ + + +#define G_TYPE_X86_MOFFS_OPERAND                  g_x86_moffs_operand_get_type() +#define G_X86_MOFFS_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_moffs_operand_get_type(), GX86MoffsOperand)) +#define G_IS_X86_MOFFS_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_moffs_operand_get_type())) +#define G_X86_MOFFS_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_moffs_operand_get_type(), GX86MoffsOperandIface)) + + +/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ +typedef struct _GX86MOffsOperand GX86MOffsOperand; + +/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ +typedef struct _GX86MOffsOperandClass GX86MOffsOperandClass; + + +/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ +GType g_x86_moffs_operand_get_type(void); -/* Crée une opérande à partir d'une adresse relative (16/32b). */ -asm_x86_operand *x86_create_rel1632_operand_in_32b(uint64_t, const uint8_t *, off_t *, off_t, bool); +/* Crée un opérande d'emplacement mémoire x86. */ +GArchOperand *g_x86_moffs_operand_new(const bin_t *, off_t *, off_t, AsmOperandSize); @@ -136,10 +193,10 @@ typedef enum _X86OperandType  /* Procède à la lecture d'un opérande donné. */ -bool x86_read_one_operand(asm_x86_instr *, const uint8_t *, off_t *, off_t, X86OperandType, ...); +bool x86_read_one_operand(GArchInstruction *, const bin_t *data, off_t *pos, off_t, X86OperandType, ...);  /* Procède à la lecture de deux opérandes donnés. */ -bool x86_read_two_operands(asm_x86_instr *, const uint8_t *, off_t *, off_t, X86OperandType, X86OperandType, ...); +bool x86_read_two_operands(GArchInstruction *, const bin_t *data, off_t *pos, off_t, X86OperandType, X86OperandType, ...); diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c index dfb2f12..82b0f23 100644 --- a/src/arch/x86/processor.c +++ b/src/arch/x86/processor.c @@ -24,182 +24,112 @@  #include "processor.h" -#include <malloc.h> -#include <stdio.h> - -  #include "../processor-int.h" -#include "instruction.h"  #include "opcodes.h" -#include "operand.h" -#include "../../common/extstr.h" - - -typedef asm_x86_instr * (* read_instr) (const uint8_t *, off_t *, off_t, uint64_t, const asm_x86_processor *); -/* Carte d'identité d'un opcode */ -typedef struct _x86_opcode +/* Définition du processeur de la x86 (instance) */ +struct _GX86Processor  { -    X86Prefix prefix;                       /* Préfixe(s) eventuel(s)      */ -    uint8_t opcode;                         /* Opcode seul                 */ -    uint8_t op_ext;                         /* Extension de l'opcode       */ - -    bool has_op_ext;                        /* Ext. à prendre en compte ?  */ - -    const char *name;                       /* Désignation humaine         */ -    read_instr read;                        /* Décodage de l'instruction   */ - -} x86_opcode; - - -#define EXT_OPCODE_MASK     0x38 - - - - - -#define register_opcode(target, _opcode, _name, _read)                          \ -    do {                                                                        \ -        target.prefix = X86_PRE_NONE;                                           \ -        target.opcode = _opcode;                                                \ -        target.has_op_ext = false;                                              \ -        target.name = _name;                                                    \ -        target.read = _read;                                                    \ -    } while (0) - -#define register_opcode_1632(target, _opcode, _name, _read)                     \ -    do {                                                                        \ -        target.prefix = X86_PRE_OPSIZE;                                         \ -        target.opcode = _opcode;                                                \ -        target.has_op_ext = false;                                              \ -        target.name = _name;                                                    \ -        target.read = _read;                                                    \ -    } while (0) - -#define register_opcode_with_ext(target, _opcode, _ext, _name, _read)           \ -    do {                                                                        \ -        target.prefix = X86_PRE_NONE;                                           \ -        target.opcode = _opcode;                                                \ -        target.op_ext = _ext << 3;                                              \ -        target.has_op_ext = true;                                               \ -        target.name = _name;                                                    \ -        target.read = _read;                                                    \ -    } while (0) - -#define register_opcode_1632_with_ext(target, _opcode, _ext, _name, _read)      \ -    do {                                                                        \ -        target.prefix = X86_PRE_OPSIZE;                                         \ -        target.opcode = _opcode;                                                \ -        target.op_ext = _ext << 3;                                              \ -        target.has_op_ext = true;                                               \ -        target.name = _name;                                                    \ -        target.read = _read;                                                    \ -    } while (0) - -#define register_2b_opcode_1632(target, _opcode, _name, _read)                  \ -    do {                                                                        \ -        target.prefix = X86_PRE_ESCAPE | X86_PRE_OPSIZE;                        \ -        target.opcode = _opcode;                                                \ -        target.has_op_ext = false;                                              \ -        target.name = _name;                                                    \ -        target.read = _read;                                                    \ -    } while (0) - - - - - - - - +    GArchProcessor parent;                  /* Instance parente            */ +}; -/* Définition générique d'une architecture */ -struct _asm_x86_processor +/* Définition du processeur de la x86 (classe) */ +struct _GX86ProcessorClass  { -    asm_processor base;                     /* A laisser en premier...     */ - -    AsmOperandSize operand_size;            /* Taille par défaut           */ - -    x86_opcode opcodes[X86_OP_COUNT];       /* Liste des opcodes supportés */ +    GArchProcessorClass parent;             /* Classe parente              */  }; +/* Initialise la classe des lignes de descriptions initiales. */ +static void g_x86_processor_class_init(GX86ProcessorClass *); +/* Initialise la classe des lignes de descriptions initiales. */ +static void g_x86_processor_init(GX86Processor *); +/* Décode une instruction dans un flux de données. */ +static GArchInstruction *g_x86_processor_decode_instruction(const GX86Processor *, const bin_t *, off_t *, off_t, vmpa_t); -/* Enregistre toutes les instructions reconnues pour x86. */ -void x86_register_instructions(asm_x86_processor *); +/* Indique le type défini par la GLib pour le processeur x86. */ +G_DEFINE_TYPE(GX86Processor, g_x86_processor, G_TYPE_ARCH_PROCESSOR); -/* Décode une instruction dans un flux de données. */ -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 exe_format *, const asm_x86_instr *, char *, size_t, AsmSyntax); +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des lignes de descriptions initiales.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ +static void g_x86_processor_class_init(GX86ProcessorClass *klass) +{ +}  /******************************************************************************  *                                                                             * -*  Paramètres  : -                                                            * +*  Paramètres  : proc = instance à initialiser.                               *  *                                                                             * -*  Description : Crée le support de l'architecture x86.                       * +*  Description : Initialise la classe des lignes de descriptions initiales.   *  *                                                                             * -*  Retour      : Architecture mise en place.                                  * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -asm_processor *create_x86_processor(void) +static void g_x86_processor_init(GX86Processor *proc)  { -    asm_x86_processor *result;              /* Architecture à retourner    */ - -    result = (asm_x86_processor *)calloc(1, sizeof(asm_x86_processor)); +    GArchProcessor *parent;                 /* Instance parente            */ -    result->operand_size = AOS_32_BITS; +    parent = G_ARCH_PROCESSOR(proc); -    x86_register_instructions(result); +    parent->endianness = SRE_BIG; -    ASM_PROCESSOR(result)->fetch_instr = (fetch_instruction_)x86_fetch_instruction; -    ASM_PROCESSOR(result)->print_instr = (print_instruction_)x86_print_instruction; - -    return ASM_PROCESSOR(result); +    parent->decode = (decode_instruction_fc)g_x86_processor_decode_instruction;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : proc = architecture visée par la consultation.               * +*  Paramètres  : -                                                            *  *                                                                             * -*  Description : Fournit la taille courante des opérandes pour x86.           * +*  Description : Crée le support de l'architecture x86.                       *  *                                                                             * -*  Retour      : Taille d'opérande (16 ou 32 bits).                           * +*  Retour      : Architecture mise en place.                                  *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -AsmOperandSize get_x86_current_operand_size(const asm_x86_processor *proc) +GArchProcessor *g_x86_processor_new(void)  { -    return proc->operand_size; +    GArchProcessor *result;                 /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_X86_PROCESSOR, NULL); + +    return result;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : proc = architecture visée par la consultation.               * -*                data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * +*  Paramètres  : proc   = architecture visée par la consultation.             * +*                prefix = bascule à consulter.                                *  *                                                                             *  *  Description : Fournit la taille supplantée des opérandes pour x86.         *  *                                                                             * @@ -209,16 +139,16 @@ AsmOperandSize get_x86_current_operand_size(const asm_x86_processor *proc)  *                                                                             *  ******************************************************************************/ -AsmOperandSize switch_x86_operand_size_if_needed(const asm_x86_processor *proc, const uint8_t *data, off_t *pos) +AsmOperandSize g_x86_processor_get_operand_size(const GX86Processor *proc, X86Prefix prefix)  {      AsmOperandSize result;                  /* Taille à renvoyer           */ -    if (data[*pos] == 0x66) -    { -        result = (proc->operand_size == AOS_32_BITS ? AOS_16_BITS : AOS_32_BITS); -        (*pos)++; -    } -    else result = proc->operand_size; +    /* FIXME */ + +    if (prefix & XPX_OPERAND_SIZE_OVERRIDE) +        result = (AOS_32_BITS/*proc->operand_size*/ == AOS_32_BITS ? AOS_16_BITS : AOS_32_BITS); +  +    else result = AOS_32_BITS/*proc->operand_size*/;      return result; @@ -228,362 +158,557 @@ AsmOperandSize switch_x86_operand_size_if_needed(const asm_x86_processor *proc,  /******************************************************************************  *                                                                             *  *  Paramètres  : proc = architecture visée par la procédure.                  * +*                data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                addr = adresse virtuelle de l'instruction.                   *  *                                                                             * -*  Description : Enregistre toutes les instructions reconnues pour x86.       * +*  Description : Décode une instruction dans un flux de données.              *  *                                                                             * -*  Retour      : -                                                            * +*  Retour      : Instruction mise en place.                                   *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -void x86_register_instructions(asm_x86_processor *proc) +static GArchInstruction *g_x86_processor_decode_instruction(const GX86Processor *proc, const bin_t *data, off_t *pos, off_t len, vmpa_t addr)  { -    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); - -    register_opcode(proc->opcodes[X86_OP_XOR_RM8_R8], 0x30, "xor", x86_read_instr_xor_rm8_with_r8); -    register_opcode_1632(proc->opcodes[X86_OP_XOR_RM1632_R1632], 0x31, "xor", x86_read_instr_xor_rm1632_with_r1632); -    register_opcode(proc->opcodes[X86_OP_XOR_R8_RM8], 0x32, "xor", x86_read_instr_xor_r8_with_rm8); -    register_opcode_1632(proc->opcodes[X86_OP_XOR_R1632_RM1632], 0x33, "xor", x86_read_instr_xor_r1632_with_rm1632); -    register_opcode(proc->opcodes[X86_OP_XOR_AL_IMM8], 0x34, "xor", x86_read_instr_xor_al_with_imm8); -    register_opcode_1632(proc->opcodes[X86_OP_XOR_E_AX_IMM1632], 0x35, "xor", x86_read_instr_xor_e_ax_with_imm1632); - -    register_opcode_1632(proc->opcodes[X86_OP_CMP_RM1632_R1632], 0x39, "cmp", x86_read_instr_cmp_rm1632_with_r1632); - -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_AX], 0x40, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_CX], 0x41, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_DX], 0x42, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_BX], 0x43, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_SP], 0x44, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_BP], 0x45, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_SI], 0x46, "inc", x86_read_instr_inc_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_INC_E_DI], 0x47, "inc", x86_read_instr_inc_r1632); - -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_AX], 0x48, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_CX], 0x49, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_DX], 0x4a, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_BX], 0x4b, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_SP], 0x4c, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_BP], 0x4d, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_SI], 0x4e, "dec", x86_read_instr_dec_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_DEC_E_DI], 0x4f, "dec", x86_read_instr_dec_r1632); - -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_AX], 0x50, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_CX], 0x51, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_DX], 0x52, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_BX], 0x53, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_SP], 0x54, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_BP], 0x55, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_SI], 0x56, "push", x86_read_instr_push_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_E_DI], 0x57, "push", x86_read_instr_push_r1632); - -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_AX], 0x58, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_CX], 0x59, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_DX], 0x5a, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_BX], 0x5b, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_SP], 0x5c, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_BP], 0x5d, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_SI], 0x5e, "pop", x86_read_instr_pop_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_POP_E_DI], 0x5f, "pop", x86_read_instr_pop_r1632); +    GArchInstruction *result;               /* Instruction à renvoyer      */ +    X86Prefix prefix;                       /* Préfixes avec l'instr.      */ +    bool care;                              /* Traitement des opcodes      */ +    X86Opcodes id;                          /* Identifiant d'instruction   */ -    register_opcode_1632(proc->opcodes[X86_OP_PUSH_IMM1632], 0x68, "push", x86_read_instr_push_imm1632); +    id = x86_guess_next_instruction(data, *pos, len, &prefix, &care); -    register_opcode(proc->opcodes[X86_OP_JB_REL8], 0x72, "jb", x86_read_instr_jb_rel8); -    register_opcode(proc->opcodes[X86_OP_JNB_REL8], 0x73, "jnb", x86_read_instr_jnb_rel8); +    if (prefix & XPX_OPERAND_SIZE_OVERRIDE) (*pos)++; -    register_opcode(proc->opcodes[X86_OP_JE_8], 0x74, "je", x86_read_instr_je_8); -    register_opcode(proc->opcodes[X86_OP_JNE_8], 0x75, "jne", x86_read_instr_jne_8); -    register_opcode(proc->opcodes[X86_OP_JG_REL8], 0x7f, "jg", x86_read_instr_jg_rel8); +    if (id != XOP_COUNT && !care) (*pos)++; -    register_opcode_with_ext(proc->opcodes[X86_OP_XOR_RM8_IMM8], 0x80, 6, "xor", x86_read_instr_xor_rm8_with_imm8); -    register_opcode_with_ext(proc->opcodes[X86_OP_CMP_RM8_IMM8], 0x80, 7, "cmp", x86_read_instr_cmp_rm8_with_imm8); +    switch (id) +    { +        case XOP_ADD_RM8_R8: +            result = x86_read_instr_add_rm8_r8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_ADD_RM1632_IMM1632], 0x81, 0, "add", x86_read_instr_add_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_OR_RM1632_IMM1632], 0x81, 1, "or", x86_read_instr_or_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_ADC_RM1632_IMM1632], 0x81, 2, "adc", x86_read_instr_adc_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SBB_RM1632_IMM1632], 0x81, 3, "sbb", x86_read_instr_sbb_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_AND_RM1632_IMM1632], 0x81, 4, "and", x86_read_instr_and_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SUB_RM1632_IMM1632], 0x81, 5, "sub", x86_read_instr_sub_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_XOR_RM1632_IMM1632], 0x81, 6, "xor", x86_read_instr_xor_rm1632_imm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_CMP_RM1632_IMM1632], 0x81, 7, "cmp", x86_read_instr_cmp_rm1632_imm1632); +        case XOP_ADD_RM1632_R1632: +            result = x86_read_instr_add_rm1632_r1632(data, pos, len, addr, prefix, proc); +            break; -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_ADD_RM1632_IMM8], 0x83, 0, "add", x86_read_instr_add_imm8_to_rm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_OR_RM1632_IMM8], 0x83, 1, "or", x86_read_instr_or_rm1632_with_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_ADC_RM1632_IMM8], 0x83, 2, "adc", x86_read_instr_adc_imm8_to_rm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SBB_RM1632_IMM8], 0x83, 3, "sbb", x86_read_instr_sbb_rm1632_with_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_AND_RM1632_IMM8], 0x83, 4, "and", x86_read_instr_and_rm1632_with_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SUB_RM1632_IMM8], 0x83, 5, "sub", x86_read_instr_sub_imm8_from_rm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_XOR_RM1632_IMM8], 0x83, 6, "xor", x86_read_instr_xor_rm1632_with_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_CMP_RM1632_IMM8], 0x83, 7, "cmp", x86_read_instr_cmp_rm1632_with_imm8); +        case XOP_ADD_R8_RM8: +            result = x86_read_instr_add_r8_rm8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode(proc->opcodes[X86_OP_TEST_RM8_R8], 0x84, "test", x86_read_instr_test_rm8_with_r8); -    register_opcode_1632(proc->opcodes[X86_OP_TEST_RM1632_R1632], 0x85, "test", x86_read_instr_test_rm1632_with_r1632); +        case XOP_ADD_R1632_RM1632: +            result = x86_read_instr_add_r1632_rm1632(data, pos, len, addr, prefix, proc); +            break; -    register_opcode(proc->opcodes[X86_OP_MOV_RM8_R8], 0x88, "mov", x86_read_instr_mov_rm8_r8); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_RM1632_R1632], 0x89, "mov", x86_read_instr_mov_r1632_to_rm1632); +        case XOP_ADD_AL_IMM8: +            result = x86_read_instr_add_al_imm8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode_1632(proc->opcodes[X86_OP_MOV_R1632_RM1632], 0x8b, "mov", x86_read_instr_mov_rm1632_to_r1632); +        case XOP_ADD_E_AX_IMM1632: +            result = x86_read_instr_add_e_ax_imm1632(data, pos, len, addr, prefix, proc); +            break; -    register_opcode_1632(proc->opcodes[X86_OP_LEA], 0x8d, "lea", x86_read_instr_lea); -    register_opcode(proc->opcodes[X86_OP_NOP], 0x90, "nop", x86_read_instr_nop); +        case XOP_OR_R8_RM8: +            result = x86_read_instr_or_r8_rm8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode(proc->opcodes[X86_OP_MOV_MOFFS_TO_AL], 0xa0, "mov", x86_read_instr_mov_moffs8_to_al); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_MOFFS_TO_E_AX], 0xa1, "mov", x86_read_instr_mov_moffs1632_to_e_ax); -    register_opcode(proc->opcodes[X86_OP_MOV_AL_TO_MOFFS], 0xa2, "mov", x86_read_instr_mov_al_to_moffs8); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_AX_TO_MOFFS], 0xa3, "mov", x86_read_instr_mov_e_ax_to_moffs1632); +        case XOP_OR_AL_IMM8: +            result = x86_read_instr_or_al_imm8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode(proc->opcodes[X86_OP_TEST_AL], 0xa8, "test", x86_read_instr_test_al); -    register_opcode_1632(proc->opcodes[X86_OP_TEST_E_AX], 0xa9, "test", x86_read_instr_test_e_ax); - -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_AX], 0xb8, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_CX], 0xb9, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_DX], 0xba, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_BX], 0xbb, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_SP], 0xbc, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_BP], 0xbd, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_SI], 0xbe, "mov", x86_read_instr_mov_imm1632_to_r1632); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_E_DI], 0xbf, "mov", x86_read_instr_mov_imm1632_to_r1632); - -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_ROL_RM1632_IMM8], 0xc1, 0, "rol", x86_read_instr_rol_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_ROR_RM1632_IMM8], 0xc1, 1, "ror", x86_read_instr_ror_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_RCL_RM1632_IMM8], 0xc1, 2, "rcl", x86_read_instr_rcl_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_RCR_RM1632_IMM8], 0xc1, 3, "rcr", x86_read_instr_rcr_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SHL_RM1632_IMM8], 0xc1, 4, "shl", x86_read_instr_shl_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SHR_RM1632_IMM8], 0xc1, 5, "shr", x86_read_instr_shr_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SAL_RM1632_IMM8], 0xc1, 6, "sal", x86_read_instr_sal_rm1632_imm8); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SAR_RM1632_IMM8], 0xc1, 7, "sar", x86_read_instr_sar_rm1632_imm8); - -    register_opcode(proc->opcodes[X86_OP_RET], 0xc3, "ret", x86_read_instr_ret); -    register_opcode(proc->opcodes[X86_OP_MOV_IMM8_TO_RM8], 0xc6, "mov", x86_read_instr_mov_imm8_to_rm8); -    register_opcode_1632(proc->opcodes[X86_OP_MOV_IMM1632_TO_RM1632], 0xc7, "mov", x86_read_instr_mov_imm1632_to_rm1632); -    register_opcode(proc->opcodes[X86_OP_LEAVE], 0xc9, "leave", x86_read_instr_leave); -    register_opcode(proc->opcodes[X86_OP_INT_3], 0xcc, "int", x86_read_instr_int_3); -    register_opcode(proc->opcodes[X86_OP_INT], 0xcd, "int", x86_read_instr_int); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_SHL_RM1632_CL], 0xd3, 4, "shl", x86_read_instr_shl_rm1632_cl); +        case XOP_ADC_RM8_R8: +            result = x86_read_instr_adc_rm8_r8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode_1632(proc->opcodes[X86_OP_CALL_REL1632], 0xe8, "call", x86_read_instr_call_rel1632); -    register_opcode_1632(proc->opcodes[X86_OP_JMP_REL1632], 0xe9, "jmp", x86_read_instr_jmp_rel1632); -    register_opcode(proc->opcodes[X86_OP_JMP_8], 0xeb, "jmp", x86_read_instr_jmp_8); +        case XOP_AND_RM8_R8: +            result = x86_read_instr_and_rm8_r8(data, pos, len, addr, prefix, proc); +            break; -    register_opcode(proc->opcodes[X86_OP_HLT], 0xf4, "hlt", x86_read_instr_hlt); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_NOT_RM1632], 0xf7, 7, "not", x86_read_instr_not_rm1632); +        case XOP_SUB_RM1632_R1632: +            result = x86_read_instr_sub_rm1632_r1632(data, pos, len, addr, prefix, proc); +            break; -    register_opcode(proc->opcodes[X86_OP_CLD], 0xfc, "cld", x86_read_instr_cld); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_CALL_RM1632], 0xff, 2, "call", x86_read_instr_call_rm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_JMP_RM1632], 0xff, 4, "jmp", x86_read_instr_jmp_rm1632); -    register_opcode_1632_with_ext(proc->opcodes[X86_OP_PUSH_RM1632], 0xff, 6, "push", x86_read_instr_push_rm1632); +        case XOP_SUB_R8_RM8: +            result = x86_read_instr_sub_r8_rm8(data, pos, len, addr, prefix, proc); +            break; -    register_2b_opcode_1632(proc->opcodes[X86_OP_MOVZX_R1632_RM8], 0xb6, "movzx", x86_read_instr_movzx_r1632_rm8); +        case XOP_SUB_AL_IMM8: +            result = x86_read_instr_sub_al_imm8(data, pos, len, addr, prefix, proc); +            break; -    register_2b_opcode_1632(proc->opcodes[X86_OP_MOVSX_R1632_RM8], 0xbe, "movsx", x86_read_instr_movsx_r1632_rm8); -} +        case XOP_SUB_E_AX_IMM1632: +            result = x86_read_instr_sub_e_ax_imm1632(data, pos, len, addr, prefix, proc); +            break; +        case XOP_XOR_RM8_R8: +            result = x86_read_instr_xor_rm8_r8(data, pos, len, addr, prefix, proc); +            break; -/****************************************************************************** -*                                                                             * -*  Paramètres  : proc   = architecture visée par la procédure.                * -*                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.                 * -*                                                                             * -*  Description : Décode une instruction dans un flux de données.              * -*                                                                             * -*  Retour      : Instruction mise en place ou NULL.                           * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +        case XOP_XOR_RM1632_R1632: +            result = x86_read_instr_xor_rm1632_r1632(data, pos, len, addr, prefix, proc); +            break; -asm_instr *x86_fetch_instruction(const asm_x86_processor *proc, const uint8_t *data, off_t *pos, off_t len, uint64_t offset) -{ -    asm_x86_instr *result;                  /* Résultat à faire remonter   */ -    X86Prefix prefix;                       /* Préfixe détecté             */ -    off_t k;                                /* Itération sur le contenu    */ -    X86Opcodes i;                           /* Boucle de parcours          */ +        case XOP_XOR_R8_RM8: +            result = x86_read_instr_xor_r8_rm8(data, pos, len, addr, prefix, proc); +            break; -    result = NULL; +        case XOP_XOR_R1632_RM1632: +            result = x86_read_instr_xor_r1632_rm1632(data, pos, len, addr, prefix, proc); +            break; -    prefix = X86_PRE_NONE; +        case XOP_XOR_AL_IMM8: +            result = x86_read_instr_xor_al_imm8(data, pos, len, addr, prefix, proc); +            break; -    for (k = *pos; k < len; k++) -        switch (data[k]) -        { -            case 0x66: -                prefix |= X86_PRE_OPSIZE; -                break; +        case XOP_XOR_E_AX_IMM1632: +            result = x86_read_instr_xor_e_ax_imm1632(data, pos, len, addr, prefix, proc); +            break; -            case 0x0f: -                prefix |= X86_PRE_ESCAPE; -                break; -            default: -                goto found_instr; -                break; -        } +        case XOP_CMP_RM1632_R1632: +            result = x86_read_instr_cmp_rm1632_r1632(data, pos, len, addr, prefix, proc); +            break; -    /* Contenu binaire tronqué */ -    return NULL; +        case XOP_INC_E_AX: +        case XOP_INC_E_CX: +        case XOP_INC_E_DX: +        case XOP_INC_E_BX: +        case XOP_INC_E_SP: +        case XOP_INC_E_BP: +        case XOP_INC_E_SI: +        case XOP_INC_E_DI: +            result = x86_read_instr_inc_r1632(data, pos, len, addr, prefix, proc); +            break; - found_instr: +        case XOP_DEC_E_AX: +        case XOP_DEC_E_CX: +        case XOP_DEC_E_DX: +        case XOP_DEC_E_BX: +        case XOP_DEC_E_SP: +        case XOP_DEC_E_BP: +        case XOP_DEC_E_SI: +        case XOP_DEC_E_DI: +            result = x86_read_instr_dec_r1632(data, pos, len, addr, prefix, proc); +            break; -    for (i = 0; i < X86_OP_COUNT; i++) -    { -        if ((prefix & proc->opcodes[i].prefix) != prefix) continue; +        case XOP_PUSH_E_AX: +        case XOP_PUSH_E_CX: +        case XOP_PUSH_E_DX: +        case XOP_PUSH_E_BX: +        case XOP_PUSH_E_SP: +        case XOP_PUSH_E_BP: +        case XOP_PUSH_E_SI: +        case XOP_PUSH_E_DI: +            result = x86_read_instr_push_r1632(data, pos, len, addr, prefix, proc); +            break; -        if (data[k] != proc->opcodes[i].opcode) continue; +        case XOP_POP_E_AX: +        case XOP_POP_E_CX: +        case XOP_POP_E_DX: +        case XOP_POP_E_BX: +        case XOP_POP_E_SP: +        case XOP_POP_E_BP: +        case XOP_POP_E_SI: +        case XOP_POP_E_DI: +            result = x86_read_instr_pop_r1632(data, pos, len, addr, prefix, proc); +            break; -        result = proc->opcodes[i].read(data, pos, len, offset, proc); -        if (result != NULL) result->type = i; -        break; +        case XOP_PUSH_IMM1632: +            result = x86_read_instr_push_imm1632(data, pos, len, addr, prefix, proc); +            break; -    } -    return ASM_INSTRUCTION(result); -} +        case XOP_JO_REL8: +            result = x86_read_instr_jo_rel8(data, pos, len, addr, prefix, proc); +            break; +        case XOP_JNO_REL8: +            result = x86_read_instr_jno_rel8(data, pos, len, addr, prefix, proc); +            break; -/****************************************************************************** -*                                                                             * -*  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.                                * -*                syntax = type de représentation demandée.                    * -*                                                                             * -*  Description : Traduit une instruction en version humainement lisible.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +        case XOP_JB_REL8: +            result = x86_read_instr_jb_rel8(data, pos, len, addr, prefix, proc); +            break; -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][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 */ - -    for (i = 0; i < ASM_INSTRUCTION(instr)->operands_count; 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], 256, syntax); -                break; -            case AOT_IMM: -                print_imm_operand(ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i]), opbuffer[i], 256, syntax); - -                offset = ASM_OPERAND(ASM_INSTRUCTION(instr)->operands[i])->unsigned_imm.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]); - -                    switch (symtype) -                    { -                        case STP_SECTION: -                            if (offset == 0) snprintf(&opbuffer[i][oplen], 256 - oplen, " <%s>", label); -                            else snprintf(&opbuffer[i][oplen], 256 - oplen, " <%s+0x%llx>", label, offset); -                            break; - -                        case STP_STRING: -                            label = escape_crlf(label); -                            snprintf(&opbuffer[i][oplen], 256 - oplen, " \"%s\"", label); -                            break; - -                    } - -                    free(label); - -                } - -                break; -            case AOT_REG: -                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], 256, syntax); -                break; -        } - -    /* Impression globale finale */ - -    if (ASM_INSTRUCTION(instr)->type == AIT_DB) -        snprintf(buffer, len, "db\t%s", opbuffer[0]); - -    else -        switch (ASM_INSTRUCTION(instr)->operands_count) -        { -            case 0: -                snprintf(buffer, len, "%s", proc->opcodes[instr->type].name); -                break; - -            case 1: -                snprintf(buffer, len, "%s\t%s", proc->opcodes[instr->type].name, opbuffer[0]); -                break; - -            case 2: -                switch (syntax) -                { -                    case ASX_INTEL: -                        snprintf(buffer, len, "%s\t%s, %s", proc->opcodes[instr->type].name, opbuffer[0], opbuffer[1]); -                        break; -                    case ASX_ATT: -                        snprintf(buffer, len, "%s\t%s, %s", proc->opcodes[instr->type].name, opbuffer[1], opbuffer[0]); -                        break; -                } -                break; - -        } +        case XOP_JNB_REL8: +            result = x86_read_instr_jnb_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JE_REL8: +            result = x86_read_instr_je_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JNE_REL8: +            result = x86_read_instr_jne_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JNA_REL8: +            result = x86_read_instr_jna_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JA_REL8: +            result = x86_read_instr_ja_rel8(data, pos, len, addr, prefix, proc); +            break; -} +        case XOP_JS_REL8: +            result = x86_read_instr_js_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JNS_REL8: +            result = x86_read_instr_jns_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JP_REL8: +            result = x86_read_instr_jp_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JNP_REL8: +            result = x86_read_instr_jnp_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JL_REL8: +            result = x86_read_instr_jl_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JNL_REL8: +            result = x86_read_instr_jnl_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JNG_REL8: +            result = x86_read_instr_jng_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JG_REL8: +            result = x86_read_instr_jg_rel8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_ADD_RM8_IMM8: +            result = x86_read_instr_add_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_OR_RM8_IMM8: +            result = x86_read_instr_or_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_ADC_RM8_IMM8: +            result = x86_read_instr_adc_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SBB_RM8_IMM8: +            result = x86_read_instr_sbb_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; +        case XOP_AND_RM8_IMM8: +            result = x86_read_instr_and_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; +        case XOP_SUB_RM8_IMM8: +            result = x86_read_instr_sub_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; +        case XOP_XOR_RM8_IMM8: +            result = x86_read_instr_xor_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; +        case XOP_CMP_RM8_IMM8: +            result = x86_read_instr_cmp_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; +        case XOP_ADD_RM1632_IMM1632: +            result = x86_read_instr_add_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; +        case XOP_OR_RM1632_IMM1632: +            result = x86_read_instr_or_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; +        case XOP_ADC_RM1632_IMM1632: +            result = x86_read_instr_adc_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SBB_RM1632_IMM1632: +            result = x86_read_instr_sbb_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_AND_RM1632_IMM1632: +            result = x86_read_instr_and_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SUB_RM1632_IMM1632: +            result = x86_read_instr_sub_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_XOR_RM1632_IMM1632: +            result = x86_read_instr_xor_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_CMP_RM1632_IMM1632: +            result = x86_read_instr_cmp_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + + + + + +        case XOP_ADD_RM1632_IMM8: +            result = x86_read_instr_add_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_OR_RM1632_IMM8: +            result = x86_read_instr_or_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_ADC_RM1632_IMM8: +            result = x86_read_instr_adc_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SBB_RM1632_IMM8: +            result = x86_read_instr_sbb_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_AND_RM1632_IMM8: +            result = x86_read_instr_and_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SUB_RM1632_IMM8: +            result = x86_read_instr_sub_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_XOR_RM1632_IMM8: +            result = x86_read_instr_xor_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_CMP_RM1632_IMM8: +            result = x86_read_instr_cmp_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_TEST_RM8_R8: +            result = x86_read_instr_test_rm8_r8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_TEST_RM1632_R1632: +            result = x86_read_instr_test_rm1632_r1632(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_MOV_RM8_R8: +            result = x86_read_instr_mov_rm8_r8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_MOV_RM1632_R1632: +            result = x86_read_instr_mov_rm1632_r1632(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_MOV_R1632_RM1632: +            result = x86_read_instr_mov_r1632_rm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_LEA_R1632_M: +            result = x86_read_instr_lea_r1632_m(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_NOP: +            result = x86_read_instr_nop(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_XCHG_R1632_E_AX: +        case XOP_XCHG_R1632_E_CX: +        case XOP_XCHG_R1632_E_DX: +        case XOP_XCHG_R1632_E_BX: +        case XOP_XCHG_R1632_E_SP: +        case XOP_XCHG_R1632_E_BP: +        case XOP_XCHG_R1632_E_SI: +        case XOP_XCHG_R1632_E_DI: +            result = x86_read_instr_xchg_r1632_e_ax(data, pos, len, addr, prefix, proc); +            break; + + + +        case XOP_MOV_AL_MOFFS8: +            result = x86_read_instr_mov_al_moffs8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_MOV_E_AX_MOFFS1632: +            result = x86_read_instr_mov_e_ax_moffs1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_MOV_MOFFS8_AL: +            result = x86_read_instr_mov_moffs8_al(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_MOV_MOFFS1632_E_AX: +            result = x86_read_instr_mov_moffs1632_e_ax(data, pos, len, addr, prefix, proc); +            break; + + + +        case XOP_TEST_AL_IMM8: +            result = x86_read_instr_test_al_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_TEST_E_AX_IMM1632: +            result = x86_read_instr_test_e_ax_imm1632(data, pos, len, addr, prefix, proc); +            break; + + + + +        case XOP_MOV_E_AX_IMM1632: +        case XOP_MOV_E_CX_IMM1632: +        case XOP_MOV_E_DX_IMM1632: +        case XOP_MOV_E_BX_IMM1632: +        case XOP_MOV_E_SP_IMM1632: +        case XOP_MOV_E_BP_IMM1632: +        case XOP_MOV_E_SI_IMM1632: +        case XOP_MOV_E_DI_IMM1632: +            result = x86_read_instr_mov_r1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + + + + +        case XOP_ROL_RM1632_IMM8: +            result = x86_read_instr_rol_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_ROR_RM1632_IMM8: +            result = x86_read_instr_ror_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_RCL_RM1632_IMM8: +            result = x86_read_instr_rcl_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_RCR_RM1632_IMM8: +            result = x86_read_instr_rcr_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SHL_RM1632_IMM8: +            result = x86_read_instr_shl_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SHR_RM1632_IMM8: +            result = x86_read_instr_shr_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SAL_RM1632_IMM8: +            result = x86_read_instr_sal_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_SAR_RM1632_IMM8: +            result = x86_read_instr_sar_rm1632_imm8(data, pos, len, addr, prefix, proc); +            break; + + + + + + +        case XOP_RET: +            result = x86_read_instr_ret(data, pos, len, addr, prefix, proc); +            break; + + + +        case XOP_MOV_RM8_IMM8: +            result = x86_read_instr_mov_rm8_imm8(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_MOV_RM1632_IMM1632: +            result = x86_read_instr_mov_rm1632_imm1632(data, pos, len, addr, prefix, proc); +            break; + + + + +        case XOP_LEAVE: +            result = x86_read_instr_leave(data, pos, len, addr, prefix, proc); +            break; + + + +        case XOP_INT_3: +            result = x86_read_instr_int_3(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_INT: +            result = x86_read_instr_int(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_SHL_RM1632_CL: +            result = x86_read_instr_shl_rm1632_cl(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_CALL_REL1632: +            result = x86_read_instr_call_rel1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JMP_REL1632: +            result = x86_read_instr_jmp_rel1632(data, pos, len, addr, prefix, proc); +            break; + + + +        case XOP_JMP_REL8: +            result = x86_read_instr_jmp_rel8(data, pos, len, addr, prefix, proc); +            break; + + + +        case XOP_HLT: +            result = x86_read_instr_hlt(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_NOT_RM1632: +            result = x86_read_instr_not_rm1632(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_CLD: +            result = x86_read_instr_cld(data, pos, len, addr, prefix, proc); +            break; + + +        case XOP_CALL_RM1632: +            result = x86_read_instr_call_rm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_JMP_RM1632: +            result = x86_read_instr_jmp_rm1632(data, pos, len, addr, prefix, proc); +            break; + +        case XOP_PUSH_RM1632: +            result = x86_read_instr_push_rm1632(data, pos, len, addr, prefix, proc); +            break; + +        default: +            result = NULL; +            break; + +    } + +    return result; + +} diff --git a/src/arch/x86/processor.h b/src/arch/x86/processor.h index 036966f..1014d11 100644 --- a/src/arch/x86/processor.h +++ b/src/arch/x86/processor.h @@ -25,24 +25,32 @@  #define _ARCH_X86_PROCESSOR_H -#include "../instruction.h"  #include "../processor.h" +#include "instruction.h" -/* Définition générique d'une architecture */ -typedef struct _asm_x86_processor asm_x86_processor; +#define G_TYPE_X86_PROCESSOR                g_x86_processor_get_type() +#define G_X86_PROCESSOR(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_processor_get_type(), GX86Processor)) +#define G_IS_X86_PROCESSOR(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_processor_get_type())) +#define G_X86_PROCESSOR_GET_IFACE(inst)     (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_processor_get_type(), GX86ProcessorIface)) -/* Crée le support de l'architecture x86. */ -asm_processor *create_x86_processor(void); +/* Définition du processeur de la x86 (instance) */ +typedef struct _GX86Processor GX86Processor; -/* Fournit la taille courante des opérandes pour x86. */ -AsmOperandSize get_x86_current_operand_size(const asm_x86_processor *); +/* Définition du processeur de la x86 (classe) */ +typedef struct _GX86ProcessorClass GX86ProcessorClass; -/* Fournit la taille supplantée des opérandes pour x86. */ -AsmOperandSize switch_x86_operand_size_if_needed(const asm_x86_processor *, const uint8_t *, off_t *); +/* Indique le type défini par la GLib pour le processeur x86. */ +GType g_x86_processor_get_type(void); + +/* Crée le support de l'architecture x86. */ +GArchProcessor *g_x86_processor_new(void); + +/* Fournit la taille supplantée des opérandes pour x86. */ +AsmOperandSize g_x86_processor_get_operand_size(const GX86Processor *, X86Prefix);  | 
