summaryrefslogtreecommitdiff
path: root/plugins/readdex/header.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/readdex/header.c')
-rw-r--r--plugins/readdex/header.c311
1 files changed, 182 insertions, 129 deletions
diff --git a/plugins/readdex/header.c b/plugins/readdex/header.c
index f3928ca..d0d0cd7 100644
--- a/plugins/readdex/header.c
+++ b/plugins/readdex/header.c
@@ -25,241 +25,294 @@
#include <i18n.h>
-#include <arch/raw.h>
-#include <format/symbol.h>
#include <format/dex/dex_def.h>
+#include <plugins/fmtp/parser.h>
-/******************************************************************************
-* *
-* Paramètres : format = description de l'exécutable à compléter. *
-* *
-* Description : Charge tous les symboles de l'en-tête DEX. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+/* Définition des champs */
-bool annotate_dex_header(GDexFormat *format)
-{
- GBinContent *content; /* Contenu binaire à lire */
- SourceEndian endian; /* Boutisme utilisé */
- 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 */
+static fmt_field_def _dex_header[] = {
+
+ {
+ .name = "magic",
+
+ .size = MDS_8_BITS,
+ .repeat = DEX_FILE_MAGIC_LEN ,
+
+ DISPLAY_RULES(IOD_CHAR, IOD_CHAR, IOD_CHAR, IOD_HEX, IOD_CHAR, IOD_CHAR, IOD_CHAR, IOD_HEX),
+
+ PLAIN_COMMENT(__("DEX magic number"))
+
+ },
- content = g_binary_format_get_content(G_BIN_FORMAT(format));
+ {
+ .name = "checksum",
- endian = SRE_LITTLE;//g_dex_format_get_endianness(format);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), 0, &pos))
- return false;
+ PLAIN_COMMENT(__("adler32 checksum used to detect file corruption"))
- /* magic */
+ },
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, DEX_FILE_MAGIC_LEN, &pos, endian);
+ {
+ .name = "signature",
- g_raw_instruction_mark_as_string(G_RAW_INSTRUCTION(instr), true);
+ .size = MDS_32_BITS,
+ .repeat = 5,
- SET_IMM_DISPLAY(instr, operand, 0, IOD_CHAR);
- SET_IMM_DISPLAY(instr, operand, 1, IOD_CHAR);
- SET_IMM_DISPLAY(instr, operand, 2, IOD_CHAR);
+ PLAIN_COMMENT(__("SHA-1 signature used to uniquely identify files"))
- SET_IMM_DISPLAY(instr, operand, 3, IOD_HEX);
+ },
- SET_IMM_DISPLAY(instr, operand, 4, IOD_CHAR);
- SET_IMM_DISPLAY(instr, operand, 5, IOD_CHAR);
- SET_IMM_DISPLAY(instr, operand, 6, IOD_CHAR);
+ {
+ .name = "file_size",
- SET_IMM_DISPLAY(instr, operand, 7, IOD_HEX);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("DEX magic number"));
+ DISPLAY_RULES(IOD_DEC),
- g_binary_symbol_define_as_block_start(symbol, true);
+ PLAIN_COMMENT(__("Size of the entire file in bytes"))
- /* checksum */
+ },
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ {
+ .name = "header_size",
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("adler32 checksum used to detect file corruption"));
+ DISPLAY_RULES(IOD_DEC),
- /* signature */
+ PLAIN_COMMENT(__("Size of the header in bytes"))
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 5, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ {
+ .name = "endian_tag",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("SHA-1 signature used to uniquely identify files"));
+ .size = MDS_32_BITS,
+ .repeat = 1,
- /* file_size */
+ PLAIN_COMMENT(__("Endianness tag ; 0x12345678 for little-endian"))
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ {
+ .name = "link_size",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Size of the entire file in bytes"));
+ .size = MDS_32_BITS,
+ .repeat = 1,
- /* header_size */
+ DISPLAY_RULES(IOD_DEC),
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Size of the link section"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Size of the header in bytes"));
+ {
+ .name = "link_off",
- /* endian_tag */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Offset to the link section"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Endianness tag ; 0x12345678 for little-endian"));
+ {
+ .name = "map_off",
- /* link_size */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Offset to the map item"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Size of the link section"));
+ {
+ .name = "string_ids_size",
- /* link_off */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ DISPLAY_RULES(IOD_DEC),
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ PLAIN_COMMENT(__("Count of strings in the string identifiers list"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the link section"));
+ },
- /* map_off */
+ {
+ .name = "string_ids_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_HEX);
+ PLAIN_COMMENT(__("Offset to the string identifiers list"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the map item"));
+ },
- /* string_ids_size */
+ {
+ .name = "type_ids_size",
- 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),
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Count of strings in the string identifiers list"));
+ PLAIN_COMMENT(__("Count of elements in the type identifiers list"))
- /* string_ids_off */
+ },
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ {
+ .name = "type_ids_off",
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the string identifiers list"));
+ PLAIN_COMMENT(__("Offset to the type identifiers list"))
- /* type_ids_size */
+ },
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ {
+ .name = "proto_ids_size",
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Count of elements in the type identifiers list"));
+ DISPLAY_RULES(IOD_DEC),
- /* type_ids_off */
+ PLAIN_COMMENT(__("Count of elements in the prototype identifiers list"))
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ {
+ .name = "proto_ids_off",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the type identifiers list"));
+ .size = MDS_32_BITS,
+ .repeat = 1,
- /* proto_ids_size */
+ PLAIN_COMMENT(__("Offset to the prototype identifiers list"))
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ {
+ .name = "field_ids_size",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Count of elements in the prototype identifiers list"));
+ .size = MDS_32_BITS,
+ .repeat = 1,
- /* proto_ids_off */
+ DISPLAY_RULES(IOD_DEC),
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Count of elements in the field identifiers list"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the prototype identifiers list"));
+ {
+ .name = "field_ids_off",
- /* field_ids_size */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Offset to the field identifiers list"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Count of elements in the field identifiers list"));
+ {
+ .name = "method_ids_size",
- /* field_ids_off */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ DISPLAY_RULES(IOD_DEC),
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ PLAIN_COMMENT(__("Count of elements in the method identifiers list"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the field identifiers list"));
+ },
- /* method_ids_size */
+ {
+ .name = "method_ids_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);
+ DISPLAY_RULES(IOD_DEC),
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Count of elements in the method identifiers list"));
+ PLAIN_COMMENT(__("Offset to the method identifiers list"))
- /* method_ids_off */
+ },
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ {
+ .name = "class_defs_size",
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the method identifiers list"));
+ DISPLAY_RULES(IOD_DEC),
- /* class_defs_size */
+ PLAIN_COMMENT(__("Count of elements in the class definitions list"))
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ {
+ .name = "class_defs_off",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Count of elements in the class definitions list"));
+ .size = MDS_32_BITS,
+ .repeat = 1,
- /* class_defs_off */
+ PLAIN_COMMENT(__("Offset to the class definitions list"))
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ {
+ .name = "data_size",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the class definitions list"));
+ .size = MDS_32_BITS,
+ .repeat = 1,
- /* data_size */
+ DISPLAY_RULES(IOD_DEC),
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Size of data section in bytes"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Size of data section in bytes"));
+ {
+ .name = "data_off",
- /* data_off */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Offset to the start of the data section"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_HEX);
+ }
+
+};
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à compléter. *
+* *
+* Description : Charge tous les symboles de l'en-tête DEX. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool annotate_dex_header(GDexFormat *format)
+{
+ bool result; /* Bilan à retourner */
+ vmpa2t pos; /* Tête de lecture des symboles*/
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Offset to the start of the data section"));
+ result = g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), 0, &pos);
- g_object_unref(G_OBJECT(content));
+ if (result)
+ result = parse_field_definitions(PARSING_DEFS(_dex_header), G_BIN_FORMAT(format), &pos, NULL);
- return true;
+ return result;
}