diff options
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/dalvik/decomp/Makefile.am | 1 | ||||
| -rw-r--r-- | src/arch/dalvik/decomp/if.c | 8 | ||||
| -rw-r--r-- | src/arch/dalvik/decomp/switch.c | 62 | ||||
| -rw-r--r-- | src/arch/dalvik/decomp/translate.h | 7 | ||||
| -rw-r--r-- | src/arch/dalvik/instruction.c | 4 | ||||
| -rw-r--r-- | src/arch/dalvik/opcodes/switch.c | 2 | ||||
| -rw-r--r-- | src/arch/instruction-int.h | 1 | ||||
| -rw-r--r-- | src/arch/instruction.c | 32 | ||||
| -rw-r--r-- | src/arch/instruction.h | 48 | 
9 files changed, 131 insertions, 34 deletions
| diff --git a/src/arch/dalvik/decomp/Makefile.am b/src/arch/dalvik/decomp/Makefile.am index 7a7f068..3a0a197 100644 --- a/src/arch/dalvik/decomp/Makefile.am +++ b/src/arch/dalvik/decomp/Makefile.am @@ -14,6 +14,7 @@ libarchdalvikdecomp_la_SOURCES =		\  	move.c								\  	new.c								\  	ret.c								\ +	switch.h switch.c					\  	translate.h  libarchdalvikdecomp_la_LIBADD = diff --git a/src/arch/dalvik/decomp/if.c b/src/arch/dalvik/decomp/if.c index 6a156ec..93e21d9 100644 --- a/src/arch/dalvik/decomp/if.c +++ b/src/arch/dalvik/decomp/if.c @@ -1,8 +1,8 @@  /* OpenIDA - Outil d'analyse de fichiers binaires - * array.c - décompilation des branchements conditionnels + * if.c - décompilation des branchements conditionnels   * - * Copyright (C) 2010-2012 Cyrille Bagard + * Copyright (C) 2010-2013 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -35,7 +35,7 @@  *  Paramètres  : instr = instruction d'origine à convertir.                   *  *                ctx   = contexte de la phase de décompilation.               *  *                                                                             * -*  Description : Décompile une instruction de comparaison d'opérandes.        * +*  Description : Décompile une instruction de branchement conditionnel.       *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * @@ -104,7 +104,7 @@ GDecInstruction *dalvik_decomp_instr_if(const GArchInstruction *instr, GDecConte  *  Paramètres  : instr = instruction d'origine à convertir.                   *  *                ctx   = contexte de la phase de décompilation.               *  *                                                                             * -*  Description : Décompile une instruction de comparaison d'opérandes.        * +*  Description : Décompile une instruction de branchement conditionnel.       *  *                                                                             *  *  Retour      : Instruction mise en place ou NULL.                           *  *                                                                             * diff --git a/src/arch/dalvik/decomp/switch.c b/src/arch/dalvik/decomp/switch.c new file mode 100644 index 0000000..83da613 --- /dev/null +++ b/src/arch/dalvik/decomp/switch.c @@ -0,0 +1,62 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * switch.c - décompilation des aiguillages multiples du flot d'exécution + * + * Copyright (C) 2013 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 "translate.h" + + + +#include "../instruction.h" +#include "../../../decomp/instr/switch.h" + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : instr = instruction d'origine à convertir.                   * +*                ctx   = contexte de la phase de décompilation.               * +*                                                                             * +*  Description : Décompile une instruction d'aiguillages multiples du flux.   * +*                                                                             * +*  Retour      : Instruction mise en place ou NULL.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_switch(const GArchInstruction *instr, GDecContext *ctx) +{ +    GDecInstruction *result;                /* Instruction à retourner     */ +    vmpa_t addr;                            /* Adresse de l'instruction    */ +    GArchOperand *operand;                  /* Opérande de l'instruction   */ +    GDecInstruction *val;                   /* Valeur décidant du flot     */ + +    g_arch_instruction_get_location(instr, NULL, NULL, &addr); + +    operand = g_arch_instruction_get_operand(instr, 0); +    val = g_dec_context_convert_register(ctx, operand, false, addr); + +    result = g_switch_instruction_new(G_DEC_EXPRESSION(val)); + +    return result; + +} diff --git a/src/arch/dalvik/decomp/translate.h b/src/arch/dalvik/decomp/translate.h index b8753db..1c9f19c 100644 --- a/src/arch/dalvik/decomp/translate.h +++ b/src/arch/dalvik/decomp/translate.h @@ -87,12 +87,15 @@ GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *, GDec  /* Décompile une instruction de type 'opérations arithmétiques'. */  GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *, GDecContext *); -/* Décompile une instruction de comparaison d'opérandes. */ +/* Décompile une instruction de branchement conditionnel. */  GDecInstruction *dalvik_decomp_instr_if(const GArchInstruction *, GDecContext *); -/* Décompile une instruction de comparaison d'opérandes. */ +/* Décompile une instruction de branchement conditionnel. */  GDecInstruction *dalvik_decomp_instr_if_zero(const GArchInstruction *, GDecContext *); +/* Décompile une instruction d'aiguillages multiples du flux. */ +GDecInstruction *dalvik_decomp_instr_switch(const GArchInstruction *, GDecContext *); +  #endif  /* _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H */ diff --git a/src/arch/dalvik/instruction.c b/src/arch/dalvik/instruction.c index 20982b7..81b8993 100644 --- a/src/arch/dalvik/instruction.c +++ b/src/arch/dalvik/instruction.c @@ -104,8 +104,8 @@ static dalvik_instruction _instructions[DOP_COUNT] = {      [DOP_GOTO]                  = { 0x28, "goto" },      [DOP_GOTO_16]               = { 0x29, "goto/16" },      [DOP_GOTO_32]               = { 0x2a, "goto/32" }, -    [DOP_PACKED_SWITCH]         = { 0x2b, "packed-switch" }, -    [DOP_SPARSE_SWITCH]         = { 0x2c, "sparse-switch" }, +    [DOP_PACKED_SWITCH]         = { 0x2b, "packed-switch",      dalvik_decomp_instr_switch }, +    [DOP_SPARSE_SWITCH]         = { 0x2c, "sparse-switch",      dalvik_decomp_instr_switch },      [DOP_CMPL_FLOAT]            = { 0x2d, "cmp-long" },      [DOP_CMPG_FLOAT]            = { 0x2e, "cmpg-float" },      [DOP_CMPL_DOUBLE]           = { 0x2f, "cmpl-double" }, diff --git a/src/arch/dalvik/opcodes/switch.c b/src/arch/dalvik/opcodes/switch.c index 0feef9a..48576e9 100644 --- a/src/arch/dalvik/opcodes/switch.c +++ b/src/arch/dalvik/opcodes/switch.c @@ -1,6 +1,6 @@  /* OpenIDA - Outil d'analyse de fichiers binaires - * array.c - décodage de l'opération récupérant la longueur d'un tableau + * switch.c - décompilation des branchements multiples   *   * Copyright (C) 2012 Cyrille Bagard   * diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h index 25d65e5..d7da215 100644 --- a/src/arch/instruction-int.h +++ b/src/arch/instruction-int.h @@ -67,6 +67,7 @@ struct _GArchInstruction      size_t from_count;                      /* Nombre de ces origines      */      GArchInstruction **to;                  /* Eventuelles lignes visées   */      InstructionLinkType *links_type;        /* Type des liens de dest.     */ +    link_extra_info *links_info;            /* Informations complémentaires*/      size_t to_count;                        /* Nombre de ces destinations  */      get_instruction_rw_regs_fc get_rw_regs; /* Liste des registres liés    */ diff --git a/src/arch/instruction.c b/src/arch/instruction.c index 06d3e71..20b5f3a 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -2,7 +2,7 @@  /* OpenIDA - Outil d'analyse de fichiers binaires   * instruction.c - gestion générique des instructions   * - * Copyright (C) 2008-2012 Cyrille Bagard + * Copyright (C) 2008-2013 Cyrille Bagard   *   *  This file is part of OpenIDA.   * @@ -24,6 +24,7 @@  #include "instruction.h" +#include <stdarg.h>  #include <string.h> @@ -350,6 +351,7 @@ bool g_arch_instruction_is_return(const GArchInstruction *instr)  *  Paramètres  : instr = instruction dont les informations sont à consulter.  *  *                dest  = ligne visée par la liaison (côté destination).       *  *                type  = type de lien à construire.                           * +*                ...   = éventuelles informations complémentaires.            *  *                                                                             *  *  Description : Etablit un lien entre deux instructions.                     *  *                                                                             * @@ -359,8 +361,10 @@ bool g_arch_instruction_is_return(const GArchInstruction *instr)  *                                                                             *  ******************************************************************************/ -void g_arch_instruction_link_with(GArchInstruction *instr, GArchInstruction *dest, InstructionLinkType type) +void g_arch_instruction_link_with(GArchInstruction *instr, GArchInstruction *dest, InstructionLinkType type, ...)  { +    va_list ap;                             /* Gestion des variations      */ +      /* Côté destination */      dest->from = (GArchInstruction **)realloc(dest->from, @@ -376,10 +380,24 @@ void g_arch_instruction_link_with(GArchInstruction *instr, GArchInstruction *des                                               instr->to_count * sizeof(GArchInstruction *));      instr->links_type = (InstructionLinkType *)realloc(instr->links_type,                                                         instr->to_count * sizeof(InstructionLinkType)); +    instr->links_info = (link_extra_info *)realloc(instr->links_info, +                                                   instr->to_count * sizeof(link_extra_info));      instr->to[instr->to_count - 1] = dest;      instr->links_type[instr->to_count - 1] = type; +    va_start(ap, type); + +    switch (type) +    { +        case ILT_CASE_JUMP: +            instr->links_info[instr->to_count - 1].imm = va_arg(ap, GImmOperand *); +            break; +        default: +            break; +    } + +    va_end(ap);  } @@ -429,6 +447,7 @@ bool g_arch_instruction_has_destinations(const GArchInstruction *instr)  *  Paramètres  : instr = instruction dont les informations sont à consulter.  *  *                dests = liste des instructions de destination. [OUT]         *  *                types = liste des types de liens présents. [OUT]             * +*                info  = éventuelles informations complémentaires. [OUT]      *  *                                                                             *  *  Description : Fournit les destinations d'une instruction donnée.           *  *                                                                             * @@ -438,10 +457,15 @@ bool g_arch_instruction_has_destinations(const GArchInstruction *instr)  *                                                                             *  ******************************************************************************/ -size_t g_arch_instruction_get_destinations(const GArchInstruction *instr, GArchInstruction ***dests, InstructionLinkType **types) +size_t g_arch_instruction_get_destinations(const GArchInstruction *instr, GArchInstruction ***dests, InstructionLinkType **types, link_extra_info **info)  {      *dests = instr->to; -    *types = instr->links_type; + +    if (types != NULL) +        *types = instr->links_type; + +    if (info != NULL) +        *info = instr->links_info;      return instr->to_count; diff --git a/src/arch/instruction.h b/src/arch/instruction.h index 051ce51..ae53dbb 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -25,35 +25,18 @@  #define _ARCH_INSTRUCTION_H -#include <stdbool.h> -#include <glib-object.h>  #include <sys/types.h> -#include "archbase.h" -#include "operand.h" +#include "immediate.h"  #include "register.h" +#include "../analysis/type.h"  #include "../decomp/context.h"  #include "../decomp/instruction.h"  #include "../format/executable.h" -/* Typage des instructions rencontrées */ -typedef enum _InstructionLinkType -{ -    ILT_NONE,                               /* Aucune instruction visée    */ -    ILT_EXEC_FLOW,                          /* Raccord attendu entre blocs */ -    ILT_JUMP,                               /* Saut inconditionnel         */ -    ILT_CASE_JUMP,                          /* Saut suite à aiguillage     */ -    ILT_JUMP_IF_TRUE,                       /* Saut conditionnel (si vrai) */ -    ILT_JUMP_IF_FALSE,                      /* Saut conditionnel (si faux) */ -    ILT_CALL,                               /* Appel d'une fonction        */ -    ILT_CATCH_EXCEPTION                     /* Gestion d'une exception     */ - -} InstructionLinkType; - -  #define G_TYPE_ARCH_INSTRUCTION                 g_arch_instruction_get_type()  #define G_ARCH_INSTRUCTION(obj)                 (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arch_instruction_get_type(), GArchInstruction))  #define G_IS_ARCH_INSTRUCTION(obj)              (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arch_instruction_get_type())) @@ -99,6 +82,29 @@ void g_arch_instruction_get_rw_registers(const GArchInstruction *, GArchRegister  /* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */ +/* Typage des instructions rencontrées */ +typedef enum _InstructionLinkType +{ +    ILT_NONE,                               /* Aucune instruction visée    */ +    ILT_EXEC_FLOW,                          /* Raccord attendu entre blocs */ +    ILT_JUMP,                               /* Saut inconditionnel         */ +    ILT_CASE_JUMP,                          /* Saut suite à aiguillage     */ +    ILT_JUMP_IF_TRUE,                       /* Saut conditionnel (si vrai) */ +    ILT_JUMP_IF_FALSE,                      /* Saut conditionnel (si faux) */ +    ILT_CALL,                               /* Appel d'une fonction        */ +    ILT_CATCH_EXCEPTION                     /* Gestion d'une exception     */ + +} InstructionLinkType; + +/* Informations complémentaires pour un lien */ +typedef union _link_extra_info +{ +    GImmOperand *imm;                       /* Valeur d'un cas de switch() */ +    GDataType *type;                        /* Type d'une exception        */ + +} link_extra_info; + +  /* Informe sur une éventuelle référence à une autre instruction. */  InstructionLinkType g_arch_instruction_get_link(const GArchInstruction *, vmpa_t *); @@ -106,7 +112,7 @@ InstructionLinkType g_arch_instruction_get_link(const GArchInstruction *, vmpa_t  bool g_arch_instruction_is_return(const GArchInstruction *instr);  /* Etablit un lien entre deux instructions. */ -void g_arch_instruction_link_with(GArchInstruction *, GArchInstruction *, InstructionLinkType); +void g_arch_instruction_link_with(GArchInstruction *, GArchInstruction *, InstructionLinkType, ...);  /* Indique si l'instruction a une ou plusieurs origines. */  bool g_arch_instruction_has_sources(const GArchInstruction *); @@ -115,7 +121,7 @@ bool g_arch_instruction_has_sources(const GArchInstruction *);  bool g_arch_instruction_has_destinations(const GArchInstruction *);  /* Fournit les destinations d'une instruction donnée. */ -size_t g_arch_instruction_get_destinations(const GArchInstruction *, GArchInstruction ***, InstructionLinkType **); +size_t g_arch_instruction_get_destinations(const GArchInstruction *, GArchInstruction ***, InstructionLinkType **, link_extra_info **);  /* Fournit la destination d'une instruction et d'un type donné. */  GArchInstruction *g_arch_instruction_get_given_destination(const GArchInstruction *, InstructionLinkType); | 
