summaryrefslogtreecommitdiff
path: root/src/format/executable.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/executable.c')
-rw-r--r--src/format/executable.c52
1 files changed, 42 insertions, 10 deletions
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);
+
+ }
}