summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-01-10 16:37:34 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-01-10 16:37:34 (GMT)
commit8ef66a1e0225c9e00175fbaf3f3038f537de511f (patch)
treedd7112dd50c02e0ad1565ce7a890991b5e1270c6 /src
parentcc3e31eecd90766ae4f0bb391428c5c59567ef4c (diff)
Extended the grammar to allow hooks inclusion.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@453 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r--src/arch/arm/context.c79
-rw-r--r--src/arch/arm/v7/link.c28
-rw-r--r--src/arch/arm/v7/link.h27
-rw-r--r--src/arch/arm/v7/opdefs/Makefile.am2
-rw-r--r--src/arch/arm/v7/opdefs/bl_A8825.d28
-rw-r--r--src/arch/arm/v7/processor.c44
6 files changed, 60 insertions, 148 deletions
diff --git a/src/arch/arm/context.c b/src/arch/arm/context.c
index 24546c0..386f21a 100644
--- a/src/arch/arm/context.c
+++ b/src/arch/arm/context.c
@@ -224,8 +224,6 @@ static size_t find_disass_arm_area(disass_arm_area *areas, virt_t addr, size_t f
size_t index; /* Indice de cellule idéale */
size_t mid; /* Division de l'espace */
- printf(" < 0x%08x > %zu / %zu...\n", addr, first, last);
-
if (first == last)
index = first;
@@ -233,8 +231,6 @@ static size_t find_disass_arm_area(disass_arm_area *areas, virt_t addr, size_t f
{
mid = first + (last - first + 1) / 2;
- printf(" --looking-- %zu / %zu -> %zu\n", first, last, mid);
-
if (areas[mid].start <= addr)
index = find_disass_arm_area(areas, addr, mid, last);
else
@@ -242,11 +238,6 @@ static size_t find_disass_arm_area(disass_arm_area *areas, virt_t addr, size_t f
}
- printf(" !! FOUND !! (for 0x%08x) -- [%zu] [%zu/%zu] 0x%08x <-> 0x%08x\n",
- (unsigned int)addr, index, first, last,
- (unsigned int)areas[index].start,
- (unsigned int)areas[index].end);
-
assert(areas[index].start <= addr && addr < areas[index].end);
return index;
@@ -283,32 +274,6 @@ void _g_arm_context_define_encoding(GArmContext *ctx, virt_t addr, unsigned int
/* Sinon on redivise... */
else
{
-
-
-
-
-
- do
- {
- unsigned int i;
-
- printf(" --sel-- %u for 0x%08x\n", (unsigned int)selected, (unsigned int)addr);
-
- for (i = 0; i < ctx->acount; i++)
- printf(" --def before-- [%u] 0x%08x <-> 0x%08x\n",
- i,
- (unsigned int)ctx->areas[i].start,
- (unsigned int)ctx->areas[i].end);
-
- }
- while (0);
-
-
-
-
-
-
-
ctx->areas = (disass_arm_area *)realloc(ctx->areas, ++ctx->acount * sizeof(disass_arm_area));
memmove(&ctx->areas[selected + 1], &ctx->areas[selected],
@@ -321,51 +286,7 @@ void _g_arm_context_define_encoding(GArmContext *ctx, virt_t addr, unsigned int
ctx->areas[selected + 1].start = addr;
ctx->areas[selected + 1].marker = marker;
-
-
- do
- {
- unsigned int i;
-
- for (i = 0; i < ctx->acount; i++)
- printf(" --def after-- [%u] 0x%08x <-> 0x%08x\n",
- i,
- (unsigned int)ctx->areas[i].start,
- (unsigned int)ctx->areas[i].end);
-
- }
- while (0);
-
-
-
-
-
-
- }
-
-
-
-
- /*
- do
- {
- unsigned int i;
-
- printf(" --sel-- %u for 0x%08x\n", (unsigned int)selected, (unsigned int)addr);
-
- for (i = 0; i < ctx->acount; i++)
- printf(" --def-- [%u] 0x%08x <-> 0x%08x\n",
- i,
- (unsigned int)ctx->areas[i].start,
- (unsigned int)ctx->areas[i].end);
-
}
- while (0);
- */
-
-
-
-
}
diff --git a/src/arch/arm/v7/link.c b/src/arch/arm/v7/link.c
index 69b43bc..fff0944 100644
--- a/src/arch/arm/v7/link.c
+++ b/src/arch/arm/v7/link.c
@@ -27,15 +27,13 @@
#include <assert.h>
-#include "context.h"
-
-
/******************************************************************************
* *
* Paramètres : instr = instruction ARMv7 à traiter. *
* context = contexte associé à la phase de désassemblage. *
* format = acès aux données du binaire d'origine. *
+* iset = type de jeu d'instructions courant à faire suivre. *
* *
* Description : Complète un désassemblage accompli pour une instruction. *
* *
@@ -45,14 +43,13 @@
* *
******************************************************************************/
-void handle_links_with_thumb_instruction_bl(GArchInstruction *instr, GArmV7Context *context, GBinFormat *format)
+void handle_links_with_instruction_bl_with_orig(GArchInstruction *instr, GArmV7Context *context, GBinFormat *format, ArmV7InstrSet iset)
{
const mrange_t *range; /* Emplacementt d'instruction */
virt_t pc; /* Position dans l'exécution */
GArchOperand *op; /* Opérande numérique en place */
int32_t offset; /* Décallage encodé en dur */
virt_t target; /* Adresse virtuelle visée */
- ArmV7InstrSet iset; /* Type de jeu courant */
range = g_arch_instruction_get_range(instr);
@@ -72,11 +69,7 @@ void handle_links_with_thumb_instruction_bl(GArchInstruction *instr, GArmV7Conte
if (g_imm_operand_get_value(G_IMM_OPERAND(op), MDS_32_BITS_SIGNED, &offset))
g_imm_operand_set_value(G_IMM_OPERAND(op), MDS_32_BITS_UNSIGNED, pc + offset);
-
- //printf("[@ 0x%08x] Add 0x%08x to %p\n", (uint32_t)get_virt_addr(get_mrange_addr(range)), (uint32_t)(pc + offset), context);
-
target = pc + offset;
- iset = g_armv7_context_find_encoding(context, get_virt_addr(get_mrange_addr(range)));
g_armv7_context_define_encoding(context, target, iset);
@@ -88,6 +81,7 @@ void handle_links_with_thumb_instruction_bl(GArchInstruction *instr, GArmV7Conte
* Paramètres : instr = instruction ARMv7 à traiter. *
* context = contexte associé à la phase de désassemblage. *
* format = acès aux données du binaire d'origine. *
+* iset = type de jeu d'instructions courant à inverser. *
* *
* Description : Complète un désassemblage accompli pour une instruction. *
* *
@@ -97,14 +91,13 @@ void handle_links_with_thumb_instruction_bl(GArchInstruction *instr, GArmV7Conte
* *
******************************************************************************/
-void handle_links_with_thumb_instruction_blx(GArchInstruction *instr, GArmV7Context *context, GBinFormat *format)
+void handle_links_with_instruction_blx_with_dest(GArchInstruction *instr, GArmV7Context *context, GBinFormat *format, ArmV7InstrSet iset)
{
const mrange_t *range; /* Emplacementt d'instruction */
virt_t pc; /* Position dans l'exécution */
GArchOperand *op; /* Opérande numérique en place */
int32_t offset; /* Décallage encodé en dur */
virt_t target; /* Adresse virtuelle visée */
- ArmV7InstrSet iset; /* Type de jeu courant */
range = g_arch_instruction_get_range(instr);
@@ -125,19 +118,8 @@ void handle_links_with_thumb_instruction_blx(GArchInstruction *instr, GArmV7Cont
if (g_imm_operand_get_value(G_IMM_OPERAND(op), MDS_32_BITS_SIGNED, &offset))
g_imm_operand_set_value(G_IMM_OPERAND(op), MDS_32_BITS_UNSIGNED, pc + offset);
-
- //printf("[@ 0x%08x] Add 0x%08x to %p\n", (uint32_t)get_virt_addr(get_mrange_addr(range)), (uint32_t)(pc + offset), context);
-
target = pc + offset;
- iset = g_armv7_context_find_encoding(context, get_virt_addr(get_mrange_addr(range)));
-
- printf(" --link-- @ 0x%08x iset = %u\n", (unsigned int)target, (unsigned int)iset);
-
- if (iset == AV7IS_ARM)
- g_armv7_context_define_encoding(context, target, AV7IS_THUMB);
- else
- g_armv7_context_define_encoding(context, target, AV7IS_ARM);
-
+ g_armv7_context_define_encoding(context, target, iset);
}
diff --git a/src/arch/arm/v7/link.h b/src/arch/arm/v7/link.h
index fa38f74..ef71bd6 100644
--- a/src/arch/arm/v7/link.h
+++ b/src/arch/arm/v7/link.h
@@ -32,10 +32,33 @@
/* Complète un désassemblage accompli pour une instruction. */
-void handle_links_with_thumb_instruction_bl(GArchInstruction *, GArmV7Context *, GBinFormat *);
+void handle_links_with_instruction_bl_with_orig(GArchInstruction *, GArmV7Context *, GBinFormat *, ArmV7InstrSet);
+
+
+static inline void handle_links_with_instruction_bl_from_arm(GArchInstruction *ins, GArmV7Context *ctx, GBinFormat *fmt)
+{
+ handle_links_with_instruction_bl_with_orig(ins, ctx, fmt, AV7IS_ARM);
+}
+
+static inline void handle_links_with_instruction_bl_from_thumb(GArchInstruction *ins, GArmV7Context *ctx, GBinFormat *fmt)
+{
+ handle_links_with_instruction_bl_with_orig(ins, ctx, fmt, AV7IS_THUMB);
+}
+
/* Complète un désassemblage accompli pour une instruction. */
-void handle_links_with_thumb_instruction_blx(GArchInstruction *, GArmV7Context *, GBinFormat *);
+void handle_links_with_instruction_blx_with_dest(GArchInstruction *, GArmV7Context *, GBinFormat *, ArmV7InstrSet);
+
+
+static inline void handle_links_with_instruction_blx_from_arm(GArchInstruction *ins, GArmV7Context *ctx, GBinFormat *fmt)
+{
+ handle_links_with_instruction_blx_with_dest(ins, ctx, fmt, AV7IS_THUMB);
+}
+
+static inline void handle_links_with_instruction_blx_from_thumb(GArchInstruction *ins, GArmV7Context *ctx, GBinFormat *fmt)
+{
+ handle_links_with_instruction_blx_with_dest(ins, ctx, fmt, AV7IS_ARM);
+}
diff --git a/src/arch/arm/v7/opdefs/Makefile.am b/src/arch/arm/v7/opdefs/Makefile.am
index 2687a92..10deadb 100644
--- a/src/arch/arm/v7/opdefs/Makefile.am
+++ b/src/arch/arm/v7/opdefs/Makefile.am
@@ -92,7 +92,7 @@ generate_final_makefile:
fix_includes_in_c_templates:
@for f in `find .gen/ -name '*tmpl.c'`; do \
if grep -q '##INCLUDES##' $$f; then \
- $(fix_verbose)sed -i 's/##INCLUDES##/\n#include "..\/instruction.h"\n#include "..\/..\/instruction.h"\n#include "..\/helpers.h"\n#include "..\/..\/..\/..\/common\/bconst.h"\n\n/' $$f; \
+ $(fix_verbose)sed -i 's/##INCLUDES##/\n#include "..\/helpers.h"\n#include "..\/instruction.h"\n#include "..\/link.h"\n#include "..\/post.h"\n#include "..\/..\/instruction.h"\n#include "..\/..\/..\/..\/common\/bconst.h"\n\n/' $$f; \
fi; \
done
diff --git a/src/arch/arm/v7/opdefs/bl_A8825.d b/src/arch/arm/v7/opdefs/bl_A8825.d
index dc9c922..96c782f 100644
--- a/src/arch/arm/v7/opdefs/bl_A8825.d
+++ b/src/arch/arm/v7/opdefs/bl_A8825.d
@@ -37,6 +37,13 @@
}
+ @hooks {
+
+ link = handle_links_with_instruction_bl_from_thumb
+ post = post_process_branch_instructions
+
+ }
+
}
@encoding(T2) {
@@ -53,6 +60,13 @@
}
+ @hooks {
+
+ link = handle_links_with_instruction_blx_from_thumb
+ post = post_process_branch_instructions
+
+ }
+
}
@encoding(A1) {
@@ -67,6 +81,13 @@
}
+ @hooks {
+
+ link = handle_links_with_instruction_bl_from_arm
+ post = post_process_branch_instructions
+
+ }
+
}
@encoding(A2) {
@@ -81,4 +102,11 @@
}
+ @hooks {
+
+ link = handle_links_with_instruction_blx_from_arm
+ post = post_process_branch_instructions
+
+ }
+
}
diff --git a/src/arch/arm/v7/processor.c b/src/arch/arm/v7/processor.c
index 45b53ae..d83c36d 100644
--- a/src/arch/arm/v7/processor.c
+++ b/src/arch/arm/v7/processor.c
@@ -240,31 +240,14 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
phys_t diff; /* Avancée dans la lecture */
uint16_t raw16; /* Donnée 16 bits à analyser */
uint32_t raw32; /* Donnée 32 bits à analyser */
-
-
-
-
-
-
-
- ArmV7InstrSet iset;
-
-
+ ArmV7InstrSet iset; /* Type de jeu d'instructions */
iset = g_armv7_context_find_encoding(ctx, get_virt_addr(pos));
-
-
- printf(" --decoding-- 0x%08x -> %u\n",
- (unsigned int)get_virt_addr(pos),
- (unsigned int)iset);
-
-
start = get_phy_addr(pos);
diff = 4;
-
switch (iset)
{
case AV7IS_ARM:
@@ -319,31 +302,6 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
result = g_raw_instruction_new_array(data, MDS_32_BITS, 1, pos, end,
G_ARCH_PROCESSOR(proc)->endianness);
-
-
-
-
- if (strcmp(g_arch_instruction_get_keyword(result, 0), "bl") == 0/* && pc == 0x000085b2*/)
- {
-
-
- g_arch_instruction_set_hook(result, IPH_LINK, (instr_hook_fc)handle_links_with_thumb_instruction_bl);
- g_arch_instruction_set_hook(result, IPH_POST, post_process_branch_instructions);
-
-
-
- }
-
- if (strcmp(g_arch_instruction_get_keyword(result, 0), "blx") == 0/* && pc == 0x000085b2*/)
- {
-
- g_arch_instruction_set_hook(result, IPH_LINK, (instr_hook_fc)handle_links_with_thumb_instruction_blx);
- g_arch_instruction_set_hook(result, IPH_POST, post_process_branch_instructions);
-
-
- }
-
-
return result;
}