diff options
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/Makefile.am | 2 | ||||
| -rw-r--r-- | src/arch/immediate.c | 71 | ||||
| -rw-r--r-- | src/arch/link.c | 22 | ||||
| -rw-r--r-- | src/arch/target.c | 89 | ||||
| -rw-r--r-- | src/arch/target.h | 3 | ||||
| -rw-r--r-- | src/arch/targetableop-int.h | 51 | ||||
| -rw-r--r-- | src/arch/targetableop.c | 85 | ||||
| -rw-r--r-- | src/arch/targetableop.h | 61 | 
8 files changed, 346 insertions, 38 deletions
diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am index 8710b13..b600557 100644 --- a/src/arch/Makefile.am +++ b/src/arch/Makefile.am @@ -20,6 +20,8 @@ libarch_la_SOURCES =					\  	register.h register.c				\  	storage.h storage.c					\  	target.h target.c					\ +	targetableop-int.h					\ +	targetableop.h targetableop.c		\  	undefined.h undefined.c				\  	vmpa.h vmpa.c diff --git a/src/arch/immediate.c b/src/arch/immediate.c index 1c084ea..5519059 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -38,6 +38,7 @@  #include "operand-int.h" +#include "targetableop-int.h"  #include "../common/asm.h"  #include "../common/extstr.h"  #include "../format/format.h" @@ -86,6 +87,9 @@ static void g_imm_operand_class_init(GImmOperandClass *);  /* Initialise la classe des lignes de descriptions initiales. */  static void g_imm_operand_init(GImmOperand *); +/* Procède à l'initialisation de l'interface de ciblage. */ +static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface *); +  /* Supprime toutes les références externes. */  static void g_imm_operand_dispose(GImmOperand *); @@ -120,8 +124,17 @@ static bool g_imm_operand_serialize(const GImmOperand *, GAsmStorage *, packed_b +/* ----------------------- INTERFACE DE CIBLAGE POUR OPERANDE ----------------------- */ + + +/* Obtient l'adresse de la cible visée par un opérande. */ +static bool g_imm_operand_get_addr(const GImmOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *); + + +  /* Indique le type défini pour un opérande de valeur numérique. */ -G_DEFINE_TYPE(GImmOperand, g_imm_operand, G_TYPE_ARCH_OPERAND); +G_DEFINE_TYPE_WITH_CODE(GImmOperand, g_imm_operand, G_TYPE_ARCH_OPERAND, +                        G_IMPLEMENT_INTERFACE(G_TYPE_TARGETABLE_OPERAND, g_imm_operand_targetable_interface_init)); @@ -182,6 +195,25 @@ static void g_imm_operand_init(GImmOperand *operand)  /******************************************************************************  *                                                                             * +*  Paramètres  : iface = interface GLib à initialiser.                        * +*                                                                             * +*  Description : Procède à l'initialisation de l'interface de ciblage.        * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface *iface) +{ +    iface->get_addr = (get_targetable_addr_fc)g_imm_operand_get_addr; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : operand = instance d'objet GLib à traiter.                   *  *                                                                             *  *  Description : Supprime toutes les références externes.                     * @@ -1464,3 +1496,40 @@ static bool g_imm_operand_serialize(const GImmOperand *operand, GAsmStorage *sto      return result;  } + + + +/* ---------------------------------------------------------------------------------- */ +/*                         INTERFACE DE CIBLAGE POUR OPERANDE                         */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = operande à consulter.                              * +*                src     = localisation de l'instruction mère.                * +*                format  = format reconnu pour le binaire chargé.             * +*                proc    = architecture associée à ce même binaire.           * +*                addr    = localisation de la cible. [OUT]                    * +*                                                                             * +*  Description : Obtient l'adresse de la cible visée par un opérande.         * +*                                                                             * +*  Retour      : true si la cible est valide, false sinon.                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_imm_operand_get_addr(const GImmOperand *operand, const vmpa2t *src, GBinFormat *format, GArchProcessor *proc, vmpa2t *addr) +{ +    bool result;                            /* Bilan à retourner           */ +    virt_t virt;                            /* Adresse virtuelle           */ + +    result = g_imm_operand_to_virt_t(operand, &virt); + +    if (result) +        result = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), virt, addr); + +    return result; + +} diff --git a/src/arch/link.c b/src/arch/link.c index c11fe54..f09621e 100644 --- a/src/arch/link.c +++ b/src/arch/link.c @@ -27,7 +27,7 @@  #include <assert.h> -#include "target.h" +#include "targetableop.h" @@ -99,11 +99,10 @@ void handle_jump_as_link(GArchInstruction *instr, GArchProcessor *proc, GProcCon  void handle_branch_as_link(GArchInstruction *instr, GArchProcessor *proc, GProcContext *context, GExeFormat *format, size_t index)  {      GArchOperand *op;                       /* Opérande numérique en place */ +    const mrange_t *range;                  /* Emplacement de l'instruction*/      bool defined;                           /* Adresse définie ?           */      vmpa2t addr;                            /* Adresse de destination      */ -    virt_t virt;                            /* Adresse virtuelle           */      GArchInstruction *target;               /* Ligne visée par la référence*/ -    const mrange_t *range;                  /* Emplacement d'instruction   */      vmpa2t next;                            /* Position suivante           */      g_arch_instruction_lock_operands(instr); @@ -114,20 +113,17 @@ void handle_branch_as_link(GArchInstruction *instr, GArchProcessor *proc, GProcC      g_arch_instruction_unlock_operands(instr); -    defined = false; - -    if (G_IS_TARGET_OPERAND(op)) +    if (G_IS_TARGETABLE_OPERAND(op))      { -        g_target_operand_get_addr(G_TARGET_OPERAND(op), &addr); -        defined = true; -    } +        range = g_arch_instruction_get_range(instr); -    else if (G_IS_IMM_OPERAND(op)) -    { -        if (g_imm_operand_to_virt_t(G_IMM_OPERAND(op), &virt)) -            defined = g_exe_format_translate_address_into_vmpa(format, virt, &addr); +        defined = g_targetable_operand_get_addr(G_TARGETABLE_OPERAND(op), get_mrange_addr(range), +                                                G_BIN_FORMAT(format), proc, &addr);      } +    else +        defined = false; +      g_object_unref(G_OBJECT(op));      if (defined) diff --git a/src/arch/target.c b/src/arch/target.c index 97b2192..6872efe 100644 --- a/src/arch/target.c +++ b/src/arch/target.c @@ -33,6 +33,7 @@  #include "operand-int.h" +#include "targetableop-int.h"  #include "../analysis/routine.h"  #include "../common/extstr.h"  #include "../format/format.h" @@ -69,6 +70,9 @@ static void g_target_operand_class_init(GTargetOperandClass *);  /* Initialise la classe des opérandes ciblant des symboles. */  static void g_target_operand_init(GTargetOperand *); +/* Procède à l'initialisation de l'interface de ciblage. */ +static void g_target_operand_targetable_interface_init(GTargetableOperandInterface *); +  /* Supprime toutes les références externes. */  static void g_target_operand_dispose(GTargetOperand *); @@ -97,8 +101,17 @@ static bool g_target_operand_serialize(const GTargetOperand *, GAsmStorage *, pa +/* ----------------------- INTERFACE DE CIBLAGE POUR OPERANDE ----------------------- */ + + +/* Obtient l'adresse de la cible visée par un opérande. */ +static bool g_target_operand_get_addr(const GTargetOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *); + + +  /* Indique le type défini pour un opérande de valeur numérique. */ -G_DEFINE_TYPE(GTargetOperand, g_target_operand, G_TYPE_ARCH_OPERAND); +G_DEFINE_TYPE_WITH_CODE(GTargetOperand, g_target_operand, G_TYPE_ARCH_OPERAND, +                        G_IMPLEMENT_INTERFACE(G_TYPE_TARGETABLE_OPERAND, g_target_operand_targetable_interface_init)); @@ -161,6 +174,25 @@ static void g_target_operand_init(GTargetOperand *operand)  /******************************************************************************  *                                                                             * +*  Paramètres  : iface = interface GLib à initialiser.                        * +*                                                                             * +*  Description : Procède à l'initialisation de l'interface de ciblage.        * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_target_operand_targetable_interface_init(GTargetableOperandInterface *iface) +{ +    iface->get_addr = (get_targetable_addr_fc)g_target_operand_get_addr; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : operand = instance d'objet GLib à traiter.                   *  *                                                                             *  *  Description : Supprime toutes les références externes.                     * @@ -452,26 +484,6 @@ MemoryDataSize g_target_operand_get_size(const GTargetOperand *operand)  /******************************************************************************  *                                                                             * -*  Paramètres  : operand = structure dont le contenu est à consulter.         * -*                addr    = localisation à renseigner. [OUT]                   * -*                                                                             * -*  Description : Fournit l'adresse en mémoire de l'élément visé.              * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_target_operand_get_addr(const GTargetOperand *operand, vmpa2t *addr) -{ -    copy_vmpa(addr, &operand->addr); - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : operand = opérande dont le contenu est à raffiner. [OUT]     *  *                format  = format du binaire d'origine à consulter.           *  *                strict  = indique la perfection attendue de la résolution.   * @@ -659,3 +671,38 @@ static bool g_target_operand_serialize(const GTargetOperand *operand, GAsmStorag      return result;  } + + + +/* ---------------------------------------------------------------------------------- */ +/*                         INTERFACE DE CIBLAGE POUR OPERANDE                         */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = operande à consulter.                              * +*                src     = localisation de l'instruction mère.                * +*                format  = format reconnu pour le binaire chargé.             * +*                proc    = architecture associée à ce même binaire.           * +*                addr    = localisation de la cible. [OUT]                    * +*                                                                             * +*  Description : Obtient l'adresse de la cible visée par un opérande.         * +*                                                                             * +*  Retour      : true si la cible est valide, false sinon.                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_target_operand_get_addr(const GTargetOperand *operand, const vmpa2t *src, GBinFormat *format, GArchProcessor *proc, vmpa2t *addr) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = true; + +    copy_vmpa(addr, &operand->addr); + +    return result; + +} diff --git a/src/arch/target.h b/src/arch/target.h index 3c68fda..f7a673c 100644 --- a/src/arch/target.h +++ b/src/arch/target.h @@ -59,9 +59,6 @@ GArchOperand *g_target_operand_new(MemoryDataSize, const vmpa2t *);  /* Renseigne la taille de la valeur indiquée à la construction. */  MemoryDataSize g_target_operand_get_size(const GTargetOperand *); -/* Fournit l'adresse en mémoire de l'élément visé. */ -void g_target_operand_get_addr(const GTargetOperand *, vmpa2t *); -  /* Tente une résolution de symbole. */  bool g_target_operand_resolve(GTargetOperand *, GBinFormat *, bool); diff --git a/src/arch/targetableop-int.h b/src/arch/targetableop-int.h new file mode 100644 index 0000000..9afce11 --- /dev/null +++ b/src/arch/targetableop-int.h @@ -0,0 +1,51 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * targetableop-int.h - définitions internes propres aux opérandes ciblant une portion de désassemblage + * + * Copyright (C) 2018 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GLIBEXT_TARGETABLEOP_INT_H +#define _GLIBEXT_TARGETABLEOP_INT_H + + +#include "targetableop.h" + + + +/* Obtient l'adresse de la cible visée par un opérande. */ +typedef bool (* get_targetable_addr_fc) (const GTargetableOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *); + + +/* Opérande ciblant une portion de désassemblage (interface) */ +struct _GTargetableOperandIface +{ +    GTypeInterface base_iface;              /* A laisser en premier        */ + +    get_targetable_addr_fc get_addr;        /* Obtention de la cible       */ + +}; + + +/* Redéfinition */ +typedef GTargetableOperandIface GTargetableOperandInterface; + + + +#endif  /* _GLIBEXT_TARGETABLEOP_INT_H */ diff --git a/src/arch/targetableop.c b/src/arch/targetableop.c new file mode 100644 index 0000000..eab26a8 --- /dev/null +++ b/src/arch/targetableop.c @@ -0,0 +1,85 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * targetableop.c - opérandes ciblant une portion de désassemblage + * + * Copyright (C) 2018 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "targetableop.h" + + +#include "targetableop-int.h" + + + +/* Procède à l'initialisation de l'interface de ciblage. */ +static void g_targetable_operand_default_init(GTargetableOperandInterface *); + + + +/* Détermine le type d'une interface pour le ciblage d'une portion de désassemblage. */ +G_DEFINE_INTERFACE(GTargetableOperand, g_targetable_operand, G_TYPE_OBJECT) + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : iface = interface GLib à initialiser.                        * +*                                                                             * +*  Description : Procède à l'initialisation de l'interface de ciblage.        * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_targetable_operand_default_init(GTargetableOperandInterface *iface) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = operande à consulter.                              * +*                src     = localisation de l'instruction mère.                * +*                format  = format reconnu pour le binaire chargé.             * +*                proc    = architecture associée à ce même binaire.           * +*                addr    = localisation de la cible. [OUT]                    * +*                                                                             * +*  Description : Obtient l'adresse de la cible visée par un opérande.         * +*                                                                             * +*  Retour      : true si la cible est valide, false sinon.                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_targetable_operand_get_addr(const GTargetableOperand *operand, const vmpa2t *src, GBinFormat *format, GArchProcessor *proc, vmpa2t *addr) +{ +    bool result;                            /* Bilan à retourner           */ +    GTargetableOperandIface *iface;         /* Interface utilisée          */ + +    iface = G_TARGETABLE_OPERAND_GET_IFACE(operand); + +    result = iface->get_addr(operand, src, format, proc, addr); + +    return result; + +} diff --git a/src/arch/targetableop.h b/src/arch/targetableop.h new file mode 100644 index 0000000..f6cc7bf --- /dev/null +++ b/src/arch/targetableop.h @@ -0,0 +1,61 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * targetableop.h - prototypes pour les opérandes ciblant une portion de désassemblage + * + * Copyright (C) 2018 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GLIBEXT_TARGETABLEOP_H +#define _GLIBEXT_TARGETABLEOP_H + + +#include <glib-object.h> +#include <stdbool.h> + + +#include "vmpa.h" +#include "../arch/processor.h" +#include "../format/format.h" + + + +#define G_TYPE_TARGETABLE_OPERAND             (g_targetable_operand_get_type()) +#define G_TARGETABLE_OPERAND(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_TARGETABLE_OPERAND, GTargetableOperand)) +#define G_TARGETABLE_OPERAND_CLASS(vtable)    (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_TARGETABLE_OPERAND, GTargetableOperandIface)) +#define G_IS_TARGETABLE_OPERAND(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_TARGETABLE_OPERAND)) +#define G_IS_TARGETABLE_OPERAND_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_TARGETABLE_OPERAND)) +#define G_TARGETABLE_OPERAND_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_TARGETABLE_OPERAND, GTargetableOperandIface)) + + +/* Opérande ciblant une portion de désassemblage (coquille vide) */ +typedef struct _GTargetableOperand GTargetableOperand; + +/* Opérande ciblant une portion de désassemblage (interface) */ +typedef struct _GTargetableOperandIface GTargetableOperandIface; + + +/* Détermine le type d'une interface pour le ciblage d'une portion de désassemblage. */ +GType g_targetable_operand_get_type(void) G_GNUC_CONST; + +/* Obtient l'adresse de la cible visée par un opérande. */ +bool g_targetable_operand_get_addr(const GTargetableOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *); + + + +#endif  /* _GLIBEXT_TARGETABLEOP_H */  | 
