diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-01-10 16:37:34 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-01-10 16:37:34 (GMT) |
commit | 8ef66a1e0225c9e00175fbaf3f3038f537de511f (patch) | |
tree | dd7112dd50c02e0ad1565ce7a890991b5e1270c6 /src/arch/arm/v7 | |
parent | cc3e31eecd90766ae4f0bb391428c5c59567ef4c (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/arch/arm/v7')
-rw-r--r-- | src/arch/arm/v7/link.c | 28 | ||||
-rw-r--r-- | src/arch/arm/v7/link.h | 27 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/Makefile.am | 2 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/bl_A8825.d | 28 | ||||
-rw-r--r-- | src/arch/arm/v7/processor.c | 44 |
5 files changed, 60 insertions, 69 deletions
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; } |