diff options
Diffstat (limited to 'src/format')
| -rw-r--r-- | src/format/dex/class.c | 92 | ||||
| -rw-r--r-- | src/format/dex/class.h | 2 | ||||
| -rwxr-xr-x | src/format/dex/dex.c | 2 | ||||
| -rw-r--r-- | src/format/dex/method.c | 31 | ||||
| -rw-r--r-- | src/format/dex/method.h | 5 | 
5 files changed, 110 insertions, 22 deletions
diff --git a/src/format/dex/class.c b/src/format/dex/class.c index 03431f0..23e08a0 100644 --- a/src/format/dex/class.c +++ b/src/format/dex/class.c @@ -66,6 +66,8 @@ static void g_dex_class_init(GDexClass *);  /* Crée une nouvelle représentation de classe issue de code. */  static GDexClass *g_dex_class_new(const GDexFormat *, off_t); +/* Inscrit les méthodes d'une classe en tant que routines. */ +static void g_dex_class_register_method(const GDexClass *, GBinFormat *); @@ -134,6 +136,7 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)      GDexClass *result;                      /* Composant à retourner       */      class_def_item def;                     /* Définition de la classe     */      class_data_item data;                   /* Contenu de la classe        */ +    uleb128_t index;                        /* Conservation du dernier id  */      uleb128_t i;                            /* Boucle de parcours          */      GDexMethod *method;                     /* Méthode chargée             */ @@ -154,9 +157,11 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)      result = g_object_new(G_TYPE_DEX_CLASS, NULL); +    index = 0; +      for (i = 0; i < data.direct_methods_size; i++)      { -        method = g_dex_method_new(format, &data.direct_methods[i]); +        method = g_dex_method_new(format, &data.direct_methods[i], &index);          if (method != NULL)          { @@ -170,11 +175,11 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)      } - +    index = 0;      for (i = 0; i < data.virtual_methods_size; i++)      { -        method = g_dex_method_new(format, &data.virtual_methods[i]); +        method = g_dex_method_new(format, &data.virtual_methods[i], &index);          if (method != NULL)          { @@ -197,6 +202,49 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)  /******************************************************************************  *                                                                             * +*  Paramètres  : class  = informations chargées à consulter.                  * +*                format = format binaire à compléter.                         * +*                                                                             * +*  Description : Inscrit les méthodes d'une classe en tant que routines.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_dex_class_register_method(const GDexClass *class, GBinFormat *format) +{ +    size_t i;                               /* Boucle de parcours          */ +    GBinRoutine *routine;                   /* Routine à inscrire          */ + +    for (i = 0; i < class->dmethods_count; i++) +    { +        routine = g_dex_method_get_routine(class->direct_methods[i]); +        g_binary_format_add_routine(format, routine); + +        printf("routine @ 0x%08llx :: '%s'\n", +               g_binary_routine_get_address(routine), +               g_binary_routine_get_name(routine)); + +    } + +    for (i = 0; i < class->vmethods_count; i++) +    { +        routine = g_dex_method_get_routine(class->virtual_methods[i]); +        g_binary_format_add_routine(format, routine); + +        printf("routine @ 0x%08llx :: '%s'\n", +               g_binary_routine_get_address(routine), +               g_binary_routine_get_name(routine)); + +    } + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : class = informations chargées à consulter.                   *  *                parts = liste à venir compléter.                             *  *                count = quantité de zones listées. [OUT]                     * @@ -244,19 +292,6 @@ GBinPart **g_dex_class_get_parts(const GDexClass *class, GBinPart **parts, size_ - - - - - - - - - - - - -  /******************************************************************************  *                                                                             *  *  Paramètres  : format = représentation interne du format DEX à compléter.   * @@ -296,3 +331,28 @@ bool load_all_dex_classes(GDexFormat *format)      return true;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format = représentation interne du format DEX à compléter.   * +*                                                                             * +*  Description : Enregistre toutes les méthodes des classes listées.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void register_all_dex_class_methods(GDexFormat *format) +{ +    size_t i;                               /* Boucle de parcours          */ +    GBinFormat *bformat;                    /* Autre version du format     */ + +    bformat = G_BIN_FORMAT(format); + +    for (i = 0; i < format->classes_count; i++) +        g_dex_class_register_method(format->classes[i], bformat); + +} diff --git a/src/format/dex/class.h b/src/format/dex/class.h index d78e6e9..810f5e1 100644 --- a/src/format/dex/class.h +++ b/src/format/dex/class.h @@ -64,6 +64,8 @@ GBinPart **g_dex_class_get_parts(const GDexClass *, GBinPart **, size_t *);  /* Charge toutes les classes listées dans le contenu binaire. */  bool load_all_dex_classes(GDexFormat *); +/* Enregistre toutes les méthodes des classes listées. */ +void register_all_dex_class_methods(GDexFormat *); diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c index 5b68d5f..b87981f 100755 --- a/src/format/dex/dex.c +++ b/src/format/dex/dex.c @@ -181,7 +181,7 @@ GBinFormat *g_dex_format_new(const bin_t *content, off_t length)          return NULL;      } - +    register_all_dex_class_methods(result); diff --git a/src/format/dex/method.c b/src/format/dex/method.c index 3a604d0..4888c89 100644 --- a/src/format/dex/method.c +++ b/src/format/dex/method.c @@ -111,6 +111,7 @@ static void g_dex_method_init(GDexMethod *method)  *                                                                             *  *  Paramètres  : format = représentation interne du format DEX à consulter.   *  *                seed   = graine des informations à extraire.                 * +*                last   = dernier indice utilisé (à mettre à jour). [OUT]     *  *                                                                             *  *  Description : Crée une nouvelle représentation de methode issue de code.   *  *                                                                             * @@ -120,7 +121,7 @@ static void g_dex_method_init(GDexMethod *method)  *                                                                             *  ******************************************************************************/ -GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *seed) +GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *seed, uleb128_t *last)  {      GDexMethod *result;                     /* Composant à retourner       */      off_t offset;                           /* Tête de lecture             */ @@ -142,19 +143,22 @@ GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *see      //printf(" code size  :: %d\n", item.insns_size); -    routine = get_routine_from_dex_pool(format, seed->method_idx_diff); +    *last += seed->method_idx_diff; +    routine = get_routine_from_dex_pool(format, *last); +    printf(" method idx :: %lld\n", *last);      result->offset = seed->code_off + 4 * sizeof(uint16_t) + 2 *sizeof(uint32_t);/* TODO : faire plus propre ! */ +    printf(" method off :: 0x%08x\n", result->offset); -    g_binary_routine_set_address(routine, result->offset); +    g_binary_routine_set_address(routine, result->offset); -    g_binary_format_add_routine(G_BIN_FORMAT(format), routine); +    result->routine = routine;      return result; @@ -166,6 +170,25 @@ GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *see  *                                                                             *  *  Paramètres  : method = représentation interne du format DEX à consulter.   *  *                                                                             * +*  Description : Fournit la routine OpenIDA correspondant à la méthode.       * +*                                                                             * +*  Retour      : Instance de routine mise en place.                           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GBinRoutine *g_dex_method_get_routine(const GDexMethod *method) +{ +    return method->routine; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : method = représentation interne du format DEX à consulter.   * +*                                                                             *  *  Description : Fournit la zone binaire correspondant à la méthode.          *  *                                                                             *  *  Retour      : Zone binaire à analyser.                                     * diff --git a/src/format/dex/method.h b/src/format/dex/method.h index dd6f4b1..0f5a465 100644 --- a/src/format/dex/method.h +++ b/src/format/dex/method.h @@ -54,7 +54,10 @@ typedef struct _GDexMethodClass GDexMethodClass;  GType g_dex_method_get_type(void);  /* Crée une nouvelle représentation de methode issue de code. */ -GDexMethod *g_dex_method_new(const GDexFormat *, const encoded_method *); +GDexMethod *g_dex_method_new(const GDexFormat *, const encoded_method *, uleb128_t *); + +/* Fournit la routine OpenIDA correspondant à la méthode. */ +GBinRoutine *g_dex_method_get_routine(const GDexMethod *);  /* Fournit la zone binaire correspondant à la méthode. */  GBinPart *g_dex_method_as_part(const GDexMethod *);  | 
