diff options
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/dalvik/Makefile.am | 5 | ||||
| -rw-r--r-- | src/arch/dalvik/operand.c | 1008 | ||||
| -rw-r--r-- | src/arch/dalvik/operand.h | 154 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/Makefile.am | 20 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/args.c | 189 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/args.h | 61 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/pool.c | 240 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/pool.h | 79 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/register.c | 212 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/register.h | 59 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/target.c | 194 | ||||
| -rw-r--r-- | src/arch/dalvik/operands/target.h | 61 | ||||
| -rw-r--r-- | src/arch/dalvik/register.c | 96 | ||||
| -rw-r--r-- | src/arch/dalvik/register.h | 4 | ||||
| -rw-r--r-- | src/arch/immediate.c | 2 | ||||
| -rw-r--r-- | src/arch/instruction.c | 83 | ||||
| -rw-r--r-- | src/arch/instruction.h | 9 | 
17 files changed, 1233 insertions, 1243 deletions
diff --git a/src/arch/dalvik/Makefile.am b/src/arch/dalvik/Makefile.am index fbd041d..e8406b9 100644 --- a/src/arch/dalvik/Makefile.am +++ b/src/arch/dalvik/Makefile.am @@ -44,6 +44,9 @@ libarchdalvik_la_SOURCES =				\  	register.h register.c				\  	translate.h +libarchdalvik_la_LIBADD =				\ +	operands/libarchdalvikoperands.la +  libarchdalvik_la_CFLAGS = $(AM_CFLAGS) @@ -54,4 +57,4 @@ AM_CPPFLAGS =  AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS =  +SUBDIRS = operands diff --git a/src/arch/dalvik/operand.c b/src/arch/dalvik/operand.c index 3227184..f6392b3 100644 --- a/src/arch/dalvik/operand.c +++ b/src/arch/dalvik/operand.c @@ -1,6 +1,6 @@  /* OpenIDA - Outil d'analyse de fichiers binaires - * operand.c - gestion des operandes de l'architecture Dalvik + * operand.c - aide à la création d'opérandes Dalvik   *   * Copyright (C) 2010 Cyrille Bagard   * @@ -28,186 +28,6 @@  #include <stdarg.h> -#include "register.h" -#include "../operand-int.h" - - - -/* ----------------------- COQUILLE VIDE POUR OPERANDE DALVIK ----------------------- */ - - -/* Définition d'un opérande de Dalvik (instance) */ -struct _GDalvikOperand -{ -    GArchOperand parent;                    /* Instance parente            */ - -}; - - -/* Définition d'un opérande de Dalvik (classe) */ -struct _GDalvikOperandClass -{ -    GArchOperandClass parent;               /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes Dalvik de base. */ -static void g_dalvik_operand_class_init(GDalvikOperandClass *); - -/* Initialise une instance d'opérande de base pour Dalvik. */ -static void g_dalvik_operand_init(GDalvikOperand *); - - - -/* --------------------- OPERANDES VISANT UN REGISTRE DE DALVIK --------------------- */ - - -/* Définition d'un opérande visant un registre Dalvik (instance) */ -struct _GDalvikRegisterOperand -{ -    GDalvikOperand parent;                  /* Instance parente            */ - -    GDalvikRegister *reg;                   /* Registre représenté         */ - -}; - - -/* Définition d'un opérande visant un registre Dalvik (classe) */ -struct _GDalvikRegisterOperandClass -{ -    GDalvikOperandClass parent;             /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes de registre Dalvik. */ -static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *); - -/* Initialise une instance d'opérande de registre Dalvik. */ -static void g_dalvik_register_operand_init(GDalvikRegisterOperand *); - -/* Compare un opérande avec un autre. */ -static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *, const GDalvikRegisterOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_dalvik_register_operand_add_text(const GDalvikRegisterOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_dalvik_register_operand_to_buffer(const GDalvikRegisterOperand *, GBufferLine *, GRenderingOptions *); - - - -/* -------------------- LISTE D'OPERANDES RASSEMBLES EN ARGUMENT -------------------- */ - - - -/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ -struct _GDalvikArgsOperand -{ -    GDalvikOperand parent;                  /* Instance parente            */ - -    GArchOperand **args;                    /* Liste d'arguments           */ -    size_t count;                           /* Taille de cette liste       */ - -}; - - -/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ -struct _GDalvikArgsOperandClass -{ -    GDalvikOperandClass parent;                /* Classe parente              */ - -}; - - -/* Initialise la classe des listes d'opérandes Dalvik. */ -static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *); - -/* Initialise une instance de liste d'opérandes Dalvik. */ -static void g_dalvik_args_operand_init(GDalvikArgsOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_dalvik_args_operand_add_text(const GDalvikArgsOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_dalvik_args_operand_to_buffer(const GDalvikArgsOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ----------------- OPERANDES POINTANT VERS LA TABLE DE CONSTANTES ----------------- */ - - -/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */ -struct _GDalvikPoolOperand -{ -    GDalvikOperand parent;                  /* Instance parente            */ - -    DalvikPoolType type;                    /* Type de table visée         */ -    uint32_t index;                         /* Indice de l'élément visé    */ - -}; - - -/* Définition d'un opérande visant un élément de table de constantes Dalvik (classe) */ -struct _GDalvikPoolOperandClass -{ -    GDalvikOperandClass parent;             /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes de constante Dalvik. */ -static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *); - -/* Initialise une instance d'opérande de constante Dalvik. */ -static void g_dalvik_pool_operand_init(GDalvikPoolOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_dalvik_pool_operand_add_text(const GDalvikPoolOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_dalvik_pool_operand_to_buffer(const GDalvikPoolOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ---------------------- OPERANDES VISANT UNE ADRESSE DE CODE ---------------------- */ - - -/* Définition d'un opérande visant une adresse de code Dalvik (instance) */ -struct _GDalvikTargetOperand -{ -    GDalvikOperand parent;                  /* Instance parente            */ - -    GImmOperand *immediate;                 /* Adresse visée reconstituée  */ - -}; - - -/* Définition d'un opérande visant une adresse de code Dalvik (classe) */ -struct _GDalvikTargetOperandClass -{ -    GDalvikOperandClass parent;             /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes de ciblage de code Dalvik. */ -static void g_dalvik_target_operand_class_init(GDalvikTargetOperandClass *); - -/* Initialise une instance d'opérande de ciblage de code Dalvik. */ -static void g_dalvik_target_operand_init(GDalvikTargetOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_dalvik_target_operand_add_text(const GDalvikTargetOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_dalvik_target_operand_to_buffer(const GDalvikTargetOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ------------------------- AIDE A LA CREATION D'OPERANDES ------------------------- */ -  /* Liste de tous les types d'opérandes */  typedef enum _DalvikOperandID @@ -241,832 +61,6 @@ static bool dalvik_read_fixed_operands(GArchInstruction *, const bin_t *, off_t -/* ---------------------------------------------------------------------------------- */ -/*                         COQUILLE VIDE POUR OPERANDE DALVIK                         */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de Dalvik. */ -G_DEFINE_TYPE(GDalvikOperand, g_dalvik_operand, G_TYPE_ARCH_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes Dalvik de base.           * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_operand_class_init(GDalvikOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande de base pour Dalvik.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_operand_init(GDalvikOperand *operand) -{ - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                       OPERANDES VISANT UN REGISTRE DE DALVIK                       */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */ -G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_DALVIK_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes de registre Dalvik.       * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande de registre Dalvik.       * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_register_operand_init(GDalvikRegisterOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente #1         */ -    GArchOperand *arch;                     /* Instance parente #2         */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_dalvik_register_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_dalvik_register_operand_to_buffer; - -    arch = G_ARCH_OPERAND(operand); - -    arch->compare = (operand_compare_fc)g_dalvik_register_operand_compare; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : data   = flux de données à analyser.                         * -*                pos    = position courante dans ce flux. [OUT]               * -*                len    = taille totale des données à analyser.               * -*                low    = position éventuelle des 4 bits visés. [OUT]         * -*                size   = taille de l'opérande, et donc du registre.          * -*                endian = ordre des bits dans la source.                      * -*                                                                             * -*  Description : Crée un opérande visant un registre Dalvik.                  * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_dalvik_register_operand_new(const bin_t *data, off_t *pos, off_t len, bool *low, MemoryDataSize size, SourceEndian endian) -{ -    GDalvikRegisterOperand *result;         /* Structure à retourner       */ -    uint8_t index8;                         /* Indice sur 8 bits           */ -    uint16_t index16;                       /* Indice sur 16 bits          */ -    bool test;                              /* Bilan de lecture            */ - -    switch (size) -    { -        case MDS_4_BITS: -            test = read_u4(&index8, data, pos, len, low, endian); -            break; -        case MDS_8_BITS: -            test = read_u8(&index8, data, pos, len, endian); -            break; -        case MDS_16_BITS: -            test = read_u16(&index16, data, pos, len, endian); -            break; -        default: -            test = false; -            break; -    } - -    if (!test) -        return NULL; - -    result = g_object_new(G_TYPE_DALVIK_REGISTER_OPERAND, NULL); - -    switch (size) -    { -        case MDS_4_BITS: -        case MDS_8_BITS: -            result->reg = g_dalvik_register_new(index8); -            break; -        case MDS_16_BITS: -            result->reg = g_dalvik_register_new(index16); -            break; -        default: -            break; -    } - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : a = premier opérande à consulter.                            * -*                b = second opérande à consulter.                             * -*                                                                             * -*  Description : Compare un opérande avec un autre.                           * -*                                                                             * -*  Retour      : Bilan de la comparaison.                                     * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b) -{ -    return g_dalvik_register_compare(a->reg, b->reg); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_register_operand_add_text(const GDalvikRegisterOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_register_operand_to_buffer(const GDalvikRegisterOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                      LISTE D'OPERANDES RASSEMBLES EN ARGUMENT                      */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ -G_DEFINE_TYPE(GDalvikArgsOperand, g_dalvik_args_operand, G_TYPE_DALVIK_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des listes d'opérandes Dalvik.          * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance de liste d'opérandes Dalvik.         * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_args_operand_init(GDalvikArgsOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_dalvik_args_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_dalvik_args_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_dalvik_args_operand_new(void) -{ -    GDalvikArgsOperand *result;             /* Structure à retourner       */ - -    result = g_object_new(G_TYPE_DALVIK_ARGS_OPERAND, NULL); - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à compléter.                              * -*                arg     = nouvel argument pour un appel.                     * -*                                                                             * -*  Description : Ajoute un élément à la liste d'arguments Dalvik.             * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg) -{ -    operand->args = (GArchOperand **)realloc(operand->args, ++operand->count * sizeof(GArchOperand *)); - -    operand->args[operand->count - 1] = arg; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_args_operand_add_text(const GDalvikArgsOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    GContentExporter *exporter;             /* Autre vision de l'objet     */ -    size_t i;                               /* Boucle de parcours          */ - -    exporter = G_CONTENT_EXPORTER(operand); - -    g_content_exporter_insert_text(exporter, stream, "{", 1, RTT_HOOK); - -    if (operand->count > 0) -    { -        g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->args[0]), -                                    options, rendering, stream); - -        for (i = 1; i < operand->count; i++) -        { -            g_content_exporter_insert_text(exporter, stream, ",", 1, RTT_NONE/* FIXME */); - -            g_content_exporter_insert_text(exporter, stream, " ", 1, RTT_NONE); - -            g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->args[i]), -                                        options, rendering, stream); - -        } - -    } - -    g_content_exporter_insert_text(exporter, stream, "}", 1, RTT_HOOK); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_args_operand_to_buffer(const GDalvikArgsOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    GContentExporter *exporter;             /* Autre vision de l'objet     */ -    size_t i;                               /* Boucle de parcours          */ - -    exporter = G_CONTENT_EXPORTER(operand); - -    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                          "{", 1, RTT_HOOK); - -    if (operand->count > 0) -    { -        g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->args[0]), buffer, options); - -        for (i = 1; i < operand->count; i++) -        { -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  ",", 1, RTT_NONE/* FIXME */); - -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  " ", 1, RTT_NONE); - -            g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->args[i]), buffer, options); - -        } - -    } - -    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                          "}", 1, RTT_HOOK); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                   OPERANDES POINTANT VERS LA TABLE DE CONSTANTES                   */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */ -G_DEFINE_TYPE(GDalvikPoolOperand, g_dalvik_pool_operand, G_TYPE_DALVIK_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes de constante Dalvik.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande de constante Dalvik.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_pool_operand_init(GDalvikPoolOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_dalvik_pool_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_dalvik_pool_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : type   = type de table visée avec la référence.              * -*                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.          * -*                endian = ordre des bits dans la source.                      * -*                                                                             * -*  Description : Crée un opérande visant un élément constant Dalvik.          * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_dalvik_pool_operand_new(DalvikPoolType type, const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, SourceEndian endian) -{ -    GDalvikPoolOperand *result;             /* Structure à retourner       */ -    uint8_t index8;                         /* Indice sur 8 bits           */ -    uint16_t index16;                       /* Indice sur 16 bits          */ -    bool test;                              /* Bilan de lecture            */ - -    switch (size) -    { -        case MDS_8_BITS: -            test = read_u8(&index8, data, pos, len, endian); -            break; -        case MDS_16_BITS: -            test = read_u16(&index16, data, pos, len, endian); -            break; -        default: -            test = false; -            break; -    } - -    if (!test) -        return NULL; - -    result = g_object_new(G_TYPE_DALVIK_POOL_OPERAND, NULL); - -    result->type = type; -    result->index = (size == MDS_8_BITS ? index8 : index16); - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_pool_operand_add_text(const GDalvikPoolOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    //g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_pool_operand_to_buffer(const GDalvikPoolOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    GContentExporter *exporter;             /* Autre vision de l'opérande  */ - -    char value[20];              /* Chaîne à imprimer           */ -    size_t len;                             /* Taille de l'élément inséré  */ - - - - -    exporter = G_CONTENT_EXPORTER(operand); - -    switch (operand->type) -    { -        case DPT_NONE: -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "????", 4, RTT_SECTION); -            break; -        case DPT_STRING: -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "string", 6, RTT_SECTION); -            break; -        case DPT_TYPE: -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "type", 4, RTT_SECTION); -            break; -        case DPT_PROTO: -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "proto", 5, RTT_SECTION); -            break; -        case DPT_FIELD: -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "field", 5, RTT_SECTION); -            break; -        case DPT_METHOD: -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "method", 6, RTT_SECTION); -            break; -    } - -    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                          "@", 1, RTT_SIGNS); - - -    //g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); - -    len = snprintf(value, 20, "%d", operand->index); -    /* -    strcpy(value, "12345"); - -    len = 5; -    */ -    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                          value, len, RTT_IMMEDIATE); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à consulter.                              * -*                                                                             * -*  Description : Indique la nature de la table de constantes visée ici.       * -*                                                                             * -*  Retour      : Type de table constantes visée.                              * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *operand) -{ -    return operand->type; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à consulter.                              * -*                                                                             * -*  Description : Indique l'indice de l'élément dans la table de constantes.   * -*                                                                             * -*  Retour      : Indice de l'élément visé dans la table de constantes.        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand) -{ -    return operand->index; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                        OPERANDES VISANT UNE ADRESSE DE CODE                        */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de ciblage de code Dalvik. */ -G_DEFINE_TYPE(GDalvikTargetOperand, g_dalvik_target_operand, G_TYPE_DALVIK_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes de ciblage de code Dalvik.* -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_target_operand_class_init(GDalvikTargetOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande de ciblage de code Dalvik.* -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_target_operand_init(GDalvikTargetOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_dalvik_target_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_dalvik_target_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  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.                               * -*                endian = ordre des bits dans la source.                      * -*                base   = adresse de référence pour le calcul.                * -*                                                                             * -*  Description : Crée un opérande visant un instruction Dalvik.               * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_dalvik_target_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, SourceEndian endian, vmpa_t base) -{ -    GDalvikTargetOperand *result;           /* Structure à retourner       */ -    int8_t val8;                            /* Valeur sur 8 bits           */ -    int16_t val16;                          /* Valeur sur 16 bits          */ -    int32_t val32;                          /* Valeur sur 32 bits          */ -    vmpa_t address;                         /* Adresse finale visée        */ - -    switch (size) -    { -        case MDS_8_BITS_SIGNED: -            read_s8(&val8, data, pos, len, endian); -            address = base + val8 * sizeof(uint16_t); -            break; -        case MDS_16_BITS_SIGNED: -            read_s16(&val16, data, pos, len, endian); -            address = base + val16 * sizeof(uint16_t); -            break; -        case MDS_32_BITS_SIGNED: -            read_s32(&val32, data, pos, len, endian); -            address = base + val32 * sizeof(uint16_t); -            break; -        default: -            return NULL; -            break; -    } - -    result = g_object_new(G_TYPE_DALVIK_TARGET_OPERAND, NULL); -    result->immediate = G_IMM_OPERAND(g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */)); - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_target_operand_add_text(const GDalvikTargetOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->immediate), options, rendering, stream); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_target_operand_to_buffer(const GDalvikTargetOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->immediate), buffer, options); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à traiter.                                * -*                                                                             * -*  Description : Fournit l'adresse représentée par une opérande Dalvik.       * -*                                                                             * -*  Retour      : Valeur portée par l'opérande.                                * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *operand) -{ -    return operand->immediate; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                           AIDE A LA CREATION D'OPERANDES                           */ -/* ---------------------------------------------------------------------------------- */ - -  /******************************************************************************  *                                                                             *  *  Paramètres  : instr  = instruction dont la définition est incomplète. [OUT]* diff --git a/src/arch/dalvik/operand.h b/src/arch/dalvik/operand.h index 452bb5e..a596225 100644 --- a/src/arch/dalvik/operand.h +++ b/src/arch/dalvik/operand.h @@ -1,6 +1,6 @@  /* OpenIDA - Outil d'analyse de fichiers binaires - * operand.h - prototypes pour la gestion des operandes de l'architecture Dalvik + * operand.h - prototypes pour l'aide à la création d'opérandes Dalvik   *   * Copyright (C) 2010 Cyrille Bagard   * @@ -25,158 +25,14 @@  #define _ARCH_DALVIK_OPERAND_H -#include "../immediate.h" +#include "operands/args.h" +#include "operands/pool.h" +#include "operands/register.h" +#include "operands/target.h"  #include "../instruction.h" -#include "../../common/endianness.h" -/* ----------------------- COQUILLE VIDE POUR OPERANDE DALVIK ----------------------- */ - - -#define G_TYPE_DALVIK_OPERAND                  g_dalvik_operand_get_type() -#define G_DALVIK_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_operand_get_type(), GDalvikOperand)) -#define G_IS_DALVIK_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_operand_get_type())) -#define G_DALVIK_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_dalvik_operand_get_type(), GDalvikOperandIface)) - - -/* Définition d'un opérande de Dalvik (instance) */ -typedef struct _GDalvikOperand GDalvikOperand; - -/* Définition d'un opérande de Dalvik (classe) */ -typedef struct _GDalvikOperandClass GDalvikOperandClass; - - -/* Indique le type défini par la GLib pour un opérande de Dalvik. */ -GType g_dalvik_operand_get_type(void); - - - -/* --------------------- OPERANDES VISANT UN REGISTRE DE DALVIK --------------------- */ - - -#define G_TYPE_DALVIK_REGISTER_OPERAND                  g_dalvik_register_operand_get_type() -#define G_DALVIK_REGISTER_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_register_operand_get_type(), GDalvikRegisterOperand)) -#define G_IS_DALVIK_REGISTER_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_register_operand_get_type())) -#define G_DALVIK_REGISTER_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_dalvik_register_operand_get_type(), GDalvikRegisterOperandIface)) - - -/* Définition d'un opérande visant un registre Dalvik (instance) */ -typedef struct _GDalvikRegisterOperand GDalvikRegisterOperand; - -/* Définition d'un opérande visant un registre Dalvik (classe) */ -typedef struct _GDalvikRegisterOperandClass GDalvikRegisterOperandClass; - - -/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */ -GType g_dalvik_register_operand_get_type(void); - -/* Crée un opérande visant un registre Dalvik. */ -GArchOperand *g_dalvik_register_operand_new(const bin_t *, off_t *, off_t, bool *, MemoryDataSize, SourceEndian); - - - -/* -------------------- LISTE D'OPERANDES RASSEMBLES EN ARGUMENT -------------------- */ - - -#define G_TYPE_DALVIK_ARGS_OPERAND                  g_dalvik_args_operand_get_type() -#define G_DALVIK_ARGS_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_args_operand_get_type(), GDalvikArgsOperand)) -#define G_IS_DALVIK_ARGS_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_args_operand_get_type())) -#define G_DALVIK_ARGS_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_dalvik_args_operand_get_type(), GDalvikArgsOperandIface)) - - -/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ -typedef struct _GDalvikArgsOperand GDalvikArgsOperand; - -/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ -typedef struct _GDalvikArgsOperandClass GDalvikArgsOperandClass; - - -/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ -GType g_dalvik_args_operand_get_type(void); - -/* Crée un réceptacle pour opérandes Dalvik servant d'arguments. */ -GArchOperand *g_dalvik_args_operand_new(void); - -/* Ajoute un élément à la liste d'arguments Dalvik. */ -void g_dalvik_args_operand_add(GDalvikArgsOperand *, GArchOperand *); - - - -/* ----------------- OPERANDES POINTANT VERS LA TABLE DE CONSTANTES ----------------- */ - - - -#define G_TYPE_DALVIK_POOL_OPERAND                  g_dalvik_pool_operand_get_type() -#define G_DALVIK_POOL_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_pool_operand_get_type(), GDalvikPoolOperand)) -#define G_IS_DALVIK_POOL_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_pool_operand_get_type())) -#define G_DALVIK_POOL_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_dalvik_pool_operand_get_type(), GDalvikPoolOperandIface)) - - -/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */ -typedef struct _GDalvikPoolOperand GDalvikPoolOperand; - -/* Définition d'un opérande visant un élément de table de constantes Dalvik (classe) */ -typedef struct _GDalvikPoolOperandClass GDalvikPoolOperandClass; - - -/* Type de table de constantes */ -typedef enum _DalvikPoolType -{ -    DPT_NONE        = 0x0, -    DPT_STRING      = 0x1, -    DPT_TYPE        = 0x2, -    DPT_PROTO       = 0x3, -    DPT_FIELD       = 0x4, -    DPT_METHOD      = 0x5 - -} DalvikPoolType; - - -/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */ -GType g_dalvik_pool_operand_get_type(void); - -/* Crée un opérande visant un élément constant Dalvik. */ -GArchOperand *g_dalvik_pool_operand_new(DalvikPoolType, const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian); - -/* Indique la nature de la table de constantes visée ici. */ -DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *); - -/* Indique l'indice de l'élément dans la table de constantes. */ -uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *); - - - -/* ---------------------- OPERANDES VISANT UNE ADRESSE DE CODE ---------------------- */ - - -#define G_TYPE_DALVIK_TARGET_OPERAND                  g_dalvik_target_operand_get_type() -#define G_DALVIK_TARGET_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_target_operand_get_type(), GDalvikTargetOperand)) -#define G_IS_DALVIK_TARGET_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_target_operand_get_type())) -#define G_DALVIK_TARGET_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_dalvik_target_operand_get_type(), GDalvikTargetOperandIface)) - - -/* Définition d'un opérande visant une adresse de code Dalvik (instance) */ -typedef struct _GDalvikTargetOperand GDalvikTargetOperand; - -/* Définition d'un opérande visant une adresse de code Dalvik (classe) */ -typedef struct _GDalvikTargetOperandClass GDalvikTargetOperandClass; - - -/* Indique le type défini par la GLib pour un opérande de ciblage de code Dalvik. */ -GType g_dalvik_target_operand_get_type(void); - -/* Crée un opérande visant un instruction Dalvik. */ -GArchOperand *g_dalvik_target_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian, vmpa_t); - -/* Fournit l'adresse représentée par une opérande Dalvik. */ -const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *); - - - -/* ------------------------- AIDE A LA CREATION D'OPERANDES ------------------------- */ - -  /**   * Cf. les documentations suivantes :   * - http://www.netmite.com/android/mydroid/dalvik/docs/instruction-formats.html diff --git a/src/arch/dalvik/operands/Makefile.am b/src/arch/dalvik/operands/Makefile.am new file mode 100644 index 0000000..b6cba3c --- /dev/null +++ b/src/arch/dalvik/operands/Makefile.am @@ -0,0 +1,20 @@ + +noinst_LTLIBRARIES = libarchdalvikoperands.la + +libarchdalvikoperands_la_SOURCES =		\ +	args.h args.c						\ +	pool.h pool.c						\ +	register.h register.c				\ +	target.h target.c + +libarchdalvik_la_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS =  + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + + +SUBDIRS =  diff --git a/src/arch/dalvik/operands/args.c b/src/arch/dalvik/operands/args.c new file mode 100644 index 0000000..367a718 --- /dev/null +++ b/src/arch/dalvik/operands/args.c @@ -0,0 +1,189 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * args.c - listes d'opérandes rassemblées en arguments + * + * Copyright (C) 2010 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 "args.h" + + +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ +struct _GDalvikArgsOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GArchOperand **args;                    /* Liste d'arguments           */ +    size_t count;                           /* Taille de cette liste       */ + +}; + + +/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ +struct _GDalvikArgsOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des listes d'opérandes Dalvik. */ +static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *); + +/* Initialise une instance de liste d'opérandes Dalvik. */ +static void g_dalvik_args_operand_init(GDalvikArgsOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *, AsmSyntax); + + + +/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ +G_DEFINE_TYPE(GDalvikArgsOperand, g_dalvik_args_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des listes d'opérandes Dalvik.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance de liste d'opérandes Dalvik.         * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_args_operand_init(GDalvikArgsOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ + +    parent = G_ARCH_OPERAND(operand); + +    parent->print = (operand_print_fc)g_dalvik_args_operand_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_dalvik_args_operand_new(void) +{ +    GDalvikArgsOperand *result;             /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_DALVIK_ARGS_OPERAND, NULL); + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                line    = ligne tampon où imprimer l'opérande donné.         * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_args_operand_print(const GDalvikArgsOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ +    size_t i;                               /* Boucle de parcours          */ + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "{", 1, RTT_HOOK); + +    if (operand->count > 0) +    { +        g_arch_operand_print(operand->args[0], line, syntax); + +        for (i = 1; i < operand->count; i++) +        { +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, ",", 1, RTT_PUNCT); +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, " ", 1, RTT_RAW); + +            g_arch_operand_print(operand->args[i], line, syntax); + +        } + +    } + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "}", 1, RTT_HOOK); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à compléter.                              * +*                arg     = nouvel argument pour un appel.                     * +*                                                                             * +*  Description : Ajoute un élément à la liste d'arguments Dalvik.             * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg) +{ +    operand->args = (GArchOperand **)realloc(operand->args, +                                             ++operand->count * sizeof(GArchOperand *)); + +    operand->args[operand->count - 1] = arg; + +} diff --git a/src/arch/dalvik/operands/args.h b/src/arch/dalvik/operands/args.h new file mode 100644 index 0000000..87ec9ae --- /dev/null +++ b/src/arch/dalvik/operands/args.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * args.h - prototypes pour les listes d'opérandes rassemblées en arguments + * + * Copyright (C) 2010 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/>. + */ + + +#ifndef _ARCH_DALVIK_OPERANDS_ARGS_H +#define _ARCH_DALVIK_OPERANDS_ARGS_H + + +#include <glib-object.h> + + +#include "../../operand.h" + + + +#define G_TYPE_DALVIK_ARGS_OPERAND                  g_dalvik_args_operand_get_type() +#define G_DALVIK_ARGS_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_args_operand_get_type(), GDalvikArgsOperand)) +#define G_IS_DALVIK_ARGS_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_args_operand_get_type())) +#define G_DALVIK_ARGS_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_ARGS_OPERAND, GDalvikArgsOperandClass)) +#define G_IS_DALVIK_ARGS_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_ARGS_OPERAND)) +#define G_DALVIK_ARGS_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_ARGS_OPERAND, GDalvikArgsOperandClass)) + + +/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ +typedef struct _GDalvikArgsOperand GDalvikArgsOperand; + +/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ +typedef struct _GDalvikArgsOperandClass GDalvikArgsOperandClass; + + +/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ +GType g_dalvik_args_operand_get_type(void); + +/* Crée un réceptacle pour opérandes Dalvik servant d'arguments. */ +GArchOperand *g_dalvik_args_operand_new(void); + +/* Ajoute un élément à la liste d'arguments Dalvik. */ +void g_dalvik_args_operand_add(GDalvikArgsOperand *, GArchOperand *); + + + +#endif  /* _ARCH_DALVIK_OPERANDS_ARGS_H */ diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c new file mode 100644 index 0000000..a7b264b --- /dev/null +++ b/src/arch/dalvik/operands/pool.c @@ -0,0 +1,240 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pool.c - opérandes pointant vers la table des constantes + * + * Copyright (C) 2010 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 "pool.h" + + +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */ +struct _GDalvikPoolOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    DalvikPoolType type;                    /* Type de table visée         */ +    uint32_t index;                         /* Indice de l'élément visé    */ + +}; + + +/* Définition d'un opérande visant un élément de table de constantes Dalvik (classe) */ +struct _GDalvikPoolOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes de constante Dalvik. */ +static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *); + +/* Initialise une instance d'opérande de constante Dalvik. */ +static void g_dalvik_pool_operand_init(GDalvikPoolOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine *, AsmSyntax); + + + +/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */ +G_DEFINE_TYPE(GDalvikPoolOperand, g_dalvik_pool_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes de constante Dalvik.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande de constante Dalvik.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_pool_operand_init(GDalvikPoolOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ + +    parent = G_ARCH_OPERAND(operand); + +    parent->print = (operand_print_fc)g_dalvik_pool_operand_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : type   = type de table visée avec la référence.              * +*                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.          * +*                endian = ordre des bits dans la source.                      * +*                                                                             * +*  Description : Crée un opérande visant un élément constant Dalvik.          * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_dalvik_pool_operand_new(DalvikPoolType type, const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, SourceEndian endian) +{ +    GDalvikPoolOperand *result;             /* Structure à retourner       */ +    uint8_t index8;                         /* Indice sur 8 bits           */ +    uint16_t index16;                       /* Indice sur 16 bits          */ +    bool test;                              /* Bilan de lecture            */ + +    switch (size) +    { +        case MDS_8_BITS: +            test = read_u8(&index8, data, pos, len, endian); +            break; +        case MDS_16_BITS: +            test = read_u16(&index16, data, pos, len, endian); +            break; +        default: +            test = false; +            break; +    } + +    if (!test) +        return NULL; + +    result = g_object_new(G_TYPE_DALVIK_POOL_OPERAND, NULL); + +    result->type = type; +    result->index = (size == MDS_8_BITS ? index8 : index16); + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                line    = ligne tampon où imprimer l'opérande donné.         * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ +    char value[20];                         /* Chaîne à imprimer           */ +    size_t len;                             /* Taille de l'élément inséré  */ + +    switch (operand->type) +    { +        case DPT_NONE: +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, "????", 4, RTT_SECTION); +            break; +        case DPT_STRING: +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, "string", 6, RTT_SECTION); +            break; +        case DPT_TYPE: +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, "type", 4, RTT_SECTION); +            break; +        case DPT_PROTO: +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, "proto", 5, RTT_SECTION); +            break; +        case DPT_FIELD: +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, "field", 5, RTT_SECTION); +            break; +        case DPT_METHOD: +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, "method", 6, RTT_SECTION); +            break; +    } + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "@", 1, RTT_SIGNS); + +    len = snprintf(value, 20, "%d", operand->index); +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, value, len, RTT_IMMEDIATE); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à consulter.                              * +*                                                                             * +*  Description : Indique la nature de la table de constantes visée ici.       * +*                                                                             * +*  Retour      : Type de table constantes visée.                              * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *operand) +{ +    return operand->type; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à consulter.                              * +*                                                                             * +*  Description : Indique l'indice de l'élément dans la table de constantes.   * +*                                                                             * +*  Retour      : Indice de l'élément visé dans la table de constantes.        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand) +{ +    return operand->index; + +} diff --git a/src/arch/dalvik/operands/pool.h b/src/arch/dalvik/operands/pool.h new file mode 100644 index 0000000..b74692d --- /dev/null +++ b/src/arch/dalvik/operands/pool.h @@ -0,0 +1,79 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pool.h - prototypes pour les opérandes pointant vers la table des constantes + * + * Copyright (C) 2010 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/>. + */ + + +#ifndef _ARCH_DALVIK_OPERANDS_POOL_H +#define _ARCH_DALVIK_OPERANDS_POOL_H + + +#include <glib-object.h> +#include <stdint.h> + + +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_DALVIK_POOL_OPERAND                  g_dalvik_pool_operand_get_type() +#define G_DALVIK_POOL_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_pool_operand_get_type(), GDalvikPoolOperand)) +#define G_IS_DALVIK_POOL_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_pool_operand_get_type())) +#define G_DALVIK_POOL_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_POOL_OPERAND, GDalvikPoolOperandClass)) +#define G_IS_DALVIK_POOL_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_POOL_OPERAND)) +#define G_DALVIK_POOL_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_POOL_OPERAND, GDalvikPoolOperandClass)) + + +/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */ +typedef struct _GDalvikPoolOperand GDalvikPoolOperand; + +/* Définition d'un opérande visant un élément de table de constantes Dalvik (classe) */ +typedef struct _GDalvikPoolOperandClass GDalvikPoolOperandClass; + + +/* Type de table de constantes */ +typedef enum _DalvikPoolType +{ +    DPT_NONE        = 0x0, +    DPT_STRING      = 0x1, +    DPT_TYPE        = 0x2, +    DPT_PROTO       = 0x3, +    DPT_FIELD       = 0x4, +    DPT_METHOD      = 0x5 + +} DalvikPoolType; + + +/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */ +GType g_dalvik_pool_operand_get_type(void); + +/* Crée un opérande visant un élément constant Dalvik. */ +GArchOperand *g_dalvik_pool_operand_new(DalvikPoolType, const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian); + +/* Indique la nature de la table de constantes visée ici. */ +DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *); + +/* Indique l'indice de l'élément dans la table de constantes. */ +uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *); + + + +#endif  /* _ARCH_DALVIK_OPERANDS_POOL_H */ diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c new file mode 100644 index 0000000..22c210e --- /dev/null +++ b/src/arch/dalvik/operands/register.c @@ -0,0 +1,212 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * register.c - opérandes visant un registre Dalvik + * + * Copyright (C) 2010 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 "register.h" + + +#include "../register.h" +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant un registre Dalvik (instance) */ +struct _GDalvikRegisterOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GDalvikRegister *reg;                   /* Registre représenté         */ + +}; + + +/* Définition d'un opérande visant un registre Dalvik (classe) */ +struct _GDalvikRegisterOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes de registre Dalvik. */ +static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *); + +/* Initialise une instance d'opérande de registre Dalvik. */ +static void g_dalvik_register_operand_init(GDalvikRegisterOperand *); + +/* Compare un opérande avec un autre. */ +static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *, const GDalvikRegisterOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBufferLine *, AsmSyntax); + + + + +/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */ +G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes de registre Dalvik.       * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande de registre Dalvik.       * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_register_operand_init(GDalvikRegisterOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ + +    parent = G_ARCH_OPERAND(operand); + +    parent->compare = (operand_compare_fc)g_dalvik_register_operand_compare; +    parent->print = (operand_print_fc)g_dalvik_register_operand_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data   = flux de données à analyser.                         * +*                pos    = position courante dans ce flux. [OUT]               * +*                len    = taille totale des données à analyser.               * +*                low    = position éventuelle des 4 bits visés. [OUT]         * +*                size   = taille de l'opérande, et donc du registre.          * +*                endian = ordre des bits dans la source.                      * +*                                                                             * +*  Description : Crée un opérande visant un registre Dalvik.                  * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_dalvik_register_operand_new(const bin_t *data, off_t *pos, off_t len, bool *low, MemoryDataSize size, SourceEndian endian) +{ +    GDalvikRegisterOperand *result;         /* Structure à retourner       */ +    uint8_t index8;                         /* Indice sur 8 bits           */ +    uint16_t index16;                       /* Indice sur 16 bits          */ +    bool test;                              /* Bilan de lecture            */ + +    switch (size) +    { +        case MDS_4_BITS: +            test = read_u4(&index8, data, pos, len, low, endian); +            break; +        case MDS_8_BITS: +            test = read_u8(&index8, data, pos, len, endian); +            break; +        case MDS_16_BITS: +            test = read_u16(&index16, data, pos, len, endian); +            break; +        default: +            test = false; +            break; +    } + +    if (!test) +        return NULL; + +    result = g_object_new(G_TYPE_DALVIK_REGISTER_OPERAND, NULL); + +    switch (size) +    { +        case MDS_4_BITS: +        case MDS_8_BITS: +            result->reg = g_dalvik_register_new(index8); +            break; +        case MDS_16_BITS: +            result->reg = g_dalvik_register_new(index16); +            break; +        default: +            break; +    } + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : a = premier opérande à consulter.                            * +*                b = second opérande à consulter.                             * +*                                                                             * +*  Description : Compare un opérande avec un autre.                           * +*                                                                             * +*  Retour      : Bilan de la comparaison.                                     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b) +{ +    return g_dalvik_register_compare(a->reg, b->reg); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                line    = ligne tampon où imprimer l'opérande donné.         * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ +    g_dalvik_pool_operand_print(operand->reg, line, syntax); + +} diff --git a/src/arch/dalvik/operands/register.h b/src/arch/dalvik/operands/register.h new file mode 100644 index 0000000..00b05fb --- /dev/null +++ b/src/arch/dalvik/operands/register.h @@ -0,0 +1,59 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * register.h - prototypes pour les opérandes visant un registre Dalvik + * + * Copyright (C) 2010 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/>. + */ + + +#ifndef _ARCH_DALVIK_OPERANDS_REGISTER_H +#define _ARCH_DALVIK_OPERANDS_REGISTER_H + + +#include <glib-object.h> + + +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_DALVIK_REGISTER_OPERAND                  g_dalvik_register_operand_get_type() +#define G_DALVIK_REGISTER_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_register_operand_get_type(), GDalvikRegisterOperand)) +#define G_IS_DALVIK_REGISTER_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_register_operand_get_type())) +#define G_DALVIK_REGISTER_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_REGISTER_OPERAND, GDalvikRegisterOperandClass)) +#define G_IS_DALVIK_REGISTER_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_REGISTER_OPERAND)) +#define G_DALVIK_REGISTER_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_REGISTER_OPERAND, GDalvikRegisterOperandClass)) + + +/* Définition d'un opérande visant un registre Dalvik (instance) */ +typedef struct _GDalvikRegisterOperand GDalvikRegisterOperand; + +/* Définition d'un opérande visant un registre Dalvik (classe) */ +typedef struct _GDalvikRegisterOperandClass GDalvikRegisterOperandClass; + + +/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */ +GType g_dalvik_register_operand_get_type(void); + +/* Crée un opérande visant un registre Dalvik. */ +GArchOperand *g_dalvik_register_operand_new(const bin_t *, off_t *, off_t, bool *, MemoryDataSize, SourceEndian); + + + +#endif  /* _ARCH_DALVIK_OPERANDS_REGISTER_H */ diff --git a/src/arch/dalvik/operands/target.c b/src/arch/dalvik/operands/target.c new file mode 100644 index 0000000..9b82ba2 --- /dev/null +++ b/src/arch/dalvik/operands/target.c @@ -0,0 +1,194 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * target.c - opérandes visant une adresse de code + * + * Copyright (C) 2010 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 "target.h" + + +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant une adresse de code Dalvik (instance) */ +struct _GDalvikTargetOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GImmOperand *immediate;                 /* Adresse visée reconstituée  */ + +}; + + +/* Définition d'un opérande visant une adresse de code Dalvik (classe) */ +struct _GDalvikTargetOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes de ciblage de code Dalvik. */ +static void g_dalvik_target_operand_class_init(GDalvikTargetOperandClass *); + +/* Initialise une instance d'opérande de ciblage de code Dalvik. */ +static void g_dalvik_target_operand_init(GDalvikTargetOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_dalvik_target_operand_print(const GDalvikTargetOperand *, GBufferLine *, AsmSyntax); + + + +/* Indique le type défini par la GLib pour un opérande de ciblage de code Dalvik. */ +G_DEFINE_TYPE(GDalvikTargetOperand, g_dalvik_target_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes de ciblage de code Dalvik.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_target_operand_class_init(GDalvikTargetOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande de ciblage de code Dalvik.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_target_operand_init(GDalvikTargetOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ + +    parent = G_ARCH_OPERAND(operand); + +    parent->print = (operand_print_fc)g_dalvik_target_operand_print; + +} + + +/****************************************************************************** +*                                                                             * +*  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.                               * +*                endian = ordre des bits dans la source.                      * +*                base   = adresse de référence pour le calcul.                * +*                                                                             * +*  Description : Crée un opérande visant un instruction Dalvik.               * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_dalvik_target_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, SourceEndian endian, vmpa_t base) +{ +    GDalvikTargetOperand *result;           /* Structure à retourner       */ +    int8_t val8;                            /* Valeur sur 8 bits           */ +    int16_t val16;                          /* Valeur sur 16 bits          */ +    int32_t val32;                          /* Valeur sur 32 bits          */ +    vmpa_t address;                         /* Adresse finale visée        */ + +    switch (size) +    { +        case MDS_8_BITS_SIGNED: +            read_s8(&val8, data, pos, len, endian); +            address = base + val8 * sizeof(uint16_t); +            break; +        case MDS_16_BITS_SIGNED: +            read_s16(&val16, data, pos, len, endian); +            address = base + val16 * sizeof(uint16_t); +            break; +        case MDS_32_BITS_SIGNED: +            read_s32(&val32, data, pos, len, endian); +            address = base + val32 * sizeof(uint16_t); +            break; +        default: +            return NULL; +            break; +    } + +    result = g_object_new(G_TYPE_DALVIK_TARGET_OPERAND, NULL); +    result->immediate = G_IMM_OPERAND(g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */)); + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                line    = ligne tampon où imprimer l'opérande donné.         * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_target_operand_print(const GDalvikTargetOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ +    g_arch_operand_print(G_ARCH_OPERAND(operand->immediate), line, syntax); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                                                                             * +*  Description : Fournit l'adresse représentée par une opérande Dalvik.       * +*                                                                             * +*  Retour      : Valeur portée par l'opérande.                                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *operand) +{ +    return operand->immediate; + +} diff --git a/src/arch/dalvik/operands/target.h b/src/arch/dalvik/operands/target.h new file mode 100644 index 0000000..9b1641c --- /dev/null +++ b/src/arch/dalvik/operands/target.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * target.h - prototypes pour les opérandes visant une adresse de code + * + * Copyright (C) 2010 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/>. + */ + + +#ifndef _ARCH_DALVIK_OPERANDS_TARGET_H +#define _ARCH_DALVIK_OPERANDS_TARGET_H + + +#include <glib-object.h> + + +#include "../../immediate.h" + + + +#define G_TYPE_DALVIK_TARGET_OPERAND                  g_dalvik_target_operand_get_type() +#define G_DALVIK_TARGET_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_target_operand_get_type(), GDalvikTargetOperand)) +#define G_IS_DALVIK_TARGET_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_target_operand_get_type())) +#define G_DALVIK_TARGET_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_TARGET_OPERAND, GDalvikTargetOperandClass)) +#define G_IS_DALVIK_TARGET_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_TARGET_OPERAND)) +#define G_DALVIK_TARGET_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_TARGET_OPERAND, GDalvikTargetOperandClass)) + + +/* Définition d'un opérande visant une adresse de code Dalvik (instance) */ +typedef struct _GDalvikTargetOperand GDalvikTargetOperand; + +/* Définition d'un opérande visant une adresse de code Dalvik (classe) */ +typedef struct _GDalvikTargetOperandClass GDalvikTargetOperandClass; + + +/* Indique le type défini par la GLib pour un opérande de ciblage de code Dalvik. */ +GType g_dalvik_target_operand_get_type(void); + +/* Crée un opérande visant un instruction Dalvik. */ +GArchOperand *g_dalvik_target_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian, vmpa_t); + +/* Fournit l'adresse représentée par une opérande Dalvik. */ +const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *); + + + +#endif  /* _ARCH_DALVIK_OPERANDS_TARGET_H */ diff --git a/src/arch/dalvik/register.c b/src/arch/dalvik/register.c index dd5a512..cf926d2 100644 --- a/src/arch/dalvik/register.c +++ b/src/arch/dalvik/register.c @@ -52,14 +52,11 @@ struct _GDalvikRegisterClass  #define MAX_REGNAME_LEN 8 -/* Construit la chaîne de caractères correspondant à l'opérande. */ -static void g_dalvik_register_to_string(const GDalvikRegister *, AsmSyntax, char [MAX_REGNAME_LEN], size_t *); +/* Initialise la classe des registres Dalvik. */ +static void g_dalvik_register_class_init(GDalvikRegisterClass *); -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_dalvik_register_add_text(const GDalvikRegister *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_dalvik_register_to_buffer(const GDalvikRegister *, GBufferLine *, GRenderingOptions *); +/* Initialise une instance de registre Dalvik. */ +static void g_dalvik_register_init(GDalvikRegister *); @@ -71,7 +68,7 @@ G_DEFINE_TYPE(GDalvikRegister, g_dalvik_register, G_TYPE_CONTENT_EXPORTER);  *                                                                             *  *  Paramètres  : klass = classe à initialiser.                                *  *                                                                             * -*  Description : Initialise la classe des lignes de représentation.           * +*  Description : Initialise la classe des registres Dalvik.                   *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -89,7 +86,7 @@ static void g_dalvik_register_class_init(GDalvikRegisterClass *klass)  *                                                                             *  *  Paramètres  : reg = instance à initialiser.                                *  *                                                                             * -*  Description : Initialise une instance de ligne de représentation.          * +*  Description : Initialise une instance de registre Dalvik.                  *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -99,12 +96,6 @@ static void g_dalvik_register_class_init(GDalvikRegisterClass *klass)  static void g_dalvik_register_init(GDalvikRegister *reg)  { -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(reg); - -    parent->add_text = (add_text_fc)g_dalvik_register_add_text; -    parent->export_buffer = (export_buffer_fc)g_dalvik_register_to_buffer;  } @@ -166,12 +157,11 @@ bool g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *  /******************************************************************************  *                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                syntax  = type de représentation demandée.                   * -*                key     = description humaine du registre. [OUT]             * -*                klen    = nombre de caractères utilisés. [OUT]               * +*  Paramètres  : reg    = registre à transcrire.                              * +*                line   = ligne tampon où imprimer l'opérande donné.          * +*                syntax = type de représentation demandée.                    *  *                                                                             * -*  Description : Construit la chaîne de caractères correspondant à l'opérande.* +*  Description : Traduit un registre en version humainement lisible.          *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -179,78 +169,28 @@ bool g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *  *                                                                             *  ******************************************************************************/ -static void g_dalvik_register_to_string(const GDalvikRegister *reg, AsmSyntax syntax, char key[MAX_REGNAME_LEN], size_t *klen) +void g_dalvik_pool_operand_print(const GDalvikRegister *reg, GBufferLine *line, AsmSyntax syntax)  { +    char key[MAX_REGNAME_LEN];              /* Mot clef principal          */ +    size_t klen;                            /* Taille de ce mot clef       */ +      switch (syntax)      {          case ASX_INTEL: -            *klen = snprintf(key, MAX_REGNAME_LEN, "v%hd", reg->index); +            klen = snprintf(key, MAX_REGNAME_LEN, "v%hd", reg->index);              break;          case ASX_ATT: -            *klen = snprintf(key, MAX_REGNAME_LEN, "%%v%hd", reg->index); +            klen = snprintf(key, MAX_REGNAME_LEN, "%%v%hd", reg->index);              break;          default: -            *klen = 0; +            klen = 0;              break;      } -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : reg       = registre X86 à transcrire.                       * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_register_add_text(const GDalvikRegister *reg, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    char key[MAX_REGNAME_LEN];              /* Mot clef principal          */ -    size_t klen;                            /* Taille de ce mot clef       */ - -    g_dalvik_register_to_string(reg, g_rendering_options_get_syntax(options), key, &klen); - -    g_content_exporter_insert_text(G_CONTENT_EXPORTER(reg), stream, -                                   key, klen, RTT_REGISTER); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : reg     = registre X86 à transcrire.                         * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_dalvik_register_to_buffer(const GDalvikRegister *reg, GBufferLine *buffer, GRenderingOptions *options) -{ -    char key[MAX_REGNAME_LEN];              /* Mot clef principal          */ -    size_t klen;                            /* Taille de ce mot clef       */ - -    g_dalvik_register_to_string(reg, g_rendering_options_get_syntax(options), key, &klen); - -    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(reg), buffer, BLC_ASSEMBLY, -                                          key, klen, RTT_REGISTER); +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, key, klen, RTT_REGISTER);  } diff --git a/src/arch/dalvik/register.h b/src/arch/dalvik/register.h index 7767a9b..9b405a5 100644 --- a/src/arch/dalvik/register.h +++ b/src/arch/dalvik/register.h @@ -30,6 +30,7 @@  #include "../archbase.h" +#include "../../glibext/gbufferline.h" @@ -57,6 +58,9 @@ GDalvikRegister *g_dalvik_register_new(uint16_t);  /* Compare un registre avec un autre. */  bool g_dalvik_register_compare(const GDalvikRegister *, const GDalvikRegister *); +/* Traduit un registre en version humainement lisible. */ +void g_dalvik_pool_operand_print(const GDalvikRegister *, GBufferLine *, AsmSyntax); +  /* Indique si le registre correspond à ebp ou similaire. */  bool g_dalvik_register_is_base_pointer(const GDalvikRegister *); diff --git a/src/arch/immediate.c b/src/arch/immediate.c index c3a2f6b..ec689b8 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -793,7 +793,7 @@ static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line, A      len = g_imm_operand_to_string(operand, syntax, value); -    g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, value, len, RTT_IMMEDIATE); +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, value, len, RTT_IMMEDIATE);  } diff --git a/src/arch/instruction.c b/src/arch/instruction.c index cfc8ace..677a1a3 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -39,10 +39,10 @@ static void g_arch_instruction_class_init(GArchInstructionClass *);  static void g_arch_instruction_init(GArchInstruction *);  /* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_arch_instruction_add_text(const GArchInstruction *, GRenderingOptions *, MainRendering, FILE *); +static void g_arch_instruction_add_text(const GArchInstruction *, GRenderingOptions *, MainRendering, FILE *) __attribute__ ((deprecated));  /*  Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_arch_instruction_to_buffer(const GArchInstruction *, GBufferLine *, GRenderingOptions *); +static void g_arch_instruction_to_buffer(const GArchInstruction *, GBufferLine *, GRenderingOptions *) __attribute__ ((deprecated)); @@ -241,7 +241,7 @@ void g_arch_instruction_set_location(GArchInstruction *instr, off_t offset, off_  *                                                                             *  ******************************************************************************/ -void g_arch_instruction_get_location(GArchInstruction *instr, off_t *offset, off_t *length, vmpa_t *address) +void g_arch_instruction_get_location(const GArchInstruction *instr, off_t *offset, off_t *length, vmpa_t *address)  {      if (offset != NULL) *offset = instr->offset;      if (length != NULL) *length = instr->length; @@ -578,6 +578,81 @@ size_t g_arch_instruction_get_destinations(const GArchInstruction *instr, GArchI  /******************************************************************************  *                                                                             * +*  Paramètres  : instr  = instruction d'assemblage à représenter.             * +*                buffer = espace où placer ledit contenu.                     * +*                syntax = type de représentation demandée.                    * +*                                                                             * +*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax) +{ +    GBufferLine *line;                      /* Ligne de destination        */ +    char address[VMPA_MAX_SIZE];            /* Adresse au format texte     */ +    size_t len;                             /* Taille de l'élément inséré  */ +    char *bin_code;                         /* Tampon du code binaire      */ +    off_t i;                                /* Boucle de parcours #1       */ +    const char *key;                        /* Mot clef principal          */ +    size_t klen;                            /* Taille de ce mot clef       */ +    size_t j;                               /* Boucle de parcours #2       */ + +    line = g_code_buffer_append_new_line(buffer); + +    /* Adresse virtuelle ou physique */ + +    len = vmpa_to_string(instr->address, msize, address); + +    g_buffer_line_insert_text(line, BLC_ADDRESS, address, len, RTT_RAW); + +    /* Code brut */ + +    bin_code = (char *)calloc(instr->length * 3, sizeof(char)); + +    for (i = 0; i < instr->length; i++) +    { +        if ((i + 1) < instr->length) +            snprintf(&bin_code[i * (2 + 1)], 4, "%02hhx ", content[instr->offset + i]); +        else +            snprintf(&bin_code[i * (2 + 1)], 3, "%02hhx", content[instr->offset + i]); +    } + +    g_buffer_line_insert_text(line, BLC_BINARY, +                              bin_code, instr->length * 3 - 1, RTT_RAW_CODE); + +    free(bin_code); + +    /* Instruction proprement dite */ + +    key = instr->get_text(instr, NULL/* FIXME */, 0/* FIXME */); +    klen = strlen(key); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, key, klen, RTT_INSTRUCTION); + +    if (instr->operands_count > 0) +    { +        g_arch_operand_print(instr->operands[0], line, syntax); + +        for (j = 1; j < instr->operands_count; j++) +        { +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, ",", 1, RTT_PUNCT); +            g_buffer_line_insert_text(line, BLC_ASSEMBLY, " ", 1, RTT_NONE); + +            g_arch_operand_print(instr->operands[j], line, syntax); + +        } + +    } + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : instr = instruction d'origine à convertir.                   *  *                ctx   = contexte de la phase de décompilation.               *  *                                                                             * @@ -643,7 +718,7 @@ void g_arch_instruction_add_to_list(GArchInstruction **list, GArchInstruction *i  *                                                                             *  ******************************************************************************/ -GArchInstruction *g_arch_instruction_get_next_iter(GArchInstruction *list, const GArchInstruction *iter, vmpa_t max) +GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *list, const GArchInstruction *iter, vmpa_t max)  {      GArchInstruction *result;               /* Elément suivant à renvoyer  */ diff --git a/src/arch/instruction.h b/src/arch/instruction.h index 7932fdc..07a6054 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -70,7 +70,7 @@ GType g_arch_instruction_get_type(void);  void g_arch_instruction_set_location(GArchInstruction *, off_t, off_t, vmpa_t);  /* Fournit la localisation d'une instruction. */ -void g_arch_instruction_get_location(GArchInstruction *, off_t *, off_t *, vmpa_t *); +void g_arch_instruction_get_location(const GArchInstruction *, off_t *, off_t *, vmpa_t *);  /* Attache un opérande supplémentaire à une instruction. */  void g_arch_instruction_attach_extra_operand(GArchInstruction *, GArchOperand *); @@ -88,7 +88,7 @@ void g_arch_instruction_replace_operand(GArchInstruction *, GArchOperand *, cons  void g_arch_instruction_detach_operand(GArchInstruction *, GArchOperand *);  /* Traduit une instruction en version humainement lisible. */ -char *g_arch_instruction_get_text(const GArchInstruction *, const GExeFormat *, AsmSyntax); +char *g_arch_instruction_get_text(const GArchInstruction *, const GExeFormat *, AsmSyntax) __attribute__ ((deprecated)); @@ -118,6 +118,9 @@ size_t g_arch_instruction_get_destinations(const GArchInstruction *, GArchInstru  /* --------------------- CONVERSIONS DU FORMAT DES INSTRUCTIONS --------------------- */ +/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +void g_arch_instruction_print(const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const bin_t *, AsmSyntax); +  /* Décompile une instruction de façon générique. */  GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *, GDecContext *); @@ -130,7 +133,7 @@ GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *, GDecCont  void g_arch_instruction_add_to_list(GArchInstruction **, GArchInstruction *);  /* Fournit l'élement suivant un autre pour un parcours. */ -GArchInstruction *g_arch_instruction_get_next_iter(GArchInstruction *, const GArchInstruction *, vmpa_t); +GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *, const GArchInstruction *, vmpa_t);  /* Recherche une instruction d'après son adresse. */  GArchInstruction *g_arch_instruction_find_by_address(GArchInstruction *, vmpa_t, bool);  | 
