/* Chrysalide - Outil d'analyse de fichiers binaires
* operand.h - prototypes pour la gestion des operandes de l'architecture x86
*
* Copyright (C) 2008-2017 Cyrille Bagard
*
* This file is part of Chrysalide.
*
* Chrysalide 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.
*
* Chrysalide 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 "operands/data.h"
#include "operands/modrm.h"
#include "operands/moffs.h"
#include "operands/register.h"
#include "operands/relative.h"
#include "../instruction.h"
/* 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_DATA_TYPE 0x1000
#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)
#define X86_OTP_DATA(b) X86_OTP_DATA_TYPE | (1 << b)
/* Types d'opérandes supportés */
typedef enum _X86OperandType
{
X86_OTP_NONE = 0, /* Aucun opérande de prévu */
X86_OTP_IMM8 = X86_OTP_IMM(1), /* Valeur immédiate sur 8 bits */
X86_OTP_IMM16 = X86_OTP_IMM(2), /* Valeur immédiate sur 16b */
X86_OTP_IMM1632 = X86_OTP_IMM(3), /* Valeur immédiate sur 16/32b */
X86_OTP_MOFFS8 = X86_OTP_IMM(4), /* Décallage immédiat 8 bits */
X86_OTP_MOFFS1632 = X86_OTP_IMM(5), /* Décallage immédiat 16/32b */
X86_OTP_REL8 = X86_OTP_IMM(6), /* Adresse relative 8 bits */
X86_OTP_REL1632 = X86_OTP_IMM(7), /* 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_R8 = X86_OTP_REG(3), /* Registre 8 bits */
X86_OTP_OP_R1632 = X86_OTP_REG(4), /* Registre 16 ou 32 bits */
X86_OTP_RM8 = X86_OTP_RM(1), /* Registre 8 bits ou mémoire */
X86_OTP_RM16 = X86_OTP_RM(2), /* Registre 16 bits ou mémoire */
X86_OTP_RM1632 = X86_OTP_RM(3), /* Registre 16/32b ou mémoire */
X86_OTP_DST_8 = X86_OTP_DATA(1), /* Emplacement sur 8 bits */
X86_OTP_DST_1632 = X86_OTP_DATA(2), /* Emplacement sur 16/32 bits */
X86_OTP_SRC_8 = X86_OTP_DATA(3), /* Emplacement sur 8 bits */
X86_OTP_SRC_1632 = X86_OTP_DATA(4), /* Emplacement sur 16/32 bits */
X86_OTP_ONE = 0x0ffc, /* Valeur immédiate "1" */
X86_OTP_CL = 0x0ffd, /* Registre cl */
X86_OTP_AL = 0x0ffe, /* Registre al */
X86_OTP_E_AX = 0x0fff /* Registre eax ou ax */
} X86OperandType;
/* Nombre maximal d'opérande */
#define MAX_OPERANDS 3
#define x86_read_one_operand(instr, data, pos, len, ...) _x86_read_operands(instr, data, pos, len, 1, __VA_ARGS__)
#define x86_read_two_operands(instr, data, pos, len, ...) _x86_read_operands(instr, data, pos, len, 2, __VA_ARGS__)
#define x86_read_three_operands(instr, data, pos, len, ...) _x86_read_operands(instr, data, pos, len, 3, __VA_ARGS__)
/* Procède à la lecture de n opérandes donnés. */
bool _x86_read_operands(GArchInstruction *, const bin_t *, off_t *, off_t, unsigned int, ...);
#endif /* _ARCH_X86_OPERAND_H */