summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
Diffstat (limited to 'src/format')
-rw-r--r--src/format/dex/dex-int.c2
-rwxr-xr-xsrc/format/dex/dex_def.h2
-rw-r--r--src/format/dex/method.c2
-rw-r--r--src/format/elf/elf.c12
-rw-r--r--src/format/executable.c52
-rw-r--r--src/format/executable.h2
6 files changed, 58 insertions, 14 deletions
diff --git a/src/format/dex/dex-int.c b/src/format/dex/dex-int.c
index 1626dde..c49445d 100644
--- a/src/format/dex/dex-int.c
+++ b/src/format/dex/dex-int.c
@@ -376,6 +376,8 @@ bool read_dex_encoded_method(const GDexFormat *format, vmpa2t *pos, encoded_meth
content = G_BIN_FORMAT(format)->content;
+ copy_vmpa(&method->origin, pos);
+
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);
diff --git a/src/format/dex/dex_def.h b/src/format/dex/dex_def.h
index 8ddcf30..e1521e8 100755
--- a/src/format/dex/dex_def.h
+++ b/src/format/dex/dex_def.h
@@ -191,6 +191,8 @@ typedef struct _encoded_method
uleb128_t access_flags; /* Conditions d'accès */
uleb128_t code_off; /* Position du code associé */
+ vmpa2t origin; /* Rajout pour suivi interne */
+
} encoded_method;
/* Type quelconque */
diff --git a/src/format/dex/method.c b/src/format/dex/method.c
index f487c0a..ec12119 100644
--- a/src/format/dex/method.c
+++ b/src/format/dex/method.c
@@ -387,7 +387,7 @@ void g_dex_method_include_as_portion(const GDexMethod *method, GExeFormat *forma
g_binary_portion_set_rights(new, PAC_READ | PAC_EXEC);
- g_exe_format_include_portion(format, new);
+ g_exe_format_include_portion(format, new, &method->info.origin);
}
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index 1ca81be..2ca3b8c 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -468,6 +468,7 @@ static void g_elf_format_refine_portions(GElfFormat *format)
uint16_t max; /* Décompte d'éléments traités */
uint16_t i; /* Boucle de parcours */
off_t offset; /* Début de part de programme */
+ vmpa2t origin; /* Origine d'une définition */
elf_phdr phdr; /* En-tête de programme ELF */
uint32_t p_flags; /* Droits associés à une partie*/
const char *background; /* Fond signigicatif */
@@ -506,6 +507,8 @@ static void g_elf_format_refine_portions(GElfFormat *format)
offset = ELF_HDR(format, format->header, e_phoff)
+ ELF_HDR(format, format->header, e_phentsize) * i;
+ init_vmpa(&origin, offset, VMPA_NO_VIRTUAL);
+
if (!read_elf_program_header(format, offset, &phdr))
continue;
@@ -535,7 +538,7 @@ static void g_elf_format_refine_portions(GElfFormat *format)
g_binary_portion_set_rights(new, rights);
- g_exe_format_include_portion(exe_format, new);
+ g_exe_format_include_portion(exe_format, new, &origin);
}
@@ -586,7 +589,12 @@ static void g_elf_format_refine_portions(GElfFormat *format)
g_binary_portion_set_rights(new, rights);
- g_exe_format_include_portion(exe_format, new);
+ offset = ELF_HDR(format, format->header, e_shoff)
+ + ELF_HDR(format, format->header, e_shentsize) * i;
+
+ init_vmpa(&origin, offset, VMPA_NO_VIRTUAL);
+
+ g_exe_format_include_portion(exe_format, new, &origin);
}
diff --git a/src/format/executable.c b/src/format/executable.c
index f121f5b..ac67d62 100644
--- a/src/format/executable.c
+++ b/src/format/executable.c
@@ -24,7 +24,9 @@
#include "executable.h"
+#include <assert.h>
#include <malloc.h>
+#include <stdio.h>
#include <stdlib.h>
@@ -330,6 +332,7 @@ bool g_executable_format_complete_loading(GExeFormat *format, GtkStatusStack *st
* *
* Paramètres : format = description de l'exécutable à modifier. *
* portion = portion à inclure dans les définitions du format. *
+* origin = source de définition de la portion fournie. *
* *
* Description : Procède à l'enregistrement d'une portion dans un format. *
* *
@@ -339,24 +342,53 @@ bool g_executable_format_complete_loading(GExeFormat *format, GtkStatusStack *st
* *
******************************************************************************/
-void g_exe_format_include_portion(GExeFormat *format, GBinPortion *portion)
+void g_exe_format_include_portion(GExeFormat *format, GBinPortion *portion, const vmpa2t *origin)
{
- phys_t max; /* Position hors limite */
+ phys_t available; /* Taille totale du bianire */
+ const mrange_t *range; /* Emplacement de la portion */
+ phys_t start; /* Début de zone de la portion */
+ char *msg; /* Description d'une erreur */
+ phys_t remaining; /* Taille maximale envisageable*/
bool truncated; /* Modification faite ? */
- max = g_binary_content_compute_size(G_BIN_FORMAT(format)->content);
+ available = g_binary_content_compute_size(G_BIN_FORMAT(format)->content);
- truncated = g_binary_portion_limit_range(portion, max);
+ range = g_binary_portion_get_range(portion);
- if (truncated)
- log_variadic_message(LMT_BAD_BINARY, _("Truncated binary portion '%s' to fit the binary content size!"),
- g_binary_portion_get_desc(portion));
+ start = get_phy_addr(get_mrange_addr(range));
- g_mutex_lock(&format->mutex);
+ if (start >= available)
+ {
+ assert(origin != NULL);
- g_binary_portion_include(format->portions, portion);
+ asprintf(&msg, _("Defined binary portion '%s' is out of the file scope... Discarding!"),
+ g_binary_portion_get_desc(portion));
- g_mutex_unlock(&format->mutex);
+ g_binary_format_add_error(G_BIN_FORMAT(format), BFE_STRUCTURE, origin, msg);
+
+ free(msg);
+
+ g_object_unref(G_OBJECT(portion));
+
+ }
+
+ else
+ {
+ remaining = available - start;
+
+ truncated = g_binary_portion_limit_range(portion, remaining);
+
+ if (truncated)
+ log_variadic_message(LMT_BAD_BINARY, _("Truncated binary portion '%s' to fit the binary content size!"),
+ g_binary_portion_get_desc(portion));
+
+ g_mutex_lock(&format->mutex);
+
+ g_binary_portion_include(format->portions, portion);
+
+ g_mutex_unlock(&format->mutex);
+
+ }
}
diff --git a/src/format/executable.h b/src/format/executable.h
index 985efb2..81e5e6c 100644
--- a/src/format/executable.h
+++ b/src/format/executable.h
@@ -68,7 +68,7 @@ const char *g_exe_format_get_target_machine(const GExeFormat *);
bool g_exe_format_get_main_address(GExeFormat *, vmpa2t *);
/* Procède à l'enregistrement d'une portion dans un format. */
-void g_exe_format_include_portion(GExeFormat *, GBinPortion *);
+void g_exe_format_include_portion(GExeFormat *, GBinPortion *, const vmpa2t *);
/* Fournit la première couche des portions composent le binaire. */
GBinPortion *g_exe_format_get_portions(GExeFormat *);