diff options
Diffstat (limited to 'src/decomp/expr')
| -rw-r--r-- | src/decomp/expr/Makefile.am | 24 | ||||
| -rw-r--r-- | src/decomp/expr/arithm.c | 197 | ||||
| -rw-r--r-- | src/decomp/expr/arithm.h | 76 | ||||
| -rw-r--r-- | src/decomp/expr/array.c | 161 | ||||
| -rw-r--r-- | src/decomp/expr/array.h | 61 | ||||
| -rw-r--r-- | src/decomp/expr/assign.c | 159 | ||||
| -rw-r--r-- | src/decomp/expr/assign.h | 60 | ||||
| -rw-r--r-- | src/decomp/expr/block.c | 185 | ||||
| -rw-r--r-- | src/decomp/expr/block.h | 62 | ||||
| -rw-r--r-- | src/decomp/expr/call.c | 163 | ||||
| -rw-r--r-- | src/decomp/expr/call.h | 61 | ||||
| -rw-r--r-- | src/decomp/expr/dalvik/Makefile.am | 14 | ||||
| -rw-r--r-- | src/decomp/expr/dalvik/array.c | 155 | ||||
| -rw-r--r-- | src/decomp/expr/dalvik/array.h | 61 | ||||
| -rw-r--r-- | src/decomp/expr/immediate.c | 150 | ||||
| -rw-r--r-- | src/decomp/expr/immediate.h | 61 | ||||
| -rw-r--r-- | src/decomp/expr/pseudo.c | 148 | ||||
| -rw-r--r-- | src/decomp/expr/pseudo.h | 59 | 
18 files changed, 1857 insertions, 0 deletions
| diff --git a/src/decomp/expr/Makefile.am b/src/decomp/expr/Makefile.am new file mode 100644 index 0000000..3c15758 --- /dev/null +++ b/src/decomp/expr/Makefile.am @@ -0,0 +1,24 @@ + +noinst_LTLIBRARIES = libdecompexpr.la + +libdecompexpr_la_SOURCES =				\ +	arithm.h arithm.c					\ +	array.h array.c						\ +	assign.h assign.c					\ +	block.h block.c						\ +	call.h call.c						\ +	immediate.h immediate.c				\ +	pseudo.h pseudo.c + +libdecompexpr_la_LDFLAGS =  + +libdecompexpr_la_LIBADD =				\ +	dalvik/libdecompexprdalvik.la + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS =  + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = dalvik diff --git a/src/decomp/expr/arithm.c b/src/decomp/expr/arithm.c new file mode 100644 index 0000000..605830d --- /dev/null +++ b/src/decomp/expr/arithm.c @@ -0,0 +1,197 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * arithm.c - représentation des opérations arithmétiques + * + * 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 "arithm.h" + + +#include "../expression-int.h" + + + +/* Définition d'une opération arithmétique définie (instance) */ +struct _GArithmExpression +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GDecExpression *op1;                    /* Premier opérande manipulé   */ +    GDecExpression *op2;                    /* Second opérande manipulé    */ + +    ArithmOperationType type;               /* Opération à représenter     */ + +}; + + +/* Définition d'une opération arithmétique définie (classe) */ +struct _GArithmExpressionClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des opérations arithmétiques définies. */ +static void g_arithm_expression_class_init(GArithmExpressionClass *); + +/* Initialise une instance d'opération arithmétique définie. */ +static void g_arithm_expression_init(GArithmExpression *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_arithm_expression_print(const GArithmExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une opération arithmétique définie. */ +G_DEFINE_TYPE(GArithmExpression, g_arithm_expression, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérations arithmétiques définies.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_arithm_expression_class_init(GArithmExpressionClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr = instance à initialiser.                               * +*                                                                             * +*  Description : Initialise une instance d'opération arithmétique définie.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_arithm_expression_init(GArithmExpression *expr) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(expr); + +    instr->print = (dec_instr_print_fc)g_arithm_expression_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : op1  = premier opérande à manipuler.                         * +*                type = type d'opération à mener ici.                         * +*                op2  = seconde opérande à manipuler.                         * +*                                                                             * +*  Description : Représente une opération arithmétique entre deux opérandes.  * +*                                                                             * +*  Retour      : Expression mise en place.                                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_arithm_expression_new(GDecExpression *op1, ArithmOperationType type, GDecExpression *op2) +{ +    GArithmExpression *result;              /* Expression à retourner      */ + +    result = g_object_new(G_TYPE_ARITHM_EXPRESSION, NULL); + +    result->op1 = op1; +    result->op2 = op2; + +    result->type = type; + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr   = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_arithm_expression_print(const GArithmExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    const char *sign;                       /* Symbole de l'opération      */ + +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->op1), +                            buffer, line, output); + +    switch (expr->type) +    { +        case AOT_ADD: +            sign = " + "; +            break; +        case AOT_SUB: +            sign = " - "; +            break; +        case AOT_MUL: +            sign = " * "; +            break; +        case AOT_DIV: +            sign = " / "; +            break; +        case AOT_REM: +            sign = " % "; +            break; +        case AOT_AND: +            sign = " & "; +            break; +        case AOT_OR: +            sign = " | "; +            break; +        case AOT_XOR: +            sign = " ^ "; +            break; +        default:    /* AOT_COUNT */ +            sign = " ? "; +            break; +    } + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, sign, 3, RTT_SIGNS); + +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->op2), +                            buffer, line, output); + +} diff --git a/src/decomp/expr/arithm.h b/src/decomp/expr/arithm.h new file mode 100644 index 0000000..1de9865 --- /dev/null +++ b/src/decomp/expr/arithm.h @@ -0,0 +1,76 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * arithm.h - prototypes pour la représentation des opérations arithmétiques + * + * 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 _ANALYSIS_DECOMP_COMMON_ARITHM_H +#define _ANALYSIS_DECOMP_COMMON_ARITHM_H + + +#include <glib-object.h> + + +#include "../expression.h" +#include "../instruction.h" + + + +#define G_TYPE_ARITHM_EXPRESSION               g_arithm_expression_get_type() +#define G_ARITHM_EXPRESSION(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arithm_expression_get_type(), GArithmExpression)) +#define G_IS_ARITHM_EXPRESSION(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arithm_expression_get_type())) +#define G_ARITHM_EXPRESSION_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARITHM_EXPRESSION, GArithmExpressionClass)) +#define G_IS_ARITHM_EXPRESSION_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARITHM_EXPRESSION)) +#define G_ARITHM_EXPRESSION_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARITHM_EXPRESSION, GArithmExpressionClass)) + + +/* Définition d'une opération arithmétique définie (instance) */ +typedef struct _GArithmExpression GArithmExpression; + +/* Définition d'une opération arithmétique définie (classe) */ +typedef struct _GArithmExpressionClass GArithmExpressionClass; + + +/* Types d'opérations menables */ +typedef enum _ArithmOperationType +{ +    AOT_ADD,                                /* Addition                    */ +    AOT_SUB,                                /* Soustraction                */ +    AOT_MUL,                                /* Multiplication              */ +    AOT_DIV,                                /* Division                    */ +    AOT_REM,                                /* Modulo                      */ +    AOT_AND,                                /* Et logique                  */ +    AOT_OR,                                 /* Ou logique                  */ +    AOT_XOR,                                /* Ou exclusif                 */ + +    AOT_COUNT + +} ArithmOperationType; + + +/* Indique le type défini pour une opération arithmétique définie. */ +GType g_arithm_expression_get_type(void); + +/* Représente une opération arithmétique entre deux opérandes. */ +GDecInstruction *g_arithm_expression_new(GDecExpression *, ArithmOperationType, GDecExpression *); + + + +#endif  /* _ANALYSIS_DECOMP_COMMON_ARITHM_H */ diff --git a/src/decomp/expr/array.c b/src/decomp/expr/array.c new file mode 100644 index 0000000..497e47a --- /dev/null +++ b/src/decomp/expr/array.c @@ -0,0 +1,161 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.c - manipulations de tableaux génériques + * + * 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 "array.h" + + +#include "../expression-int.h" + + + +/* Définition d'un accès à une cellule de tableau (instance) */ +struct _GArrayAccess +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GDecExpression *array;                  /* Elément auquel accéder      */ +    GDecExpression *index;                  /* Position de la cellule      */ + +}; + + +/* Définition d'un accès à une cellule de tableau (classe) */ +struct _GArrayAccessClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des accès aux cellules de tableau. */ +static void g_array_access_class_init(GArrayAccessClass *); + +/* Initialise une instance d'accès à une cellule de tableau. */ +static void g_array_access_init(GArrayAccess *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_array_access_print(const GArrayAccess *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un accès à une cellule de tableau. */ +G_DEFINE_TYPE(GArrayAccess, g_array_access, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des accès aux cellules de tableau.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_array_access_class_init(GArrayAccessClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr = instance à initialiser.                               * +*                                                                             * +*  Description : Initialise une instance d'accès à une cellule de tableau.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_array_access_init(GArrayAccess *expr) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(expr); + +    instr->print = (dec_instr_print_fc)g_array_access_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : array = tableau auquel on doit accéder.                      * +*                index = indice de la cellule concernée.                      * +*                                                                             * +*  Description : Construit un accès à une cellule de tableau comme expression.* +*                                                                             * +*  Retour      : Expression mise en place.                                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_array_access_new(GDecExpression *array, GDecExpression *index) +{ +    GArrayAccess *result;                 /* Expression à retourner      */ + +    result = g_object_new(G_TYPE_ARRAY_ACCESS, NULL); + +    result->array = array; +    result->index = index; + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr   = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_array_access_print(const GArrayAccess *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->array), +                            buffer, line, output); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "[", 1, RTT_RAW); + +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->index), +                            buffer, line, output); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "]", 1, RTT_RAW); + +} diff --git a/src/decomp/expr/array.h b/src/decomp/expr/array.h new file mode 100644 index 0000000..0007a8e --- /dev/null +++ b/src/decomp/expr/array.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.h - prototypes pour les manipulations de tableaux génériques + * + * 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 _DECOMP_EXPR_ARRAY_H +#define _DECOMP_EXPR_ARRAY_H + + +#include <glib-object.h> + + +#include "../expression.h" +#include "../instruction.h" + + + +#define G_TYPE_ARRAY_ACCESS               g_array_access_get_type() +#define G_ARRAY_ACCESS(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_array_access_get_type(), GArrayAccess)) +#define G_IS_ARRAY_ACCESS(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_array_access_get_type())) +#define G_ARRAY_ACCESS_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARRAY_ACCESS, GArrayAccessClass)) +#define G_IS_ARRAY_ACCESS_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARRAY_ACCESS)) +#define G_ARRAY_ACCESS_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARRAY_ACCESS, GArrayAccessClass)) + + + +/* Définition d'un accès à une cellule de tableau (instance) */ +typedef struct _GArrayAccess GArrayAccess; + +/* Définition d'un accès à une cellule de tableau (classe) */ +typedef struct _GArrayAccessClass GArrayAccessClass; + + + +/* Indique le type défini pour un accès à une cellule de tableau. */ +GType g_array_access_get_type(void); + +/* Construit un accès à une cellule de tableau comme expression. */ +GDecInstruction *g_array_access_new(GDecExpression *, GDecExpression *); + + + +#endif  /* _DECOMP_EXPR_ARRAY_H */ diff --git a/src/decomp/expr/assign.c b/src/decomp/expr/assign.c new file mode 100644 index 0000000..561fb0f --- /dev/null +++ b/src/decomp/expr/assign.c @@ -0,0 +1,159 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * assign.c - représentation des assignations + * + * 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 "assign.h" + + +#include "../expression-int.h" + + + +/* Définition d'une assignation quelconque (instance) */ +struct _GAssignExpression +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GDecExpression *dest;                   /* Destination de l'assignat°  */ +    GDecExpression *src;                    /* Source de l'assignation     */ + +}; + + +/* Définition d'une assignation quelconque (classe) */ +struct _GAssignExpressionClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des assignations quelconques. */ +static void g_assign_expression_class_init(GAssignExpressionClass *); + +/* Initialise une instance d'assignation quelconque. */ +static void g_assign_expression_init(GAssignExpression *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_assign_expression_print(const GAssignExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une assignation quelconque. */ +G_DEFINE_TYPE(GAssignExpression, g_assign_expression, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des assignations quelconques.           * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_assign_expression_class_init(GAssignExpressionClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr = instance à initialiser.                               * +*                                                                             * +*  Description : Initialise une instance d'assignation quelconque.            * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_assign_expression_init(GAssignExpression *expr) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(expr); + +    instr->print = (dec_instr_print_fc)g_assign_expression_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : dest = expression servant de destination.                    * +*                src  = source de l'expression à transférer.                  * +*                                                                             * +*  Description : Assigne le contenu d'une expression dans une autre.          * +*                                                                             * +*  Retour      : Expression mise en place.                                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_assign_expression_new(GDecExpression *dest, GDecExpression *src) +{ +    GAssignExpression *result;              /* Expression à retourner      */ + +    result = g_object_new(G_TYPE_ASSIGN_EXPRESSION, NULL); + +    result->dest = dest; +    result->src = src; + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr   = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_assign_expression_print(const GAssignExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->dest), +                            buffer, line, output); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, " = ", 3, RTT_SIGNS); + +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->src), +                            buffer, line, output); + +} diff --git a/src/decomp/expr/assign.h b/src/decomp/expr/assign.h new file mode 100644 index 0000000..87d167e --- /dev/null +++ b/src/decomp/expr/assign.h @@ -0,0 +1,60 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * assign.h - prototypes pour la représentation des assignations + * + * 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 _DECOMP_EXPR_ASSIGN_H +#define _DECOMP_EXPR_ASSIGN_H + + +#include <glib-object.h> + + +#include "../expression.h" +#include "../instruction.h" + + + +#define G_TYPE_ASSIGN_EXPRESSION               g_assign_expression_get_type() +#define G_ASSIGN_EXPRESSION(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_assign_expression_get_type(), GAssignExpression)) +#define G_IS_ASSIGN_EXPRESSION(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_assign_expression_get_type())) +#define G_ASSIGN_EXPRESSION_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ASSIGN_EXPRESSION, GAssignExpressionClass)) +#define G_IS_ASSIGN_EXPRESSION_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ASSIGN_EXPRESSION)) +#define G_ASSIGN_EXPRESSION_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ASSIGN_EXPRESSION, GAssignExpressionClass)) + + + +/* Définition d'une assignation quelconque (instance) */ +typedef struct _GAssignExpression GAssignExpression; + +/* Définition d'une assignation quelconque (classe) */ +typedef struct _GAssignExpressionClass GAssignExpressionClass; + + +/* Indique le type défini pour une assignation quelconque. */ +GType g_assign_expression_get_type(void); + +/* Assigne le contenu d'une expression dans une autre. */ +GDecInstruction *g_assign_expression_new(GDecExpression *, GDecExpression *); + + + +#endif  /* _DECOMP_EXPR_ASSIGN_H */ diff --git a/src/decomp/expr/block.c b/src/decomp/expr/block.c new file mode 100644 index 0000000..c14e169 --- /dev/null +++ b/src/decomp/expr/block.c @@ -0,0 +1,185 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * block.c - regroupement d'un lot d'instructions + * + * 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 "block.h" + + +#include <malloc.h> + + +#include "../expression-int.h" + + + +/* Définition d'un ensemble d'instructions décompilées (instance) */ +struct _GExprBlock +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GDecInstruction **list;                 /* Instructions contenues      */ +    size_t count;                           /* Taille de cette liste       */ + +}; + + +/* Définition d'un ensemble d'instructions décompilées (classe) */ +struct _GExprBlockClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des ensembles d'instructions. */ +static void g_expr_block_class_init(GExprBlockClass *); + +/* Initialise une instance d'ensemble d'instructions. */ +static void g_expr_block_init(GExprBlock *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_expr_block_print(const GExprBlock *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un ensemble d'instructions décompilées. */ +G_DEFINE_TYPE(GExprBlock, g_expr_block, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des ensembles d'instructions.           * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_expr_block_class_init(GExprBlockClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : block = instance à initialiser.                              * +*                                                                             * +*  Description : Initialise une instance d'ensemble d'instructions.           * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_expr_block_init(GExprBlock *block) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(block); + +    instr->print = (dec_instr_print_fc)g_expr_block_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : item = premier élément du nouvel ensemble.                   * +*                                                                             * +*  Description : Constuit un conteneur pour diverses instructions décompilées.* +*                                                                             * +*  Retour      : Conteneur d'instructions mis en place.                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_expr_block_new(GDecInstruction *item) +{ +    GExprBlock *result;                /* Groupe d'instructions à renvoyer */ + +    result = g_object_new(G_TYPE_EXPR_BLOCK, NULL); + +    g_expr_block_add_item(result, item); + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : block  = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_expr_block_print(const GExprBlock *block, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    size_t i;                               /* Boucle de parcours          */ + +    for (i = 0; i < block->count; i++) +    { +        if (i > 0) +            line = g_code_buffer_append_new_line(buffer);   /* FIXME : n° de ligne */ + +        g_dec_instruction_print(block->list[i], buffer, line, output); + +    } + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : block = ensemble à faire évoluer.                            * +*                item  = nouvel élément à placer dans l'ensemble.             * +*                                                                             * +*  Description : Ajoute une instruction décompilée au conteneur existant.     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_expr_block_add_item(GExprBlock *block, GDecInstruction *item) +{ +    block->list = (GDecInstruction **)realloc(block->list,  +                                              ++block->count * sizeof(GDecInstruction *)); +    block->list[block->count - 1] = item; + +} diff --git a/src/decomp/expr/block.h b/src/decomp/expr/block.h new file mode 100644 index 0000000..4ae4ff1 --- /dev/null +++ b/src/decomp/expr/block.h @@ -0,0 +1,62 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * block.h - prototypes pour le regroupement d'un lot d'instructions + * + * 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 _DECOMP_EXPR_BLOCK_H +#define _DECOMP_EXPR_BLOCK_H + + +#include <glib-object.h> + + +#include "../instruction.h" + + + +#define G_TYPE_EXPR_BLOCK               g_expr_block_get_type() +#define G_EXPR_BLOCK(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_expr_block_get_type(), GExprBlock)) +#define G_IS_EXPR_BLOCK(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_expr_block_get_type())) +#define G_EXPR_BLOCK_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_EXPR_BLOCK, GExprBlockClass)) +#define G_IS_EXPR_BLOCK_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_EXPR_BLOCK)) +#define G_EXPR_BLOCK_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_EXPR_BLOCK, GExprBlockClass)) + + + +/* Définition d'un ensemble d'instructions décompilées (instance) */ +typedef struct _GExprBlock GExprBlock; + +/* Définition d'un ensemble d'instructions décompilées (classe) */ +typedef struct _GExprBlockClass GExprBlockClass; + + +/* Indique le type défini pour un ensemble d'instructions décompilées. */ +GType g_expr_block_get_type(void); + +/* Constuit un conteneur pour diverses instructions décompilées. */ +GDecInstruction *g_expr_block_new(GDecInstruction *); + +/* Ajoute une instruction décompilée au conteneur existant. */ +void g_expr_block_add_item(GExprBlock *, GDecInstruction *); + + + +#endif  /* _DECOMP_EXPR_BLOCK_H */ diff --git a/src/decomp/expr/call.c b/src/decomp/expr/call.c new file mode 100644 index 0000000..8f73c4f --- /dev/null +++ b/src/decomp/expr/call.c @@ -0,0 +1,163 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * call.c - encadrement des appels de routine + * + * 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 "call.h" + + +#include <string.h> + + +#include "../expression-int.h" + + + +/* Définition d'un appel à une routine quelconque (instance) */ +struct _GRoutineCall +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GBinRoutine *routine;                   /* Routine sollicitée          */ +    bool is_object;                         /* Nature de l'argument n°1    */ + +}; + + +/* Définition d'un appel à une routine quelconque (classe) */ +struct _GRoutineCallClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des appels à une routine quelconque. */ +static void g_routine_call_class_init(GRoutineCallClass *); + +/* Initialise une instance d'appel à une routine quelconque. */ +static void g_routine_call_init(GRoutineCall *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_routine_call_print(const GRoutineCall *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un appel à une routine quelconque. */ +G_DEFINE_TYPE(GRoutineCall, g_routine_call, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des appels à une routine quelconque.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_routine_call_class_init(GRoutineCallClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr = instance à initialiser.                               * +*                                                                             * +*  Description : Initialise une instance d'appel à une routine quelconque.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_routine_call_init(GRoutineCall *expr) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(expr); + +    instr->print = (dec_instr_print_fc)g_routine_call_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : routine   = routine dont il est fait appel.                  * +*                is_object = indique la nature du premier argument.           * +*                                                                             * +*  Description : Exprime un appel à une routine quelconque.                   * +*                                                                             * +*  Retour      : Expression mise en place.                                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object) +{ +    GRoutineCall *result;              /* Expression à retourner      */ + +    result = g_object_new(G_TYPE_ROUTINE_CALL, NULL); + +    result->routine = routine; +    result->is_object = is_object; + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr   = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_routine_call_print(const GRoutineCall *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    const char *name;                       /* Désignation de la routine   */ + +    name = g_binary_routine_get_name(expr->routine); +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, name, strlen(name), RTT_RAW); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "(", 1, RTT_PUNCT); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, ")", 1, RTT_PUNCT); + +} diff --git a/src/decomp/expr/call.h b/src/decomp/expr/call.h new file mode 100644 index 0000000..7515261 --- /dev/null +++ b/src/decomp/expr/call.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * call.h - prototypes pour l'encadrement des appels de routine + * + * 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 _DECOMP_EXPR_CALL_H +#define _DECOMP_EXPR_CALL_H + + +#include <glib-object.h> + + +#include "../expression.h" +#include "../instruction.h" +#include "../../analysis/routine.h" + + + +#define G_TYPE_ROUTINE_CALL               g_routine_call_get_type() +#define G_ROUTINE_CALL(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_routine_call_get_type(), GRoutineCall)) +#define G_IS_ROUTINE_CALL(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_routine_call_get_type())) +#define G_ROUTINE_CALL_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ROUTINE_CALL, GRoutineCallClass)) +#define G_IS_ROUTINE_CALL_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ROUTINE_CALL)) +#define G_ROUTINE_CALL_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ROUTINE_CALL, GRoutineCallClass)) + + + +/* Définition d'un appel à une routine quelconque (instance) */ +typedef struct _GRoutineCall GRoutineCall; + +/* Définition d'un appel à une routine quelconque (classe) */ +typedef struct _GRoutineCallClass GRoutineCallClass; + + +/* Indique le type défini pour un appel à une routine quelconque. */ +GType g_routine_call_get_type(void); + +/* Exprime un appel à une routine quelconque. */ +GDecInstruction *g_routine_call_new(GBinRoutine *, bool); + + + +#endif  /* _DECOMP_EXPR_CALL_H */ diff --git a/src/decomp/expr/dalvik/Makefile.am b/src/decomp/expr/dalvik/Makefile.am new file mode 100644 index 0000000..a14b9dd --- /dev/null +++ b/src/decomp/expr/dalvik/Makefile.am @@ -0,0 +1,14 @@ + +noinst_LTLIBRARIES = libdecompexprdalvik.la + +libdecompexprdalvik_la_SOURCES =		\ +	array.h array.c + +libdecompexprdalvik_la_LDFLAGS =  + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS =  + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/src/decomp/expr/dalvik/array.c b/src/decomp/expr/dalvik/array.c new file mode 100644 index 0000000..55b9d07 --- /dev/null +++ b/src/decomp/expr/dalvik/array.c @@ -0,0 +1,155 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.c - manipulations de tableaux propres à 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 "array.h" + + +#include "../../expression-int.h" + + + +/* Définition d'une expression de mesure de tableau (instance) */ +struct _GDalvikALength +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GDecExpression *array;                  /* Elément auquel accéder      */ + +}; + + +/* Définition d'une expression de mesure de tableau (classe) */ +struct _GDalvikALengthClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des expressions de mesure de tableau. */ +static void g_dalvik_alength_class_init(GDalvikALengthClass *); + +/* Initialise une instance d'expression de mesure de tableau. */ +static void g_dalvik_alength_init(GDalvikALength *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_dalvik_alength_print(const GDalvikALength *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une expression de mesure de tableau. */ +G_DEFINE_TYPE(GDalvikALength, g_dalvik_alength, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des expressions de mesure de tableau.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_alength_class_init(GDalvikALengthClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr = instance à initialiser.                               * +*                                                                             * +*  Description : Initialise une instance d'expression de mesure de tableau.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_alength_init(GDalvikALength *expr) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(expr); + +    instr->print = (dec_instr_print_fc)g_dalvik_alength_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : array = tableau dont on doit mesurer la taille.              * +*                                                                             * +*  Description : Construit une expression à partir d'une mesure de tableau.   * +*                                                                             * +*  Retour      : Expression mise en place.                                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_dalvik_alength_new(GDecExpression *array) +{ +    GDalvikALength *result;                 /* Expression à retourner      */ + +    result = g_object_new(G_TYPE_DALVIK_ALENGTH, NULL); + +    result->array = array; + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr   = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dalvik_alength_print(const GDalvikALength *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    g_dec_instruction_print(G_DEC_INSTRUCTION(expr->array), +                            buffer, line, output); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, ".", 1, RTT_RAW); + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "length", 6, RTT_RAW); + +} diff --git a/src/decomp/expr/dalvik/array.h b/src/decomp/expr/dalvik/array.h new file mode 100644 index 0000000..15670ab --- /dev/null +++ b/src/decomp/expr/dalvik/array.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.h - prototypes pour les manipulations de tableaux propres à 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 _DECOMP_EXPR_DALVIK_ARRAY_H +#define _DECOMP_EXPR_DALVIK_ARRAY_H + + +#include <glib-object.h> + + +#include "../../expression.h" +#include "../../instruction.h" + + + +#define G_TYPE_DALVIK_ALENGTH               g_dalvik_alength_get_type() +#define G_DALVIK_ALENGTH(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_alength_get_type(), GDalvikALength)) +#define G_IS_DALVIK_ALENGTH(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_alength_get_type())) +#define G_DALVIK_ALENGTH_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_ALENGTH, GDalvikALengthClass)) +#define G_IS_DALVIK_ALENGTH_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_ALENGTH)) +#define G_DALVIK_ALENGTH_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_ALENGTH, GDalvikALengthClass)) + + + +/* Définition d'une expression de mesure de tableau (instance) */ +typedef struct _GDalvikALength GDalvikALength; + +/* Définition d'une expression de mesure de tableau (classe) */ +typedef struct _GDalvikALengthClass GDalvikALengthClass; + + + +/* Indique le type défini pour une expression de mesure de tableau. */ +GType g_dalvik_alength_get_type(void); + +/* Construit une expression à partir d'une mesure de tableau. */ +GDecInstruction *g_dalvik_alength_new(GDecExpression *); + + + +#endif  /* _DECOMP_EXPR_DALVIK_ARRAY_H */ diff --git a/src/decomp/expr/immediate.c b/src/decomp/expr/immediate.c new file mode 100644 index 0000000..a97c8bd --- /dev/null +++ b/src/decomp/expr/immediate.c @@ -0,0 +1,150 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * immediate.c - raccord avec les opérandes de valeur immédiate + * + * 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 "immediate.h" + + +#include "../expression-int.h" + + + +/* Définition d'une expression de valeur immédiate (instance) */ +struct _GImmExpression +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +    GImmOperand *operand;                   /* Conteneur d'origine         */ + +}; + + +/* Définition d'une expression de valeur immédiate (classe) */ +struct _GImmExpressionClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des expressions de valeur immédiate. */ +static void g_imm_expression_class_init(GImmExpressionClass *); + +/* Initialise une instance d'expression de valeur immédiate. */ +static void g_imm_expression_init(GImmExpression *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_imm_expression_print(const GImmExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une expression de valeur immédiate. */ +G_DEFINE_TYPE(GImmExpression, g_imm_expression, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des expressions de valeur immédiate.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_imm_expression_class_init(GImmExpressionClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr = instance à initialiser.                               * +*                                                                             * +*  Description : Initialise une instance d'expression de valeur immédiate.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_imm_expression_init(GImmExpression *expr) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(expr); + +    instr->print = (dec_instr_print_fc)g_imm_expression_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = conteneur d'origie de la valeur immédiate.         * +*                                                                             * +*  Description : Construit une expression à partir d'une valeur immédiate.    * +*                                                                             * +*  Retour      : Expression mise en place.                                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_imm_expression_new(GImmOperand *operand) +{ +    GImmExpression *result;                 /* Expression à retourner      */ + +    result = g_object_new(G_TYPE_IMM_EXPRESSION, NULL); + +    result->operand = operand; + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : expr   = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_imm_expression_print(const GImmExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ +    g_arch_operand_print(G_ARCH_OPERAND(expr->operand), line, ASX_COUNT); + +} diff --git a/src/decomp/expr/immediate.h b/src/decomp/expr/immediate.h new file mode 100644 index 0000000..c86a15c --- /dev/null +++ b/src/decomp/expr/immediate.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * immediate.h - prototypes pour le raccord avec les opérandes de valeur immédiate + * + * 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 _DECOMP_EXPR_IMMEDIATE_H +#define _DECOMP_EXPR_IMMEDIATE_H + + +#include <glib-object.h> + + +#include "../instruction.h" +#include "../../arch/immediate.h" + + + +#define G_TYPE_IMM_EXPRESSION               g_imm_expression_get_type() +#define G_IMM_EXPRESSION(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_imm_expression_get_type(), GImmExpression)) +#define G_IS_IMM_EXPRESSION(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_imm_expression_get_type())) +#define G_IMM_EXPRESSION_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_IMM_EXPRESSION, GImmExpressionClass)) +#define G_IS_IMM_EXPRESSION_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_IMM_EXPRESSION)) +#define G_IMM_EXPRESSION_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_IMM_EXPRESSION, GImmExpressionClass)) + + + +/* Définition d'une expression de valeur immédiate (instance) */ +typedef struct _GImmExpression GImmExpression; + +/* Définition d'une expression de valeur immédiate (classe) */ +typedef struct _GImmExpressionClass GImmExpressionClass; + + + +/* Indique le type défini pour une expression de valeur immédiate. */ +GType g_imm_expression_get_type(void); + +/*Construit une expression à partir d'une valeur immédiate. */ +GDecInstruction *g_imm_expression_new(GImmOperand *); + + + +#endif  /* _DECOMP_EXPR_IMMEDIATE_H */ diff --git a/src/decomp/expr/pseudo.c b/src/decomp/expr/pseudo.c new file mode 100644 index 0000000..393f32c --- /dev/null +++ b/src/decomp/expr/pseudo.c @@ -0,0 +1,148 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pseudo.c - définition des pseudo-registres + * + * 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 "pseudo.h" + + +#include "../expression-int.h" + + + +/* Définition d'un pseudo-registre (instance) */ +struct _GPseudoRegister +{ +    GDecExpression parent;                  /* A laisser en premier        */ + +}; + + +/* Définition d'un pseudo-registre (classe) */ +struct _GPseudoRegisterClass +{ +    GDecExpressionClass parent;             /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des pseudo-registres. */ +static void g_pseudo_register_class_init(GPseudoRegisterClass *); + +/* Initialise une instance de pseudo-registre. */ +static void g_pseudo_register_init(GPseudoRegister *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_pseudo_register_print(const GPseudoRegister *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un pseudo-registre. */ +G_DEFINE_TYPE(GPseudoRegister, g_pseudo_register, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des pseudo-registres.                   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_pseudo_register_class_init(GPseudoRegisterClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : reg = instance à initialiser.                                * +*                                                                             * +*  Description : Initialise une instance de pseudo-registre.                  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_pseudo_register_init(GPseudoRegister *reg) +{ +    GDecInstruction *instr;                 /* Autre version de l'objet    */ + +    instr = G_DEC_INSTRUCTION(reg); + +    instr->print = (dec_instr_print_fc)g_pseudo_register_print; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Assigne le contenu d'une expression dans une autre.          * +*                                                                             * +*  Retour      : Pseudo-registre mis en place.                                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *g_pseudo_register_new(void) +{ +    GPseudoRegister *result;                /* Pseudo-registre à renvoyer  */ + +    result = g_object_new(G_TYPE_PSEUDO_REGISTER, NULL); + +    return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : reg    = expression à transcrire en version humaine.         * +*                buffer = tampon où doit se réaliser l'insertion.             * +*                line   = ligne d'impression prête à emploi ou NULL.          * +*                output = langage de programmation de sortie.                 * +*                                                                             * +*  Description : Imprime pour l'écran un version humaine d'une expression.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_pseudo_register_print(const GPseudoRegister *reg, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + +    g_buffer_line_insert_text(line, BLC_ASSEMBLY, "varX", 4, RTT_RAW); + + +} diff --git a/src/decomp/expr/pseudo.h b/src/decomp/expr/pseudo.h new file mode 100644 index 0000000..9734625 --- /dev/null +++ b/src/decomp/expr/pseudo.h @@ -0,0 +1,59 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pseudo.h - prototypes pour la définition des pseudo-registres + * + * 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 _DECOMP_EXPR_PSEUDO_H +#define _DECOMP_EXPR_PSEUDO_H + + +#include <glib-object.h> + + +#include "../instruction.h" + + + +#define G_TYPE_PSEUDO_REGISTER               g_pseudo_register_get_type() +#define G_PSEUDO_REGISTER(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_pseudo_register_get_type(), GPseudoRegister)) +#define G_IS_PSEUDO_REGISTER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_pseudo_register_get_type())) +#define G_PSEUDO_REGISTER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PSEUDO_REGISTER, GPseudoRegisterClass)) +#define G_IS_PSEUDO_REGISTER_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PSEUDO_REGISTER)) +#define G_PSEUDO_REGISTER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PSEUDO_REGISTER, GPseudoRegisterClass)) + + + +/* Définition d'un pseudo-registre (instance) */ +typedef struct _GPseudoRegister GPseudoRegister; + +/* Définition d'un pseudo-registre (classe) */ +typedef struct _GPseudoRegisterClass GPseudoRegisterClass; + + +/* Indique le type défini pour un pseudo-registre. */ +GType g_pseudo_register_get_type(void); + +/* Assigne le contenu d'une expression dans une autre. */ +GDecInstruction *g_pseudo_register_new(void); + + + +#endif  /* _DECOMP_EXPR_PSEUDO_H */ | 
