/* OpenIDA - Outil d'analyse de fichiers binaires * operand.h - prototypes pour la gestion des operandes de l'architecture x86 * * Copyright (C) 2008 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 . */ #ifndef _ARCH_X86_OPERAND_H #define _ARCH_X86_OPERAND_H #include #include #include "instruction.h" /* Définition d'une opérande x86 */ typedef struct _asm_x86_operand asm_x86_operand; /* Crée une opérande vierge pour x86. */ asm_x86_operand *create_new_x86_operand(void); /* 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); /* 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); /* 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, ...); /* 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, ...); /* Traduit une opérande de registre en texte. */ void x86_print_reg_operand(const asm_x86_operand *, char *, size_t, AsmSyntax); /* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ /* 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); /* 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); /* ------------------------- 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); /* 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); /* ------------------------- AIDE A LA CREATION D'OPERANDES ------------------------- */ /* Construction d'identifiants typés */ #define X86_OTP_IMM_TYPE 0x8000 #define X86_OTP_REG_TYPE 0x4000 #define X86_OTP_RM_TYPE 0x2000 #define X86_OTP_IMM(b) X86_OTP_IMM_TYPE | (1 << b) #define X86_OTP_REG(b) X86_OTP_REG_TYPE | (1 << b) #define X86_OTP_RM(b) X86_OTP_RM_TYPE | (1 << b) /* Types d'opérandes supportés */ typedef enum _X86OperandType { X86_OTP_IMM8 = X86_OTP_IMM(1), /* Valeur immédiate sur 8 bits */ X86_OTP_IMM1632 = X86_OTP_IMM(2), /* Valeur immédiate sur 16/32b */ X86_OTP_MOFFS8 = X86_OTP_IMM(3), /* Décallage immédiat 8 bits */ X86_OTP_MOFFS1632 = X86_OTP_IMM(4), /* Décallage immédiat 16/32b */ X86_OTP_REL8 = X86_OTP_IMM(5), /* Adresse relative 8 bits */ X86_OTP_REL1632 = X86_OTP_IMM(6), /* Adresse relative 16/32 bits */ X86_OTP_R8 = X86_OTP_REG(1), /* Registre 8 bits */ X86_OTP_R1632 = X86_OTP_REG(2), /* Registre 16 ou 32 bits */ X86_OTP_OP_R1632 = X86_OTP_REG(3), /* Registre 16 ou 32 bits */ X86_OTP_RM8 = X86_OTP_RM(1), /* Registre 8 bits ou mémoire */ X86_OTP_RM1632 = X86_OTP_RM(2), /* Registre 16/32b ou mémoire */ X86_OTP_CL = 0x0ffd, /* Registre cl */ X86_OTP_AL = 0x0ffe, /* Registre al */ X86_OTP_E_AX = 0x0fff /* Registre eax ou ax */ } 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, ...); /* 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, ...); #endif /* _ARCH_X86_OPERAND_H */