diff options
Diffstat (limited to 'plugins/readdex/class.c')
-rw-r--r-- | plugins/readdex/class.c | 451 |
1 files changed, 206 insertions, 245 deletions
diff --git a/plugins/readdex/class.c b/plugins/readdex/class.c index c08fe4a..7b7b253 100644 --- a/plugins/readdex/class.c +++ b/plugins/readdex/class.c @@ -24,206 +24,232 @@ #include "class.h" -#include <assert.h> -#include <malloc.h> -#include <stdio.h> - - #include <i18n.h> -#include <arch/raw.h> -#include <format/symbol.h> #include <format/dex/class.h> #include <format/dex/dex_def.h> +#include <plugins/fmtp/parser.h> #include "code.h" -/* Commente les définitions des classes pour la VM Dalvik. */ -static bool annotate_dex_class_data(const GDexFormat *, const GDexClass *, uint32_t ); +/* Définition des champs */ -/* Commente les définitions des champs encodés. */ -static bool annotate_dex_encoded_field(const GDexFormat *, vmpa2t *); +static fmt_field_def _dex_class_defs[] = { -/* Commente les définitions des méthodes encodées. */ -static bool annotate_dex_encoded_method(const GDexFormat *, const encoded_method *, vmpa2t *); + { + .name = "class_idx", + .size = MDS_32_BITS, + .repeat = 1, + DISPLAY_RULES(IOD_DEC), -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* status = barre de statut à tenir informée. * -* * -* Description : Commente les définitions des classes pour la VM Dalvik. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ + PLAIN_COMMENT(__("Index into the type_ids list for this class")) -bool annotate_dex_class_defs(const GDexFormat *format, GtkStatusStack *status) -{ - bool result; /* Bilan à retourner */ - GBinContent *content; /* Contenu binaire à lire */ - const dex_header *header; /* En-tête principale */ - SourceEndian endian; /* Boutisme utilisé */ - vmpa2t pos; /* Tête de lecture des symboles*/ - activity_id_t msg; /* Message de progression */ - uint32_t i; /* Boucle de parcours */ - GArchInstruction *instr; /* Instruction décodée */ - GArchOperand *operand; /* Opérande à venir modifier */ - GDbComment *comment; /* Définition de commentaire */ - GBinSymbol *symbol; /* Symbole à intégrer */ - char *text; /* Texte constant à insérer */ - GDexClass *class; /* Classe chargée à manipuler */ - const class_def_item *def; /* Définition brute à lire */ + }, - result = true; + { + .name = "access_flags", - content = g_binary_format_get_content(G_BIN_FORMAT(format)); + .size = MDS_32_BITS, + .repeat = 1, - header = g_dex_format_get_header(format); - endian = SRE_LITTLE;//g_dex_format_get_endianness(format); + PLAIN_COMMENT(__("Access flags for the class")) - if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), header->class_defs_off, &pos)) - return false; + }, - msg = gtk_status_stack_add_activity(status, _("Writing annotations for all Dex classes..."), - header->class_defs_size); + { + .name = "superclass_idx", + + .size = MDS_32_BITS, + .repeat = 1, + + DISPLAY_RULES(IOD_DEC), + + PLAIN_COMMENT(__("Index for the superclass or NO_INDEX if this class has no superclass")) + + }, + + { + .name = "interfaces_off", + + .size = MDS_32_BITS, + .repeat = 1, + + PLAIN_COMMENT(__("Offset to the list of interfaces")) + + }, - for (i = 0; i < header->class_defs_size && result; i++) { - /* class_idx */ + .name = "source_file_idx", - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + .size = MDS_32_BITS, + .repeat = 1, - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + DISPLAY_RULES(IOD_DEC), - asprintf(&text, _("Index into the type_ids list for this class")); + PLAIN_COMMENT(__("Index for the name of the file containing the original source or NO_INDEX")) - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + }, - free(text); + { + .name = "annotations_off", - if (i == 0) - g_binary_symbol_define_as_block_start(symbol, true); + .size = MDS_32_BITS, + .repeat = 1, - /* access_flags */ + PLAIN_COMMENT(__("Offset to the annotations structure for this class")) - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + }, - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); + { + .name = "class_data_off", - asprintf(&text, _("Access flags for the class")); + .size = MDS_32_BITS, + .repeat = 1, - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + PLAIN_COMMENT(__("Offset to the associated class data for this item")) - free(text); + }, - /* superclass_idx */ + { + .name = "static_values_off", - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + .size = MDS_32_BITS, + .repeat = 1, - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + PLAIN_COMMENT(__("Offset to the list of initial values for static fields")) - asprintf(&text, _("Index for the superclass or NO_INDEX if this class has no superclass")); + } - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); +}; - free(text); +static fmt_field_def _dex_class_data[] = { - /* interfaces_off */ + { + .name = "static_fields_size", - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + .is_uleb128 = true, - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); + DISPLAY_RULES(IOD_DEC), - asprintf(&text, _("Offset to the list of interfaces")); + PLAIN_COMMENT(__("Number of static fields defined in this item")) - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + }, - free(text); + { + .name = "instance_fields_size", - /* source_file_idx */ + .is_uleb128 = true, - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + DISPLAY_RULES(IOD_DEC), - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + PLAIN_COMMENT(__("Number of instance fields defined in this item")) - asprintf(&text, _("Index for the name of the file containing the original source or NO_INDEX")); + }, - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + { + .name = "direct_methods_size", - free(text); + .is_uleb128 = true, - /* annotations_off */ + DISPLAY_RULES(IOD_DEC), - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + PLAIN_COMMENT(__("Number of direct methods defined in this item")) - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); + }, - asprintf(&text, _("Offset to the annotations structure for this class")); + { + .name = "virtual_methods_size", - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + .is_uleb128 = true, - free(text); + DISPLAY_RULES(IOD_DEC), - /* class_data_off */ + PLAIN_COMMENT(__("Number of virtual methods defined in this item")) + + } - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); +}; - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); +static fmt_field_def _dex_encoded_field[] = { - asprintf(&text, _("Offset to the associated class data for this item")); + { + .name = "field_idx_diff", - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + .is_uleb128 = true, - free(text); + DISPLAY_RULES(IOD_DEC), - /* static_values_off */ + PLAIN_COMMENT(__("Index into the field_ids list for the identity of this field")) - instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian); + }, - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); + { + .name = "access_flags", - asprintf(&text, _("Offset to the list of initial values for static fields")); + .is_uleb128 = true, - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + PLAIN_COMMENT(__("Access flags for the field")) - free(text); + } - /* Annotations supplémentaires */ +}; - class = g_dex_format_get_class(format, i); +static fmt_field_def _dex_encoded_method[] = { - def = g_dex_class_get_definition(class); + { + .name = "method_idx_diff", - if (def->class_data_off > 0) - result = annotate_dex_class_data(format, class, def->class_data_off); + .is_uleb128 = true, - /* TODO : g_object_unref(G_OBJECT(class));*/ + DISPLAY_RULES(IOD_DEC), - gtk_status_stack_update_activity_value(status, msg, 1); + PLAIN_COMMENT(__("Index into the method_ids list for the identity of this method")) + + }, + + { + .name = "access_flags", + + .is_uleb128 = true, + + DISPLAY_RULES(IOD_DEC), + + PLAIN_COMMENT(__("Access flags for the method")) + + }, + + { + .name = "code_off", + + .is_uleb128 = true, + + PLAIN_COMMENT(__("Offset to the code structure for this method")) } - gtk_status_stack_remove_activity(status, msg); +}; - g_object_unref(G_OBJECT(content)); - return result; -} +/* Commente les définitions des classes pour la VM Dalvik. */ +static bool annotate_dex_class_data(const GDexFormat *, const GDexClass *, uint32_t ); + +/* Commente les définitions des champs encodés. */ +static bool annotate_dex_encoded_field(const GDexFormat *, vmpa2t *); + +/* Commente les définitions des méthodes encodées. */ +static bool annotate_dex_encoded_method(const GDexFormat *, const encoded_method *, vmpa2t *); + /****************************************************************************** * * * Paramètres : format = description de l'exécutable à compléter. * -* class = classe Dex dont les données sont à commenter. * -* offset = tête de lecture physique des symboles. * +* status = barre de statut à tenir informée. * * * * Description : Commente les définitions des classes pour la VM Dalvik. * * * @@ -233,78 +259,94 @@ bool annotate_dex_class_defs(const GDexFormat *format, GtkStatusStack *status) * * ******************************************************************************/ -static bool annotate_dex_class_data(const GDexFormat *format, const GDexClass *class, uint32_t offset) +bool annotate_dex_class_defs(const GDexFormat *format, GtkStatusStack *status) { bool result; /* Bilan à retourner */ - GBinContent *content; /* Contenu binaire à lire */ + const dex_header *header; /* En-tête principale */ vmpa2t pos; /* Tête de lecture des symboles*/ - GArchInstruction *instr; /* Instruction décodée */ - GArchOperand *operand; /* Opérande à venir modifier */ - GDbComment *comment; /* Définition de commentaire */ - GBinSymbol *symbol; /* Symbole à intégrer */ - char *text; /* Texte constant à insérer */ - const class_data_item *data; /* Données chargées à lire */ - uleb128_t i; /* Boucle de parcours */ - - content = g_binary_format_get_content(G_BIN_FORMAT(format)); - - if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), offset, &pos)) - return false; + activity_id_t msg; /* Message de progression */ + GBinFormat *bformat; /* Autre version du format */ + uint32_t i; /* Boucle de parcours */ + GDexClass *class; /* Classe chargée à manipuler */ + const class_def_item *def; /* Définition brute à lire */ - /* static_fields_size */ + header = g_dex_format_get_header(format); - instr = g_raw_instruction_new_uleb128(content, &pos); + result = g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), header->class_defs_off, &pos); - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + if (!result) + goto adcd_exit; - asprintf(&text, _("Number of static fields defined in this item")); + msg = gtk_status_stack_add_activity(status, _("Writing annotations for all Dex classes..."), + header->class_defs_size); - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + bformat = G_BIN_FORMAT(format); - free(text); + for (i = 0; i < header->class_defs_size && result; i++) + { + result = parse_field_definitions(PARSING_DEFS(_dex_class_defs), bformat, &pos, NULL); + if (!result) break; - g_binary_symbol_define_as_block_start(symbol, true); + /* Annotations supplémentaires */ - /* instance_fields_size */ + class = g_dex_format_get_class(format, i); - instr = g_raw_instruction_new_uleb128(content, &pos); + def = g_dex_class_get_definition(class); - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + if (def->class_data_off > 0) + result = annotate_dex_class_data(format, class, def->class_data_off); - asprintf(&text, _("Number of instance fields defined in this item")); + /* TODO : g_object_unref(G_OBJECT(class));*/ - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + gtk_status_stack_update_activity_value(status, msg, 1); - free(text); + } - /* direct_methods_size */ + gtk_status_stack_remove_activity(status, msg); - instr = g_raw_instruction_new_uleb128(content, &pos); + adcd_exit: - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + return result; - asprintf(&text, _("Number of direct methods defined in this item")); +} - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); - free(text); +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à compléter. * +* class = classe Dex dont les données sont à commenter. * +* offset = tête de lecture physique des symboles. * +* * +* Description : Commente les définitions des classes pour la VM Dalvik. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - /* virtual_methods_size */ +static bool annotate_dex_class_data(const GDexFormat *format, const GDexClass *class, uint32_t offset) +{ + bool result; /* Bilan à retourner */ + vmpa2t pos; /* Tête de lecture des symboles*/ + GBinFormat *bformat; /* Autre version du format */ + const class_data_item *data; /* Données chargées à lire */ + uleb128_t i; /* Boucle de parcours */ - instr = g_raw_instruction_new_uleb128(content, &pos); + result = g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), offset, &pos); - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); + if (!result) + goto adcd_exit; - asprintf(&text, _("Number of virtual methods defined in this item")); + bformat = G_BIN_FORMAT(format); - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); + result = parse_field_definitions(PARSING_DEFS(_dex_class_data), bformat, &pos, NULL); - free(text); + if (!result) + goto adcd_exit; /* Chargements complémentaires */ - result = true; - data = g_dex_class_get_data(class); if (data != NULL) @@ -323,9 +365,7 @@ static bool annotate_dex_class_data(const GDexFormat *format, const GDexClass *c } - /* Nettoyage final */ - - g_object_unref(G_OBJECT(content)); + adcd_exit: return result; @@ -347,46 +387,14 @@ static bool annotate_dex_class_data(const GDexFormat *format, const GDexClass *c static bool annotate_dex_encoded_field(const GDexFormat *format, vmpa2t *pos) { - GBinContent *content; /* Contenu binaire à lire */ - GArchInstruction *instr; /* Instruction décodée */ - GArchOperand *operand; /* Opérande à venir modifier */ - GDbComment *comment; /* Définition de commentaire */ - GBinSymbol *symbol; /* Symbole à intégrer */ - char *text; /* Texte constant à insérer */ - - content = g_binary_format_get_content(G_BIN_FORMAT(format)); - - /* field_idx_diff */ - - instr = g_raw_instruction_new_uleb128(content, pos); - - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); - - asprintf(&text, _("Index into the field_ids list for the identity of this field")); - - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); - - free(text); - - g_binary_symbol_define_as_block_start(symbol, true); - - /* access_flags */ - - instr = g_raw_instruction_new_uleb128(content, pos); - - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); - - asprintf(&text, _("Access flags for the field")); - - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); - - free(text); + bool result; /* Bilan à retourner */ + GBinFormat *bformat; /* Autre version du format */ - /* Nettoyage final */ + bformat = G_BIN_FORMAT(format); - g_object_unref(G_OBJECT(content)); + result = parse_field_definitions(PARSING_DEFS(_dex_encoded_field), bformat, pos, NULL); - return true; + return result; } @@ -408,63 +416,16 @@ static bool annotate_dex_encoded_field(const GDexFormat *format, vmpa2t *pos) static bool annotate_dex_encoded_method(const GDexFormat *format, const encoded_method *method, vmpa2t *pos) { bool result; /* Bilan à retourner */ - GBinContent *content; /* Contenu binaire à lire */ - GArchInstruction *instr; /* Instruction décodée */ - GArchOperand *operand; /* Opérande à venir modifier */ - GDbComment *comment; /* Définition de commentaire */ - GBinSymbol *symbol; /* Symbole à intégrer */ - char *text; /* Texte constant à insérer */ - - content = g_binary_format_get_content(G_BIN_FORMAT(format)); - - /* method_idx_diff */ - - instr = g_raw_instruction_new_uleb128(content, pos); - - SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC); - - asprintf(&text, _("Index into the method_ids list for the identity of this method")); - - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); - - free(text); - - g_binary_symbol_define_as_block_start(symbol, true); - - /* access_flags */ + GBinFormat *bformat; /* Autre version du format */ - instr = g_raw_instruction_new_uleb128(content, pos); + bformat = G_BIN_FORMAT(format); - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); - - asprintf(&text, _("Access flags for the method")); - - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); - - free(text); - - /* code_off */ - - instr = g_raw_instruction_new_uleb128(content, pos); - - SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX); - - asprintf(&text, _("Offset to the code structure for this method")); - - ADD_RAW_AS_SYM(format, symbol, instr, comment, text); - - free(text); + result = parse_field_definitions(PARSING_DEFS(_dex_encoded_method), bformat, pos, NULL); /* Chargements complémentaires, si non abstraite ni native */ - if (method->code_off > 0) + if (result && method->code_off > 0) result = annotate_dex_code_item(format, method->code_off); - else - result = true; - - /* Nettoyage final */ - - g_object_unref(G_OBJECT(content)); return result; |