summaryrefslogtreecommitdiff
path: root/src/format/dex/dex-int.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/dex/dex-int.c')
-rw-r--r--src/format/dex/dex-int.c370
1 files changed, 158 insertions, 212 deletions
diff --git a/src/format/dex/dex-int.c b/src/format/dex/dex-int.c
index 5ce0675..79cdc57 100644
--- a/src/format/dex/dex-int.c
+++ b/src/format/dex/dex-int.c
@@ -51,48 +51,46 @@
* *
******************************************************************************/
-bool read_dex_header(const GDexFormat *format, off_t *pos, dex_header *header)
+bool read_dex_header(const GDexFormat *format, vmpa2t *pos, dex_header *header)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
size_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
for (i = 0; i < DEX_FILE_MAGIC_LEN && result; i++)
- result = read_u8(&header->magic[i], content, pos, length);
+ result = g_binary_content_read_u8(content, pos, &header->magic[i]);
- result &= read_u32(&header->checksum, content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->checksum);
for (i = 0; i < 20 && result; i++)
- result = read_u8(&header->signature[i], content, pos, length);
-
- result &= read_u32(&header->file_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->header_size, content, pos, length, SRE_LITTLE);
-
- result &= read_u32(&header->endian_tag, content, pos, length, SRE_LITTLE);
-
- result &= read_u32(&header->link_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->link_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->map_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->string_ids_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->string_ids_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->type_ids_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->type_ids_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->proto_ids_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->proto_ids_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->field_ids_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->field_ids_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->method_ids_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->method_ids_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->class_defs_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->class_defs_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->data_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&header->data_off, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u8(content, pos, &header->signature[i]);
+
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->file_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->header_size);
+
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->endian_tag);
+
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->link_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->link_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->map_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->string_ids_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->string_ids_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->type_ids_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->type_ids_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->proto_ids_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->proto_ids_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->field_ids_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->field_ids_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->method_ids_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->method_ids_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->class_defs_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->class_defs_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->data_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &header->data_off);
return result;
@@ -119,18 +117,14 @@ bool read_dex_header(const GDexFormat *format, off_t *pos, dex_header *header)
* *
******************************************************************************/
-bool read_dex_string_id_item(const GDexFormat *format, off_t *pos, string_id_item *str_id)
+bool read_dex_string_id_item(const GDexFormat *format, vmpa2t *pos, string_id_item *str_id)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
- result = true;
-
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u32(&str_id->string_data_off, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u32(content, pos, SRE_LITTLE, &str_id->string_data_off);
return result;
@@ -151,20 +145,17 @@ bool read_dex_string_id_item(const GDexFormat *format, off_t *pos, string_id_ite
* *
******************************************************************************/
-bool read_dex_string_data_item(const GDexFormat *format, off_t *pos, string_data_item *str_data)
+bool read_dex_string_data_item(const GDexFormat *format, vmpa2t *pos, string_data_item *str_data)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
-
- result = true;
+ GBinContent *content; /* Contenu binaire à lire */
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_uleb128(&str_data->utf16_size, content, pos, length);
+ result = g_binary_content_read_uleb128(content, pos, &str_data->utf16_size);
- str_data->data = &content[*pos];
+ if (result)
+ str_data->data = g_binary_content_get_raw_access(content, pos, str_data->utf16_size);
return result;
@@ -185,18 +176,14 @@ bool read_dex_string_data_item(const GDexFormat *format, off_t *pos, string_data
* *
******************************************************************************/
-bool read_dex_type_id_item(const GDexFormat *format, off_t *pos, type_id_item *item)
+bool read_dex_type_id_item(const GDexFormat *format, vmpa2t *pos, type_id_item *item)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
-
- result = true;
+ GBinContent *content; /* Contenu binaire à lire */
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u32(&item->descriptor_idx, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u32(content, pos, SRE_LITTLE, &item->descriptor_idx);
return result;
@@ -217,20 +204,16 @@ bool read_dex_type_id_item(const GDexFormat *format, off_t *pos, type_id_item *i
* *
******************************************************************************/
-bool read_dex_proto_id_item(const GDexFormat *format, off_t *pos, proto_id_item *proto_id)
+bool read_dex_proto_id_item(const GDexFormat *format, vmpa2t *pos, proto_id_item *proto_id)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
-
- result = true;
+ GBinContent *content; /* Contenu binaire à lire */
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u32(&proto_id->shorty_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&proto_id->return_type_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&proto_id->parameters_off, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u32(content, pos, SRE_LITTLE, &proto_id->shorty_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &proto_id->return_type_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &proto_id->parameters_off);
return result;
@@ -251,20 +234,16 @@ bool read_dex_proto_id_item(const GDexFormat *format, off_t *pos, proto_id_item
* *
******************************************************************************/
-bool read_dex_field_id_item(const GDexFormat *format, off_t *pos, field_id_item *field_id)
+bool read_dex_field_id_item(const GDexFormat *format, vmpa2t *pos, field_id_item *field_id)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
- result = true;
-
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u16(&field_id->class_idx, content, pos, length, SRE_LITTLE);
- result &= read_u16(&field_id->type_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&field_id->name_idx, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u16(content, pos, SRE_LITTLE, &field_id->class_idx);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &field_id->type_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &field_id->name_idx);
return result;
@@ -285,20 +264,16 @@ bool read_dex_field_id_item(const GDexFormat *format, off_t *pos, field_id_item
* *
******************************************************************************/
-bool read_dex_method_id_item(const GDexFormat *format, off_t *pos, method_id_item *meth_id)
+bool read_dex_method_id_item(const GDexFormat *format, vmpa2t *pos, method_id_item *meth_id)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
-
- result = true;
+ GBinContent *content; /* Contenu binaire à lire */
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u16(&meth_id->class_idx, content, pos, length, SRE_LITTLE);
- result &= read_u16(&meth_id->proto_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&meth_id->name_idx, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u16(content, pos, SRE_LITTLE, &meth_id->class_idx);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &meth_id->proto_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &meth_id->name_idx);
return result;
@@ -319,25 +294,21 @@ bool read_dex_method_id_item(const GDexFormat *format, off_t *pos, method_id_ite
* *
******************************************************************************/
-bool read_dex_class_def_item(const GDexFormat *format, off_t *pos, class_def_item *class_def)
+bool read_dex_class_def_item(const GDexFormat *format, vmpa2t *pos, class_def_item *class_def)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
-
- result = true;
+ GBinContent *content; /* Contenu binaire à lire */
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u32(&class_def->class_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->access_flags, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->superclass_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->interfaces_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->source_file_idx, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->annotations_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->class_data_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&class_def->static_values_off, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->class_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->access_flags);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->superclass_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->interfaces_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->source_file_idx);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->annotations_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->class_data_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &class_def->static_values_off);
return result;
@@ -364,19 +335,17 @@ bool read_dex_class_def_item(const GDexFormat *format, off_t *pos, class_def_ite
* *
******************************************************************************/
-bool read_dex_encoded_field(const GDexFormat *format, off_t *pos, encoded_field *field)
+bool read_dex_encoded_field(const GDexFormat *format, vmpa2t *pos, encoded_field *field)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_uleb128(&field->field_idx_diff, content, pos, length);
- result &= read_uleb128(&field->access_flags, content, pos, length);
+ result &= g_binary_content_read_uleb128(content, pos, &field->field_idx_diff);
+ result &= g_binary_content_read_uleb128(content, pos, &field->access_flags);
return result;
@@ -397,20 +366,18 @@ bool read_dex_encoded_field(const GDexFormat *format, off_t *pos, encoded_field
* *
******************************************************************************/
-bool read_dex_encoded_method(const GDexFormat *format, off_t *pos, encoded_method *method)
+bool read_dex_encoded_method(const GDexFormat *format, vmpa2t *pos, encoded_method *method)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_uleb128(&method->method_idx_diff, content, pos, length);
- result &= read_uleb128(&method->access_flags, content, pos, length);
- result &= read_uleb128(&method->code_off, content, pos, length);
+ result &= g_binary_content_read_uleb128(content, pos, &method->method_idx_diff);
+ result &= g_binary_content_read_uleb128(content, pos, &method->access_flags);
+ result &= g_binary_content_read_uleb128(content, pos, &method->code_off);
return result;
@@ -431,18 +398,14 @@ bool read_dex_encoded_method(const GDexFormat *format, off_t *pos, encoded_metho
* *
******************************************************************************/
-bool read_dex_type_item(const GDexFormat *format, off_t *pos, type_item *item)
+bool read_dex_type_item(const GDexFormat *format, vmpa2t *pos, type_item *item)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
- result = true;
-
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u16(&item->type_idx, content, pos, length, SRE_LITTLE);
+ result = g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->type_idx);
return result;
@@ -463,21 +426,19 @@ bool read_dex_type_item(const GDexFormat *format, off_t *pos, type_item *item)
* *
******************************************************************************/
-bool read_dex_type_list(const GDexFormat *format, off_t *pos, type_list *list)
+bool read_dex_type_list(const GDexFormat *format, vmpa2t *pos, type_list *list)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u32(&list->size, content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &list->size);
- list->list = (type_item *)&content[*pos];
- result &= ((*pos + list->size * sizeof(type_item)) <= length);
+ list->list = (type_item *)g_binary_content_get_raw_access(content, pos, list->size * sizeof(type_item));
+ result &= (list->list != NULL);
return result;
@@ -498,27 +459,25 @@ bool read_dex_type_list(const GDexFormat *format, off_t *pos, type_list *list)
* *
******************************************************************************/
-bool read_dex_class_data_item(const GDexFormat *format, off_t *pos, class_data_item *item)
+bool read_dex_class_data_item(const GDexFormat *format, vmpa2t *pos, class_data_item *item)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
uleb128_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
-
item->static_fields = NULL;
item->instance_fields = NULL;
item->direct_methods = NULL;
item->virtual_methods = NULL;
- result &= read_uleb128(&item->static_fields_size, content, pos, length);
- result &= read_uleb128(&item->instance_fields_size, content, pos, length);
- result &= read_uleb128(&item->direct_methods_size, content, pos, length);
- result &= read_uleb128(&item->virtual_methods_size, content, pos, length);
+ content = G_BIN_FORMAT(format)->content;
+
+ result &= g_binary_content_read_uleb128(content, pos, &item->static_fields_size);
+ result &= g_binary_content_read_uleb128(content, pos, &item->instance_fields_size);
+ result &= g_binary_content_read_uleb128(content, pos, &item->direct_methods_size);
+ result &= g_binary_content_read_uleb128(content, pos, &item->virtual_methods_size);
if (result && item->static_fields_size > 0)
{
@@ -617,19 +576,17 @@ void reset_dex_class_data_item(class_data_item *item)
* *
******************************************************************************/
-bool read_dex_encoded_type_addr_pair(const GDexFormat *format, off_t *pos, encoded_type_addr_pair *pair)
+bool read_dex_encoded_type_addr_pair(const GDexFormat *format, vmpa2t *pos, encoded_type_addr_pair *pair)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_uleb128(&pair->type_idx, content, pos, length);
- result &= read_uleb128(&pair->addr, content, pos, length);
+ result &= g_binary_content_read_uleb128(content, pos, &pair->type_idx);
+ result &= g_binary_content_read_uleb128(content, pos, &pair->addr);
return result;
@@ -650,22 +607,20 @@ bool read_dex_encoded_type_addr_pair(const GDexFormat *format, off_t *pos, encod
* *
******************************************************************************/
-bool read_dex_encoded_catch_handler(const GDexFormat *format, off_t *pos, encoded_catch_handler *handler)
+bool read_dex_encoded_catch_handler(const GDexFormat *format, vmpa2t *pos, encoded_catch_handler *handler)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
leb128_t count; /* Nombre de gestionnaires */
leb128_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- handler->offset = *pos;
+ handler->offset = get_phy_addr(pos);
- result &= read_leb128(&handler->size, content, pos, length);
+ result &= g_binary_content_read_leb128(content, pos, &handler->size);
count = leb128_abs(handler->size);
@@ -680,7 +635,8 @@ bool read_dex_encoded_catch_handler(const GDexFormat *format, off_t *pos, encode
else handler->handlers = NULL;
if (handler->size < 0)
- result &= read_uleb128(&handler->catch_all_addr, content, pos, length);
+ result &= g_binary_content_read_uleb128(content, pos, &handler->catch_all_addr);
+
else
handler->catch_all_addr = ULEB128_MAX;
@@ -723,22 +679,20 @@ void reset_dex_encoded_catch_handler(encoded_catch_handler *handler)
* *
******************************************************************************/
-bool read_dex_encoded_catch_handler_list(const GDexFormat *format, off_t *pos, encoded_catch_handler_list *list)
+bool read_dex_encoded_catch_handler_list(const GDexFormat *format, vmpa2t *pos, encoded_catch_handler_list *list)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
off_t saved_off; /* Sauvegarde de position */
+ GBinContent *content; /* Contenu binaire à lire */
uleb128_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ saved_off = get_phy_addr(pos);
- saved_off = *pos;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_uleb128(&list->size, content, pos, length);
+ result &= g_binary_content_read_uleb128(content, pos, &list->size);
if (list->size > 0 && result)
{
@@ -800,20 +754,18 @@ void reset_dex_encoded_catch_handler_list(encoded_catch_handler_list *list)
* *
******************************************************************************/
-bool read_dex_try_item(const GDexFormat *format, off_t *pos, try_item *item)
+bool read_dex_try_item(const GDexFormat *format, vmpa2t *pos, try_item *item)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
- result &= read_u32(&item->start_addr, content, pos, length, SRE_LITTLE);
- result &= read_u16(&item->insn_count, content, pos, length, SRE_LITTLE);
- result &= read_u16(&item->handler_off, content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &item->start_addr);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->insn_count);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->handler_off);
return result;
@@ -834,33 +786,29 @@ bool read_dex_try_item(const GDexFormat *format, off_t *pos, try_item *item)
* *
******************************************************************************/
-bool read_dex_code_item(const GDexFormat *format, off_t *pos, code_item *item)
+bool read_dex_code_item(const GDexFormat *format, vmpa2t *pos, code_item *item)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
uint16_t padding; /* Eventuel alignement */
uint16_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
-
- result &= read_u16(&item->registers_size, content, pos, length, SRE_LITTLE);
- result &= read_u16(&item->ins_size, content, pos, length, SRE_LITTLE);
- result &= read_u16(&item->outs_size, content, pos, length, SRE_LITTLE);
- result &= read_u16(&item->tries_size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&item->debug_info_off, content, pos, length, SRE_LITTLE);
- result &= read_u32(&item->insns_size, content, pos, length, SRE_LITTLE);
+ content = G_BIN_FORMAT(format)->content;
- item->insns = (uint16_t *)pos;
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->registers_size);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->ins_size);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->outs_size);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &item->tries_size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &item->debug_info_off);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &item->insns_size);
- *pos += item->insns_size * sizeof(uint16_t);
+ item->insns = (uint16_t *)g_binary_content_get_raw_access(content, pos, item->insns_size * sizeof(uint16_t));
/* Padding ? */
if (item->tries_size > 0 && item->insns_size % 2 == 1)
- result &= read_u16(&padding, content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &padding);
if (item->tries_size > 0 && result)
{
@@ -928,30 +876,28 @@ void reset_dex_code_item(code_item *item)
* *
******************************************************************************/
-bool read_dex_packed_switch(const GDexFormat *format, off_t *pos, packed_switch *packed)
+bool read_dex_packed_switch(const GDexFormat *format, vmpa2t *pos, packed_switch *packed)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
uint16_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
-
packed->targets = NULL;
- result &= read_u16(&packed->ident, content, pos, length, SRE_LITTLE);
- result &= read_u16(&packed->size, content, pos, length, SRE_LITTLE);
- result &= read_u32(&packed->first_key, content, pos, length, SRE_LITTLE);
+ content = G_BIN_FORMAT(format)->content;
+
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &packed->ident);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &packed->size);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &packed->first_key);
if (result && packed->size > 0)
{
packed->targets = (uint32_t *)calloc(packed->size, sizeof(uint32_t));
for (i = 0; i < packed->size && result; i++)
- result &= read_u32(&packed->targets[i], content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &packed->targets[i]);
}
@@ -997,23 +943,21 @@ void reset_dex_packed_switch(packed_switch *packed)
* *
******************************************************************************/
-bool read_dex_sparse_switch(const GDexFormat *format, off_t *pos, sparse_switch *sparse)
+bool read_dex_sparse_switch(const GDexFormat *format, vmpa2t *pos, sparse_switch *sparse)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
uint16_t i; /* Boucle de parcours */
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
sparse->keys = NULL;
sparse->targets = NULL;
- result &= read_u16(&sparse->ident, content, pos, length, SRE_LITTLE);
- result &= read_u16(&sparse->size, content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &sparse->ident);
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &sparse->size);
if (result && sparse->size > 0)
{
@@ -1021,10 +965,10 @@ bool read_dex_sparse_switch(const GDexFormat *format, off_t *pos, sparse_switch
sparse->targets = (uint32_t *)calloc(sparse->size, sizeof(uint32_t));
for (i = 0; i < sparse->size && result; i++)
- result &= read_u32(&sparse->keys[i], content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &sparse->keys[i]);
for (i = 0; i < sparse->size && result; i++)
- result &= read_u32(&sparse->targets[i], content, pos, length, SRE_LITTLE);
+ result &= g_binary_content_read_u32(content, pos, SRE_LITTLE, &sparse->targets[i]);
}
@@ -1073,19 +1017,21 @@ void reset_dex_sparse_switch(sparse_switch *sparse)
* *
******************************************************************************/
-bool read_dex_switch(const GDexFormat *format, off_t *pos, dex_switch *dswitch)
+bool read_dex_switch(const GDexFormat *format, vmpa2t *pos, dex_switch *dswitch)
{
bool result; /* Bilan à retourner */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
uint16_t ident; /* Pseudo-code d'identification*/
result = true;
- content = NULL; //G_BIN_FORMAT(format)->content;
- length = 0; //G_BIN_FORMAT(format)->length;
+ content = G_BIN_FORMAT(format)->content;
+
+ result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &ident);
- result &= read_u16(&ident, content, (off_t []) { *pos }, length, SRE_LITTLE);
+ /**
+ * La tête de lecture n'est pas mise à jour volontairement !
+ */
if (result)
{