summaryrefslogtreecommitdiff
path: root/plugins/fmtp
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-04-30 19:21:29 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-04-30 19:21:29 (GMT)
commit33880cfe5e5de8b81e8a825878b3bbe8ef736f3f (patch)
tree9dcbe3e9e9903e447eeac916be689cd2d39614de /plugins/fmtp
parentb16071a35adaf95d5e67b0dd984e9ba9d7ba28f9 (diff)
Parsed Dex format fields using the new generic parser.
Diffstat (limited to 'plugins/fmtp')
-rw-r--r--plugins/fmtp/def.h18
-rw-r--r--plugins/fmtp/parser.c39
-rw-r--r--plugins/fmtp/parser.h2
3 files changed, 47 insertions, 12 deletions
diff --git a/plugins/fmtp/def.h b/plugins/fmtp/def.h
index d69d20a..f1ec7c7 100644
--- a/plugins/fmtp/def.h
+++ b/plugins/fmtp/def.h
@@ -34,16 +34,24 @@
/**
- * Assurément utile pour les déclarations...
+ * Assurément utile pour les déclarations ou les appels...
*/
#define __(s) s
+#define PARSING_DEFS(a) a, ARRAY_SIZE(a)
+
/**
* Méthodes de définitions des déclarations.
*/
+/* Définition générale */
+typedef struct _fmt_field_def fmt_field_def;
+
+/* Eventuel appel préalable */
+typedef bool (* get_fdef_value_cb) (const fmt_field_def *, GBinContent *, vmpa2t *, SourceEndian, void *);
+
/* Possibilités pour un champ à commenter */
typedef struct _field_desc_switch
{
@@ -89,10 +97,14 @@ typedef enum _FieldCommentType
} FieldCommentType;
/* Définition générale */
-typedef struct _fmt_field_def
+struct _fmt_field_def
{
const char *name; /* Nom du champ */
+ get_fdef_value_cb get_value; /* Obtention de la valeur */
+
+ bool is_uleb128; /* Element de type uleb128 */
+ bool is_leb128; /* Element de type sleb128 */
MemoryDataSize size; /* Taille d'un élément */
size_t repeat; /* Quantité d'éléments présents*/
@@ -122,7 +134,7 @@ typedef struct _fmt_field_def
} comment;
-} fmt_field_def;
+};
/* Règles d'affichage */
diff --git a/plugins/fmtp/parser.c b/plugins/fmtp/parser.c
index b484a0e..8fc693f 100644
--- a/plugins/fmtp/parser.c
+++ b/plugins/fmtp/parser.c
@@ -33,8 +33,7 @@
/* Effectue l'interprétation d'une définition de champ. */
-static bool parse_field_definition(const fmt_field_def *, GBinFormat *, vmpa2t *);
-
+static bool parse_field_definition(const fmt_field_def *, GBinFormat *, vmpa2t *, void *);
@@ -43,6 +42,7 @@ static bool parse_field_definition(const fmt_field_def *, GBinFormat *, vmpa2t *
* Paramètres : def = définition de champ à considérer. *
* format = description de l'exécutable à compléter. *
* pos = tête de lecture pour les données. *
+* data = infos complémentaires éventuellement fournies. *
* *
* Description : Effectue l'interprétation d'une définition de champ. *
* *
@@ -52,10 +52,11 @@ static bool parse_field_definition(const fmt_field_def *, GBinFormat *, vmpa2t *
* *
******************************************************************************/
-static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format, vmpa2t *pos)
+static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format, vmpa2t *pos, void *data)
{
GBinContent *content; /* Contenu binaire à lire */
SourceEndian endian; /* Boutisme utilisé */
+ vmpa2t mod; /* Position modifiable */
bool result; /* Bilan à retourner */
GArchInstruction *instr; /* Instruction décodée */
GImmOperand *imm; /* Opérande à transformer */
@@ -74,9 +75,28 @@ static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format,
content = g_binary_format_get_content(format);
endian = g_binary_format_get_endianness(format);
- assert(def->repeat > 0);
+ if (def->get_value != NULL)
+ {
+ copy_vmpa(&mod, pos);
+
+ result = def->get_value(def, content, &mod, endian, data);
+
+ if (!result)
+ goto pfd_exit;
+
+ }
+
+ if (def->is_uleb128)
+ instr = g_raw_instruction_new_uleb128(content, pos);
+
+ else if (def->is_leb128)
+ instr = g_raw_instruction_new_sleb128(content, pos);
- instr = g_raw_instruction_new_array(content, def->size, def->repeat, pos, endian);
+ else
+ {
+ assert(def->repeat > 0);
+ instr = g_raw_instruction_new_array(content, def->size, def->repeat, pos, endian);
+ }
result = (instr != NULL);
@@ -88,7 +108,9 @@ static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format,
if (def->has_display_rules)
{
- assert(def->disp_count <= def->repeat);
+ assert((def->is_uleb128 && def->disp_count == 1)
+ || (def->is_leb128 && def->disp_count == 1)
+ || (!def->is_uleb128 && !def->is_leb128 && def->disp_count <= def->repeat));
for (i = 0; i < def->disp_count; i++)
{
@@ -198,6 +220,7 @@ static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format,
* count = taille de cette liste. *
* format = description de l'exécutable à compléter. *
* pos = tête de lecture pour les données. *
+* data = infos complémentaires éventuellement fournies. *
* *
* Description : Lance l'interprétation d'une série de définitions de champs. *
* *
@@ -207,7 +230,7 @@ static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format,
* *
******************************************************************************/
-bool parse_field_definitions(const fmt_field_def *defs, size_t count, GBinFormat *format, vmpa2t *pos)
+bool parse_field_definitions(const fmt_field_def *defs, size_t count, GBinFormat *format, vmpa2t *pos, void *data)
{
bool result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
@@ -215,7 +238,7 @@ bool parse_field_definitions(const fmt_field_def *defs, size_t count, GBinFormat
result = true;
for (i = 0; i < count && result; i++)
- result = parse_field_definition(defs + i, format, pos);
+ result = parse_field_definition(defs + i, format, pos, data);
return result;
diff --git a/plugins/fmtp/parser.h b/plugins/fmtp/parser.h
index dcd9bf2..0d5dff3 100644
--- a/plugins/fmtp/parser.h
+++ b/plugins/fmtp/parser.h
@@ -36,7 +36,7 @@
/* Lance l'interprétation d'une série de définitions de champs. */
-bool parse_field_definitions(const fmt_field_def *, size_t, GBinFormat *, vmpa2t *);
+bool parse_field_definitions(const fmt_field_def *, size_t, GBinFormat *, vmpa2t *, void *);