summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-03-08 19:30:52 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-03-08 19:30:52 (GMT)
commit68bb7efaf61e4f5ca2f2cffce84995ffd667c4cc (patch)
tree9b6a6f63ee20b08d8c2ac35849ee051d61787447 /src/arch
parentdc9e68505c4cc7ad208e63dbc7d0e0e8f582d0d9 (diff)
Handle cross references as well as entry points.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@482 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/immediate.c31
-rw-r--r--src/arch/immediate.h3
-rw-r--r--src/arch/instruction.c40
-rw-r--r--src/arch/instruction.h5
-rw-r--r--src/arch/target.c13
5 files changed, 82 insertions, 10 deletions
diff --git a/src/arch/immediate.c b/src/arch/immediate.c
index 3a3e64c..fc8e40d 100644
--- a/src/arch/immediate.c
+++ b/src/arch/immediate.c
@@ -858,10 +858,39 @@ static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line, A
{
char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */
size_t len; /* Taille de l'élément inséré */
+ GBufferSegment *segment; /* Nouveau segment mis en place*/
len = g_imm_operand_to_string(operand, syntax, value);
- g_buffer_line_insert_text(line, BLC_MAIN, value, len, RTT_IMMEDIATE);
+ segment = g_buffer_line_insert_text(line, BLC_MAIN, value, len, RTT_IMMEDIATE);
+ g_buffer_segment_set_creator(segment, G_OBJECT(operand));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* addr = valeur résultante. [OUT] *
+* *
+* Description : Convertit une valeur immédiate en adresse de type virt_t. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_imm_operand_to_virt_t(const GImmOperand *operand, virt_t *addr)
+{
+ bool result; /* Bilan à renvoyer */
+
+ result = !MDS_IS_SIGNED(operand->size);
+
+ if (result)
+ *addr = operand->raw;
+
+ return result;
}
diff --git a/src/arch/immediate.h b/src/arch/immediate.h
index a0721b2..6d1d62e 100644
--- a/src/arch/immediate.h
+++ b/src/arch/immediate.h
@@ -108,6 +108,9 @@ bool g_imm_operand_is_negative(const GImmOperand *);
/* Indique si une valeur immédiate est nulle ou non. */
bool g_imm_operand_is_null(const GImmOperand *);
+/* Convertit une valeur immédiate en adresse de type virt_t. */
+bool g_imm_operand_to_virt_t(const GImmOperand *, virt_t *);
+
/* Convertit une valeur immédiate en adresse de type vmpa_t. */
bool g_imm_operand_to_vmpa_t(const GImmOperand *, vmpa_t *) __attribute__ ((deprecated));
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index c9811cf..aced77e 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -1011,6 +1011,35 @@ GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *list,
/******************************************************************************
* *
+* Paramètres : list = liste de lignes à parcourir. *
+* range = emplacement mémoire à comparer. *
+* *
+* Description : Recherche une instruction d'après son emplacement mémoire. *
+* *
+* Retour : Instruction trouvée à l'adresse donnée, NULL si aucune. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_arch_instruction_find_by_range(GArchInstruction *list, const mrange_t *range)
+{
+ GArchInstruction *result; /* Trouvaille à retourner */
+
+ ainstr_list_for_each(result, list)
+ {
+ if (cmp_mrange(&result->range, range) == 0)
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : list = liste de lignes à parcourir. *
* addr = position en mémoire ou physique à chercher. *
* strict = définit la considération à porter à l'adresse. *
@@ -1023,16 +1052,19 @@ GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *list,
* *
******************************************************************************/
-GArchInstruction *g_arch_instruction_find_by_address(GArchInstruction *list, vmpa_t addr, bool strict)
+GArchInstruction *g_arch_instruction_find_by_address(GArchInstruction *list, const vmpa2t *addr, bool strict)
{
GArchInstruction *result; /* Trouvaille à retourner */
+ bool found; /* Bilan de comparaisons */
ainstr_list_for_each(result, list)
{
- if (strict && result->offset == addr) break;
+ if (strict)
+ found = (cmp_vmpa(get_mrange_addr(&result->range), addr) == 0);
+ else
+ found = mrange_contains_addr(&result->range, addr);
- else if (!strict && result->offset < addr
- && addr < (result->offset + result->length)) break;
+ if (found) break;
}
diff --git a/src/arch/instruction.h b/src/arch/instruction.h
index f1ce67f..12cfbb9 100644
--- a/src/arch/instruction.h
+++ b/src/arch/instruction.h
@@ -218,8 +218,11 @@ GArchInstruction *g_arch_instruction_get_prev_iter(const GArchInstruction *, con
/* Fournit l'élement suivant un autre pour un parcours. */
GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *, const GArchInstruction *, vmpa_t);
+/* Recherche une instruction d'après son emplacement mémoire. */
+GArchInstruction *g_arch_instruction_find_by_range(GArchInstruction *, const mrange_t *);
+
/* Recherche une instruction d'après son adresse. */
-GArchInstruction *g_arch_instruction_find_by_address(GArchInstruction *, vmpa_t, bool);
+GArchInstruction *g_arch_instruction_find_by_address(GArchInstruction *, const vmpa2t *, bool);
diff --git a/src/arch/target.c b/src/arch/target.c
index 40e9598..7509711 100644
--- a/src/arch/target.c
+++ b/src/arch/target.c
@@ -212,6 +212,7 @@ GArchOperand *g_target_operand_new(MemoryDataSize size, virt_t addr)
static void g_target_operand_print(const GTargetOperand *operand, GBufferLine *line, AsmSyntax syntax)
{
const char *label; /* Etiquette liée à un symbole */
+ GBufferSegment *segment; /* Nouveau segment mis en place*/
vmpa2t tmp; /* Coquille vide pour argument */
VMPA_BUFFER(value); /* Adresse brute à imprimer */
size_t len; /* Taille de l'élément inséré */
@@ -222,16 +223,19 @@ static void g_target_operand_print(const GTargetOperand *operand, GBufferLine *l
g_buffer_line_insert_text(line, BLC_MAIN, "<", 1, RTT_LTGT);
label = g_binary_symbol_get_label(operand->symbol);
- g_buffer_line_insert_text(line, BLC_MAIN, label, strlen(label), RTT_LABEL);
+ segment = g_buffer_line_insert_text(line, BLC_MAIN, label, strlen(label), RTT_LABEL);
+ g_buffer_segment_set_creator(segment, G_OBJECT(operand));
if (operand->diff > 0)
{
- g_buffer_line_insert_text(line, BLC_MAIN, "+", 1, RTT_SIGNS);
+ segment = g_buffer_line_insert_text(line, BLC_MAIN, "+", 1, RTT_SIGNS);
+ g_buffer_segment_set_creator(segment, G_OBJECT(operand));
init_vmpa(&tmp, operand->diff, VMPA_NO_VIRTUAL);
vmpa2_phys_to_string(&tmp, MDS_4_BITS, value, &len);
- g_buffer_line_insert_text(line, BLC_MAIN, value, len, RTT_LABEL);
+ segment = g_buffer_line_insert_text(line, BLC_MAIN, value, len, RTT_LABEL);
+ g_buffer_segment_set_creator(segment, G_OBJECT(operand));
g_buffer_line_insert_text(line, BLC_MAIN, ">", 1, RTT_LTGT);
@@ -243,7 +247,8 @@ static void g_target_operand_print(const GTargetOperand *operand, GBufferLine *l
init_vmpa(&tmp, VMPA_NO_PHYSICAL, operand->addr);
vmpa2_virt_to_string(&tmp, operand->size, value, &len);
- g_buffer_line_insert_text(line, BLC_MAIN, value, len, RTT_LABEL);
+ segment = g_buffer_line_insert_text(line, BLC_MAIN, value, len, RTT_LABEL);
+ g_buffer_segment_set_creator(segment, G_OBJECT(operand));
}