diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-03-31 23:20:33 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-03-31 23:20:33 (GMT) |
commit | 5cc7bd39ae41af40a0c939acf98f90bf1375effd (patch) | |
tree | 4f7140e2c5a8d939c672fb941e66903300229e82 /src/analysis/disass/macro.c | |
parent | 52e036040b5e0ad8acde3d467ac8d9ca43ed414c (diff) |
Saved some progress in the definition of basic blocks.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@497 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/disass/macro.c')
-rw-r--r-- | src/analysis/disass/macro.c | 105 |
1 files changed, 101 insertions, 4 deletions
diff --git a/src/analysis/disass/macro.c b/src/analysis/disass/macro.c index 218371b..087f1ae 100644 --- a/src/analysis/disass/macro.c +++ b/src/analysis/disass/macro.c @@ -297,6 +297,9 @@ static bool code_coverage_stop_here(const code_coverage *coverage, const vmpa2t { void *ptr; /* Résultat des recherches */ + if (!mrange_contains_addr(&coverage->range, addr)) + return true; + ptr = bsearch(addr, coverage->ends, coverage->ends_count, sizeof(vmpa2t), (__compar_fn_t)cmp_vmpa); @@ -532,10 +535,21 @@ static void find_next_hops(GArchInstruction *instrs, const vmpa2t *start, const InstructionLinkType *types; /* Type de lien entre lignes */ size_t dcount; /* Nombre de liens de dest. */ size_t i; /* Boucle de parcours #2 */ + size_t not_handled; /* Nombre d'éléments écartés */ + + printf(" ---- FN [ %p ] ---------------------------\n", info); + + + printf("CONTAINS ? %d\n", mrange_contains_addr(&coverage->range, start)); /* Si la position est déjà présente, on évite de boucler... */ if (!add_hop_into_branch(info, start)) + { + printf(" ++ !add 0x%08x\n", (unsigned int)start->virtual); return; + } + else + printf(" ++ add 0x%08x\n", (unsigned int)start->virtual); /* On suit le flot jusqu'à la prochaine bifurcation */ for (iter = g_arch_instruction_find_by_address(instrs, start, true); @@ -544,20 +558,43 @@ static void find_next_hops(GArchInstruction *instrs, const vmpa2t *start, const { range = g_arch_instruction_get_range(iter); + + if (code_coverage_stop_here(coverage, get_mrange_addr(range))) + printf(" ++ stop here 0x%08x\n", (unsigned int)range->addr.virtual); + if (code_coverage_stop_here(coverage, get_mrange_addr(range))) break; + + if (g_arch_instruction_has_sources(iter)) + add_hop_into_branch(info, get_mrange_addr(range)); + + + + if (g_arch_instruction_is_return(iter)) + printf(" ++ return 0x%08x\n", (unsigned int)range->addr.virtual); + if (g_arch_instruction_is_return(iter)) { iter = NULL; break; } + /* + if (!g_arch_instruction_has_destinations(iter)) + printf(" ++ no dest 0x%08x\n", (unsigned int)range->addr.virtual); + */ + if (!g_arch_instruction_has_destinations(iter)) continue; + + printf(" ++ dcount 0x%08x\n", (unsigned int)range->addr.virtual); + dcount = g_arch_instruction_get_destinations(iter, &dests, &types, NULL); + not_handled = 0; + for (i = 0; i < dcount; i++) { range = g_arch_instruction_get_range(dests[i]); @@ -577,19 +614,23 @@ static void find_next_hops(GArchInstruction *instrs, const vmpa2t *start, const break; default: + not_handled++; break; } } - break; + if (not_handled < dcount) + break; } /* Si on termine... */ if (iter != NULL) add_hop_into_branch(info, get_mrange_addr(range)); + printf(" ------- [ %p ] ---\n", info); + } @@ -614,6 +655,20 @@ static bool compute_first_common_addr(const branch_info *a, const branch_info *b result = false; + + printf("....................\n"); + + printf(" A :: "); + for (i = 0; i < a->count; i++) + printf("0x%08x ", a->hops[i].virtual); + printf("\n"); + + printf(" B :: "); + for (i = 0; i < b->count; i++) + printf("0x%08x ", b->hops[i].virtual); + printf("\n"); + + for (i = 0; i < a->count && !result; i++) if (is_addr_in_branch(b, &a->hops[i])) { @@ -621,6 +676,13 @@ static bool compute_first_common_addr(const branch_info *a, const branch_info *b copy_vmpa(c, &a->hops[i]); } + if (result) + printf(" N :: 0x%08x\n", (unsigned int)c->virtual); + else + printf(" N :: ----\n"); + + printf("....................\n"); + return result; } @@ -862,6 +924,7 @@ static GInstrBlock *build_instruction_blocks_ite(GArchInstruction *instrs, code_ GInstrBlock *block; /* Nouveau bloc mis en place */ has_common = compute_first_common_addr(true_branch, false_branch, next); + if (!has_common) printf(" === nothing in common\n"); if (!has_common) return NULL; result = g_virtual_block_new(); @@ -980,7 +1043,7 @@ static void add_instruction_blocks_except(GInstrBlock **result, GInstrBlock **ca * Remarques : - * * * ******************************************************************************/ - +#include "../../arch/instruction-int.h" static GInstrBlock *build_instruction_blocks(GArchInstruction *instrs, code_coverage *coverage) { GInstrBlock *result; /* Regroupement à retourner */ @@ -1059,11 +1122,25 @@ static GInstrBlock *build_instruction_blocks(GArchInstruction *instrs, code_cove case ILT_EXEC_FLOW: case ILT_JUMP: + + //break; + { + GArchInstruction *_saved0; + + _saved0 = first; + block = build_instruction_block_simple(instrs, coverage, &first, iter); + printf(" -- simple block JMP -- @ 0x%08x <-> 0x%08x\n", + (unsigned int)(_saved0 ? _saved0->range.addr.virtual : ~0), + (unsigned int)iter->range.addr.virtual); + fflush(NULL); + } DELAYED_BLOCK_ADDING(result, result_cached, block); range = g_arch_instruction_get_range(iter); - copy_vmpa(&next_addr, get_mrange_addr(range)); + compute_mrange_end_addr(range, &next_addr); + + first = NULL; break; @@ -1072,10 +1149,12 @@ static GInstrBlock *build_instruction_blocks(GArchInstruction *instrs, code_cove break; case ILT_JUMP_IF_TRUE: + printf("FIND TRUE BRANCH @ 0x%08x\n", (unsigned int)iter->range.addr.virtual); branch = &true_branch; break; case ILT_JUMP_IF_FALSE: + printf("FIND FALSE BRANCH @ 0x%08x\n", (unsigned int)iter->range.addr.virtual); branch = &false_branch; break; @@ -1097,10 +1176,13 @@ static GInstrBlock *build_instruction_blocks(GArchInstruction *instrs, code_cove /* Si on a une branche à compléter... */ if (branch != NULL) { - range = g_arch_instruction_get_range(iter); + range = g_arch_instruction_get_range(dests[i]); addr = get_mrange_addr(range); + printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); + printf("BUILD @ 0x%08x\n", (unsigned int)addr->virtual); find_next_hops(instrs, addr, coverage, branch); + printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"); } @@ -1126,10 +1208,25 @@ static GInstrBlock *build_instruction_blocks(GArchInstruction *instrs, code_cove else if (true_branch.count > 0 || false_branch.count > 0) { block = build_instruction_block_simple(instrs, coverage, &first, iter); + + GArchInstruction *_saved1; + + _saved1 = first; + + + + printf(" -- branches -- %d vs %d\n", (int)true_branch.count, (int)false_branch.count); + + printf(" -- simple block ITE -- @ 0x%08x <-> 0x%08x\n", + (unsigned int)(_saved1 ? _saved1->range.addr.virtual : ~0), + (unsigned int)iter->range.addr.virtual); + fflush(NULL); DELAYED_BLOCK_ADDING(result, result_cached, block); group = build_instruction_blocks_ite(instrs, coverage, &true_branch, &false_branch, &next_addr); + printf(" --> group = %p - next = 0x%08x\n", group, next_addr.virtual); + if (group != NULL) { DELAYED_BLOCK_ADDING(result, result_cached, group); |