summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-08-16 22:26:41 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-08-16 22:26:41 (GMT)
commitd3f9ef68a9939ee43e8a70748dd4b7e97352179e (patch)
tree08f6d5cd4bddbd42448a0a4efe0522c0a96c99a2 /src/format
parented763539951307353042c04af5c2278db0d05298 (diff)
Kept only the first submission when preloading instructions.
Diffstat (limited to 'src/format')
-rw-r--r--src/format/elf/strings.c25
-rw-r--r--src/format/preload.c75
-rw-r--r--src/format/preload.h7
3 files changed, 87 insertions, 20 deletions
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index 53d4e92..e885632 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -159,6 +159,7 @@ static bool parse_elf_string_data(GElfFormat *format, phys_t start, phys_t size,
phys_t i; /* Boucle de parcours */
phys_t end; /* Position de fin de chaîne */
GArchInstruction *instr; /* Instruction décodée */
+ bool inserted; /* Bilan d'une insertion */
const mrange_t *range; /* Espace occupé par une chaîne*/
GBinSymbol *symbol; /* Symbole à intégrer */
char *label; /* Désignation de la chaîne */
@@ -203,22 +204,26 @@ static bool parse_elf_string_data(GElfFormat *format, phys_t start, phys_t size,
g_raw_instruction_mark_as_string(G_RAW_INSTRUCTION(instr), true);
- g_preload_info_add_instruction(base->info, instr);
+ inserted = g_preload_info_add_instruction(base->info, instr);
- range = g_arch_instruction_get_range(instr);
+ if (inserted)
+ {
+ range = g_arch_instruction_get_range(instr);
- symbol = g_binary_symbol_new(range, STP_RO_STRING);
- g_binary_format_add_symbol(base, symbol);
+ symbol = g_binary_symbol_new(range, STP_RO_STRING);
+ g_binary_format_add_symbol(base, symbol);
- /* Jointure avec la chaîne précédente ? */
+ /* Jointure avec la chaîne précédente ? */
- if (cut)
- {
- label = create_string_label(base, get_mrange_addr(range), end - i);
+ if (cut)
+ {
+ label = create_string_label(base, get_mrange_addr(range), end - i);
- g_binary_symbol_set_alt_label(symbol, label);
+ g_binary_symbol_set_alt_label(symbol, label);
- free(label);
+ free(label);
+
+ }
}
diff --git a/src/format/preload.c b/src/format/preload.c
index cddc60e..14bb4b0 100644
--- a/src/format/preload.c
+++ b/src/format/preload.c
@@ -259,20 +259,24 @@ void g_preload_info_unlock_instructions(GPreloadInfo *info)
* *
* Description : Ajoute une instruction supplémentaire aux préchargements. *
* *
-* Retour : - *
+* Retour : true si l'instruction a bien été insérée, false sinon. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr)
+bool g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr)
{
+ bool result; /* Bilan à retourner */
+
g_preload_info_lock_instructions(info);
- _g_preload_info_add_instruction(info, instr);
+ result = _g_preload_info_add_instruction(info, instr);
g_preload_info_unlock_instructions(info);
+ return result;
+
}
@@ -283,14 +287,16 @@ void g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr)
* *
* Description : Ajoute une instruction supplémentaire aux préchargements. *
* *
-* Retour : - *
+* Retour : true si l'instruction a bien été insérée, false sinon. *
* *
* Remarques : - *
* *
******************************************************************************/
-void _g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr)
+bool _g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr)
{
+ bool result; /* Bilan à retourner */
+
int cmp_instr_by_addr(const GArchInstruction **a, const GArchInstruction **b)
{
const mrange_t *range_a; /* Emplacement pour l'instr. A */
@@ -303,8 +309,16 @@ void _g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr
}
- insert_item_into_flat_array(&info->instructions, &instr, sizeof(GArchInstruction *),
- (__compar_fn_t)cmp_instr_by_addr);
+ result = _g_preload_info_has_instruction_for(info, g_arch_instruction_get_range(instr));
+
+ if (result)
+ insert_item_into_flat_array(&info->instructions, &instr, sizeof(GArchInstruction *),
+ (__compar_fn_t)cmp_instr_by_addr);
+
+ else
+ g_object_unref(G_OBJECT(instr));
+
+ return result;
}
@@ -312,7 +326,52 @@ void _g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr
/******************************************************************************
* *
* Paramètres : info = instance à mettre à jour. *
-* addr = localisation du commentaire recherché. *
+* range = emplacement de l'instruction recherchés. *
+* *
+* Description : Détermine si une instruction existe sur un espace donné. *
+* *
+* Retour : true si une instruction existe à l'emplacement indiqué. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool _g_preload_info_has_instruction_for(GPreloadInfo *info, const mrange_t *range)
+{
+ bool result; /* Bilan à retourner */
+ GArchInstruction **ptr; /* Adresse dans le tableau */
+
+ int check_for_overlap(const mrange_t *key, const GArchInstruction **i)
+ {
+ const mrange_t *irange; /* Emplacement pour l'instr. */
+ int status; /* Bilan de la recherche */
+
+ irange = g_arch_instruction_get_range(*i);
+
+ if (mrange_intersects_mrange(irange, key))
+ status = 0;
+
+ else
+ status = cmp_vmpa(get_mrange_addr(key), get_mrange_addr(irange));
+
+ return status;
+
+ }
+
+ ptr = find_item_in_flat_array(info->instructions, sizeof(GArchInstruction *),
+ (__compar_fn_t)check_for_overlap, range);
+
+ result = (ptr != NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à mettre à jour. *
+* addr = localisation de l'instruction recherchée. *
* *
* Description : Détermine si une instruction est présente à un point donné. *
* *
diff --git a/src/format/preload.h b/src/format/preload.h
index 1e28222..de79f83 100644
--- a/src/format/preload.h
+++ b/src/format/preload.h
@@ -64,10 +64,13 @@ void g_preload_info_lock_instructions(GPreloadInfo *);
void g_preload_info_unlock_instructions(GPreloadInfo *);
/* Ajoute une instruction supplémentaire aux préchargements. */
-void g_preload_info_add_instruction(GPreloadInfo *, GArchInstruction *);
+bool g_preload_info_add_instruction(GPreloadInfo *, GArchInstruction *);
/* Ajoute une instruction supplémentaire aux préchargements. */
-void _g_preload_info_add_instruction(GPreloadInfo *, GArchInstruction *);
+bool _g_preload_info_add_instruction(GPreloadInfo *, GArchInstruction *);
+
+/* Détermine si une instruction existe sur un espace donné. */
+bool _g_preload_info_has_instruction_for(GPreloadInfo *, const mrange_t *);
/* Détermine si une instruction est présente à un point donné. */
bool _g_preload_info_has_instruction_at(GPreloadInfo *, const vmpa2t *);